public void Update() { //player move float deltaY = verticalSpeed * GfxTools.Win.deltaTime; float deltaX = horizontalSpeed * GfxTools.Win.deltaTime; position.X += deltaX; position.Y -= deltaY; force = (mass * verticalSpeed) / 100; sprite.Translate(deltaX, -deltaY); //force checker if (force < -80f) { danger.Draw(); } //heart checker int lifePoint = nrg * 50; //platform checker SpaceStation platform = Game.GetPlatform(); checkPlatform = platform.CheckAlive(); if (checkPlatform) { scoreWinner += GfxTools.Win.deltaTime; } //platform collision if (OnPlatformEnter()) { verticalSpeed = 0; horizontalSpeed = 0; Game.AddScore((int)scoreWinner + lifePoint); GUI gui = Game.GetGUI(); gui.YouWin(); Game.isPlayble = false; Game.isSavable = true; Game.Exit(); } //player score if (IsAlive && !OnPlatformEnter()) { counterScore += 0.9f * GfxTools.Win.deltaTime; if (counterScore >= 1) { Game.AddScore(1); counterScore = 0; } } }
public bool OnPlatformEnter() { SpaceStation platform = Game.GetPlatform(); if (platform.IsAlive) { if (position.Y + height / 2 >= platform.Position.Y) { if (position.X - ray >= platform.Position.X - platform.Radius && position.X + ray <= platform.Position.X + platform.Radius) { if (force >= -100f) { return(true); } else { IsAlive = false; } } } } return(false); }
public static void Reset() { //PLAYER Vector2 playerPos; playerPos.X = GfxTools.Win.width / 2; playerPos.Y = GfxTools.Win.height - 100; float fpsPalyer = 20; int numSpritePlayer = 8; int verticalMaxSpeedPlayer = Gravity.gravity * 3; int horizontalMaxSpeedPlayer = Gravity.gravity * 3; int numOfLifes = 3; player = new Player(playerPos, numSpritePlayer, fpsPalyer, verticalMaxSpeedPlayer, horizontalMaxSpeedPlayer, numOfLifes); //COIN Vector2 coinPosition = new Vector2(50, RandomGenerator.GetRandom(50, GfxTools.Win.height - 50)); float fpsCoin = 8; int numSpriteCoin = 6; float verticalMaxSpeedCoin = Gravity.gravity * 150f; float horizontalMaxSpeedCoin = Gravity.gravity * 100f; coin = new Coin(coinPosition, numSpriteCoin, fpsCoin, verticalMaxSpeedCoin, horizontalMaxSpeedCoin); //ASTEROID Vector2 asteroidPosition = new Vector2(80, RandomGenerator.GetRandom(50, GfxTools.Win.height - 50)); float fpsAsteroid = 24; int numSpriteAsteroid = 64; float verticalMaxSpeedAsteroid = Gravity.gravity * 7.52f; float horizontalMaxSpeedAsteroid = Gravity.gravity * 2.5f; int numOfAsteroid = 4; asteroid = new Asteroid(numSpriteAsteroid, fpsAsteroid, verticalMaxSpeedAsteroid, horizontalMaxSpeedAsteroid); AsteroidMng.Init(numOfAsteroid, numSpriteAsteroid, fpsAsteroid, verticalMaxSpeedAsteroid, horizontalMaxSpeedAsteroid); //LIFE Vector2 lifePosition = new Vector2(GfxTools.Win.width - 50, 20); int offSetX = 30; LifeMng.Init(lifePosition, numOfLifes, offSetX); //PLATFORM Vector2 platformPosition = new Vector2(GfxTools.Win.width / 2, GfxTools.Win.height - 30); float fpsPlatform = 0; int numSpritePlatform = 1; //int verticalMaxSpeedPlatform = 0; //int horizontalMaxSpeedPlatform = 0; platform = new SpaceStation(platformPosition, numSpritePlatform, fpsPlatform); //SCORE score = 0; scoreText = new SpriteText(new Vector2(GfxTools.Win.width / 4, 20), "000000"); //GUI Vector2 guiPosition = new Vector2(GfxTools.Win.width / 2, GfxTools.Win.height / 2); int numSpriteGui = 2; gui = new GUI(guiPosition, numSpriteGui); //AUDIOGAMEOVER string[] audioPath = { @"Assets\media\gameover\decrease_bell_3.wav" }; audio = new Audio(audioPath, false); }