private void TmrGame_Tick(object sender, EventArgs e) { if (right) // if right arrow key pressed { move = "right"; player.MovePlayer(move); } if (left) // if left arrow key pressed { move = "left"; player.MovePlayer(move); } if (jump == true) //If space is pressed { move = "jump"; player.MovePlayer(move); } if (player.y == 220) //Reset jump when the player hits the ground, so the player my jump again { jump = false; player.ySpeed = 18; } bush.MoveBush(); crate.MoveCrate(); tree.MoveTree(); //If the objects intersect with each other, move them if (tree.treeRec.IntersectsWith(crate.crateRec) || tree.treeRec.IntersectsWith(bush.bushRec)) { tree.x += 20; } if (crate.crateRec.IntersectsWith(tree.treeRec) || crate.crateRec.IntersectsWith(bush.bushRec)) { crate.x += 10; } if (score > 100) //Allow enemies to move only when score is > 100 { bat1.MoveEnemy(); } foreach (Bullet b in bullets) //If the bat intersects with the bullet reset the bat and remove the bullet, or the bullet reaches the right side of the panel, remove the bullet { if (bat1.enemyRec.IntersectsWith(b.bulletRec)) { bat1.x = -50; bullets.Remove(b); break; } if (b.bulletRec.X >= 700) { bullets.Remove(b); break; } } if (player.playerRec.IntersectsWith(crate.crateRec) || player.playerRec.IntersectsWith(tree.treeRec) || player.playerRec.IntersectsWith(bush.bushRec) || player.playerRec.IntersectsWith(bat1.enemyRec)) { //If the player intersects with any bad objects, stop the game and show the restart label tmrGame.Enabled = false; tmrRestart.Enabled = true; tmrScore.Enabled = false; tmrAnim.Enabled = false; BtnScore.Enabled = true; LblRestart.Visible = true; MnuStart.Enabled = false; shoot = false; } PnlGame.Invalidate(); //makes the paint event fire to redraw the panel }