Made Soldier Public and Made MouseInput Collision

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-09-25 21:00:03 +02:00
committed by Simon Holmberg
parent 52bb50ce6e
commit 7e88d7c68a
11 changed files with 311 additions and 196 deletions
+31 -31
View File
@@ -1,31 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Collision : Component
{
public Rectangle Rectangle;
public int Width;
public int Height;
public Collision(Entity parent, int width, int height)
: base(parent)
{
this.Width = width;
this.Height = height;
this.Rectangle = new Rectangle(0, 0, width, height);
}
public void Update(GameTime gameTime)
{
PixelTransform pt = this.Parent.GetComponent<PixelTransform>();
this.Rectangle.X = (int)pt.X;
this.Rectangle.Y = (int)pt.Y;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Collision : Component
{
public Rectangle Rectangle;
public int Width;
public int Height;
public Collision(Entity parent, int width, int height)
: base(parent)
{
this.Width = width;
this.Height = height;
this.Rectangle = new Rectangle(0, 0, width, height);
}
public void Update(GameTime gameTime)
{
PixelTransform pt = this.Parent.GetComponent<PixelTransform>();
this.Rectangle.X = (int)pt.X;
this.Rectangle.Y = (int)pt.Y;
}
}
}
@@ -0,0 +1,65 @@
<<<<<<< HEAD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Collision : Component
{
public Rectangle Rectangle;
public int Width;
public int Height;
public Collision(Entity parent, int width, int height)
: base(parent)
{
this.Width = width;
this.Height = height;
this.Rectangle = new Rectangle(0, 0, width, height);
}
public void Update(GameTime gameTime)
{
PixelTransform pt = this.Parent.GetComponent<PixelTransform>();
this.Rectangle.X = (int)pt.X;
this.Rectangle.Y = (int)pt.Y;
}
}
}
=======
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Collision : Component
{
public Rectangle Rectangle;
public int Width;
public int Height;
public Collision(Entity parent, int width, int height)
: base(parent)
{
this.Width = width;
this.Height = height;
this.Rectangle = new Rectangle(0, 0, width, height);
}
public void Update(GameTime gameTime)
{
PixelTransform pt = this.Parent.GetComponent<PixelTransform>();
this.Rectangle.X = (int)pt.X;
this.Rectangle.Y = (int)pt.Y;
}
}
}
>>>>>>> Made Soldier Public and Made MouseInput Collision
+23 -23
View File
@@ -1,23 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Component
{
public Entity Parent;
public Component(Entity parent)
{
Parent = parent;
}
public virtual void Update(GameTime gameTime)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Component
{
public Entity Parent;
public Component(Entity parent)
{
Parent = parent;
}
public virtual void Update(GameTime gameTime)
{
}
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ namespace DepthsBelow
public Camera camera;
MouseInput mouse;
Soldier soldier;
public Soldier soldier;
public Core()
{
+15 -15
View File
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
<PropertyGroup>
<EnableSecurityDebugging>false</EnableSecurityDebugging>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
<PropertyGroup>
<EnableSecurityDebugging>false</EnableSecurityDebugging>
</PropertyGroup>
</Project>
+47 -47
View File
@@ -1,47 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow
{
public class Entity
{
List<Component.Component> Components;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Entity()
{
Components = new List<Component.Component>();
pixelTransform = new Component.PixelTransform(this);
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform);
}
public T GetComponent<T>() where T : Component.Component
{
foreach (Component.Component c in Components)
{
if (c is T)
return (T)c;
}
return null;
}
public void AddComponent(Component.Component c)
{
Components.Add(c);
}
public virtual void Update(GameTime gameTime)
{
// Update components
foreach (Component.Component c in Components)
c.Update(gameTime);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow
{
public class Entity
{
List<Component.Component> Components;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Entity()
{
Components = new List<Component.Component>();
pixelTransform = new Component.PixelTransform(this);
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform);
}
public T GetComponent<T>() where T : Component.Component
{
foreach (Component.Component c in Components)
{
if (c is T)
return (T)c;
}
return null;
}
public void AddComponent(Component.Component c)
{
Components.Add(c);
}
public virtual void Update(GameTime gameTime)
{
// Update components
foreach (Component.Component c in Components)
c.Update(gameTime);
}
}
}
+3 -3
View File
@@ -49,10 +49,10 @@ namespace DepthsBelow
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
{
/*if (selectionRectangle.Intersects())
if (selectionRectangle.Intersects(core.soldier.collision.Rectangle))
{
}*/
core.soldier.selected = true;
}
selectionRectangle = Rectangle.Empty;
}
+21 -21
View File
@@ -1,21 +1,21 @@
using System;
namespace DepthsBelow
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (Core game = new Core())
{
game.Run();
}
}
}
#endif
}
using System;
namespace DepthsBelow
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (Core game = new Core())
{
game.Run();
}
}
}
#endif
}
+54 -54
View File
@@ -1,54 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace DepthsBelow
{
public class Soldier : Entity
{
Core game;
bool selected = false;
static Texture2D Texture;
private KeyboardState lastKeyboardState;
static public void LoadContent(Core game)
{
Texture = game.Content.Load<Texture2D>("images/soldier");
}
public Soldier(Core game)
{
if (Texture == null)
LoadContent(game);
Component.SpriteRenderer rc = new Component.SpriteRenderer(this);
rc.Texture = Texture;
rc.Color = Color.HotPink;
this.AddComponent(rc);
Component.Collision cc = new Component.Collision(this, 32, 32);
this.AddComponent(cc);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
/*KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
gridTransform.Position.X += 1;
lastKeyboardState = ks;*/
if (pixelTransform.Position.X < gridTransform.X * 32)
{
pixelTransform.Position.X += 2;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace DepthsBelow
{
public class Soldier : Entity
{
Core game;
public bool selected = false;
static Texture2D Texture;
private KeyboardState lastKeyboardState;
static public void LoadContent(Core game)
{
Texture = game.Content.Load<Texture2D>("images/soldier");
}
public Soldier(Core game)
{
if (Texture == null)
LoadContent(game);
Component.SpriteRenderer rc = new Component.SpriteRenderer(this);
rc.Texture = Texture;
rc.Color = Color.HotPink;
this.AddComponent(rc);
Component.Collision cc = new Component.Collision(this, 32, 32);
this.AddComponent(cc);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
/*KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
gridTransform.Position.X += 1;
lastKeyboardState = ks;*/
if (pixelTransform.Position.X < gridTransform.X * 32)
{
pixelTransform.Position.X += 2;
}
}
}
}
+50
View File
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace DepthsBelow
{
public class Soldier : Entity
{
Core game;
public bool selected = false;
static Texture2D Texture;
private KeyboardState lastKeyboardState;
static public void LoadContent(Core game)
{
Texture = game.Content.Load<Texture2D>("images/soldier");
}
public Soldier(Core game)
{
if (Texture == null)
LoadContent(game);
Component.SpriteRenderer rc = new Component.SpriteRenderer(this);
rc.Texture = Texture;
rc.Color = Color.HotPink;
this.AddComponent(rc);
}
public void Update(GameTime gameTime)
{
/*KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
gridTransform.Position.X += 1;
lastKeyboardState = ks;*/
if (pixelTransform.Position.X < gridTransform.X * 32)
{
pixelTransform.Position.X += 2;
}
}
}
}
+1 -1
View File
@@ -1,2 +1,2 @@
DepthsBelow
DepthsBelow
===========