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 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 void Collect(Hero gameHero) { switch (Type) { case PickupType.Health: gameHero.Health += 100f; AudioController.PlaySFX("collect_health", 1f, 0f, 0f); break; } Active = false; }
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 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 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, 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 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 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); }
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; }
public void Update(GameTime gameTime, Room currentRoom, Hero gameHero) { foreach (Bomb b in Bombs) b.Update(gameTime, currentRoom, gameHero); Bombs.RemoveAll(bom => !bom.Active); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { generatedPercent = 0; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); if (firstRun) { AudioController.LoadContent(Content); tileSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tileSheet); doorSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "door.vxs"), ref doorSheet); objectSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "dynamic.vxs"), ref objectSheet); } else if (AudioController.instances["roomscrape"].State == SoundState.Playing) AudioController.instances["roomscrape"].Pause(); gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport); particleController = new ParticleController(GraphicsDevice); projectileController = new ProjectileController(GraphicsDevice); pickupController = new PickupController(GraphicsDevice); bombController = new BombController(GraphicsDevice, objectSheet); enemyController = new EnemyController(GraphicsDevice); projectileController.LoadContent(Content); pickupController.LoadContent(Content); enemyController.LoadContent(Content); drawEffect = new BasicEffect(GraphicsDevice) { World = gameCamera.worldMatrix, View = gameCamera.viewMatrix, Projection = gameCamera.projectionMatrix, VertexColorEnabled = true, }; gameHero = new Hero(0, 0, Vector3.Zero, Vector3.Zero); gameHero.LoadContent(Content, GraphicsDevice); ThreadPool.QueueUserWorkItem(delegate { CreateRoomsAsync(); }); doorCountdown = 10000; roomMovesLeft = 0; roomShift = null; roomState = RoomState.DoorsOpen; deadTime = 0; allRoomsComplete = false; shownComplete = false; showCompleteTime = 0; showCompleteAlpha = 0f; Doors.Clear(); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE,Voxel.HALF_SIZE,Voxel.HALF_SIZE), 0, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet)); if (firstRun) { roomIcon = Content.Load<Texture2D>("roomicon"); texHud = Content.Load<Texture2D>("hud"); texTitle = Content.Load<Texture2D>("titlesheet"); texTitleBG = Content.Load<Texture2D>("title-bg"); texStingers = Content.Load<Texture2D>("stingers"); font = Content.Load<SpriteFont>("font"); timerFontLarge = Content.Load<SpriteFont>("timerfont-large"); timerFontSmall = Content.Load<SpriteFont>("timerfont-small"); } firstRun = false; }
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; } }
public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, Room currentRoom) { foreach (Projectile p in Projectiles.Where(proj => proj.Active)) { p.Update(gameTime, currentRoom, gameHero); } Projectiles.RemoveAll(proj => !proj.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List<Door> doors) { if (currentRoom != Room) return; 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; CheckCollisions(currentRoom.World, doors, currentRoom, gameHero); Position += Speed; Speed.Z += (0.01f * bobDir); if (Speed.Z > 0.2f) bobDir = -1f; if (Speed.Z < -0.2f) bobDir = 1f; 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, 2f); if (knockbackTime > 0) knockbackTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (hitAlpha > 0f) hitAlpha -= 0.1f; if (Health <= 0f) Die(); }
public void Update(GameTime gameTime, Camera gameCamera, Room currentRoom, Hero gameHero, List<Door> doors) { for(int i=Enemies.Count-1;i>=0;i--) Enemies[i].Update(gameTime, currentRoom, gameHero, doors); Enemies.RemoveAll(en => !en.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { generatedPercent = 0; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); if (firstRun) { AudioController.LoadContent(Content); tileSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tileSheet); doorSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "door.vxs"), ref doorSheet); objectSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "dynamic.vxs"), ref objectSheet); } else if (AudioController.instances["roomscrape"].State == SoundState.Playing) { AudioController.instances["roomscrape"].Pause(); } gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport); particleController = new ParticleController(GraphicsDevice); projectileController = new ProjectileController(GraphicsDevice); pickupController = new PickupController(GraphicsDevice); bombController = new BombController(GraphicsDevice, objectSheet); enemyController = new EnemyController(GraphicsDevice); projectileController.LoadContent(Content); pickupController.LoadContent(Content); enemyController.LoadContent(Content); drawEffect = new BasicEffect(GraphicsDevice) { World = gameCamera.worldMatrix, View = gameCamera.viewMatrix, Projection = gameCamera.projectionMatrix, VertexColorEnabled = true, }; gameHero = new Hero(0, 0, Vector3.Zero, Vector3.Zero); gameHero.LoadContent(Content, GraphicsDevice); ThreadPool.QueueUserWorkItem(delegate { CreateRoomsAsync(); }); doorCountdown = 10000; roomMovesLeft = 0; roomShift = null; roomState = RoomState.DoorsOpen; deadTime = 0; allRoomsComplete = false; shownComplete = false; showCompleteTime = 0; showCompleteAlpha = 0f; Doors.Clear(); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 0, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet)); if (firstRun) { roomIcon = Content.Load <Texture2D>("roomicon"); texHud = Content.Load <Texture2D>("hud"); texTitle = Content.Load <Texture2D>("titlesheet"); texTitleBG = Content.Load <Texture2D>("title-bg"); texStingers = Content.Load <Texture2D>("stingers"); font = Content.Load <SpriteFont>("font"); timerFontLarge = Content.Load <SpriteFont>("timerfont-large"); timerFontSmall = Content.Load <SpriteFont>("timerfont-small"); } firstRun = false; }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List<Door> doors) { if (currentRoom != Room) return; Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), Rotation, 1f, 0.5f); Speed.Z += (0.001f * bobDir); if (Speed.Z > 0.05f) bobDir = -1f; if (Speed.Z < -0.05f) bobDir = 1f; Position += Speed; 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; } } //base.Update(gameTime, currentRoom, gameHero, doors); boundingSphere = new BoundingSphere(Position, 4f); if (!attacking && Helper.Random.Next(300) == 1) { attacking = true; attackDir = 1; attackMode = Helper.Random.Next(2); AudioController.PlaySFX("face_open", 1f, 0f, 0f); } if (attacking) { if (attackMode == 0) offsetFrame = 0; if (attackMode == 1) offsetFrame = 7; attackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (attackTime >= attackTargetTime) { attackTime = 0; if((attackDir==1 && attackFrame<numAttackFrames-1) || attackDir==-1) attackFrame += attackDir; } if (attackFrame == numAttackFrames-1 && attackDir == 1) { switch (attackMode) { case 0: missileDelay += gameTime.ElapsedGameTime.TotalMilliseconds; if (missileDelay >= 500) { missileDelay = 0; float rot = (Rotation - 0.5f) + ((float)Helper.Random.NextDouble() * 1f); ProjectileController.Instance.Spawn(ProjectileType.Rocket, Room, Position + new Vector3(0f,0f,-2f), Matrix.CreateRotationZ(rot), new Vector3(Helper.AngleToVector(rot, 0.5f), 0.2f), 7000, false); missilesLaunched++; AudioController.PlaySFX("face_missile", 1f, 0f, 0f); } if (missilesLaunched == 3) { attackDir = -1; missilesLaunched = 0; } break; case 1: if (!gunSoundPlayed) { AudioController.PlaySFX("face_gun", 1f, 0f, 0f); gunSoundPlayed = true; } missileDelay += gameTime.ElapsedGameTime.TotalMilliseconds; if (missileDelay >= 50) { missileDelay = 0; float rot = (Rotation - 0.1f) + ((float)Helper.Random.NextDouble() * 0.2f); ProjectileController.Instance.Spawn(ProjectileType.Gatling, Room, Position + new Vector3(0f, 0f, 2f), Matrix.CreateRotationZ(rot), new Vector3(Helper.AngleToVector(rot, 1f), 0.1f), 5000, false); missilesLaunched++; } if (missilesLaunched == 20) { attackDir = -1; missilesLaunched = 0; } break; } } if (attackFrame == -1) { attackFrame = 0; attacking = false; offsetFrame = 0; attackDir = 1; gunSoundPlayed = false; } } if (hitAlpha > 0f) hitAlpha -= 0.1f; if (Health <= 0f) Die(); }