Skip to content

Commit

Permalink
new file: Character.cs
Browse files Browse the repository at this point in the history
	new file:   CharacterTest.cs
	new file:   Forest 01a.JPG
	new file:   Game1.cs
	new file:   Game1Test.cs
	new file:   Program.cs
	new file:   ProgramTest.cs
	new file:   Sprite.cs
	new file:   SpriteTest.cs
	new file:   test.png
  • Loading branch information
aslone committed Mar 3, 2012
1 parent 6c4a62f commit dd5f00d
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 25 deletions.
63 changes: 63 additions & 0 deletions Game/AnimatedSprite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
class AnimatedSprite : Sprite
{
float timer = 0f;
float interval = 200f;
int currentFrame = 0;
int spriteWidth = 32;
int spriteHeight = 48;
int spriteSpeed;
Rectangle sourceRect;
Vector2 origin;

public AnimatedSprite()
{
}

public void HandleSourceRect(GameTime gameTime)
{

sourceRect = new Rectangle(currentFrame * spriteWidth, 0, spriteWidth, spriteHeight);

origin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);
}



public Vector2 Position
{
get { return pos; }
set { pos = value; }
}

public Vector2 Origin
{
get { return origin; }
set { origin = value; }
}

public Texture2D Texture
{
get { return tex; }
set { tex = value; }
}

public Rectangle SourceRect
{
get { return sourceRect; }
set { sourceRect = value; }
}


}
}
Binary file added Game/BG2.bmp
Binary file not shown.
7 changes: 3 additions & 4 deletions Game/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace WindowsGame1
{
class Character : Sprite
class Character : AnimatedSprite
{
const string CHARACTER_ASSETNAME = "test";
const int START_POSITION_X = 400;
Expand All @@ -24,11 +24,10 @@ enum State
{
Walking, Running, Stationary
}

State mCurrentState = State.Walking;

public Vector2 mDirection = Vector2.Zero;
public Vector2 mSpeed = Vector2.Zero;
Vector2 mDirection = Vector2.Zero;
Vector2 mSpeed = Vector2.Zero;

KeyboardState mPreviousKeyboardState;

Expand Down
77 changes: 58 additions & 19 deletions Game/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@

namespace WindowsGame1
{

/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
{
enum gamestate
{
menu, play
}
gamestate state;
KeyboardState keystate;
KeyboardState lastKeyState;
GraphicsDeviceManager graphics;
public SpriteBatch spriteBatch;
SpriteBatch spriteBatch;
Sprite BG0;

Sprite menu;

Character player;

public Game1()
Expand All @@ -39,12 +47,16 @@ protected override void Initialize()
{
// TODO: Add your initialization logic here

//Game starts with the menu
state = gamestate.menu;

//Player that can move around
player = new Character();

//Background
//Backgrounds
menu = new Sprite();
BG0 = new Sprite();

base.Initialize();
}

Expand All @@ -58,9 +70,10 @@ protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);

//Background
menu.LoadContent(this.Content, "Menu");
BG0.LoadContent(this.Content, "Forest 01a");
BG0.pos = new Vector2(-500, -500);
BG0.updatePos(new Vector2(-500, -500));

player.LoadContent(this.Content);

// TODO: use this.Content to load your game content here
Expand All @@ -82,16 +95,33 @@ protected override void UnloadContent()
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
//Get keyboard state
keystate = Keyboard.GetState();

// Allows the game to exit
if (keystate.IsKeyDown(Keys.Escape) == true)
this.Exit();

//Vector2 newPos = new Vector2(400, 300);
//player.updatePos(newPos);

player.Update(gameTime);

if (state == gamestate.menu)
{
// Allows the game to exit
if ((keystate.IsKeyDown(Keys.Escape) == true)
&& (lastKeyState.IsKeyUp(Keys.Escape) == true))
this.Exit();

if ((keystate.IsKeyDown(Keys.Space) == true)
&& (lastKeyState.IsKeyUp(Keys.Space) == true))
{
state = gamestate.play;
}
}
else if (state == gamestate.play)
{
if ((keystate.IsKeyDown(Keys.Escape) == true)
&& (lastKeyState.IsKeyUp(Keys.Escape) == true))
state = gamestate.menu;

player.Update(gameTime);
}

lastKeyState = keystate;
base.Update(gameTime);
}

Expand All @@ -105,13 +135,22 @@ protected override void Draw(GameTime gameTime)

spriteBatch.Begin();

BG0.Draw(this.spriteBatch);

player.Draw(this.spriteBatch);

if (state == gamestate.menu)
{
menu.Draw(this.spriteBatch);
}

if (state == gamestate.play)
{
BG0.Draw(this.spriteBatch);

player.Draw(this.spriteBatch);
}

spriteBatch.End();

base.Draw(gameTime);
}

}
}
Binary file added Game/Grass _amp_ Pebbles _32x32_.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Game/Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame1
{
class Menu
{

}
}
4 changes: 2 additions & 2 deletions Game/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class Sprite
{

//The current position of the Sprite
public Vector2 pos = new Vector2(0, 0);
protected Vector2 pos = new Vector2(0, 0);

//The texture object used when drawing the sprite
private Texture2D tex;
protected Texture2D tex;

//The asset name for the Sprite's Texture
public string assetName;
Expand Down
Binary file added Game/Terrain_Grass01_SR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Terrain_Grass02_SR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/road01_a.bmp
Binary file not shown.
Binary file added Game/road01_b.bmp
Binary file not shown.
Binary file added Game/road02_a.bmp
Binary file not shown.
Binary file modified Game/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd5f00d

Please sign in to comment.