Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kaisellgren/Osmium-Wars
Browse files Browse the repository at this point in the history
Conflicts:
	Osmium Wars/Osmium Wars/Classes/Entity.cs
  • Loading branch information
kaisellgren committed Feb 4, 2012
2 parents 8e63f8b + 10af5af commit 9db9189
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Osmium Wars/Osmium Wars/Classes/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class Entity : Microsoft.Xna.Framework.DrawableGameComponent
protected Model model;

protected Vector3 position = Vector3.Zero;
protected Vector3 faceposition = Vector3.Forward;
protected float rotation = 0.0f;

/// <summary>
Expand Down Expand Up @@ -54,7 +55,7 @@ public override void Draw(GameTime gameTime)
effect.EnableDefaultLighting();
effect.AmbientLightColor = new Vector3(255, 255, 255);
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateScale(0.1f, 0.1f, 0.1f) * Matrix.CreateRotationY(this.rotation) * Matrix.CreateTranslation(this.position);
effect.View = Matrix.CreateLookAt(this.game.cameraPosition, Vector3.Zero, Vector3.Forward);
effect.View = Matrix.CreateLookAt(this.game.cameraPosition, Vector3.Zero, faceposition);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), this.game.aspectRatio, 1.0f, 10000.0f);
}
// Draw the mesh, using the effects set above.
Expand All @@ -64,4 +65,4 @@ public override void Draw(GameTime gameTime)
base.Draw(gameTime);
}
}
}
}
32 changes: 32 additions & 0 deletions Osmium Wars/Osmium Wars/Classes/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace OW
{
class Player : Infantry
{
private static int SPEED = 10;
private double angle;
public Player(Game game) : base(game)
{
this.game = game;
Expand All @@ -24,5 +26,35 @@ protected override void LoadContent()
this.model = this.game.Content.Load<Model>("Units/Player");
//this.rotation += (float)gameTime.TotalGameTime.Seconds / 100;
}

public override void Update(GameTime gameTime)
{
KeyboardState keyState = Keyboard.GetState();
MouseState mouseState = Mouse.GetState();

//Implement movement with WASD controls
if (keyState.IsKeyDown(Keys.W))
{
this.position.Z -= SPEED;
}
else if (keyState.IsKeyDown(Keys.S))
{
this.position.Z += SPEED;
}
else if (keyState.IsKeyDown(Keys.A))
{
this.position.X -= SPEED;
}
else if (keyState.IsKeyDown(Keys.D))
{
this.position.X += SPEED;
}

//Now make him look at the direction of the mouse

angle = Math.Atan2((double)mouseState.Y - this.position.Y, (double)mouseState.X - this.position.X); //this will return the angle(in radians) from sprite to mouse.
this.faceposition.X = (float)Math.Cos(angle);
this.faceposition.Y = (float)Math.Sin(angle);
}
}
}
2 changes: 2 additions & 0 deletions Osmium Wars/Osmium Wars/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public Game()
graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
graphics.IsFullScreen = true;

this.IsMouseVisible = true;

// Create one player instance.
Player player = new Player(this);
this.Components.Add(player);
Expand Down
7 changes: 7 additions & 0 deletions Osmium Wars/Osmium WarsContent/Osmium WarsContent.contentproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
<Processor>ModelProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Nature\Ground\Dirt2.jpg">
<Name>Dirt2</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 9db9189

Please sign in to comment.