public GameView(GameForm gameForm) { // Form settings InitializeComponent(); this.DoubleBuffered = true; typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, sceneControl, new object[] { true }); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); // Scene setup this.gameForm = gameForm; AllAnimations.InitializeAnimations(); this.gameScene = new Scene(sceneControl); menuPanel.Location = new Point(0, GameSettings.mapUpperBoundY); // Adjust the location of the menu Stream str = Properties.Resources.fire; this.fireBullet = new SoundPlayer(str); // Main timer initialization sceneTimer = new Timer(); sceneTimer.Tick += new EventHandler(sceneTimer_Tick); sceneTimer.Interval = 50; sceneTimer.Start(); sceneTimer.Enabled = true; }
void sceneTimer_Tick(object sender, EventArgs e) { this.Refresh(); if (isInGame) { btn_continue.Enabled = true; btn_continue.BackgroundImage = Properties.Resources.btn_continue; gameScene.moveMap(); // Scroll the map vertically] gameScene.moveBullets(); // Move current bullets on map gameScene.moveEnemies(); // Move the enemies if they are created gameScene.createEnemies(); if (!canFire) { fireTick -= 1; if (fireTick <= 0) { canFire = true; } } if (gameScene.currentLevel == Constants.LEVELS.ISPIT) { bossTick++; if (bossTick >= 40) { bossTick = 0; gameScene.gameBoss.targetLocation = Constants.BossTargetLocations[Constants.randomGenerator.Next(4)]; gameScene.createBossKids(); } if (bossTick % 10 == 0) { gameScene.gameBoss.Animation.nextImage(); } if (gameScene.gameBoss.IsDead) { int score = gameScene.player.Score; gameScene.restartGame(); openMenu(); btn_continue.Enabled = false; btn_continue.BackgroundImage = Properties.Resources.btn_ProdolziDisabled; MessageBox.Show("Колега, успешно го положивте испитот со вкупно " + score + " Поени!"); } } // Iterate through animation sprites AllAnimations.nextImage(); if (movingKeyPressed) { gameScene.MovePlayer(); if (gameScene.enemies.Count == 0 && gameScene.playerAtEnd()) { gameScene.changeLevel(gameScene.currentLevel + 1); } } // If the map has "eaten" the player or the player died if (gameScene.player.PositionY > GameSettings.mapLowerBoundY || gameScene.player.Health <= 0) { btn_continue.Enabled = false; btn_continue.BackgroundImage = Properties.Resources.btn_ProdolziDisabled; gameScene.restartGame(); openMenu(); MessageBox.Show("Жалам колега, не успеавте да го положивте испитот!"); } //Collision detection removal of enemies and bullets gameScene.enemies.RemoveAll(enemy => enemy.IsDead); gameScene.activeBullets.RemoveAll(b => b.RemoveMark && b.Animation.isAnimFinished()); } }