Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mcgrue/demon_door
Browse files Browse the repository at this point in the history
Conflicts:
	DemonDoor/DemonDoor/Game1.cs
  • Loading branch information
zumpiez committed Apr 1, 2012
2 parents 30f00d6 + bad2e9c commit a204710
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 24 deletions.
5 changes: 5 additions & 0 deletions DemonDoor/DemonDoor/CivvieController.cs
Expand Up @@ -130,6 +130,11 @@ public void Collided(ICollidable other)
this.behaviorState = BehaviorState.Dead;
myCorpse.SetAnimationState(CivvieSprite.AnimationState.Dead);
}

if (this.behaviorState == BehaviorState.Dead)
{
_world.StopPhysicsing(_fsBody);
}
}

if (other is CivvieController)
Expand Down
17 changes: 13 additions & 4 deletions DemonDoor/DemonDoor/CivvieSpawner.cs
Expand Up @@ -14,16 +14,16 @@ class CivvieSpawner : IDrawableThing, IBrainyThing
private McgLayer layer;
private World world;
private Vector2 location;
private SpriteBasis civvieSpriteBasis;
private SpriteBasis[] civvieSpriteBasisList;
private int spawnRateFuzzMillis;

public CivvieSpawner(World world, McgLayer layer, Vector2 location, TimeSpan spawnRate, SpriteBasis civvieSpriteBasis, int spawnRateFuzzMillis = 0)
public CivvieSpawner(World world, McgLayer layer, Vector2 location, TimeSpan spawnRate, SpriteBasis[] civvieSpriteBasis, int spawnRateFuzzMillis = 0)
{
this.layer = layer;
this.world = world;
this.spawnRate = spawnRate;
this.location = location;
this.civvieSpriteBasis = civvieSpriteBasis;
this.civvieSpriteBasisList = civvieSpriteBasis;
this.spawnRateFuzzMillis = spawnRateFuzzMillis;
}

Expand All @@ -42,12 +42,21 @@ public RenderDelegate GetDrawDelegate()
return (x, y) => { };
}

private static int nextIdx = 0;
public int getnextCivvieIdx() {
nextIdx++;
if( nextIdx >= civvieSpriteBasisList.Length ) {
nextIdx = 0;
}
return nextIdx;
}

public void ProcessBehavior(Microsoft.Xna.Framework.GameTime time)
{
spawnTimeAccumulator += time.ElapsedGameTime;
if (spawnTimeAccumulator > spawnRate)
{
layer.AddNode(new McgNode(new CivvieController(world, new Vector2(location.X, location.Y), new CivvieSprite(civvieSpriteBasis)), layer,
layer.AddNode(new McgNode(new CivvieController(world, new Vector2(location.X, location.Y), new CivvieSprite(civvieSpriteBasisList[getnextCivvieIdx()])), layer,
(int)location.X, (int)location.Y));
spawnTimeAccumulator = TimeSpan.FromMilliseconds(VERGEGame.rand.Next(-spawnRateFuzzMillis, 0));
}
Expand Down
182 changes: 182 additions & 0 deletions DemonDoor/DemonDoor/CopController.cs
@@ -0,0 +1,182 @@

using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using Microsoft.Xna.Framework;

using XNAVERGE;
using System;

namespace DemonDoor
{

class CopController : IDrawableThing, ICollidable, IBrainyThing
{
CopSprite copSprite = null;
Vector2 screen;

private Body _fsBody;
private Shape _fsShape;
private Fixture _fsFixture;
private World _world;

private enum BehaviorState
{
Flying, Walking, Dead, Aiming, Shooting
}
private BehaviorState behaviorState = BehaviorState.Flying;

public CopController( World w, Vector2 r0, CopSprite sprite )
{
_world = w;

_fsBody = w.NewBody();
_fsBody.BodyType = BodyType.Dynamic;
_fsBody.Position = r0;

copSprite = sprite;

MakeLivingFixture();
}

private void MakeLivingFixture()
{
if (_fsFixture != null)
{
_fsBody.DestroyFixture(_fsFixture);
}

_fsShape = new CircleShape(1f, 1.0f);
_fsFixture = _fsBody.CreateFixture(_fsShape, this);
_fsFixture.Restitution = 0.2f;
_fsFixture.OnCollision += BehaviorCollided;
}

private void MakeDeadFixture()
{
if (_fsFixture != null)
{
_fsBody.DestroyFixture(_fsFixture);
}

PolygonShape shape = new PolygonShape(1.0f);
shape.SetAsBox(1.0f, 1.0f);
_fsFixture = _fsBody.CreateFixture(_fsShape, this);
_fsFixture.Restitution = 0.2f;
_fsFixture.OnCollision += BehaviorCollided;
}

public int GetX() {
return (int)_fsBody.Position.X;
}
public int GetY() {
return (int)_fsBody.Position.Y;
}

RenderDelegate _myDrawDelegate;

public RenderDelegate GetDrawDelegate() {
if( _myDrawDelegate != null ) return _myDrawDelegate;

_myDrawDelegate = ( int x, int y ) => {
this.screen = Coords.Physics2Screen( new Vector2 { X = Position.X, Y = Position.Y } );
// maybe update the screen here?
copSprite.Sprite.x = (int)screen.X - 8;
copSprite.Sprite.y = (int)screen.Y - 8;
copSprite.Sprite.Draw();
};

return _myDrawDelegate;
}

private bool BehaviorCollided(Fixture f1, Fixture f2, Contact contact)
{
Fixture self = null, other = null;

if (f1 == _fsFixture)
{
self = f1;
other = f2;
}
else if (f2 == _fsFixture)
{
self = f2;
other = f1;
}

if (other.UserData is ICollidable)
{
this.Collided(other.UserData as ICollidable);
(other.UserData as ICollidable).Collided(this);
}

return true;
}

public void Collided(ICollidable other)
{
if (other == _world)
{
//Console.WriteLine("Velocity " + _fsBody.LinearVelocity.Y);
if (Math.Abs(_fsBody.LinearVelocity.Y) < 1 && behaviorState == BehaviorState.Flying)
{
this.behaviorState = BehaviorState.Walking;
}
else if (_fsBody.LinearVelocity.Y < -20 && behaviorState == BehaviorState.Flying)
{
this.behaviorState = BehaviorState.Dead;
copSprite.SetAnimationState(CopSprite.AnimationState.Dead);
}
}

if (other is CivvieController)
{
var otherCivvie = other as CivvieController;
if (otherCivvie._fsBody.LinearVelocity.Length() > 50)
{
otherCivvie.Die();
this.Die();
}
}
}

public Vector2 Position
{
get
{
return _fsBody.Position;
}
}

public float Theta
{
get
{
return _fsBody.Rotation;
}
}

public void ProcessBehavior(GameTime time)
{
if (Math.Abs(_fsBody.LinearVelocity.Y) > 1 && behaviorState != BehaviorState.Dead) {
behaviorState = BehaviorState.Flying;
copSprite.SetAnimationState(CopSprite.AnimationState.Flying);
}
if (behaviorState == BehaviorState.Walking)
{
copSprite.SetAnimationState(CopSprite.AnimationState.WalkingLeft);
_fsBody.LinearVelocity = new Vector2(-20, _fsBody.LinearVelocity.Y);
_fsBody.Rotation = 0;
}
}

private void Die()
{
this.behaviorState = BehaviorState.Dead;
copSprite.SetAnimationState(CopSprite.AnimationState.Dead);
}
}
}
56 changes: 56 additions & 0 deletions DemonDoor/DemonDoor/CopSpawner.cs
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNAVERGE;
using Microsoft.Xna.Framework;

namespace DemonDoor
{
class CopSpawner : IDrawableThing, IBrainyThing
{
TimeSpan spawnRate;
private TimeSpan spawnTimeAccumulator;
private McgLayer layer;
private World world;
private Vector2 location;
private SpriteBasis copSpriteBasis;
private int spawnRateFuzzMillis;

public CopSpawner(World world, McgLayer layer, Vector2 location, TimeSpan spawnRate, SpriteBasis copSpriteBasis, int spawnRateFuzzMillis = 0)
{
this.layer = layer;
this.world = world;
this.spawnRate = spawnRate;
this.location = location;
this.copSpriteBasis = copSpriteBasis;
this.spawnRateFuzzMillis = spawnRateFuzzMillis;
}

public int GetX()
{
return (int)location.X;
}

public int GetY()
{
return (int)location.Y;
}

public RenderDelegate GetDrawDelegate()
{
return (x, y) => { };
}

public void ProcessBehavior(Microsoft.Xna.Framework.GameTime time)
{
spawnTimeAccumulator += time.ElapsedGameTime;
if (spawnTimeAccumulator > spawnRate)
{
layer.AddNode(new McgNode(new CopController(world, new Vector2(location.X, location.Y), new CopSprite(copSpriteBasis)), layer,
(int)location.X, (int)location.Y));
spawnTimeAccumulator = TimeSpan.FromMilliseconds(VERGEGame.rand.Next(-spawnRateFuzzMillis, 0));
}
}
}
}
7 changes: 6 additions & 1 deletion DemonDoor/DemonDoor/DemonController.cs
Expand Up @@ -54,7 +54,12 @@ class DemonController : IDrawableThing, ICollidable {

public void Collided(ICollidable other) {
if( other is CivvieController ) {
(Game1.game as Game1).LoadLevel("gameover");

if( ( sprite.CurrentState == DemonSprite.AnimationState.Idle || sprite.CurrentState == DemonSprite.AnimationState.Pressing ) ) {
( Game1.game as Game1 ).LoadLevel( "gameover" );
} else {
/// do something if a "miss" happens? disintegrate the corpse?
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions DemonDoor/DemonDoor/DemonDoor.csproj.Debug.cachefile
Expand Up @@ -19,6 +19,12 @@ Content\art\cloud_08.xnb
Content\art\cloud_09.xnb
Content\art\demon.xnb
Content\art\gameover.xnb
Content\art\civilian_02.xnb
Content\art\civilian_03.xnb
Content\art\civilian_04.xnb
Content\art\civilian_05.xnb
Content\art\civilian_06.xnb
Content\art\civilian_07.xnb
Content\music.xgs
Content\Wave Bank.xwb
Content\Sound Bank.xsb
15 changes: 11 additions & 4 deletions DemonDoor/DemonDoor/DoorController.cs
Expand Up @@ -50,9 +50,12 @@ private bool PhysicsCollided(Fixture f1, Fixture f2, Contact contact)
if ((other.UserData is CivvieController || other.UserData is CopController) && !_alreadyShot.Contains(other)) {
//Console.WriteLine("collided with corpse {0}, kickin' it", c);

other.Body.ApplyLinearImpulse(Impulse);
Game1.game.PlayCue("door_hit");
_alreadyShot.Add(other);
if (Impulse.Length() > 0)
{
other.Body.ApplyLinearImpulse(Impulse);
Game1.game.PlayCue("door_hit");
_alreadyShot.Add(other);
}
}

return false;
Expand Down Expand Up @@ -173,7 +176,7 @@ public void UpdateGunImpulse(GameTime gameTime)
sprite.SetAnimationState(DoorSprite.AnimationState.Fast);
} else if (GunImpulse / MaxGunImpulse > 0.5) {
sprite.SetAnimationState(DoorSprite.AnimationState.Medium);
} else if (GunImpulse / MaxGunImpulse > 0.1) {
} else if (GunImpulse / MaxGunImpulse > 0) {
sprite.SetAnimationState(DoorSprite.AnimationState.Slow);
} else {
sprite.SetAnimationState(DoorSprite.AnimationState.Stopped);
Expand All @@ -185,6 +188,10 @@ public string DoorSpeedDescription
{
get
{
if (GunImpulse == 0)
{
return "stopped";
}
if (GunImpulse < 0.1 * MaxGunImpulse)
{
return "mild";
Expand Down

0 comments on commit a204710

Please sign in to comment.