public SpaceshipCamera(Viewport viewPort, Spaceship ship, Vector3 startingPos, float lrRot, float udRot) { this.ship = ship; this.leftrightRot = lrRot; this.updownRot = udRot; this.cameraPosition = startingPos; this.viewPort = viewPort; float viewAngle = MathHelper.PiOver4; float nearPlane = 0.1f; float farPlane = 100.0f; projectionMatrix = Matrix.CreatePerspectiveFieldOfView(viewAngle, viewPort.AspectRatio, nearPlane, farPlane); Mouse.SetPosition(viewPort.Width / 2, viewPort.Height / 2); originalMouseState = Mouse.GetState(); }
// hämtar in lista med skott // syftet med metoden är att checka om ett skott(Line) kolliderar med en asteroid protected virtual void CollisionWithLine(int asteroidIndex) { // för varje instans av Lazer tittar om kollision med astroid; for (int index = lazerList.Count - 1; index > -1; index--) { // om skott krockar med astroid if (Raylib.CheckCollisionCircleRec(asteroidList[asteroidIndex].GetCirclePos, asteroidList[asteroidIndex].GetAsteroidHitboxSize, lazerList[index].GetRect)) { // - skott dmg && ta bort skott && + score för spaceship asteroidList[asteroidIndex].Hp -= lazerList[index].GetDamage; // om hp efter -dmg >=0 ta bort astroid också if (asteroidList[asteroidIndex].Hp <= 0) { // lägger till poäng för asteroid Spaceship.AddToScore(lazerList[index].GetID, asteroidList[asteroidIndex].worth); // tar bort instans av astroid asteroidList.Remove(asteroidList[asteroidIndex]); } // tar bort skott(index) Lazer.RemoceInstanceOfLine(index); } } }
public override void Draw() { Spaceship.DrawAll(); Lazer.DrawAll(); Asteroid.DrawAll(); }
public override void Update() { userInterface.UpdateUI(); spaceShipScore = Spaceship.GetSpaceshipScore(1); switch (createdSpaceShip) { case 0: { if (!regularSpaceship.IsSpaceshipAlive) { this.isGameOn = false; } else if (regularSpaceship.Shoot()) { Lazer lazer = new Lazer ( regularSpaceship.TriangleX, regularSpaceship.TriangleY, regularSpaceship.TriangleV, regularSpaceship.TriangleR, regularSpaceship.Damage, regularSpaceship.GetID ); } } break; case 1: { if (!scoutSpaceship.IsSpaceshipAlive) { this.isGameOn = false; } else if (scoutSpaceship.Shoot()) { Lazer lazer = new Lazer ( scoutSpaceship.TriangleX, scoutSpaceship.TriangleY, scoutSpaceship.TriangleV, scoutSpaceship.TriangleR, scoutSpaceship.Damage, scoutSpaceship.GetID ); } } break; case 2: { if (!heavySpaceship.IsSpaceshipAlive) { this.isGameOn = false; } else if (heavySpaceship.Shoot()) { Lazer lazer = new Lazer ( heavySpaceship.TriangleX, heavySpaceship.TriangleY, heavySpaceship.TriangleV, heavySpaceship.TriangleR, heavySpaceship.Damage, heavySpaceship.GetID ); } } break; case 3: { if (!sniperSpaceship.IsSpaceshipAlive) { this.isGameOn = false; } else if (sniperSpaceship.Shoot()) { Lazer lazer = new Lazer ( sniperSpaceship.TriangleX, sniperSpaceship.TriangleY, sniperSpaceship.TriangleV, sniperSpaceship.TriangleR, sniperSpaceship.Damage, sniperSpaceship.GetID ); } } break; } if (time[0] >= 10 * (4 - ButtonSeries.GetSelectedMultiplier(2))) { Asteroid asteroid = new Asteroid(); time[0] = 0; } else { time[0]++; } if (spaceShipScore >= 2000) { wave = 2; if (time[1] == 600) { MissileAsteroid missileAsteroid = new MissileAsteroid(); time[1] = 0; } else { time[1]++; } } if (spaceShipScore >= 4000) { wave = 3; if (time[2] == 1000) { ScatterAsteroid scatterAsteroid = new ScatterAsteroid(); time[2] = 0; } else { time[2]++; } } if (spaceShipScore >= 6000) { wave = 4; if (time[3] == 2000) { MissileScatterAsteroid missileScatterAsteroid = new MissileScatterAsteroid(); time[3] = 0; } else { time[3]++; } } if (spaceShipScore >= 8000 && ButtonSeries.GetSelectedButtonID(4) == 0) { wave = 5; if (time[4] == 2000) { LimitScreen limitScreen = new LimitScreen(); time[4] = 0; } else { time[4]++; } } if (spaceShipScore >= 10000) { if (ButtonSeries.GetSelectedButtonID(4) == 0) { wave = 6; } else { wave = 5; } if (time[5] == 4000) { MissileScatterAsteroidMissile missileScatterAsteroidMissile = new MissileScatterAsteroidMissile(); time[5] = 0; } else { time[5]++; } } if (spaceShipScore >= 20000) { if (time[6] == 0) { time[6] = 20000 - spaceShipScore / 10; } else { time[6]--; } if (ButtonSeries.GetSelectedButtonID(2) == 4) { wave = 7; } else { wave = 6; } int t = time[6]; switch (t) { case 1: { for (int i = 0; i < 200; i++) { Asteroid asteroid = new Asteroid(); } } break; case 2000: { for (int i = 0; i < 3; i++) { MissileAsteroid missileAsteroid = new MissileAsteroid(); } } break; case 4000: { for (int i = 0; i < 5; i++) { ScatterAsteroid scatterAsteroid = new ScatterAsteroid(); } } break; case 6000: { for (int i = 0; i < 3; i++) { MissileScatterAsteroid missileScatterAsteroid = new MissileScatterAsteroid(); } } break; case 8000: { for (int i = 0; i < 4; i++) { MissileScatterAsteroidMissile missileScatterAsteroidMissile = new MissileScatterAsteroidMissile(); } } break; } } base.Update(); }
internal void createMissile(Spaceship spaceship) { objectsList.Add(new Missile(spaceship.getPosition(), spaceship.getVelocity(), spaceship.getAngle(), this)); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); if (Keyboard.GetState().IsKeyDown(Keys.R)) Draw(gameTime); int totalTime = (int) gameTime.TotalGameTime.TotalSeconds; gameClock = totalTime.ToString(); powerupTimer -= (float) gameTime.ElapsedGameTime.TotalSeconds; if (powerupTimer <= 0) { SpawnPowerup(rng); powerupTimer = POWERUP_SPAWN_INTERVAL; } reloadTimer -= (float) gameTime.ElapsedGameTime.TotalSeconds; if (reloadTimer < 0) reloadTimer = 0; Vector3 direction = camera.GetDirection(); particleEngine.Update(gameTime); if (spaceship != null && spaceship.Lives > 0) { spaceship.Update(direction, collisionEngine, soundEngine, particleEngine, asteroids, powerups, originalMouseState, gameTime, device); camera.Update(spaceship); ProcessClick(gameTime); } else spaceship = null; for (int i = 0; i < powerups.Count; i++) if (powerups[i].Collected) powerups.RemoveAt(i); for (int i = 0; i < torpedoes.Count; i++) { if (!(torpedoes[i].Destroyed)) torpedoes[i].Update(collisionEngine, soundEngine, particleEngine, gameTime, asteroids); else torpedoes.RemoveAt(i); } for (int i = 0; i < asteroids.Count; i++) { if (!(asteroids[i].Destroyed)) asteroids[i].Update(collisionEngine, soundEngine, gameTime, torpedoes, asteroids, asteroidModels, asteroidBSRadius); else asteroids.RemoveAt(i); } base.Update(gameTime); }
protected override void UnloadContent() { camera = null; spaceship = null; skybox = null; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); device = graphics.GraphicsDevice; Mouse.SetPosition(device.Viewport.Width / 2, device.Viewport.Height / 2); originalMouseState = Mouse.GetState(); billboardEffect = this.Content.Load<Effect>("Shaders/billboard_effect"); camera = new Camera(device); lifeTexture = this.Content.Load<Texture2D>("Sprites/spaceship_sprite"); explosionParticleTexture = this.Content.Load<Texture2D>("Sprites/explosion_particle"); shieldSprite = this.Content.Load<Texture2D>("Sprites/power_up_shield"); shrinkSprite = this.Content.Load<Texture2D>("Sprites/power_up_shrink"); timeFont = Content.Load<SpriteFont>("Fonts/Courier New"); collisionEngine = new CollisionEngine(); particleEngine = new ParticleEngine(explosionParticleTexture, billboardEffect, device); soundEngine = new SoundEngine(this.Content); skybox = new Skybox(); skybox.LoadModel(this.Content, effect); spaceship = new Spaceship(); spaceship.LoadModelAndTexture(this.Content, effect); torpedoes = new List<Torpedo>(); powerups = new List<Powerup>(); LoadAsteroids(); }
private void StartNewGame() { ship = new Spaceship(Content); camera = new SpaceshipCamera(graphics.GraphicsDevice.Viewport, ship); int x, y, z, pos_x, pos_y, pos_z; Random random = new Random(); for (int i = 0; i < NUM_ASTEROIDS; ++i) { x = random.Next(2); z = random.Next(2); y = random.Next(2); pos_x = random.Next(-30, 31); pos_y = random.Next(-30, 31); pos_z = random.Next(-30, 31); asteroids[i] = new Asteroid(Content, new Vector3(x, y, z)); asteroids[i].Position = new Vector3(pos_x, pos_y, pos_z); } spriteDrawer = new SpriteDrawer(device, Content); spriteManager = new SpriteManager(device, Content); spFont = Content.Load<SpriteFont>(@"Arial"); spBatch = new SpriteBatch(graphics.GraphicsDevice); particleSystem = new ParticleSystem(spriteManager); jetParticleEffect = new JetParticleEffect(particleSystem, ship); points = 0; jetParticleEffect.MinXDirection = -0.3f; jetParticleEffect.MaxXDirection = 0.3f; jetParticleEffect.MinZDirection = 0.6f; jetParticleEffect.MaxZDirection = 0.8f; jetParticleEffect.MinYDirection = -0.2f; jetParticleEffect.MaxYDirection = 0.2f; jetParticleEffect.ParticlesPerSecond = 50.0; jetParticleEffect.ParticleLifetime = 400.0; jetParticleEffect.ParticleSize = 0.5f; jetParticleEffect.ParticleSpeed = 0.7f; jetParticleEffect.FinalColor = Color.Red; }
public Missile(ContentManager content, Spaceship ship) : this(content, Vector3.Transform(Vector3.Forward, ship.Rotation), ship.Position) { }
public SpaceshipCamera(Viewport viewPort, Spaceship ship) : this(viewPort, ship, new Vector3(0, 1, 15), 0, 0) { //calls the constructor below with default startingPos and rotation values }