• 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.
Sign in to follow this  
Followers 0
  • entries
    5
  • comments
    17
  • views
    5199

Move, <player>!

Sign in to follow this  
Followers 0
Truerror

978 views

Yes, this entry is about movement. I think it'll be a short one, though I must admit, movement in a tile-based game is harder than I thought. Ok, now on to the technical bits.

You see, the difficulty (at least for me) of making a tile-based game mostly lies on the fact that everything, virtually everything must adhere to a certain set of grid; The positions of the the objects, the map, the tiles themselves, and last but not least, the movement. Now, of course there are are aspects of it that makes the development process easier. The collision for example, is easier to implement compared to, say, a platformer, since all we need to do is mark a certain tile "occupied" and tell the objects they can't enter an occupied tile, other than their current tile. While that certainly sounds easier to do than the actual practice, it's still simpler to implement than the full-fledged collision checking often required in other types of games.

For the game, I needed a way to select a certain game object when the user clicks on it, which (since the end destination would also be determined by a mouse click) means I also needed a way to know which tile my mouse is currently in when I clicked the left/right button. I had a solution in my mind, but I wasn't certain it'd be good enough, since it involves scanning through the entire tileArray. So, I searched around and found something called "picking". Unfortunately though, further inquiries only revealed 3D solutions. The few answers I found regarding 2D tile-based picking were pretty much similar to my own solution. One StackOverflow question answer however, said that while it would certainly be heavy, it's still good enough, since we're not doing it every single frame, only on a mouse click. So, I decided to go with it.[code=auto:140] public static Point MouseCoordinate(MapParser mapParser) { Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); foreach (Tile tile in mapParser.tileArray) { if (mousePos.X >= tile.position.X && mousePos.X < tile.position.X + 20) { if (mousePos.Y >= tile.position.Y && mousePos.Y < tile.position.Y + 20) { Console.WriteLine(tile.coordinate.X.ToString() + " " + tile.coordinate.Y.ToString()); // For debugging only. return tile.coordinate; } } } return new Point(0, 0); }
First of all, please disregard the magic numbers. My tiles are 20 by 20 pixels in size. I plan to refactor that, so that it can accept an arbitrary size.

As you can see, I've put a console output there, just so I can be sure it works. I also tweaked the MapParser and GameObject class a bit since using a 2D array means your coordinate axes are flipped. And now that I have a way to tell which tile my mouse is in, I'll also need a way to tell which object I selected, or whether I have any object selected at all.[code=auto:157] public void SelectedObject(List objectCollection) { foreach (GameObject item in objectCollection) { if (item.Coordinate == MouseCoordinate(mapParser)) { currentObject = item; } else { currentObject = null; } } }
There! Now I not only know which tile is selected, and which object is selected. That leaves the movement function.[code=auto:172] public void Movement(GameObject gameObject = null) { if (gameObject != null) { gameObject.Coordinate = destinationTileCoord; if ((int)gameObject.Position.X < (int)destinationTile.position.X) { gameObject.Position = new Vector2(gameObject.Position.X + 1, gameObject.Position.Y); } else gameObject.Position = new Vector2(gameObject.Position.X - 1, gameObject.Position.Y); if ((int)gameObject.Position.X == (int)destinationTile.position.X) { if ((int)gameObject.Position.Y < (int)destinationTile.position.Y) { gameObject.Position = new Vector2(gameObject.Position.X, gameObject.Position.Y + 1); } else gameObject.Position = new Vector2(gameObject.Position.X, gameObject.Position.Y - 1); } if (gameObject.Position == destinationTile.position) gameObject.isMoving = false; } }
Yes, I know, that code looks superheavy, and superbad. I also think so, but turns out the performance doesn't get any perceivable hit. The superbad is true though. I don't have any profiling tools, so I simply fired up the trusty Task Manager wink.png and played around while checking to see if it's too heavy. For now, it gets 7-10% CPU usage and around 9MB memory. However, I realize that this is still very early, and the game contains too few objects for it to be accurately measured. So things will certainly get heavier from here on.

Oh, and if you're wondering why I had make sure the X movement is finished before starting the Y movement, that's because I wanted the movement to be like Super Robot Wars, which is the inspiration for this experimental game. In SRW (at least the GBA version, I haven't played SRW in any other platforms) objects would move in a straight line along an axis, no diagonal movements. The end result is this:

[media]
[/media]

0
Sign in to follow this  
Followers 0


2 Comments


Couldnt you use a simple mathematical expression to find the tile coordinates out of the mouse position (translate,scale,offset and round the mouse position to get the tile integer position)

1

Share this comment


Link to comment

translate,scale,offset and round the mouse position to get the tile integer position

 

Can you elaborate more on that?

 

Edit: Nevermind. I think I understand. And now I feel stupid. tongue.png

 

Yes, you're right. The width and height of each tiles are fixed, so I shouln't have any problems getting the tile coordinate from the mouse position. Thanks for the suggestion.

0

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now