private void MoveRight() { int PosX = 0; int PosY = 0; for (int x = ALIEN_COLUMNS - 1; 0 <= x && PosX == 0; x--) { for (int y = ALIEN_ROWS - 1; 0 <= y && PosY == 0; y--) { if (aliens[x, y] != null) { PosX = x; PosY = y; } } } if (Constaints.GameArea.Width <= (aliens[PosX, PosY].Position.X + aliens[PosX, PosY].getWidth() + 1)) { direction = AlienMoveDiration.Left; MoveFleet(0, DEFAULT_ALIEN_VERTICAL_MOVEMENT_SPEED); } else { MoveFleet(currentMovementSpeed, 0); } }
private void MoveLeft() { int PosX = 0; int PosY = 0; for (int x = 0; x < ALIEN_COLUMNS && PosX == 0; x++) { for (int y = ALIEN_ROWS - 1; 0 <= y && PosY == 0; y--) { if (aliens[x, y] != null) { PosX = x; PosY = y; } } } if (aliens[PosX, PosY].Position.X <= Constaints.GameArea.X) { direction = AlienMoveDiration.Right; MoveFleet(0, DEFAULT_ALIEN_VERTICAL_MOVEMENT_SPEED); } else { MoveFleet(-currentMovementSpeed, 0); } }
public AlienManager() { direction = AlienMoveDiration.Right; state = GameState.Playing; aliens = new Alien[ALIEN_COLUMNS, ALIEN_ROWS]; bulletsShot = new List <Bullet>(); currentMovementSpeed = DEFAULT_ALIEN_HORIZONTAL_MOVEMENT_SPEED; rand = new Random(); // Here, all we are doing is initializing the aliens. We can not set the position until the 'RestAlienPosition() // function is called. If the playe dies mid gamethe aliens need to be rested to the middle of the screen. for (int x = 0; x < ALIEN_COLUMNS; x++) { for (int y = 0; y < ALIEN_ROWS; y++) { aliens[x, y] = new Alien(new Vector2(0), y); } } ResetAlienPosition(); }
public void ResetAlienPosition() { if (new Random().Next(100) < 50) { direction = AlienMoveDiration.Right; } else { direction = AlienMoveDiration.Left; } for (int x = 0; x < ALIEN_COLUMNS; x++) { for (int y = 0; y < ALIEN_ROWS; y++) { if (aliens[x, y] != null) { Alien alien = aliens[x, y]; alien.setPosition((int)((x * 16) * aliens[x, y].DrawOptions.Scale.X), 0); } } } float WidestAlienPos = getColumnWidth(); for (int x = ALIEN_COLUMNS - 1; 0 <= x && WidestAlienPos == 0; x--) { for (int y = ALIEN_ROWS - 1; 0 <= y && WidestAlienPos == 0; y--) { if (aliens[x, y] != null) { WidestAlienPos = (float)(aliens[ALIEN_COLUMNS - 1, ALIEN_ROWS - 1].Position.X + aliens[ALIEN_COLUMNS - 1, ALIEN_ROWS - 1].getWidth()); WidestAlienPos = (int)(WidestAlienPos) >> 1; } } } int ScreenWidth = Constaints.ScreenResolution.ScreenWidth; for (int x = 0; x < ALIEN_COLUMNS; x++) { for (int y = 0; y < ALIEN_ROWS; y++) { if (aliens[x, y] != null) { if (aliens[x, y] != null) { Alien alien = aliens[x, y]; float PosX = (ScreenWidth >> 1) - WidestAlienPos; float PosY = (float)(32 + (y * 16) * alien.DrawOptions.Scale.X); // We offset the location of the alien with the smallest width to align it with the // its other firends. int offset = 0; if (alien.getWidth() == alien.DrawOptions.Scale.X * 8) { offset = 5; } alien.addPosition(PosX + offset, PosY); aliensAlive++; } } } } }