public override void UpdateObject(MainGameEnginePanel _mainGameEnginePanel) { if (gameManager.keysDown.Contains(Keys.W)) { this.objectVelocity = new PointF(this.objectVelocity.X, -playerSpeed); } else if (gameManager.keysDown.Contains(Keys.S)) { this.objectVelocity = new PointF(this.objectVelocity.X, playerSpeed); } else { this.objectVelocity = new PointF(this.objectVelocity.X, 0); } if (gameManager.keysDown.Contains(Keys.D)) { this.objectVelocity = new PointF(playerSpeed, this.objectVelocity.Y); } else if (gameManager.keysDown.Contains(Keys.A)) { this.objectVelocity = new PointF(-playerSpeed, this.objectVelocity.Y); } else { this.objectVelocity = new PointF(0, this.objectVelocity.Y); } if (gameManager.keysDown.Contains(Keys.Space)) { if (gameManager.gameTime - lastShootTime > shootDelay) { Console.Out.WriteLine(gameManager.mouseLocation + " " + this.gameObjectLocation); PointF locationDifference = PointHelper.Subtract(gameManager.mouseLocation, this.gameObjectLocation); PointF projectileVelocity = new PointF(0, 0); if (locationDifference.X > locationDifference.Y) { float yVelocity = locationDifference.Y * 100 / locationDifference.X; projectileVelocity = new PointF(projectileMaxVelocity, yVelocity * projectileMaxVelocity / 100); } else //Y bigger { float xVelocity = locationDifference.X * 100 / locationDifference.Y; projectileVelocity = new PointF(xVelocity * projectileMaxVelocity / 100, projectileMaxVelocity); } Console.Out.WriteLine(projectileVelocity); Projectile newProjectile = new Projectile(gameManager, this.gameObjectLocation, projectileVelocity); gameManager.AddGameObjectToScene(newProjectile, 0); lastShootTime = gameManager.gameTime; } } base.UpdateObject(_mainGameEnginePanel); }
private void Form1_Load(object sender, EventArgs e) { mainGameEnginePanel = new MainGameEnginePanel(this, gamePanelSize, new Point(0, 0)); gameManager = new GameManager(this, mainGameEnginePanel); WallGameObject wall1 = new WallGameObject(gameManager, new Point(0, 0)); List <WallGameObject> walls = CreateStartupWalls(); GameScene gameScene1 = new GameScene(walls.ToList <GameObject>()); gameManager.AddScene(gameScene1); player = new Player(gameManager, new Point(100, 100)); gameManager.AddGameObjectToScene(player, 0); UiManager gameUi1 = new UiManager(); gameManager.AddUi(gameUi1); gameManager.Tick += GameManager_Tick; ConnectionStateLabel.Text = "Not connected"; }
private void Form1_Load(object sender, EventArgs e) { mainGamePanel = new MainGameEnginePanel(this, new Size(200, 400), new Point(0, 0)); gameManager = new GameManager(this, mainGamePanel); playerShip = new PlayerShip(gameManager, new Point(100, 350)); GameScene gameScene = new GameScene(new List <GameObject>() { playerShip }); gameManager.AddScene(gameScene); gameManager.Tick += GameManager_Tick; scoreBox = new Box2dGameObject(gameManager, new Point(0, 400), new Size(200, 1)); scoreBox.colliding = true; scoreBox.OnCollision += ScoreBox_OnCollision; gameManager.AddGameObjectToScene(scoreBox, 0); Box2dGameObject topBlock = new Box2dGameObject(gameManager, new Point(0, -1), new Size(200, 1)); topBlock.colliding = true; topBlock.objectTag = "wall"; gameManager.AddGameObjectToScene(topBlock, 0); Box2dGameObject bottomBlock = new Box2dGameObject(gameManager, new Point(0, 401), new Size(200, 1)); bottomBlock.colliding = true; gameManager.AddGameObjectToScene(bottomBlock, 0); Box2dGameObject rightBlock = new Box2dGameObject(gameManager, new Point(201, 0), new Size(1, 400)); rightBlock.colliding = true; gameManager.AddGameObjectToScene(rightBlock, 0); Box2dGameObject leftBlock = new Box2dGameObject(gameManager, new Point(-1, 0), new Size(1, 400)); leftBlock.colliding = true; gameManager.AddGameObjectToScene(leftBlock, 0); UiManager gameUi = new UiManager(); gameManager.AddUi(gameUi); playerLifeText = new TextGameObject(gameManager, new Point(0, 0)); gameManager.AddWidgetToUi(playerLifeText, 0); playerLifeText.text = playerLife.ToString(); //GAME OVER SCENE AND UI GameScene gameOverScene = new GameScene(); gameManager.AddScene(gameOverScene); UiManager gameOverUi = new UiManager(); gameManager.AddUi(gameOverUi); TextGameObject gameOverText = new TextGameObject(gameManager, new Point(100, 200)); gameOverText.text = "Game over"; gameManager.AddWidgetToUi(gameOverText, 1); }
private void Form1_Load(object sender, EventArgs e) { MainGameEnginePanel mainGameEnginePanel = new MainGameEnginePanel(this, new Size(400, 200), new Point(0, 0)); gameManager = new GameManager(this, mainGameEnginePanel); Box2dGameObject leftTrigger = new Box2dGameObject(gameManager, new Point(-1, 0), new Size(1, 200)); leftTrigger.objectTag = "leftTrigger"; leftTrigger.colliding = true; Box2dGameObject rightTrigger = new Box2dGameObject(gameManager, new Point(400, 0), new Size(1, 200)); rightTrigger.objectTag = "rightTrigger"; rightTrigger.colliding = true; Box2dGameObject topSide = new Box2dGameObject(gameManager, new Point(0, -1), new Size(400, 1)); topSide.objectTag = "side"; topSide.colliding = true; Box2dGameObject bottomSide = new Box2dGameObject(gameManager, new Point(0, 200), new Size(400, 1)); bottomSide.objectTag = "side"; bottomSide.colliding = true; leftHandle = new Box2dGameObject(gameManager, new Point(25, 100), new Size(10, 50)); leftHandle.boxColor = Color.Green; leftHandle.colliding = true; leftHandle.objectTag = "handle"; rightHandle = new Box2dGameObject(gameManager, new Point(375, 100), new Size(10, 50)); rightHandle.boxColor = Color.Green; rightHandle.colliding = true; rightHandle.objectTag = "handle"; ballObject = new Box2dGameObject(gameManager, new Point(200, 100), new Size(10, 10)); ballObject.boxColor = Color.Black; Random r = new Random(); ballVelocities = new List <Point>() { new Point(ballSpeed, ballSpeed), new Point(-ballSpeed, -ballSpeed), new Point(-ballSpeed, ballSpeed), new Point(ballSpeed, -ballSpeed) }; ballObject.objectVelocity = ballVelocities[r.Next(0, ballVelocities.Count())]; ballObject.objectTag = "ball"; ballObject.colliding = true; ballObject.OnCollision += BallCollision; rightScoreText = new TextGameObject(gameManager, new Point(350, 0)); rightScoreText.text = rightScore.ToString(); leftScoreText = new TextGameObject(gameManager, new Point(20, 0)); leftScoreText.text = leftScore.ToString(); gameTimeText = new TextGameObject(gameManager, new Point(200, 0)); gameTimeText.text = "0"; List <GameObject> scene1GameObjects = new List <GameObject>() { leftHandle, rightHandle, ballObject, topSide, bottomSide, leftTrigger, rightTrigger }; GameScene gameScene = new GameScene(scene1GameObjects); gameManager.AddScene(gameScene); UiManager gameUi = new UiManager(); gameUi.AddWidget(gameTimeText); gameManager.AddUi(gameUi); victoryText = new TextGameObject(gameManager, new Point(200, 100)); GameScene victoryScene = new GameScene(); gameManager.AddScene(victoryScene); UiManager victoryUi = new UiManager(); victoryUi.AddWidget(victoryText); gameManager.AddUi(victoryUi); VictoryScoreAmountTextBox.Text = victoryScoreAmount.ToString(); BallSpeedTextBox.Text = ballSpeed.ToString(); gameManager.Tick += GameManager_Tick; }