public void CheckPlayerBulletCollision(GameTime gameTime, GraphicsDevice graphicsDevice, Handler handler) { Player e = null; for(LinkedListNode<GameObject> i = handler.List.First; i != null; i = i.Next) { if (i.Value.Id == ObjectId.Player) { e = (Player)i.Value; if (e.IndexOfPlayer != _owner) if (HitBox.Intersects(e.Bounds)) { e.Health -= 10; Random rand = new Random(); int antal = rand.Next(5, 15); for (int j = 0; j < antal; j++) { double angle = 2 * rand.NextDouble() * Math.PI; Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); handler.Add(new BloodParticle(_position, direction, (float)rand.Next(5, 15))); Sounds.Blood.CreateInstance().Play(); } _state = ObjectState.Unactive; } else continue; } } }
public override void Update(GameTime gameTime, GraphicsDevice graphicsDevice, Handler handler) { base.Update(gameTime, graphicsDevice, handler); if(_state == ObjectState.Active) { _position.X += _direction.X * _speed; _position.Y += _direction.Y * _speed; _speed--; if (_speed <= 0) _state = ObjectState.Unactive; } }
public bool LoadMap(Handler handler) { for(int x = 0; x < _width; x++) { for(int y = 0; y < _height; y++) { int currentNode = _map[x, y]; switch (currentNode) { case 1: handler.Add(new Wall(new Vector2(x * 32, y * 32))); break; case 2: handler.Add(new Player(new Vector2(x * 32, y * 32))); break; case 3: handler.Add(new Player(new Vector2(x * 32, y * 32),PlayerIndex.Two)); break; } } } return true; }
protected override void Initialize() { handler = new Handler(); map1 = new Map("Maps/map1.txt"); base.Initialize(); }
public override void Update(GameTime gameTime, GraphicsDevice graphicsDevice, Handler handler) { CheckPlayerBulletCollision(gameTime, graphicsDevice, handler); _position.X += _direction.X * _speed; _position.Y += -_direction.Y * _speed; for (LinkedListNode<GameObject> i = handler.List.First; i != null; i = i.Next) { if (i.Value.Id == ObjectId.Wall) { if (HitBox.Intersects(i.Value.BottomBounds)) { Random rand = new Random(); int amount = rand.Next(5, 10); for (int k = 0; k < amount; k++) { double angle = rand.NextDouble() * Math.PI; Vector2 dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); handler.Add(new WallParticle(_position, dir, rand.Next(5, 15))); Sounds.Wall.CreateInstance().Play(); } _state = ObjectState.Unactive; } else if (HitBox.Intersects(i.Value.TopBounds)) { Random rand = new Random(); int amount = rand.Next(5, 10); for (int k = 0; k < amount; k++) { double angle = rand.NextDouble() * Math.PI; Vector2 dir = new Vector2((float)Math.Cos(angle), -(float)Math.Sin(angle)); handler.Add(new WallParticle(_position, dir, rand.Next(5, 15))); Sounds.Wall.CreateInstance().Play(); } _state = ObjectState.Unactive; } else if (HitBox.Intersects(i.Value.LeftBounds)) { Random rand = new Random(); int amount = rand.Next(5, 10); for (int k = 0; k < amount; k++) { double angle = (rand.NextDouble() * Math.PI) / 2.0; Vector2 dir = new Vector2(-(float)Math.Cos(angle), (float)Math.Sin(angle)); handler.Add(new WallParticle(_position, dir, rand.Next(5, 15))); Sounds.Wall.CreateInstance().Play(); } _state = ObjectState.Unactive; } else if (HitBox.Intersects(i.Value.RightBounds)) { Random rand = new Random(); int amount = rand.Next(5, 10); for (int k = 0; k < amount; k++) { double angle = (rand.NextDouble() * Math.PI) / 2.0; Vector2 dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); handler.Add(new WallParticle(_position, dir, rand.Next(5, 15))); Sounds.Wall.CreateInstance().Play(); } _state = ObjectState.Unactive; } } } }
public virtual void Update(GameTime gameTime, GraphicsDevice graphicsDevice, Handler handler) { }
public void Update(GameTime gameTime, GraphicsDevice graphicsDevice, Handler handler) { try { for (LinkedListNode<GameObject> i = list.First; i != null; i = i.Next) { if (i.Value.Id == ObjectId.Bullet || i.Value.Id == ObjectId.Player) { if (i.Value.State == ObjectState.Unactive) { list.Remove(i.Value); continue; } } i.Value.Update(gameTime, graphicsDevice, handler); } } catch (Exception e) { Console.WriteLine(e.Message); } }