static Game() { window = new Window(1000, 700, "Space Invaders", PixelFormat.RGB); GfxTools.Init(window); EnemiesManager.Init(); player = new Player(); scoreText = new SpriteText(new Vector2(window.width - Edge - 140, window.height - Edge), Player.Score.ToString("D6")); }
// DRAW public void Draw(Window window) { if (this.state) { GfxTools.DrawSprite(window, this.position, this.spriteA); } else { GfxTools.DrawSprite(window, this.position, this.spriteB); } }
// DRAW private void DrawAllBullets(Window window) { for (int i = 0; i < this.bullets.Length; i++) { if (this.bullets[i].IsFired) { this.bullets[i].Draw(window); } if (this.bullets[i].IsExploded) { Vector2 explosionPosition = new Vector2(bullets[i].Position.X - bullets[i].ExplosionWidth / 2, bullets[i].Position.Y - bullets[i].ExplosionHeight); GfxTools.DrawSprite(window, explosionPosition, this.bullets[i].ExplosionSprite); } } }
public static void Play() { while (window.opened) { GfxTools.Clean(); // INPUT if (window.GetKey(KeyCode.Esc) || window.GetKey(KeyCode.Return)) { return; } if (window.GetKey(KeyCode.P) && pauseCooldown <= 0) { isPause = !isPause; pauseCooldown = pauseTempo; } player.Input(); // UPDATE if (!isPause && Player.Lives > 0 && EnemiesManager.EnemiesAlive > 0) { player.Update(); EnemiesManager.Update(); } pauseCooldown -= window.deltaTime; scoreText.Text = Player.Score.ToString("D6"); // DRAW player.Draw(); scoreText.Draw(); EnemiesManager.Draw(); if (isPause) { GfxTools.DrawRectangle(window.width / 2 - 30, window.height / 2 - 45, 60, 90, 0, 0, 0); GfxTools.DrawRectangle(window.width / 2 - 25, window.height / 2 - 40, 20, 80, 255, 255, 255); GfxTools.DrawRectangle(window.width / 2 + 5, window.height / 2 - 40, 20, 80, 255, 255, 255); } window.Blit(); } }
// DRAW private void DrawScore(Window window) { Vector2 position = this.position; for (int i = 0; i < sprites.Length; i++) { if (sprites[i] == null) { return; } else { GfxTools.DrawSprite(window, position, sprites[i]); position.X += sprites[i].width + 2; } } }
//test static Game() { window = new Window(1900, 1000, "Space Invaders", PixelFormat.RGB); score = 0; GfxTools.Init(window); Vector2 playerPos; playerPos.X = window.width / 2; playerPos.Y = window.height - 20; EnemyMgr.Init(45, 3); switcher = 0; player = new Player(playerPos, new Color(22, 22, 200)); scoretext = new spriteText(new Vector2(220, 48), "000000"); PlayerSound.Play("Assets/spaceship.wav", "suono"); //music = new SoundPlayer(); //music.SoundLocation = "Assets/spaceship.wav"; //music.Load(); //music.PlayLooping(); bg = new backgorund("Assets/space_3.png"); bg2 = new backgorundMenu("Assets/space_menu.png"); m = new Menu(); barriers = new Barrier[3]; for (int i = 0; i < barriers.Length; i++) { barriers[i] = new Barrier(new Vector2((GfxTools.Win.width) * (i + 1) / 4, (GfxTools.Win.height / 2) + 300)); } //test }
//DRAW public void Draw(Window window) { GfxTools.DrawRectangle(window, this.position, this.side, this.side, this.color); }
public void Draw() { GfxTools.DrawRect((int)position.X, (int)position.Y, width, height, color.R, color.G, color.B); }
public void Draw() { GfxTools.DrawSprite(sprite, (int)position.X, (int)position.Y); }
// DRAW public void Draw(Window window) { GfxTools.DrawSprite(window, this.position, this.sprite); }
public void Draw() { GfxTools.DrawRect((int)(Position.X - width / 2), (int)(Position.Y - height / 2), width, height, color.R, color.G, color.B); }