public void UpdateStarField(GameTime gameTime, VoxelWorld gameWorld, float scrollSpeed) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) { Speed.Z += GRAVITY; if (Speed.Z > 0f) { Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f,0f,Scale)); if (v.Active && gameWorld.CanCollideWith(v.Type)) Speed = new Vector3(Speed.X/2,Speed.Y/2,-(Speed.Z / 2f)); } Speed.Z = (float)Math.Round(Speed.Z, 3); } Position += Speed * scrollSpeed; if (Position.Z > 20f) Active = false; if (Time >= Life && scrollSpeed>0f) { Scale -= 0.01f; if(Scale<=0f) Active = false; } }
public void UpdateStarField(GameTime gameTime, VoxelWorld gameWorld, float scrollSpeed) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) { Speed.Z += GRAVITY; if (Speed.Z > 0f) { Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f, 0f, Scale)); if (v.Active && gameWorld.CanCollideWith(v.Type)) { Speed = new Vector3(Speed.X / 2, Speed.Y / 2, -(Speed.Z / 2f)); } } Speed.Z = (float)Math.Round(Speed.Z, 3); } Position += Speed * scrollSpeed; if (Position.Z > 20f) { Active = false; } if (Time >= Life && scrollSpeed > 0f) { Scale -= 0.01f; if (Scale <= 0f) { Active = false; } } }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld) { foreach (Particle p in Particles.Where(part => part.Active)) { p.Update(gameTime, gameWorld); } updateTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (updateTime >= updateTargetTime) { updateTime = 0; parts = 0; foreach (Particle p in Particles.Where(part => part.Active)) { ParticleCube.Create(ref verts, ref indexes, p.Position, parts, p.Scale / 2, p.Color); parts++; } } currentParticleCount = Particles.Count(part => part.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, float scrollSpeed) { foreach (Particle p in Particles.Where(part => part.Active)) { p.UpdateStarField(gameTime, gameWorld, scrollSpeed); } updateTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (updateTime >= updateTargetTime) { updateTime = 0; parts = 0; foreach (Particle p in Particles.Where(part => part.Active)) { ParticleCube.Create(ref verts, ref indexes, p.Position, parts, p.Scale / 2, p.Color); parts++; } } currentParticleCount = Particles.Count(part => part.Active); //drawEffect.World = Matrix.Identity; //drawEffect.View = gameCamera.viewMatrix; //drawEffect.Projection = gameCamera.projectionMatrix; }
public virtual void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { CheckCollisions(gameWorld, gameHero); Position += Speed; animTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (animTime >= animTargetTime) { animTime = 0; CurrentFrame++; if (CurrentFrame == numFrames) { CurrentFrame = 0; } } boundingSphere = new BoundingSphere(Position, 3f); if (hitAlpha > 0f) { hitAlpha -= 0.1f; } if (Health <= 0f) { Die(); } currentAttackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (currentAttackTime >= attackRate) { DoAttack(); } }
public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer) { gameWorld.Explode(checkPosition, 5f); Die(); base.DoCollide(x, y, z, checkPosition, gameHero, gameWorld, withPlayer); }
public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { Rotation += rotSpeed; if(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false); base.Update(gameTime, gameWorld, gameHero); }
public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { barrelRot = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), barrelRot, 1f, 0.1f); barrelRot = Inverted ? MathHelper.Clamp(barrelRot, 0.5f, MathHelper.Pi - 0.5f) : MathHelper.Clamp(barrelRot, -MathHelper.Pi + 0.5f, -0.5f); //f(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false); base.Update(gameTime, gameWorld, gameHero); }
public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { barrelRot = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), barrelRot, 1f, 0.1f); barrelRot = Inverted ? MathHelper.Clamp(barrelRot, 0.5f, MathHelper.Pi-0.5f) : MathHelper.Clamp(barrelRot, -MathHelper.Pi + 0.5f, -0.5f); //f(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false); base.Update(gameTime, gameWorld, gameHero); }
public void Update(GameTime gameTime, Hero gameHero, VoxelWorld gameWorld, float scrollPos) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) Speed.Z += GRAVITY; CheckCollisions(gameHero, gameWorld); Position += Speed; if (Owner is Hero && Position.X > scrollPos + 75f) Active = false; Color c; switch (Type) { case ProjectileType.Rocket: foreach(Enemy e in EnemyController.Instance.Enemies.OrderBy(en => Vector3.Distance(en.Position,Position))) { if (e.Position.X < scrollPos - 75f || !e.Active) continue; target = e; break; } if(target!=null) { if (target.Position.X > Position.X) Speed.X += 0.03f; if (target.Position.X < Position.X) Speed.X -= 0.03f; if (target.Position.Y > Position.Y) Speed.Y += 0.03f; if (target.Position.Y < Position.Y) Speed.Y -= 0.03f; Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y))); Speed = Vector3.Clamp(Speed, new Vector3(-1f, -1f, 0f), new Vector3(1f, 1f, 0f)); } if (Helper.Random.Next(5) == 1) ParticleController.Instance.Spawn(Position + new Vector3(Helper.RandomFloat(-0.1f,1f),Helper.RandomFloat(-0.1f,1f),0f) , Vector3.Zero, 0.3f, new Color(new Vector3(1f, Helper.RandomFloat(0f, 1.0f), 0f) * Helper.RandomFloat(0.5f, 1.0f)), 1000, false); break; } if (Time >= Life) { if (Type == ProjectileType.Rocket) { ParticleController.Instance.SpawnExplosion(Position); } Active = false; } }
public override void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { Rotation += rotSpeed; //if(Helper.Random.Next(10)==1) ParticleController.Instance.Spawn(new Vector3(Helper.RandomPointInCircle(new Vector2(Position.X, Position.Y), 0f, 4f), Position.Z), Vector3.Zero, 0.3f, new Color(Color.Gray.ToVector3() * Helper.RandomFloat(0.4f, 0.8f)), 1000, false); boundingSphere = new BoundingSphere(Position, 5f); base.Update(gameTime, gameWorld, gameHero); }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, float scrollSpeed) { Vector2 v2Pos = new Vector2(Position.X, Position.Y); tempSpeed = Speed; tempSpeed.X += scrollSpeed; CollisionBox.Min = Position - (collisionBoxSize / 2); CollisionBox.Max = Position + (collisionBoxSize / 2); CheckCollisions(gameWorld, gameCamera); Position += tempSpeed; if (Helper.Random.Next(3) == 1) { ParticleController.Instance.Spawn(Position + new Vector3(-4f, 0f, 0f), new Vector3(Helper.RandomFloat(-0.5f, -0.3f), Helper.RandomFloat(-0.05f, 0.05f), 0f), 0.3f, new Color(new Vector3(1f, Helper.RandomFloat(0f, 1.0f), 0f) * Helper.RandomFloat(0.5f, 1.0f)), 1000, false); } fireCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds; rocketCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (hitAlpha > 0f) { hitAlpha -= 0.1f; } if (orbActive) { orbAngle += 0.1f; orbPosition = new Vector3(Helper.PointOnCircle(ref v2Pos, 15f, orbAngle), Position.Z); orbRotation += new Vector3(0.1f, -0.01f, 0.025f); foreach (Enemy e in EnemyController.Instance.Enemies) { if (e.boundingSphere.Contains(new BoundingSphere(orbPosition, 1.5f)) == ContainmentType.Intersects) { e.DoHit(orbPosition, Vector3.Zero, 3f); } } } CheckLevelUp(); drawEffect.Projection = gameCamera.projectionMatrix; drawEffect.View = gameCamera.viewMatrix; }
public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, VoxelWorld gameWorld, float scrollPos) { foreach (Projectile p in Projectiles.Where(proj => proj.Active)) { p.Update(gameTime, gameHero, gameWorld, scrollPos); } Projectiles.RemoveAll(proj => !proj.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero, float scrollPos) { Position += Speed; if(Position.X < scrollPos - 75f) Active = false; if (Vector3.Distance(gameHero.Position, Position) < 25f) Position = Vector3.Lerp(Position, gameHero.Position, 0.05f); if (Vector3.Distance(gameHero.Position, Position) < 10f) Position = Vector3.Lerp(Position, gameHero.Position, 0.1f); if(Vector3.Distance(gameHero.Position, Position) < 3f) { gameHero.XP += 0.15f; Active = false; } }
public void Update(GameTime gameTime, VoxelWorld gameWorld) { //Offset = new Vector3(0, 60, -50);// -(new Vector3(0, Position.Z, -Position.Z) * 0.3f); //Offset = new Vector3(0, 20, -10);// - (new Vector3(0,Position.Z,-Position.Z) * 0.3f); //Position = Vector3.Clamp(Position, gameWorld.ToScreenSpace(140, 115, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE - 140, gameWorld.Y_SIZE - 90, 20)); //Position = Vector3.Clamp(Position, new Vector3(70, 60, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE, gameWorld.Y_SIZE, 0) - new Vector3(100, 60, 50)); //Target = Vector3.Clamp(Target, gameWorld.ToScreenSpace(140, 115, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE - 140, gameWorld.Y_SIZE - 90, 20)); Position = Vector3.Lerp(Position, Target, moveSpeed); //worldMatrix = Matrix.CreateWorld(-Position, Vector3.Forward, Vector3.Up); viewMatrix = Matrix.CreateLookAt(Position + Offset, Position, Vector3.Down); //viewMatrix = Matrix.CreateLookAt(Position + Offset, Position + new Vector3(0, 0, 0), Vector3.Down); boundingFrustum.Matrix = viewMatrix * projectionMatrix; }
public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, VoxelWorld gameWorld, float scrollPos, float scrollSpeed) { for (int i = Spawns.Count - 1; i >= 0; i--) { if (gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 5).X < (int)scrollPos + 75) { if (Spawns[i].Properties.Contains("IsWave")) { Wave w; switch (Spawns[i].Properties["IsWave"]) { case "Line": w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Line, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties); break; default: w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Circle, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties); break; } Waves.Add(w); } else { Spawn((EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), Spawns[i].Properties); } Spawns.RemoveAt(i); } } for (int i = Enemies.Count - 1; i >= 0; i--) { Enemies[i].Update(gameTime, gameWorld, gameHero); } Enemies.RemoveAll(en => !en.Active || en.Position.X < scrollPos - 110f); foreach (Wave w in Waves) { w.Update(gameTime, scrollSpeed); } 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() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("font"); hudTex = Content.Load<Texture2D>("hud"); tilesSprite = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tilesSprite); gameMap = Content.Load<Map>("1"); tileLayer = (TileLayer)gameMap.GetLayer("tiles"); MapObjectLayer spawnLayer = (MapObjectLayer)gameMap.GetLayer("spawns"); gameWorld = new VoxelWorld(gameMap.Width, 11, 1); for(int yy=0;yy<11;yy++) for(int xx=0;xx<12;xx++) if(tileLayer.Tiles[xx,yy]!=null) gameWorld.CopySprite(xx*Chunk.X_SIZE, yy*Chunk.Y_SIZE, 0, tilesSprite.AnimChunks[tileLayer.Tiles[xx,yy].Index-1]); scrollColumn = 12; gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport); gameCamera.Position = new Vector3(0f, gameWorld.Y_SIZE * Voxel.HALF_SIZE, 0f); gameCamera.Target = gameCamera.Position; gameHero = new Hero(); gameHero.LoadContent(Content, GraphicsDevice); enemyController = new EnemyController(GraphicsDevice); enemyController.LoadContent(Content, spawnLayer); projectileController = new ProjectileController(GraphicsDevice); projectileController.LoadContent(Content); particleController = new ParticleController(GraphicsDevice); powerupController = new PowerupController(GraphicsDevice); powerupController.LoadContent(Content); gameStarfield = new Starfield(GraphicsDevice); drawEffect = new BasicEffect(GraphicsDevice) { World = gameCamera.worldMatrix, View = gameCamera.viewMatrix, Projection = gameCamera.projectionMatrix, VertexColorEnabled = true, }; }
public Chunk(VoxelWorld world, int wx, int wy, int wz, bool createGround) { parentWorld = world; worldX = wx; worldY = wy; worldZ = wz; boundingSphere = new BoundingSphere(new Vector3(worldX * (X_SIZE * Voxel.SIZE), worldY * (Y_SIZE * Voxel.SIZE), worldZ * (Z_SIZE * Voxel.SIZE)) + (new Vector3(X_SIZE * Voxel.SIZE, Y_SIZE * Voxel.SIZE, Z_SIZE * Voxel.SIZE) / 2f), (X_SIZE * Voxel.SIZE)); if (createGround) { for (int y = 0; y < Y_SIZE; y++) for (int x = 0; x < X_SIZE; x++) { for (int z = Chunk.Z_SIZE - 1; z >= Chunk.Z_SIZE - 5; z--) { SetVoxel(x, y, z, true, 0, VoxelType.Ground, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.1f), 0f), new Color(0f, 0.3f, 0f)); } } } }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, Hero gameHero, float scrollPos) { foreach (Powerup p in Powerups.Where(part => part.Active)) { p.Update(gameTime, gameWorld, gameHero, scrollPos); } updateTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (updateTime >= updateTargetTime) { updateTime = 0; parts = 0; foreach (Powerup p in Powerups.Where(part => part.Active)) { Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 0f) * 1f; Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 0f) * 1f; Vector3 topRightFront = new Vector3(1.0f, 1.0f, 0f) * 1f; Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 0f) * 1f; verts[(parts * 4) + 0] = new VertexPositionNormalTexture(p.Position + topLeftFront, Vector3.Normalize(topLeftFront), new Vector2(0, 0)); verts[(parts * 4) + 1] = new VertexPositionNormalTexture(p.Position + bottomLeftFront, Vector3.Normalize(bottomLeftFront), new Vector2(0, 1)); verts[(parts * 4) + 2] = new VertexPositionNormalTexture(p.Position + topRightFront, Vector3.Normalize(topRightFront), new Vector2(1, 0)); verts[(parts * 4) + 3] = new VertexPositionNormalTexture(p.Position + bottomRightFront, Vector3.Normalize(bottomRightFront), new Vector2(1, 1)); for (int i = 0; i < 6; i++) { indexes[(parts * 6) + i] = (short)((parts * 4) + faceIndices[i]); } parts += 1; } } currentPowerupCount = Powerups.Count(part => part.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public Chunk(VoxelWorld world, int wx, int wy, int wz, bool createGround) { parentWorld = world; worldX = wx; worldY = wy; worldZ = wz; boundingSphere = new BoundingSphere(new Vector3(worldX * (X_SIZE * Voxel.SIZE), worldY * (Y_SIZE * Voxel.SIZE), worldZ * (Z_SIZE * Voxel.SIZE)) + (new Vector3(X_SIZE * Voxel.SIZE, Y_SIZE * Voxel.SIZE, Z_SIZE * Voxel.SIZE) / 2f), (X_SIZE * Voxel.SIZE)); if (createGround) { for (int y = 0; y < Y_SIZE; y++) { for (int x = 0; x < X_SIZE; x++) { for (int z = Chunk.Z_SIZE - 1; z >= Chunk.Z_SIZE - 5; z--) { SetVoxel(x, y, z, true, 0, VoxelType.Ground, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.1f), 0f), new Color(0f, 0.3f, 0f)); } } } } }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, Hero gameHero, float scrollPos) { foreach (Powerup p in Powerups.Where(part => part.Active)) { p.Update(gameTime, gameWorld, gameHero, scrollPos); } updateTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (updateTime >= updateTargetTime) { updateTime = 0; parts = 0; foreach (Powerup p in Powerups.Where(part => part.Active)) { Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 0f) * 1f; Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 0f) * 1f; Vector3 topRightFront = new Vector3(1.0f, 1.0f, 0f) * 1f; Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 0f) * 1f; verts[(parts * 4) + 0] = new VertexPositionNormalTexture(p.Position + topLeftFront, Vector3.Normalize(topLeftFront), new Vector2(0, 0)); verts[(parts * 4) + 1] = new VertexPositionNormalTexture(p.Position + bottomLeftFront, Vector3.Normalize(bottomLeftFront), new Vector2(0, 1)); verts[(parts * 4) + 2] = new VertexPositionNormalTexture(p.Position + topRightFront, Vector3.Normalize(topRightFront), new Vector2(1, 0)); verts[(parts * 4) + 3] = new VertexPositionNormalTexture(p.Position + bottomRightFront, Vector3.Normalize(bottomRightFront), new Vector2(1, 1)); for (int i = 0; i < 6; i++) indexes[(parts * 6) + i] = (short)((parts * 4) + faceIndices[i]); parts+=1; } } currentPowerupCount = Powerups.Count(part => part.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero, float scrollPos) { Position += Speed; if (Position.X < scrollPos - 75f) { Active = false; } if (Vector3.Distance(gameHero.Position, Position) < 25f) { Position = Vector3.Lerp(Position, gameHero.Position, 0.05f); } if (Vector3.Distance(gameHero.Position, Position) < 10f) { Position = Vector3.Lerp(Position, gameHero.Position, 0.1f); } if (Vector3.Distance(gameHero.Position, Position) < 3f) { gameHero.XP += 0.15f; Active = false; } }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld, float scrollSpeed) { Vector2 v2Pos= new Vector2(Position.X,Position.Y); tempSpeed = Speed; tempSpeed.X += scrollSpeed; CollisionBox.Min = Position - (collisionBoxSize/2); CollisionBox.Max = Position + (collisionBoxSize/2); CheckCollisions(gameWorld, gameCamera); Position += tempSpeed; if(Helper.Random.Next(3)==1) ParticleController.Instance.Spawn(Position + new Vector3(-4f, 0f, 0f), new Vector3(Helper.RandomFloat(-0.5f, -0.3f), Helper.RandomFloat(-0.05f, 0.05f), 0f), 0.3f, new Color(new Vector3(1f, Helper.RandomFloat(0f, 1.0f), 0f) * Helper.RandomFloat(0.5f, 1.0f)), 1000, false); fireCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds; rocketCooldown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (hitAlpha > 0f) hitAlpha -= 0.1f; if (orbActive) { orbAngle += 0.1f; orbPosition = new Vector3(Helper.PointOnCircle(ref v2Pos, 15f, orbAngle), Position.Z); orbRotation += new Vector3(0.1f, -0.01f, 0.025f); foreach(Enemy e in EnemyController.Instance.Enemies) { if (e.boundingSphere.Contains(new BoundingSphere(orbPosition,1.5f)) == ContainmentType.Intersects) { e.DoHit(orbPosition, Vector3.Zero, 3f); } } } CheckLevelUp(); drawEffect.Projection = gameCamera.projectionMatrix; drawEffect.View = gameCamera.viewMatrix; }
void CheckCollisions(VoxelWorld world, Camera gameCamera) { float checkRadius = 3.5f; float radiusSweep = 0.1f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (tempSpeed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y/2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0; } } if (tempSpeed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0; } } if (tempSpeed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } if (tempSpeed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } }
void CheckCollisions(Hero gameHero, VoxelWorld gameWorld) { Vector3 worldSpace; switch (Type) { case ProjectileType.Laser1: case ProjectileType.Laser2: case ProjectileType.Laser3: case ProjectileType.Laser4: case ProjectileType.Rocket: for (float d = 0f; d < 1f; d += 0.1f) { if (!Active) continue; worldSpace = gameWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = gameWorld.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { if (v.Destructable >= 1 && Owner is Hero) { gameWorld.Explode(Position + (d * ((Position + Speed) - Position)), Type!= ProjectileType.Rocket?3f:5f); gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, -3f), Type != ProjectileType.Rocket ? 3f : 5f); gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, 3f), Type != ProjectileType.Rocket ? 3f : 5f); //gameWorld.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); //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(Owner is Enemy) if (!gameHero.Dead && gameHero.CollisionBox.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), this); Active = false; if(Type== ProjectileType.Rocket) ParticleController.Instance.SpawnExplosion(Position); } if(Owner is Hero) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Active)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, Damage); Active = false; if (Type == ProjectileType.Rocket) ParticleController.Instance.SpawnExplosion(Position); } } } break; } }
public virtual void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer) { if (x) { Speed.X = 0; } if (y) { Speed.Y = 0; } if (z) { Speed.Z = 0; } }
void CheckCollisions(VoxelWorld world, Camera gameCamera) { float checkRadius = 3.5f; float radiusSweep = 0.1f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (tempSpeed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.Y = 0; } } } if (tempSpeed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.Y = 0; } } } if (tempSpeed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } if (tempSpeed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } }
public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer) { //gameWorld.Explode(checkPosition, 5f); //Die(); base.DoCollide(x, y, z, checkPosition, gameHero, gameWorld, withPlayer); }
public virtual void CheckCollisions(VoxelWorld world, 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; if (gameHero.CollisionBox.Intersects(boundingSphere)) { gameHero.DoHit(Position, null); } 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, gameHero, world, false); } } } 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;} } } }
void CheckCollisions(Hero gameHero, VoxelWorld gameWorld) { Vector3 worldSpace; switch (Type) { case ProjectileType.Laser1: case ProjectileType.Laser2: case ProjectileType.Laser3: case ProjectileType.Laser4: case ProjectileType.Rocket: for (float d = 0f; d < 1f; d += 0.1f) { if (!Active) { continue; } worldSpace = gameWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = gameWorld.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { if (v.Destructable >= 1 && Owner is Hero) { gameWorld.Explode(Position + (d * ((Position + Speed) - Position)), Type != ProjectileType.Rocket?3f:5f); gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, -3f), Type != ProjectileType.Rocket ? 3f : 5f); gameWorld.Explode((Position + (d * ((Position + Speed) - Position))) + new Vector3(0f, 0f, 3f), Type != ProjectileType.Rocket ? 3f : 5f); //gameWorld.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); //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 (Owner is Enemy) { if (!gameHero.Dead && gameHero.CollisionBox.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), this); Active = false; if (Type == ProjectileType.Rocket) { ParticleController.Instance.SpawnExplosion(Position); } } } if (Owner is Hero) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Active)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, Damage); Active = false; if (Type == ProjectileType.Rocket) { ParticleController.Instance.SpawnExplosion(Position); } } } } } break; } }
public void Update(GameTime gameTime, Hero gameHero, VoxelWorld gameWorld, float scrollPos) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) { Speed.Z += GRAVITY; } CheckCollisions(gameHero, gameWorld); Position += Speed; if (Owner is Hero && Position.X > scrollPos + 75f) { Active = false; } Color c; switch (Type) { case ProjectileType.Rocket: foreach (Enemy e in EnemyController.Instance.Enemies.OrderBy(en => Vector3.Distance(en.Position, Position))) { if (e.Position.X < scrollPos - 75f || !e.Active) { continue; } target = e; break; } if (target != null) { if (target.Position.X > Position.X) { Speed.X += 0.03f; } if (target.Position.X < Position.X) { Speed.X -= 0.03f; } if (target.Position.Y > Position.Y) { Speed.Y += 0.03f; } if (target.Position.Y < Position.Y) { Speed.Y -= 0.03f; } Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y))); Speed = Vector3.Clamp(Speed, new Vector3(-1f, -1f, 0f), new Vector3(1f, 1f, 0f)); } if (Helper.Random.Next(5) == 1) { ParticleController.Instance.Spawn(Position + new Vector3(Helper.RandomFloat(-0.1f, 1f), Helper.RandomFloat(-0.1f, 1f), 0f), Vector3.Zero, 0.3f, new Color(new Vector3(1f, Helper.RandomFloat(0f, 1.0f), 0f) * Helper.RandomFloat(0.5f, 1.0f)), 1000, false); } break; } if (Time >= Life) { if (Type == ProjectileType.Rocket) { ParticleController.Instance.SpawnExplosion(Position); } Active = false; } }
public void Update(GameTime gameTime, Camera gameCamera, Hero gameHero, VoxelWorld gameWorld, float scrollPos, float scrollSpeed) { for(int i=Spawns.Count-1;i>=0;i--) { if (gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 5).X < (int)scrollPos + 75) { if (Spawns[i].Properties.Contains("IsWave")) { Wave w; switch (Spawns[i].Properties["IsWave"]) { case "Line": w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Line, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties); break; default: w = new Wave(gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), WaveType.Circle, (EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), Convert.ToInt16(Spawns[i].Properties["Count"]), Spawns[i].Properties); break; } Waves.Add(w); } else { Spawn((EnemyType)Enum.Parse(typeof(EnemyType), Spawns[i].Name), gameWorld.ToScreenSpace(Spawns[i].Location.Center.X, Spawns[i].Location.Center.Y, 10), Spawns[i].Properties); } Spawns.RemoveAt(i); } } for(int i=Enemies.Count-1;i>=0;i--) Enemies[i].Update(gameTime, gameWorld, gameHero); Enemies.RemoveAll(en => !en.Active || en.Position.X<scrollPos-110f); foreach (Wave w in Waves) w.Update(gameTime, scrollSpeed); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public virtual void Update(GameTime gameTime, VoxelWorld gameWorld, Hero gameHero) { CheckCollisions(gameWorld, gameHero); Position += Speed; animTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (animTime >= animTargetTime) { animTime = 0; CurrentFrame++; if (CurrentFrame == numFrames) CurrentFrame = 0; } boundingSphere = new BoundingSphere(Position, 3f); if (hitAlpha > 0f) hitAlpha -= 0.1f; if (Health <= 0f) Die(); currentAttackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (currentAttackTime >= attackRate) DoAttack(); }
public virtual void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Hero gameHero, VoxelWorld gameWorld, bool withPlayer) { if (x) Speed.X = 0; if (y) Speed.Y = 0; if (z) Speed.Z = 0; }