public void Respawn(float minX, float maxX, float minY, float maxY) { //change planet int tempIndex = indexPlanet; do { indexPlanet = RandomGenerator.GetRandom(0, numSprite); } while (tempIndex == indexPlanet); sprite.SetSprite(sprites[indexPlanet]); //change angle verticalSpeed = RandomGenerator.GetRandom(-(int)this.verticalMaxSpeed, (int)this.verticalMaxSpeed); if (position.X < GfxTools.Win.width / 2) { horizontalSpeed = RandomGenerator.GetRandom((int)this.horizontalMaxSpeed / 3, (int)this.horizontalMaxSpeed); } else if (position.X > GfxTools.Win.width / 2) { horizontalSpeed = RandomGenerator.GetRandom(-(int)this.horizontalMaxSpeed, -(int)this.horizontalMaxSpeed / 3); } //reset position position.GetRandom(minX, minX, minY, maxY); sprite.SetPosition(position); sprite.Translate(-ray, -height / 2); IsAlive = true; }
public Asteroid(int numSprite, float fps, float verticalMaxSpeed, float horizontalMaxSpeed) { verticalSpeed = (RandomGenerator.GetRandom((int)1, (int)+verticalMaxSpeed)); horizontalSpeed = (RandomGenerator.GetRandom((int)1, (int)+horizontalMaxSpeed)); this.verticalMaxSpeed = verticalMaxSpeed; this.horizontalMaxSpeed = horizontalMaxSpeed; IsAlive = false; this.numSprite = numSprite; cdSprite = fps; sprites = new string[numSprite]; for (int i = 0; i < sprites.Length; i++) { sprites[i] = "Assets/asteroid/" + i + ".png"; } sprite = new SpriteObj(sprites[0], position); animation = new Animation(sprites, sprite, cdSprite); position.GetRandom(sprite.Width, GfxTools.Win.width / 2 + sprite.Width + 10, 1, 10); sprite.SetPosition(position); width = sprite.Width; height = sprite.Height; ray = width / 2; sprite.Translate(-ray, -height / 2); }
public Planet(Vector2 position, int numSprite, float fps, float verticalMaxSpeed, float horizontalMaxSpeed) { this.position = position; position.AddRandom(0, GfxTools.Win.width / 2, -GfxTools.Win.height / 2, 0); this.verticalMaxSpeed = verticalMaxSpeed; this.horizontalMaxSpeed = horizontalMaxSpeed; do { horizontalSpeed = RandomGenerator.GetRandom(-(int)this.horizontalMaxSpeed, (int)this.horizontalMaxSpeed); verticalSpeed = RandomGenerator.GetRandom(-(int)this.verticalMaxSpeed, (int)this.verticalMaxSpeed); } while (verticalSpeed == 0 || horizontalSpeed == 0); IsAlive = true; this.numSprite = numSprite; cdSprite = fps; indexPlanet = 0; sprites = new string[numSprite]; for (int i = 0; i < sprites.Length; i++) { sprites[i] = "Assets/background/" + i + ".png"; } sprite = new SpriteObj(sprites[indexPlanet], position); animation = new Animation(sprites, sprite, cdSprite); width = sprite.Width; height = sprite.Height; ray = width / 2; sprite.Translate(-ray, -height / 2); }
SoundPlayer SetPlayer() { int random = RandomGenerator.GetRandom(0, audio.Length); player = new SoundPlayer(audio[random]); return(player); }
public static void Update() { for (int i = 0; i < stars.Length; i++) { GfxTools.PutPixel(RandomGenerator.GetRandom(0, GfxTools.Win.width), RandomGenerator.GetRandom(0, GfxTools.Win.height), 255, 255, 255); } sprites.Update(); }
public void Respawn() { position.GetRandom(sprite.Width, GfxTools.Win.width / 2 + sprite.Width + 10, 1, 10); sprite.SetPosition(position); horizontalSpeed = (RandomGenerator.GetRandom((int)0, (int)+horizontalMaxSpeed)); verticalSpeed = (RandomGenerator.GetRandom((int)0, (int)+verticalMaxSpeed)); IsAlive = true; counterRespawn = RandomGenerator.GetRandom(2, 5); }
public void Update() { if (IsAlive) { animation.Start(); animation.Update(); counterMovement += GfxTools.Win.deltaTime; float deltaX = (RandomGenerator.GetRandom((int)0, (int)+horizontalMaxSpeed)) * GfxTools.Win.deltaTime; float deltaY = (RandomGenerator.GetRandom((int)-verticalMaxSpeed, (int)+verticalMaxSpeed)) * GfxTools.Win.deltaTime; if (counterMovement >= 1.25f) { position.X += deltaX; position.Y += deltaY; sprite.Translate(deltaX, deltaY); counterMovement = 0; } Player player = Game.GetPlayer(); if (player.IsAlive) { if (OnCollisionEnter(player.Position, player.Radius)) { Game.AddScore(10); //audio.Play(); IsAlive = false; //Index.audio.Play(); } } } else if (!IsAlive) { counterSpawn += GfxTools.Win.deltaTime; if (counterSpawn >= 10) { Respawn(); } animation.Stop(); } }
public void Effect() { float counter = 0.02f; float deltaX = 0; float deltaY = 0; counter -= GfxTools.Win.deltaTime; if (counter > 0) { deltaX = RandomGenerator.GetRandom((int)-horizontalMaxSpeed, (int)horizontalMaxSpeed) * GfxTools.Win.deltaTime; position.X += deltaX; sprite.Translate(deltaX, 0); } else if (counter <= 0) { deltaY = (verticalMaxSpeed * GfxTools.Win.deltaTime); position.Y += deltaY; sprite.Translate(0, deltaY); if (position.Y <= GfxTools.Win.height) { IsAlive = 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); }
public void AddRandom(float minX, float maxX, float minY, float maxY) { X += RandomGenerator.GetRandom((int)minX, (int)maxX); Y += RandomGenerator.GetRandom((int)minY, (int)maxY); }