public void Shoot() { BulletPlayer b = GetFreeBullet(); if (b != null) { b.Shoot(new Vector2(position.X, position.Y - height - 15), new Vector2(0, -1000)); } }
public static bool CollideWithBullet(BulletPlayer bulletPlayer) { for (int i = 0; i < aliens.Length; i++) { if (aliens[i].IsAlive) { //Vector2 dist = aliens[i].Position.Sub(bullet.Position); //if (dist.GetLength() <= aliens[i].GetWidth()/2 + bullet.GetWidth()/2) if (bulletPlayer.Collides(aliens[i].Position, aliens[i].GetWidth() / 2)) { //alien dies if (aliens[i].OnHit()) { Game.AddScore(5); IncAliensSpeed(1.05f); //he's dead if (aliens[i].CanShoot) { int prevAlienIndex = i - aliensPerRow; while (prevAlienIndex >= 0) { if (aliens[prevAlienIndex].IsAlive) { aliens[prevAlienIndex].CanShoot = true; break; } prevAlienIndex -= aliensPerRow; } } numAlives--; } return(true); } } } return(false); }
public Player(Vector2 pos, Color col) { position = pos; distToSide = 20; shootDelay = 0.3f; color = col; nrg = 10; score = 0; IsAlive = true; spriteobj = new SpriteObj("Assets/playerYellow.png", pos); spriteobj.Translate(-spriteobj.width / 2, -spriteobj.height); width = spriteobj.width; height = spriteobj.height; ray = width / 2; musicP = new SoundPlayer(); musicP.SoundLocation = "Assets/shoot.wav"; musicP.Load(); //baseRect = new Rect(position.X - width / 2, position.Y - height / 2, width, height / 2, color); //int cannWidth = width / 3; //cannonRect = new Rect(position.X - cannWidth / 2, position.Y - height, cannWidth, height / 2, color); bulletPlayer = new BulletPlayer[30]; Color bulletCol = new Color(200, 0, 0); for (int i = 0; i < bulletPlayer.Length; i++) { bulletPlayer[i] = new BulletPlayer(10, 20, bulletCol); } }