public void Update(GameTime gameTime, Room currentRoom, Hero gameHero) { explodeTime -= gameTime.ElapsedGameTime.TotalMilliseconds; animTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (animTime >= animTargetTime) { animTargetTime = animTargetTime / 1.3; animTime = 0; CurrentFrame = 1 - CurrentFrame; } if (explodeTime <= 0) { Active = false; Room.World.Explode(Position, 8f, (currentRoom == Room)); if (Room == currentRoom) ParticleController.Instance.SpawnExplosion(Position); foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (Vector3.Distance(Position, e.Position) < 10f) { float dam = (100f / 10f) * Vector3.Distance(Position, e.Position); Vector3 speed = (Position-e.Position); speed.Normalize(); e.DoHit(e.Position, speed * 0.5f, dam); } } gameHero.DoExplosionHit(Position, 10f); AudioController.PlaySFX("explosion1", 1f, -0.1f, 0.1f); } }
public Enemy(Vector3 pos, Room room, VoxelSprite sprite) { Position = pos; Room = room; spriteSheet = sprite; }
public void Draw(Camera gameCamera, Room currentRoom) { foreach (Enemy e in Enemies.Where(en=>en.Room==currentRoom)) { drawEffect.DiffuseColor = new Vector3(1f,1f-e.hitAlpha,1f-e.hitAlpha); drawEffect.Alpha = 1f; drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(e.Rotation-MathHelper.PiOver2) * Matrix.CreateScale(e.Scale) * Matrix.CreateTranslation(e.Position); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); if (e.Type != EnemyType.Ooze) { if (!e.attacking) graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray.Length, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].IndexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray.Length / 2); else graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, e.spriteSheet.AnimChunks[e.numFrames + e.offsetFrame + e.attackFrame].VertexArray, 0, e.spriteSheet.AnimChunks[e.numFrames + e.offsetFrame + e.attackFrame].VertexArray.Length, e.spriteSheet.AnimChunks[e.numFrames + e.offsetFrame + e.attackFrame].IndexArray, 0, e.spriteSheet.AnimChunks[e.numFrames + e.offsetFrame + e.attackFrame].VertexArray.Length / 2); } } if (e.Type == EnemyType.Ooze) { foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame + 3].VertexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame + 3].VertexArray.Length, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame + 3].IndexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame + 3].VertexArray.Length / 2); } drawEffect.Alpha = 0.5f; foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray.Length, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].IndexArray, 0, e.spriteSheet.AnimChunks[e.CurrentFrame + e.offsetFrame].VertexArray.Length / 2); } } drawEffect.DiffuseColor = new Vector3(1f, 1f, 1f); drawEffect.Alpha = 0.2f; drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(e.Rotation-MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(0, 0, (-(e.spriteSheet.Z_SIZE * SpriteVoxel.HALF_SIZE)) + SpriteVoxel.HALF_SIZE)) * Matrix.CreateScale(e.Scale) * Matrix.CreateScale(new Vector3(1f,1f,0.1f)) * Matrix.CreateTranslation(new Vector3(e.Position.X,e.Position.Y, e.groundHeight-0.35f)); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, e.spriteSheet.AnimChunks[e.spriteSheet.AnimChunks.Count - 1].VertexArray, 0, e.spriteSheet.AnimChunks[e.spriteSheet.AnimChunks.Count - 1].VertexArray.Length, e.spriteSheet.AnimChunks[e.spriteSheet.AnimChunks.Count - 1].IndexArray, 0, e.spriteSheet.AnimChunks[e.spriteSheet.AnimChunks.Count - 1].VertexArray.Length / 2); } } }
public void Update(GameTime gameTime, Hero gameHero, ref Room[,] Rooms) { float dist = 4f - Vector3.Distance(new Vector3(gameHero.RoomX, gameHero.RoomY, 0f), new Vector3(RoomX, RoomY, 0f)); dist = MathHelper.Clamp(dist, 0f, 3f); Vector3 dir = new Vector3(RoomX, RoomY, 0f) - new Vector3(gameHero.RoomX, gameHero.RoomY, 0f); AudioController.instances["roomscrape"].Pan = (1f / 3f) * dir.X; AudioController.instances["roomscrape"].Volume = (1f / 3f) * dist; shiftTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (shiftTime >= targetShiftTime) { AudioController.instances["roomscrape"].Pause(); AudioController.PlaySFX("roomclunk", (1f / 3f) * dist, 0f, (1f / 3f) * dir.X); Complete = true; Room tempRoom = Rooms[RoomX, RoomY]; Rooms[RoomX, RoomY] = Rooms[RoomTargetX, RoomTargetY]; Rooms[RoomTargetX, RoomTargetY] = tempRoom; if (gameHero.RoomX == RoomX && gameHero.RoomY == RoomY) { gameHero.RoomX = RoomTargetX; gameHero.RoomY = RoomTargetY; } } dist = 3f - Vector3.Distance(new Vector3(gameHero.RoomX, gameHero.RoomY, 0f), new Vector3(RoomX, RoomY, 0f)); dist = MathHelper.Clamp(dist, 0f, 3f); if (Helper.Random.Next(2) == 1) dist = -dist; cameraShake = new Vector3(((float)Helper.Random.NextDouble() * dist), 0f, ((float)Helper.Random.NextDouble() * dist)) * 0.1f; }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List<Door> doors) { if (currentRoom != Room) return; Vector3 dir = Target - Position; if (dir.Length() > 0f) dir.Normalize(); Speed = dir * 0.05f; if (Vector3.Distance(Position, Target) <= 1f) Target = Position + (new Vector3(Helper.AngleToVector(((Rotation + MathHelper.Pi) - MathHelper.PiOver2) + ((float)Helper.Random.NextDouble() * MathHelper.Pi), 100f), 0f)); Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(Position.X, Position.Y) + (new Vector2(Speed.X, Speed.Y) * 50f), Rotation, 1f, 0.5f); boundingSphere = new BoundingSphere(Position, 3f - (1f * Iteration)); if (Helper.Random.Next(300) == 1) { dir = gameHero.Position - Position; dir.Normalize(); ProjectileController.Instance.Spawn(ProjectileType.Acid, Room, Position, Matrix.Identity, new Vector3(dir.X * 0.3f, dir.Y * 0.3f, -(float)Helper.Random.NextDouble()), 5000, true); AudioController.PlaySFX("ooze_spit", 1f, 0f, 0f); } Scale = 1f - (0.2f * (float)Iteration); if (hitAlpha > 0f) hitAlpha -= 0.1f; base.Update(gameTime, currentRoom, gameHero, doors); }
public Manhack(Vector3 pos, Room room, VoxelSprite sprite) : base(pos, room, sprite) { Type = EnemyType.Manhack; Position.Z -= 2f; animTargetTime = 30f; Health = 50f; }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List<Door> doors) { if (currentRoom != Room) return; if (Vector3.Distance(Position, gameHero.Position) < 30f) attacking = true; if (attacking) { Speed = Vector3.Zero; Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), Rotation, 1f, 0.5f); attackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (attackTime >= attackTargetTime) { attackTime = 0; attackFrame += attackDir; if (attackFrame == numAttackFrames-1 && attackDir == 1) { ProjectileController.Instance.Spawn(ProjectileType.Laserbolt, Room, Position, Matrix.CreateRotationZ(Rotation), new Vector3(Helper.AngleToVector(Rotation, 0.5f),0f), 5000, false); AudioController.PlaySFX("sentinel_shoot", 1f, 0f, 0f); } if (attackFrame == numAttackFrames-1) { attackDir = -1; attackFrame = numAttackFrames-2; } if (attackFrame == -1) { attackFrame = 0; if (Vector3.Distance(Position, gameHero.Position) >= 30f) attacking = false; attackDir = 1; } } } else { Vector3 dir = Target - Position; if (dir.Length() > 0f) dir.Normalize(); Speed = dir * 0.2f; if (Vector3.Distance(Position, Target) <= 1f) Target = Position + (new Vector3(Helper.AngleToVector(((Rotation + MathHelper.Pi) - MathHelper.PiOver2) + ((float)Helper.Random.NextDouble() * MathHelper.Pi), 100f), 0f)); Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(Position.X, Position.Y) + (new Vector2(Speed.X, Speed.Y) * 50f), Rotation, 1f, 0.5f); base.Update(gameTime, currentRoom, gameHero, doors); } boundingSphere = new BoundingSphere(Position, 3f); for (float z = Position.Z; z < 25f; z += 0.1f) { if (Room.World.GetVoxel(new Vector3(Position.X, Position.Y, z)).Active) { groundHeight = z; break; } } if (hitAlpha > 0f) hitAlpha -= 0.1f; if (Health <= 0f) Die(); }
public Ooze(Vector3 pos, Room room, VoxelSprite sprite) : base(pos, room, sprite) { Type = EnemyType.Ooze; animTargetTime = 500; numFrames = 3; offsetFrame = 1; Target = Position; Health = 50; Rotation = (float)(Helper.Random.NextDouble() * MathHelper.TwoPi); }
public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Room currentRoom, Hero gameHero, bool withPlayer) { // Target = new Vector3(Helper.Random.Next(Room.World.X_SIZE) * Voxel.SIZE, Helper.Random.Next(Room.World.Y_SIZE) * Voxel.SIZE, Position.Z); Target = Position + (new Vector3(Helper.AngleToVector(((Rotation + MathHelper.Pi) - MathHelper.PiOver2) + ((float)Helper.Random.NextDouble() * MathHelper.Pi), 100f), 0f)); //new Vector3(Helper.Random.Next(Room.World.X_SIZE) * Voxel.SIZE, Helper.Random.Next(Room.World.Y_SIZE) * Voxel.SIZE, Position.Z); //Position + (-Speed * 100f); Vector3 dir = Target - Position; if (dir.Length() > 0f) dir.Normalize(); Speed = dir * 0.2f; base.DoCollide(x, y, z, checkPosition, currentRoom, gameHero, withPlayer); }
public void Update(GameTime gameTime, Room currentRoom, Hero gameHero) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) Speed.Z += GRAVITY; CheckCollisions(currentRoom, gameHero); Position += Speed; Color c; switch (Type) { case ProjectileType.Laserbolt: break; case ProjectileType.Rocket: if (gameHero.Position.X < Position.X) Speed.X -= 0.01f; if (gameHero.Position.X > Position.X) Speed.X += 0.01f; if (gameHero.Position.Y < Position.Y) Speed.Y -= 0.01f; if (gameHero.Position.Y > Position.Y) Speed.Y += 0.01f; Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y))); if(Helper.Random.Next(2)==0) c = new Color(new Vector3(1.0f, (float)Helper.Random.NextDouble(), 0.0f)) * (0.7f + ((float)Helper.Random.NextDouble() * 0.3f)); else c = new Color(Vector3.One * (0.5f+((float)Helper.Random.NextDouble()*0.3f))); ParticleController.Instance.Spawn(Position, -(Speed*0.3f) + new Vector3(-0.01f + ((float)Helper.Random.NextDouble() * 0.02f), -0.01f + ((float)Helper.Random.NextDouble() * 0.02f), -0.01f + ((float)Helper.Random.NextDouble() * 0.02f)), 0.4f, c, 100, false); break; case ProjectileType.Gatling: c = new Color(new Vector3(1.0f, (float)Helper.Random.NextDouble(), 0.0f)) * (0.7f + ((float)Helper.Random.NextDouble() * 0.3f)); ParticleController.Instance.Spawn(Position, Vector3.Zero, 0.4f, c, 20, false); break; case ProjectileType.Acid: c = new Color(new Vector3(0f, 1f, 0.0f)) * (0.5f + ((float)Helper.Random.NextDouble() * 0.5f)); if(Helper.Random.Next(2)==1) ParticleController.Instance.Spawn(Position, Vector3.Zero, 0.5f, c, 0, false); break; } if (Time >= Life) { //if (Type == ProjectileType.Grenade || Type == ProjectileType.Rocket) //{ // ParticleController.Instance.SpawnExplosion(Position); // gameWorld.Explode(Position + new Vector3(0,0,-2f), 5f); //} Active = false; } }
public Sentinel(Vector3 pos, Room room, VoxelSprite sprite) : base(pos, room, sprite) { Type = EnemyType.Sentinel; animTargetTime = 100; numFrames = 5; offsetFrame = 1; Target = Position; Rotation = (float)(Helper.Random.NextDouble() * MathHelper.TwoPi); numAttackFrames = 6; }
public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, Room currentRoom) { foreach (Pickup p in Pickups.Where(proj => proj.Active)) { p.Update(gameTime, currentRoom, gameHero); if (gameHero.boundingSphere.Intersects(p.boundingSphere) && p.Room==currentRoom) p.Collect(gameHero); } Pickups.RemoveAll(proj => !proj.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public Head(Vector3 pos, Room room, VoxelSprite sprite) : base(pos, room, sprite) { Type = EnemyType.Head; Position.Z -= 5f; numFrames = 1; offsetFrame = 0; numAttackFrames = 7; Health = 500f; }
public Pickup(PickupType type, Room room, Vector3 pos) { Type = type; Room = room; Position = pos; Rotation = (float)Helper.Random.NextDouble() * MathHelper.TwoPi; Active = true; switch (Type) { case PickupType.Health: numFrames = 3; frameOffset = 8; break; } }
public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Room currentRoom, Hero gameHero, bool withPlayer) { if (withPlayer) { if (!gameHero.DoHit(checkPosition, Speed, 0.5f)) { if (x) Speed.X = (Speed.X * -0.9f); if (y) Speed.Y = (Speed.Y * -0.9f); if (z) Speed.Z = (Speed.Z * -0.9f); } else { if (x) Speed.X = 0f; if (y) Speed.Y = 0f; if (z) Speed.Z = 0f; } } else { if (x) Speed.X = (Speed.X * -0.9f); if (y) Speed.Y = (Speed.Y * -0.9f); if (z) Speed.Z = (Speed.Z * -0.9f); } if (Speed.Length() > 0.2f) { Vector3 worldSpace = VoxelWorld.FromScreenSpace(checkPosition); Voxel v = Room.World.GetVoxel(checkPosition); if (v.Active && Active) { if (v.Destructable == 1) { if (Helper.Random.Next(4) == 1) { Room.World.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); if (Room == currentRoom) ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true); } } //Active = false; } } //base.DoCollide(x, y, z); }
public void Draw(Camera gameCamera, Room currentRoom) { foreach (Pickup p in Pickups.Where(proj => proj.Type == PickupType.Health && proj.Room == currentRoom)) { drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(p.Rotation - MathHelper.PiOver2) * Matrix.CreateScale(1f) * Matrix.CreateTranslation(p.Position); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, pickupStrip.AnimChunks[p.currentFrame + p.frameOffset].VertexArray, 0, pickupStrip.AnimChunks[p.currentFrame + p.frameOffset].VertexArray.Length, pickupStrip.AnimChunks[p.currentFrame + p.frameOffset].IndexArray, 0, pickupStrip.AnimChunks[p.currentFrame + p.frameOffset].VertexArray.Length / 2); } } }
public void Draw(Camera gameCamera, Room currentRoom) { drawEffect.Projection = gameCamera.projectionMatrix; drawEffect.View = gameCamera.viewMatrix; foreach (Bomb b in Bombs.Where(bom=>bom.Room==currentRoom)) { drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(-MathHelper.PiOver2) * Matrix.CreateScale(0.75f) * Matrix.CreateTranslation(b.Position); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, spriteSheet.AnimChunks[1 + b.CurrentFrame].VertexArray, 0, spriteSheet.AnimChunks[1 + b.CurrentFrame].VertexArray.Length, spriteSheet.AnimChunks[1 + b.CurrentFrame].IndexArray, 0, spriteSheet.AnimChunks[1 + b.CurrentFrame].VertexArray.Length / 2); } } }
public void Draw(Camera gameCamera, Room currentRoom) { foreach (Projectile p in Projectiles.Where(proj => proj.Type == ProjectileType.Laserbolt && proj.Room == currentRoom)) { drawEffect.Alpha = 0.5f; drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(-MathHelper.PiOver2) * p.Rotation * Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(p.Position); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, projectileStrip.AnimChunks[1].VertexArray, 0, projectileStrip.AnimChunks[1].VertexArray.Length, projectileStrip.AnimChunks[1].IndexArray, 0, projectileStrip.AnimChunks[1].VertexArray.Length / 2); } drawEffect.Alpha = 1f; } foreach (Projectile p in Projectiles.Where(proj => proj.Type == ProjectileType.Rocket && proj.Room == currentRoom)) { drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(-MathHelper.PiOver2) * p.Rotation * Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(p.Position); foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, projectileStrip.AnimChunks[0].VertexArray, 0, projectileStrip.AnimChunks[0].VertexArray.Length, projectileStrip.AnimChunks[0].IndexArray, 0, projectileStrip.AnimChunks[0].VertexArray.Length / 2); } } }
public void Update(GameTime gameTime, Room currentRoom, Hero gameHero) { if (currentRoom != Room) return; Speed.Z += (0.001f * bobDir); if (Speed.Z > 0.05f) bobDir = -1f; if (Speed.Z < -0.05f) bobDir = 1f; frameTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (frameTime >= frameTargetTime) { frameTime = 0; currentFrame+=frameDir; if (currentFrame == numFrames) { currentFrame -= 2; frameDir = -1; } if (currentFrame == -1) { currentFrame = 1; frameDir = 1; } } Rotation += 0.01f; Position += Speed; boundingSphere = new BoundingSphere(Position, 1f); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); if (generatedPercent >= 100) { MouseState cms = Mouse.GetState(); KeyboardState cks = Keyboard.GetState(); GamePadState cgs = GamePad.GetState(PlayerIndex.One); Vector2 mp2D = Vector2.Clamp(new Vector2(cms.X, cms.Y), Vector2.Zero, new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height)); Vector3 mousePos = Helper.ProjectMousePosition(mp2D, GraphicsDevice.Viewport, gameCamera.worldMatrix, gameCamera.viewMatrix, gameCamera.projectionMatrix, 0f); Vector2 virtualJoystick = Vector2.Zero; if (cks.IsKeyDown(Keys.W) || cks.IsKeyDown(Keys.Up)) virtualJoystick.Y = -1; if (cks.IsKeyDown(Keys.A) || cks.IsKeyDown(Keys.Left)) virtualJoystick.X = -1; if (cks.IsKeyDown(Keys.S) || cks.IsKeyDown(Keys.Down)) virtualJoystick.Y = 1; if (cks.IsKeyDown(Keys.D) || cks.IsKeyDown(Keys.Right)) virtualJoystick.X = 1; if (virtualJoystick.Length() > 0f) virtualJoystick.Normalize(); if (cgs.ThumbSticks.Left.Length() > 0.1f) { virtualJoystick = cgs.ThumbSticks.Left; virtualJoystick.Y = -virtualJoystick.Y; } if(gameHero.introTargetReached) gameHero.Move(virtualJoystick); if ((cks.IsKeyDown(Keys.Space) && !lks.IsKeyDown(Keys.Space)) || (cgs.Buttons.B == ButtonState.Pressed && lgs.Buttons.B != ButtonState.Pressed)) gameHero.TryPlantBomb(currentRoom); if (cks.IsKeyDown(Keys.Z) || cks.IsKeyDown(Keys.Enter) || cgs.Buttons.A == ButtonState.Pressed) gameHero.DoAttack(); if (cks.IsKeyDown(Keys.X) || cks.IsKeyDown(Keys.RightShift) || cgs.Buttons.X == ButtonState.Pressed) gameHero.DoDefend(true, virtualJoystick); else gameHero.DoDefend(false, virtualJoystick); int openCount = 0; foreach (Door d in Doors) if (d.IsOpen) openCount++; if (gameHero.introTargetReached) { #region ROOM STATE SHIT switch (roomState) { case RoomState.DoorsOpening: OpenDoors(); if (openCount > 0) roomState = RoomState.DoorsOpen; doorCountdown = doorCountdownTarget; break; case RoomState.DoorsOpen: if (doorCountdown > 0) { doorCountdown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (doorCountdown <= 0) { roomState = RoomState.DoorsClosing; } } break; case RoomState.DoorsClosing: foreach (Door d in Doors) d.Close(false); if (openCount == 0) { roomMovesLeft = 3 + Helper.Random.Next(5); DoRoomShift(); roomState = RoomState.RoomsShifting; } break; case RoomState.RoomsShifting: foreach (Door d in Doors) d.Close(true); if (roomShift != null) { roomShift.Update(gameTime, gameHero, ref Rooms); if (roomShift.Complete) { if (roomMovesLeft > 0) DoRoomShift(); else roomShift = null; } } if (roomShift == null && roomMovesLeft == 0) { roomState = RoomState.DoorsOpening; } break; } #endregion } else { if (Vector3.Distance(gameHero.Position, gameHero.IntroTarget) < 5f) { exitDoor.Close(false); } } if (gameHero.RoomX == exitRoomX && gameHero.RoomY == exitRoomY) { if (exitDoor.IsOpen) { particleController.Spawn(exitDoor.ParticlePosition, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f)) + exitDoor.ParticleDir * 0.2f, 2f, Color.White * 0.5f, 1000, false); } } if (roomShift != null) gameCamera.Update(gameTime, currentRoom.World, roomShift.cameraShake); else gameCamera.Update(gameTime, currentRoom.World, Vector3.Zero); foreach (Room r in Rooms) if (r.World != null) r.World.Update(gameTime, gameCamera, currentRoom == r); //currentRoom.World.Update(gameTime, gameCamera); gameHero.Update(gameTime, gameCamera, currentRoom, Doors, ref Rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); currentRoom = Rooms[gameHero.RoomX, gameHero.RoomY]; currentRoom.Update(gameTime); enemyController.Update(gameTime, gameCamera, currentRoom, gameHero, Doors); particleController.Update(gameTime, gameCamera, currentRoom.World); pickupController.Update(gameTime, gameCamera, gameHero, currentRoom); projectileController.Update(gameTime, gameCamera, gameHero, currentRoom); bombController.Update(gameTime, currentRoom, gameHero); AudioController.Update(gameTime); foreach (Door d in Doors) d.Update(gameTime); drawEffect.View = gameCamera.viewMatrix; drawEffect.World = gameCamera.worldMatrix; lms = cms; lks = cks; lgs = cgs; if (gameHero.Dead || gameHero.exitReached) { deadTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (deadTime >= 5000) { Reset(); } if (showCompleteAlpha < 1f) showCompleteAlpha += 0.1f; AudioController.StopMusic(); } allRoomsComplete = true; foreach (Room r in Rooms) if (!r.IsComplete) allRoomsComplete = false; if (allRoomsComplete && !shownComplete) { if (gameHero.RoomX == exitRoomX && gameHero.RoomY == exitRoomY && roomState == RoomState.DoorsOpen) exitDoor.Open(false); if(showCompleteAlpha<1f) showCompleteAlpha += 0.1f; showCompleteTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (showCompleteTime > 5000) { shownComplete = true; } } if (shownComplete && showCompleteAlpha > 0f && !gameHero.exitReached) showCompleteAlpha -= 0.1f; //if (gameHero.exitReached && showCompleteAlpha < 1f) showCompleteAlpha += 0.1f; //if (gameHero.exitReached) //{ // dead //} } else { titleFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (titleFrameTime >= 100) { titleFrameTime = 0; titleCurrentFrame++; if (titleCurrentFrame == 4) titleCurrentFrame = 0; } titleScrollPos += Vector2.One; if (titleScrollPos.X == texTitleBG.Width) titleScrollPos = Vector2.Zero; } base.Update(gameTime); }
public virtual void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom, Hero gameHero) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; Vector3 mapBoundsMin = new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); Vector3 mapBoundsMax = new Vector3(world.X_SIZE * Voxel.SIZE, world.Y_SIZE * Voxel.SIZE, world.Z_SIZE) - new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en!=this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;} if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } }
public virtual void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List<Door> doors) { CheckCollisions(currentRoom.World, doors, currentRoom, gameHero); Position += Speed; if (Speed.Length() > 0) { animTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (animTime >= animTargetTime) { animTime = 0; CurrentFrame++; if (CurrentFrame == numFrames) CurrentFrame = 0; } } for (float z = Position.Z; z < 25f;z+=0.1f) { if (Room.World.GetVoxel(new Vector3(Position.X, Position.Y, z)).Active) { groundHeight = z; break; } } boundingSphere = new BoundingSphere(Position, 3f); if (knockbackTime > 0) knockbackTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (Health <= 0f) Die(); }
public virtual void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Room currentRoom, Hero gameHero, bool withPlayer) { if (x) Speed.X = 0; if (y) Speed.Y = 0; if (z) Speed.Z = 0; }
private void ResetDoors(List<Door> doors, ref Room[,] rooms, bool allRoomsComplete, int exitRoomX, int exitRoomY, Door exitDoor) { if (RoomX <= -1) { RoomX = 0; exitReached = true; exitDoor.Close(false); } if (RoomY <= -1) { RoomY = 0; exitReached = true; exitDoor.Close(false); } if (RoomX >= 4) { RoomX = 3; exitReached = true; exitDoor.Close(false); } if (RoomY >= 4) { RoomX = 3; exitReached = true; exitDoor.Close(false); } if (!exitReached) { if (RoomX > 0 && !rooms[RoomX - 1, RoomY].IsGap) doors[3].Open(true); else doors[3].Close(true); if (RoomX < 3 && !rooms[RoomX + 1, RoomY].IsGap) doors[1].Open(true); else doors[1].Close(true); if (RoomY > 0 && !rooms[RoomX, RoomY - 1].IsGap) doors[0].Open(true); else doors[0].Close(true); if (RoomY < 3 && !rooms[RoomX, RoomY + 1].IsGap) doors[2].Open(true); else doors[2].Close(true); if (allRoomsComplete && RoomX == exitRoomX && RoomY == exitRoomY) exitDoor.Open(true); ParticleController.Instance.Reset(); ProjectileController.Instance.Reset(); } }
void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos)==ContainmentType.Contains) Speed.Y = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f,0f,-5f)) == ContainmentType.Contains) Speed.Y = 0f; } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.Y = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.Y = 0f; } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; } } } }
internal void TryPlantBomb(Room currentRoom) { if (Dead || !introTargetReached) return; if (numBombs > 0) { BombController.Instance.Spawn(Position + new Vector3(0f, 0f, -3f), currentRoom); numBombs--; if (bombRespawnTime <= 0) bombRespawnTime = 5000; AudioController.PlaySFX("bomb_place", 1f, 0f, 0f); } }
public void Update(GameTime gameTime, Camera gameCamera, Room currentRoom, List<Door> doors, ref Room[,] rooms, bool allRoomsComplete, int exitRoomX, int exitRoomY, Door exitDoor) { if (Dead) return; Health = MathHelper.Clamp(Health, 0f, MaxHealth); //Health = MaxHealth; Vector2 v2pos = new Vector2(Position.X, Position.Y); Vector2 v2speed = new Vector2(Speed.X, Speed.Y); if (Speed.Length() > 0f) { //if (!defending) Rotation = Helper.TurnToFace(v2pos, v2pos + (v2speed * 50f), Rotation, 1f, 0.5f); } if(introTargetReached) CheckCollisions(currentRoom.World, doors, currentRoom); Position += Speed; v2speed = new Vector2(Speed.X, Speed.Y); if (Speed.Length() > 0f) { frameTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (frameTime >= frameTargetTime) { frameTime = 0; currentFrame++; if (currentFrame == 4) currentFrame = 0; } } if (RoomX == exitRoomX && RoomY == exitRoomY && introTargetReached) { if (Position.X < doors[3].Position.X - 5f && doors[3] == exitDoor) { exitReached = true; } if (Position.X > doors[1].Position.X + 5f && doors[1] == exitDoor) { exitReached = true; } if (Position.Y < doors[0].Position.Y - 5f && doors[0] == exitDoor) { exitReached = true; } if (Position.Y > doors[2].Position.Y + 5f && doors[2] == exitDoor) { exitReached = true; } } if (introTargetReached) { if (Position.X < doors[3].Position.X && !(doors[3] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomX--; Position = doors[1].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); } if (Position.X > doors[1].Position.X && !(doors[1] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomX++; Position = doors[3].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); } if (Position.Y < doors[0].Position.Y && !(doors[0] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomY--; Position = doors[2].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); } if (Position.Y > doors[2].Position.Y && !(doors[2] == exitDoor && RoomX == exitRoomX && RoomY == exitRoomY)) { RoomY++; Position = doors[0].Position + new Vector3(0f, 0f, 4f); ResetDoors(doors, ref rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); } } Vector2 p = Helper.RandomPointInCircle(Helper.PointOnCircle(ref v2pos, 1f, (Rotation - MathHelper.Pi) + 0.1f), 0f, 2f); ParticleController.Instance.Spawn(new Vector3(p, Position.Z-1f), new Vector3(0f, 0f, -0.01f - ((float)Helper.Random.NextDouble() * 0.01f)), 0.5f, Color.Black*0.2f, 2000, false); drawEffect.Projection = gameCamera.projectionMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.World = gameCamera.worldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(Rotation - MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(0, 0, (-(spriteSheet.Z_SIZE * SpriteVoxel.HALF_SIZE)) + SpriteVoxel.HALF_SIZE)) * Matrix.CreateScale(0.9f) * Matrix.CreateTranslation(Position); boundingSphere = new BoundingSphere(Position + new Vector3(0f,0f,-4f), 3f); timeSinceLastHit -= gameTime.ElapsedGameTime.TotalMilliseconds; if (attacking) { attackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (attackTime >= attackTargetTime) { attackTime = 0; attackFrame+=attackDir; if (attackFrame == 1 && attackDir == 1) { bool hit = false; float radiusSweep = 1f; foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { for (float az = 0f; az > -8f; az -= 1f) { for (float a = Rotation - radiusSweep; a < Rotation + radiusSweep; a += 0.02f) { for (float dist = 0f; dist < 5f; dist += 0.2f) { Vector3 attackPos = new Vector3(Helper.PointOnCircle(ref v2pos, dist, Rotation), Position.Z + az); if (e.boundingSphere.Contains(attackPos) == ContainmentType.Contains && !hit) { e.DoHit(attackPos, new Vector3(Helper.AngleToVector(Rotation, 0.01f), 0f), 10f); hit = true; } } } } } } if (attackFrame == 3) { attackDir = -1; attackFrame = 1; } if (attackFrame == -1) { attackFrame = 0; attacking = false; } } } if (hitAlpha > 0f) hitAlpha -= 0.1f; if (Health <= 0f) Die(); bombRespawnTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (bombRespawnTime <= 0 && numBombs < 3) { numBombs++; bombRespawnTime = 5000; if (numBombs == 3) bombRespawnTime = 0; } if (!introTargetReached) { if (IntroTarget.X < Position.X) Move(new Vector2(-0.3f, 0f)); if (IntroTarget.X > Position.X) Move(new Vector2(0.3f, 0f)); if (IntroTarget.Y < Position.Y) Move(new Vector2(0f,-0.3f)); if (IntroTarget.Y > Position.Y) Move(new Vector2(0f,0.3f)); if(Vector3.Distance(IntroTarget, Position)<1f) introTargetReached = true; } }
public Bomb(Vector3 pos, Room room) { Position = pos; Room = room; }
void CreateRoomsAsync() { int gapRoomX = Helper.Random.Next(4); int gapRoomY = Helper.Random.Next(4); float roomPercent = 100f / 16f; for (int x = 0; x < 4; x++) for (int y = 0; y < 4; y++) { if (!(x == gapRoomX && y == gapRoomY)) { Rooms[x, y] = new Room(tileSheet, objectSheet, false); } else Rooms[x, y] = new Room(tileSheet, objectSheet, true); generatedPercent += (int)roomPercent; } // make exit bool made = false; while (!made) { int side = Helper.Random.Next(4); switch (side) { case 0: exitRoomX = Helper.Random.Next(4); exitRoomY = -1; if (!Rooms[exitRoomX, exitRoomY + 1].IsGap) made = true; break; case 1: exitRoomY = Helper.Random.Next(4); exitRoomX = 4; if (!Rooms[exitRoomX - 1, exitRoomY].IsGap) made = true; break; case 2: exitRoomX = Helper.Random.Next(4); exitRoomY = 4; if (!Rooms[exitRoomX, exitRoomY - 1].IsGap) made = true; break; case 3: exitRoomY = Helper.Random.Next(4); exitRoomX = -1; if (!Rooms[exitRoomX + 1, exitRoomY].IsGap) made = true; break; } } gameHero.RoomX = exitRoomX;// = new Hero(exitRoomX, exitRoomY, new Vector3(0, 0, 0)); gameHero.RoomY = exitRoomY; //VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE,Voxel.HALF_SIZE,Voxel.HALF_SIZE), 0, doorSheet)); ///VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet)); //VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet)); //VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet)); if (gameHero.RoomX == -1) { gameHero.RoomX = 0; exitRoomX = 0; gameHero.IntroTarget = Doors[3].Position + new Vector3(7f, 0f, 4f); gameHero.Position = Doors[3].Position + new Vector3(-7f, 0f, 4f); gameHero.Rotation = 0f; Doors[3].Open(true); exitDoor = Doors[3]; } if (gameHero.RoomX == 4) { gameHero.RoomX = 3; exitRoomX = 3; gameHero.IntroTarget = Doors[1].Position + new Vector3(-7f, 0f, 4f); gameHero.Position = Doors[1].Position + new Vector3(7f, 0f, 4f); gameHero.Rotation = -MathHelper.Pi; Doors[1].Open(true); exitDoor = Doors[1]; } if (gameHero.RoomY == -1) { gameHero.RoomY = 0; exitRoomY = 0; gameHero.IntroTarget = Doors[0].Position + new Vector3(0f, 7f, 4f); gameHero.Position = Doors[0].Position + new Vector3(0f, -7f, 4f); gameHero.Rotation = MathHelper.PiOver2; Doors[0].Open(true); exitDoor = Doors[0]; } if (gameHero.RoomY == 4) { gameHero.RoomY = 3; exitRoomY = 3; gameHero.IntroTarget = Doors[2].Position + new Vector3(0f, -7f, 4f); gameHero.Position = Doors[2].Position + new Vector3(0f, 7f, 4f); gameHero.Rotation = -MathHelper.PiOver2; Doors[2].Open(true); exitDoor = Doors[2]; } currentRoom = Rooms[gameHero.RoomX, gameHero.RoomY]; enemyController.Enemies.RemoveAll(en => en.Room == currentRoom); gameCamera.Position = new Vector3((currentRoom.World.X_SIZE * Voxel.SIZE) / 2, (currentRoom.World.Y_SIZE * Voxel.SIZE) / 2, 0f); gameCamera.Target = new Vector3((currentRoom.World.X_SIZE * Voxel.SIZE) / 2, (currentRoom.World.Y_SIZE * Voxel.SIZE) / 2, 0f); generatedPercent = 100; OpenDoors(); AudioController.PlayMusic("0"); }
void CheckCollisions(Room currentRoom, Hero gameHero) { Vector3 worldSpace; switch (Type) { case ProjectileType.Laserbolt: case ProjectileType.Gatling: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d*((Position+Speed)-Position))); if (v.Active && Active) { if (v.Destructable == 1) { Room.World.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); if(Room == currentRoom) for (int i = 0; i < 4; i++) ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true); } Active = false; } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 2f)) { Speed = -Speed; float rot = Helper.V2ToAngle(new Vector2(Speed.X,Speed.Y)); if(Type== ProjectileType.Gatling) rot = (rot-0.2f) + ((float)Helper.Random.NextDouble() * 0.4f); Speed = new Vector3(Helper.AngleToVector(rot, 1f),0f); Deflected = true; Rotation = Matrix.CreateRotationZ(rot); AudioController.PlaySFX(Type== ProjectileType.Laserbolt?"deflect":"gatling_deflect", Type== ProjectileType.Laserbolt?0.5f:1f, -0.1f, 0.1f); } else Active = false; } if (Deflected) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f); Active = false; } } } break; case ProjectileType.Rocket: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) ParticleController.Instance.SpawnExplosion(Position); gameHero.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); if (Deflected) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { e.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) ParticleController.Instance.SpawnExplosion(Position); } } Active = false; AudioController.PlaySFX("explosion2",1f, -0.1f, 0.1f); } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 0f)) { Speed = -Speed; Deflected = true; Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y))); AudioController.PlaySFX("deflect", 0.5f, -0.1f, 0.1f); } else { gameHero.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) ParticleController.Instance.SpawnExplosion(Position); Active = false; AudioController.PlaySFX("explosion2", 1f, -0.1f, 0.1f); } } if (Deflected) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) ParticleController.Instance.SpawnExplosion(Position); Active = false; AudioController.PlaySFX("explosion2", 1f, -0.1f, 0.1f); } } } break; case ProjectileType.Acid: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 2f, Room == currentRoom); for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.5f, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.5f), 0f), 1000, true); } Active = false; AudioController.PlaySFX("acid_hit", 1f, -0.1f, 0.1f); } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f)) { Speed = -Speed; float rot = Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y)); if (Type == ProjectileType.Gatling) rot = (rot - 0.2f) + ((float)Helper.Random.NextDouble() * 0.4f); Speed = new Vector3(Helper.AngleToVector(rot, 0.2f), Speed.Z); Deflected = true; Rotation = Matrix.CreateRotationZ(rot); } else { Active = false; AudioController.PlaySFX("acid_hit", 1f, -0.1f, 0.1f); for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.5f, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.5f), 0f), 1000, true); } } } //if (Deflected) // foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) // { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f); Active = false; } } } break; //case ProjectileType.Grenade: // float checkRadius = 1f; // float radiusSweep = 0.5f; // Vector2 v2Pos = new Vector2(Position.X,Position.Y); // Voxel checkVoxel; // Vector3 checkPos; // if (Speed.Z > 0f) // { // for (float z = 0f; z < 2f; z+=1f) // { // Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f, 0f, z)); // if (v.Active && gameWorld.CanCollideWith(v.Type)) Speed = new Vector3(Speed.X * 0.6f, Speed.Y * 0.6f, -(Speed.Z / 2f)); // } // } // if (Speed.Y < 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.Y = 0f; // } // } // } // } // if (Speed.Y > 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.Y = 0f; // } // } // } // } // if (Speed.X < 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.X = 0f; // } // } // } // } // if (Speed.X > 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.X = 0f; // } // } // } // } // break; } }