using System; using System.Collections.Generic; using System.Text; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace OperationDrawDown { public class Player { public static int scale; Texture2D texture; Vector2 position; int rateOfSpeed = 2; public Player() { position = Vector2.Zero; } public void Load(XmlNode node) { // Unpack Xml for (int k = 0; k < node.ChildNodes.Count; k++) { texture = Engine.content.Load(node.ChildNodes[k].Attributes["texture"].Value); position = new Vector2( float.Parse(node.ChildNodes[k].Attributes["x"].Value), float.Parse(node.ChildNodes[k].Attributes["y"].Value)); scale = int.Parse(node.ChildNodes[k].Attributes["scale"].Value); } } public void MoveRight() { if (SceneGraph.IsWalkable_ByScreenCoord((int)this.position.X + rateOfSpeed, (int)this.position.Y)) { this.position.X += rateOfSpeed; } } public void MoveLeft() { if (SceneGraph.IsWalkable_ByScreenCoord((int)this.position.X - rateOfSpeed, (int)this.position.Y)) { this.position.X -= rateOfSpeed; } } public void MoveUp() { if (SceneGraph.IsWalkable_ByScreenCoord((int)this.position.X, (int)this.position.Y - rateOfSpeed)) { this.position.Y -= rateOfSpeed; } } public void MoveDown() { if (SceneGraph.IsWalkable_ByScreenCoord((int)this.position.X, (int)this.position.Y + rateOfSpeed)) { this.position.Y += rateOfSpeed; } } public void Update(float dt) { } public void Draw() { Engine.spriteBatch.Draw( texture, new Rectangle((int)position.X, (int)position.Y, scale, scale), Color.White ); } } }