public bool IsCollided(Shot shot, Room room) { var intersectionDeter = new IntersectionDeterminant(); var border = room.Border; if (intersectionDeter.IsIntersected(shot.Form, new RectangleF(room.Form.Left, room.Form.Top, border.Width, room.Form.Height))) { return true; } if (intersectionDeter.IsIntersected(shot.Form, new RectangleF(room.Form.Left, room.Form.Top, room.Form.Width, -border.Height))) { return true; } if (intersectionDeter.IsIntersected(shot.Form, new RectangleF(room.Form.Right - border.Width, room.Form.Top, border.Width, room.Form.Height))) { return true; } if (intersectionDeter.IsIntersected(shot.Form, new RectangleF(room.Form.Left, room.Form.Bottom + border.Height, room.Form.Width, -border.Height))) { return true; } return false; }
public void Draw(Room room) { GL.BindTexture(TextureTarget.Texture2D, _textures[room.Texture]); new RectangleDrawer().Draw(room.Form); var borderDrawer = new RoomBorderDrawer(_textures); borderDrawer.Draw(room, room.Border); foreach(var t in room.Obstacles) { var obsDrawer = new ObstacleDrawer(_textures); obsDrawer.Draw(room, t); } foreach (var t in room.Enemies) { var enemyDrawer = new EnemyDrawer(_textures); enemyDrawer.Draw(t); } foreach (var t in room.Shots) { var shotDrawer = new ShotDrawer(_textures); shotDrawer.Draw(t); } if(room.FinishZone.IsActive) { var finishZoneDrawer = new FinishZoneDrawer(_textures); finishZoneDrawer.Draw(room.FinishZone); } }
public void Run(Player player, Room room) { foreach (var t in room.Enemies) { var distance = new Vector2(player.X - t.X, player.Y - t.Y).Length; var direction = new Vector2(player.X - t.X, player.Y - t.Y); if (distance > 0.8f*t.ShotChar.Range) { t.Move(direction); } else { t.Shoot(room, new Shot(t.Form.Left, t.Form.Top, direction, t)); } } foreach (var t in room.Shots) { t.Move(); } room.Shots.RemoveAll(ShotIsRemoved); var collisionChecker = new CollisionChecker(); foreach (var t in room.Shots) { if (collisionChecker.IsCollided(t, room)) { OnShotBorderCollision(t, room); } if (collisionChecker.IsCollided(t, player)) { if (t.Owner.GetType() != player.GetType()) { OnShotPlayerCollision(t, player); } } foreach(var item in room.Enemies) { if (collisionChecker.IsCollided(t, item)) { if (t.Owner != item) { OnShotEnemyCollision(t, item); } } } } if (collisionChecker.IsCollided(player, room.FinishZone) && room.FinishZone.IsActive) { OnPlayerFinishZoneCollision(player, room.FinishZone); } room.Shots.RemoveAll(ShotIsRemoved); room.Enemies.RemoveAll(EnemyIsDead); }
public void Draw(Room room, RoomBorder roomBorder) { GL.BindTexture(TextureTarget.Texture2D, _textures[roomBorder.Texture]); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 0); GL.Vertex2(room.Form.Left, room.Form.Top); GL.TexCoord2(0, 1); GL.Vertex2(room.Form.Left + roomBorder.Width, room.Form.Top - roomBorder.Height); GL.TexCoord2(1, 1); GL.Vertex2(room.Form.Right - roomBorder.Width, room.Form.Top - roomBorder.Height); GL.TexCoord2(1, 0); GL.Vertex2(room.Form.Right, room.Form.Top); GL.End(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 1); GL.Vertex2(room.Form.Right - roomBorder.Width, room.Form.Top - roomBorder.Height); GL.TexCoord2(1, 1); GL.Vertex2(room.Form.Right - roomBorder.Width, room.Form.Bottom + roomBorder.Height); GL.TexCoord2(1, 0); GL.Vertex2(room.Form.Right, room.Form.Bottom); GL.TexCoord2(0, 0); GL.Vertex2(room.Form.Right, room.Form.Top); GL.End(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 0); GL.Vertex2(room.Form.Right, room.Form.Bottom); GL.TexCoord2(0, 1); GL.Vertex2(room.Form.Right - roomBorder.Width, room.Form.Bottom + roomBorder.Height); GL.TexCoord2(1, 1); GL.Vertex2(room.Form.Left + roomBorder.Width, room.Form.Bottom + roomBorder.Height); GL.TexCoord2(1, 0); GL.Vertex2(room.Form.Left, room.Form.Bottom); GL.End(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 0); GL.Vertex2(room.Form.Left, room.Form.Bottom); GL.TexCoord2(0, 1); GL.Vertex2(room.Form.Left + roomBorder.Width, room.Form.Bottom + roomBorder.Height); GL.TexCoord2(1, 1); GL.Vertex2(room.Form.Left + roomBorder.Width, room.Form.Top - roomBorder.Height); GL.TexCoord2(1, 0); GL.Vertex2(room.Form.Left, room.Form.Top); GL.End(); }
public void Control(Player player, Room room) { var state = OpenTK.Input.Keyboard.GetState(); bool _allKeys = true; foreach(var t in _commands) { foreach (var key in t.Keys) { if (!state[key]) { _allKeys = false; } } if(_allKeys) { foreach(var act in t.Actions) { act.Invoke(player, room); } } _allKeys = true; } }
public void Shoot(Room room, Shot shot) { if (_canShoot) { room.Shots.Add(shot); _canShoot = false; var timer = new Timer(_attackSpeed); timer.AutoReset = false; timer.Elapsed += OnTimedEvent; timer.Start(); } }
public virtual bool CanMove(Vector2 direction, Room room) { return true; }
private void MoveDown(Person player, Room room) { var direction = new Vector2(0, -1); if (player.CanMove(direction, room)) { player.Move(direction); } }
private void ShootUp(Player player, Room room) { var direction = new Vector2(0, 1); player.Shoot(room, new Shot(player.Form.Left, player.Form.Top, direction, player)); }
private void MoveRight(Person player, Room room) { var direction = new Vector2(1, 0); if (player.CanMove(direction, room)) { player.Move(direction); } }
private void ShotBorderHandle(Shot shot, Room room) { shot.IsRemoved = true; }
public void Draw(Room room, Obstacle obstacle) { GL.BindTexture(TextureTarget.Texture2D, _textures[obstacle.Texture]); new RectangleDrawer().Draw(obstacle.Form); }