• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Kaan Aksoy

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Kaan Aksoy

  • Rank
    Newbie
  1. Hey. I am working on a 2D Terraria-Like game, and I needed some help with the movement. To handle both collisions and physics, I am using the Farseer Physics Engine. I have two questions, which are probably quite simple. 1. How can I make my character stop moving once the movement keys are released. With the code below, the character still continues to roll: [source lang="java"]if(k.IsKeyDown(Keys.Left)) { circleBody.ApplyTorque(-1000); } else if (k.IsKeyDown(Keys.Right)) { circleBody.ApplyTorque(1000); }[/source] 2. Can I make the character not bounce at all after colliding with a platform? I have set the RestitutionCoefficient to 0, but it still bounces a very small amount. 3. Is there a way to prevent the character from rotating its texture? Thanks for the help
  2. Hi, for my game in XNA, I decided to use a Windows Form as the inventory interface. On the Form, I added a ListView item. So far it is working well, but now that I want to add quantities of items, it is not going to work. How can I set it so that the list of items in the ListView are my own custom objects (I have an Item class). If I could find a way to implement this, I think it would be much easier. All help would be appreciated
  3. Hi. I am working on an enemy class in my tile-based 2d rpg game in xna, and I am having difficulty with the AI. I attempted to make my own custom method; It works sometimes but not always. Right now, I am testing it on a simple map with a river running through it and a bridge. When my player's X position is the same as the bridge's, the enemy is able to reach me. When it is not, the enemy simply walks towards the river until it can't move anymore (enemy's can't enter water). By the way, the enemy and the player are on opposite sides of the river. Before trying this method, I looked into the A* method. Unfortunately, I am only in 8th grade, so it is a bit too confusing for me. Could you please try to modify or explain to me why my code is not working. I do understand why it is not working, but do not understand how to fix the problem. Here is the AI Method.: [CODE] public void Move() { if (movetimer > 0) { movetimer--; } if (movetimer == 0) { int TargetX; int TargetY; List<Vector2> possibleTiles = new List<Vector2>(); List<Vector2> movableTiles = new List<Vector2>(); List<Vector2> movableDesiredTiles = new List<Vector2>(); if (X < Main.map.grid.GetLength(1)) { possibleTiles.Add(new Vector2(X + 1, Y)); } possibleTiles.Add(new Vector2(X, Y + 1)); if (X > 0) { possibleTiles.Add(new Vector2(X - 1, Y)); } possibleTiles.Add(new Vector2(X, Y - 1)); foreach (Vector2 tile in possibleTiles) { if (tile.X < Main.map.grid.GetLength(1) && tile.Y < Main.map.grid.GetLength(0)) { if (Main.map.grid[(int)tile.Y, (int)tile.X] != 2) { movableTiles.Add(new Vector2(tile.X, tile.Y)); } } } foreach (Vector2 tile in movableTiles) { if (Vector2.Distance(new Vector2(tile.X, tile.Y), new Vector2(Main.player.X, Main.player.Y)) < Vector2.Distance(new Vector2(X, Y), new Vector2(Main.player.X, Main.player.Y))) { movableDesiredTiles.Add(new Vector2(tile.X, tile.Y)); } } if (movableDesiredTiles.Count > 0) { Vector2 mostDesiredTile = new Vector2(X, Y); int distanceX; int distanceY; int totalDistance = 100; foreach (Vector2 tile in movableDesiredTiles) { int specificDistance; distanceX = Main.player.X - X; if (distanceX < 0) { distanceX *= -1; } distanceY = Main.player.Y - Y; if (distanceY < 0) { distanceY *= -1; } specificDistance = distanceX + distanceY; if (specificDistance < totalDistance) { mostDesiredTile = new Vector2(tile.X, tile.Y); totalDistance = specificDistance; } } TargetX = (int)mostDesiredTile.X; TargetY = (int)mostDesiredTile.Y; X = TargetX; Y = TargetY; } movetimer = 60; } [/CODE]
  4. Hello. Yesterday, I was working on a game in xna. I got everything to work, and then saved it for the night. Now, I wake up to find that all the classes are fine except for one. Instead of having my code, it has this text in it:   O¿PKO¿PKOÑÅK c HTTP:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/372683_100002489225494_1119274177_q.jpg request-method GET response-head HTTP/1.1 200 OK Content-Type: image/jpeg Content-Length: 2592 X-Backend: hs1433.ash4 X-Blockid: 372683 Last-Modified: Fri, 01 Jan 2010 00:00:00 GMT Access-Control-Allow-Origin: * Cache-Control: max-age=1209600 Expires: Fri, 08 Jun 2012 09:26:44 GMT Date: Fri, 25 May 2012 09:26:44 GMT security-info FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojJrhKnIPx6drbNrgwAWYKMiaRXE/7uyCJhaYy3wUAAAAAAAAAAMAAAAAAAABGAAADdjCCA3IwggLboAMCAQICBAcnf00wDQYJKoZIhvcNAQEFBQAwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD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wIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdIICAaUwRQYDVR0fBD4wPDA6oDigNoY0aHR0cDovL3d3dy5wdWJsaWMtdHJ1c3QuY29tL2NnaS1iaW4vQ1JMLzIwMTgvY2RwLmNybDANBgkqhkiG9w0BAQUFAAOBgQA9imYX9omKH9mL9XXYVdddeOPh/1+CYf1iStzxBzGtuc37XMxJKBnUR4FJwSynjC0/gmMzL8N00k55IuFdNS7ITbhrQoa7Ks7AYWGUdSuFW6yl4UNNpKHrAJffY5YLCOGAzI4gVZ9ruS6GNPbDOLEa3ffDo9KxowhdupaghD6kvwAAAQAAAAEAAAAAB0FFUy0yNTYAAAABAAAAAAAAAAAAAAAAAAAAAAA= atic void Draw(SpriteBatch spriteBatch) { int itemY = 70; if (open == true) { //INVENTORY spriteBatch.DrawString(Globals.font, "Inventory", new Vector2(90, 25), Color.Red); spriteBatch.Draw(background, new Rectangle(90, 50, 280 , 360), Color.White); spriteBatch.Draw(outline, new Rectangle(90, 50, 280, 360), Color.Yellow); spriteBatch.DrawString(Globals.font, "Press 'D' to De  €  O¿PKO¿dOÑ‘d O ^ ÿHTTP:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/373114_21295715752_917005752_s.jpg request-method GET response-head HTTP/1.1 200 OK Content-Type: image/jpeg Content-Length: 6991 X-Backend: hs811.ash4 X-Blockid: 373114 Last-Modified: Fri, 01 Jan 2010 00:00:00 GMT Access-Control-Allow-Origin: * Cache-Control: max-age=1209600 Expires: Fri, 08 Jun 2012 05:45:17 GMT Date: Fri, 25 May 2012 05:45:17 GMT security-info FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojJrhKnIPx6drbNrgwAWYKMiaRXE/7uyCJhaYy3wUAAAAAAAAAAMAAAAAAAABGAAADdjCCA3IwggLboAMCAQICBAcnf00wDQYJKoZIhvcNAQEFBQAwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD0dURSBDb3Jwb3JhdGlvbjEnMCUGA1UECxMeR1RFIEN5YmVyVHJ1c3QgU29sdXRpb25zLCBJbmMuMSMwIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdDAeFw0xMTA5MDExODI2MTFaFw0xMjA4MzExODIzNTZaME0xCzAJBgNVBAYTAlVTMSIwIAYDVQQKExlBa2FtYWkgVGVjaG5vbG9naWVzLCBJbmMuMRowGAYDVQQDExFhMjQ4LmUuYWthbWFpLm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtAE08ZCuvkgGb5E3FMMQVuiqcsQgM4RN2SSM4PhQcQ6mWdAAqUGFmCFJE+K3QNlnd0DlNlm8tMvRlipik3NT8aiEBBCv0pkLAadUsz38GkA4vmbe6DLJdhXZCXHWHh19gAeR1C70FTNQL4ssMEU25ONP+C2nE3T0g3qSB6GXuhcCAwEAAaOCATUwggExMAkGA1UdEwQCMAAwRAYDVR0RBD0wO4IRYTI0OC5lLmFrYW1haS5uZXSCDiouYWthbWFpaGQubmV0ghYqLmFrYW1haWhkLXN0YWdpbmcubmV0MAsGA1UdDwQEAwIFIDCBiQYDVR0jBIGBMH+heaR3MHUxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9HVEUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNvbHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJvb3SCAgGlMEUGA1UdHwQ+MDwwOqA4oDaGNGh0dHA6Ly93d3cucHVibGljLXRy Part of my code is in there, but where is everything else? Is there a way to retrieve the code, because I really dont want to restart. All help would be EXTREMELY appreciated.
  5. Sorry :/ that was a stupid mistake. When I run the program, this is the error I get: Error 1 There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 6, position 4.
  6. Hello. I am trying to create items for my game by putting their settings in an xml file, but I am having no help. I have had little previous experience with xml, so my mistake is probably a very simple one. To load the settings, I use the Load() method in my Item class. I have added the xml file to my game's content, but it is still not working. The error is: [CODE]Error 1 There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 6, position 4.[/CODE] Here is the Item Class: [CODE] using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework.Graphics; using System.Xml; using Microsoft.Xna.Framework; namespace RPG { class Item { protected string assetName; protected string description; protected Texture2D graphicIcon; protected int goldValue; protected bool dropable; public void Load(string asset) { XmlDocument doc = new XmlDocument(); doc.Load(@"Content/Items/" + asset + ".xml"); foreach (XmlNode root in doc.ChildNodes) { foreach (XmlNode node in root.ChildNodes) { if (node.Name == "Asset") assetName = node.InnerText; if (node.Name == "Description") description = node.InnerText; if (node.Name == "GraphicIcon") graphicIcon = LoadTexture(node.InnerText); if (node.Name == "GoldValue") goldValue = int.Parse(node.InnerText); if (node.Name == "Dropable") dropable = bool.Parse(node.InnerText); }//end child nodes } } protected Texture2D LoadTexture(string asset) { return Globals.Content.Load<Texture2D>("" + asset); } } } [/CODE] and XML code: [CODE] <?xml version="1.0" encoding="utf-8" ?> <XnaContent> <!-- TODO: replace this Asset with your own XML asset data. --> <Asset Type="System.String"></Asset> <Item> <Asset>BronzeBand</Asset> <Description>This worn ring looks rusted</Description> <GoldValue>1</GoldValue> <Dropable>true</Dropable> </Item> </XnaContent> [/CODE]
  7. Hi, I am working on a game, and I need help with my ball bouncing off a line(which is a list of Vector2s). Right now, I am trying to use the Vector2.Reflect(Vector2, Vector2) to bounce in the ball's CheckCollision method, but it is not working. When the ball hits the line, it simple dissapears. All help would be greatly appreciated. Here is the ball class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Geometry { class Ball { Vector2 Location; Vector2 Direction; Vector2 targetLocation; Texture2D texture; int Power; int PowerRemoveTimer = 50; public Ball(Vector2 position, Vector2 target, ContentManager content, int speed) { Location = position; targetLocation = target; FindDirection(); Power = speed; texture = content.Load<Texture2D>("ball"); } public void FindDirection() { Direction = targetLocation - Location; Direction.Normalize(); } public void Move() { Location += Direction * Power; } public void CheckCollision(List<Line> lines) { foreach (Line l in lines) { foreach (Vector2 point in l.points) { if (Vector2.Distance(point, Location) < 20) { Direction = Vector2.Reflect(Direction, l.GetPerpendicular()); Direction.Normalize(); } } } } public void Draw(SpriteBatch spriteBatch) { if (PowerRemoveTimer > 0) { PowerRemoveTimer--; } if (PowerRemoveTimer == 0) { Power--; PowerRemoveTimer = 50; } CheckCollision(Game1.lines); Move(); spriteBatch.Draw(texture, Location, Color.Yellow); } } } [/CODE] Game1 Class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Geometry { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D redPoint; List<Vector2> clickedPoints = new List<Vector2>(); public static List<Line> lines = new List<Line>(); MouseState newMouseState; MouseState oldMouseState; Ball ball; Line addingLine; KeyboardState newKeyBoardState; KeyboardState oldKeyBoardState; Vector2 PointOne; Vector2 PointTwo; Line directionLine; int Power = 10; Vector2 startPoint = new Vector2(400, 400); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IsMouseVisible = true; base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Line.pointTexture = Content.Load<Texture2D>("point"); redPoint = Content.Load<Texture2D>("redpoint"); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { directionLine = new Line(new Vector2(newMouseState.X, newMouseState.Y), startPoint, Color.Green); newMouseState = Mouse.GetState(); newKeyBoardState = Keyboard.GetState(); if (newMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) { PointOne = new Vector2(newMouseState.X, newMouseState.Y); } if (newMouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released) { PointTwo = new Vector2(newMouseState.X, newMouseState.Y); } if(newKeyBoardState.IsKeyDown(Keys.Enter) && oldKeyBoardState.IsKeyUp(Keys.Enter)) { addingLine = new Line(PointOne, PointTwo, Color.Red); lines.Add(addingLine); } if (newKeyBoardState.IsKeyDown(Keys.Escape) && oldKeyBoardState.IsKeyUp(Keys.Escape)) { lines.Clear(); } if (newKeyBoardState.IsKeyDown(Keys.OemMinus) && oldKeyBoardState.IsKeyUp(Keys.OemMinus)) { if (Power > 1) { Power--; } } if (newKeyBoardState.IsKeyDown(Keys.OemPlus) && oldKeyBoardState.IsKeyUp(Keys.OemPlus)) { if (Power < 11) { Power++; } } if(newKeyBoardState.IsKeyDown(Keys.Space) && oldKeyBoardState.IsKeyUp(Keys.Space)) { ball = new Ball(startPoint, new Vector2(newMouseState.X, newMouseState.Y), Content, Power); } oldMouseState = Mouse.GetState(); oldKeyBoardState = Keyboard.GetState(); base.Update(gameTime); } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); if (ball != null) { ball.Draw(spriteBatch); } if (PointOne != null) { spriteBatch.Draw(redPoint, PointOne, Color.White); } directionLine.Draw(spriteBatch); spriteBatch.Draw(redPoint, new Rectangle(10, 10, Power * 20, 15), Color.Green); foreach (Line l in lines) { l.Draw(spriteBatch); } if (PointTwo != null) { spriteBatch.Draw(redPoint, PointTwo, Color.White); } spriteBatch.End(); base.Draw(gameTime); } } } [/CODE] and finally, line class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Geometry { public class Line { public Vector2 startPos; public Vector2 endPos; public List<Vector2> points = new List<Vector2>(); public static Texture2D pointTexture; Color color; public Vector2 slope; public Line(Vector2 start, Vector2 end, Color col) { slope = startPos - endPos; slope.Normalize(); startPos = start; endPos = end; color = col; findPoints(); } public void findPoints() { Vector2 linePoint = startPos; float xIncrement = (endPos.X - startPos.X) / 10000; float yIncrement = (endPos.Y - startPos.Y) / 10000; for (int i = 0; i < 10000; i++) { linePoint.X += xIncrement; linePoint.Y += yIncrement; points.Add(linePoint); } } public void Draw(SpriteBatch spriteBatch) { foreach (Vector2 point in points) { spriteBatch.Draw(pointTexture, point , color); } } public Vector2 GetPerpendicular() { return new Vector2(slope.Y, -slope.X); } } } [/CODE]
  8. Hey. I made a game where you shoot balls at walls, and you try to get the ball to bounce into a goal. So, when the ball bounces of one wall and hits the other, I realized a problem. Instead of going in another direction, it bounces right back to the first line, and then the second, in an endless cycle. Right now, when the ball collides, I am simply multiplying its direction vector2 by -1. Is there a better way to do this to create a more realistic bounce? All help would be appreciated.
  9. Hello. I just started an xna rpg game, and needed help with the collision. So, I have a map and a character. I don't want the character to walk onto the water. To do this, I check the block in front of( or whichever direction the player is moving) the character, and see if it is water. If it is, I dont allow the character to walk. Unfortunately, this is not working. I am getting an IndexOutOfRangeException and sometimes no error but it just doesnt work. All help would be appreciated. Player class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace RPG { class Player { int X; int Y; Texture2D image; KeyboardState newstate; KeyboardState oldstate; Map map; public Player(int xPos, int yPos, ContentManager content, Map currentmap) { map = currentmap; X = xPos; Y = yPos; image = content.Load<Texture2D>("player"); } public void Move() { newstate = Keyboard.GetState(); if (newstate.IsKeyDown(Keys.Down) && oldstate.IsKeyUp(Keys.Down)) { if (map.grid[X, Y + 1] != 2) { Y += 1; } } if (newstate.IsKeyDown(Keys.Up) && oldstate.IsKeyUp(Keys.Up)) { Y -= 1; } if (newstate.IsKeyDown(Keys.Left) && oldstate.IsKeyUp(Keys.Left)) { X -= 1; } if (newstate.IsKeyDown(Keys.Right) && oldstate.IsKeyUp(Keys.Right)) { X += 1; } oldstate = newstate; } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(image, new Vector2(X * 32, Y * 32), Color.White); } } } [/CODE] Map Class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace RPG { class Map { public int[,] grid = new int[,] { { 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,0,0,0}, { 2, 2, 2, 2, 2, 2, 2, 0, 0, 0,0,0,0}, { 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,0,0,0}, { 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,0,0,0}, { 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,0,0,0}, { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,2,2,2}, { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,1,1,1}, { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,1,1,1}, { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,1,1,1}, { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,1,1,1}, { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,1,1,1}, }; static int TileWidth = 64; static int TileHeight = 64; int mapWidth; int mapHeight; public List<Texture2D> tileList = new List<Texture2D>(); public void Draw(SpriteBatch spriteBatch) { mapWidth = grid.GetLength(1); mapHeight = grid.GetLength(0); for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { spriteBatch.Draw(tileList[grid[y, x]], new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight), Color.White); } } } public Map(ContentManager content) { tileList.Add(content.Load<Texture2D>("dirt")); tileList.Add(content.Load<Texture2D>("grass")); tileList.Add(content.Load<Texture2D>("water")); } } } [/CODE] Game Class: [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace RPG { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Map map; Player player; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here map = new Map(this.Content); player = new Player(0, 0, this.Content, map); base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); player.Move(); // TODO: Add your update logic here base.Update(gameTime); } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); map.Draw(spriteBatch); player.Draw(spriteBatch); // TODO: Add your drawing code here spriteBatch.End(); base.Draw(gameTime); } } } [/CODE]