Robot Foot Games Helping you improve your games as we improve our own. :)

12May/120

Moving a sprite around the screen – part 1 – point A to point B

We're going back to some basics with this tutorial. I plan on doing a couple of spin-offs of this to address other issues like; facing the direction you're moving, moving along a series of points and some other ways of moving sprites that are a little more complex.

So here's the scenario for this part. You have a top-down point and click game and wherever you click on the screen, your character moves to that point. Nice and simple to begin with.

 

Starting out.

I created a new Windows Game 4.0 named "PointAndClickGame". I also added the image below to the "Content" folder:

 

Code. I tried to comment the code well enough to explain everything but I'll give some extra insight if I believe it'll help.

At the top of the Game1.cs class, lets add a few variables:

 

Now onto our LoadContent()method, should be pretty self-explanatory with the comments:

 

Inside of the Update(GameTime gameTime)method:

This is where the magic happens, so there's quite a bit going on. We get the direction from our player to his destination and then we move in that direction. When we reach our destination we set our direction to 0 in order to stop the character.

 

Now all we need to do is draw the image. Inside of Draw(GameTime gameTime):

We used one of the longer overloads that takes a Vector2 position and a Vector2 origin. This lets us draw the image so that 'spritePosition' is located at the very center of our character ('spriteTexture').

 

That's everything! When you run the game you should be able to click (and hold if you want) anywhere on the screen and the sprite will move to that location. If you want to increase/decrease the speed that the sprite moves you can change the 'speed' variable at the very top. I'm not sure what I'll tackle next for part 2 of this series but you can always follow me on twitter or add our RSS feed to your favorite reader to catch the next post when it goes live.

19Mar/120

Drawing extra symbols (squared/square root) in XNA

I'm starting to work on adding squared (i.e. 6²) and square root (i.e. √169) math to Math Buster 2 and I realized that I wouldn't be able to draw the square/square root symbol out of the box so I needed to modify a spritefont to include these characters.

First off, you need a font that supports these characters. An easy way to check if there is a specific character in your font, and you have the font installed to your windows font folder, is to use the built in Character Map in windows. You can find this at Programs » Accessories » System Tools » Character Map or you can press Windows+R (for the run dialog) then type in charmap and hit enter. This brings up a little windows that allows you to select a font and see all characters available for the selected font. Some fonts, as long as it's not a really obscure one, will even display the keystroke needed to type it in the bottom right of the window. When I double click on the subscript 2 (²) it shows "Keystroke: Alt+0178" in the bottom right. Neat!

Now you should have a font that supports the character we want, we need to modify our spritefont to include this character. By default spritefonts include characters 32-126, which includes most letter/numbers/symbols you can see on your keyboard. If you want extra symbols like ™ and ® you'll have to add them separately. Here's my spritefont that's been modified to include squared and square root symbols:

We add a CharacterRegion for each individual character we want to add to our spritefont (you can also add ranges of characters, like the default 32-126 CharacterRegion). As for where I found the numbers, like "&#8730" for the square root symbol, I just did some Googling to figure out what the square root symbol was (this site was helpful which had the squared symbol, but not the square root symbol). Now that you've modified your spritefont with these extra characters, you should be able to draw them with this spritefont! You just have to remember the specific keystroke so you can actually enter it in code. You can enter these new symbols straight into your DrawString call by using the specific keystroke:

 

18Feb/120

Math Buster 2 Announcement!

It's been a while since we released anything, but that's about to change!

What's new and improved in Math Buster 2?

  • The game uses a Silverlight/XNA hybrid, so when you're navigating the menus you'll have an experience that you'll be familiar with and we're using XNA for the gameplay to keep everything nice and smooth!
  • New game modes! In Math Buster you would choose the type (addition, subtraction, etc) and the difficulty before you played. This is now how the Practice mode works in Math Buster 2. The new leaderboard enabled modes have a more arcade-y feel to them and I think it's much smoother and keeps you on your toes more than the single type - single difficulty style of Math Buster.
  • Additional math types. Addition/subtraction/multiplication/division were in the previous game and I'm debating what to include with the new release. At the very least, I'd like to add more options to the Practice mode, like percentages and square roots.
  • Global leaderboards! This was by far the most requested feature so it was a no-brainer to add it.

No release date to announce at the moment but I'm hoping to have everything ready to go within the next month. As we get closer to release and things get polished you'll see more info about the game pop up on the blog, so stay tuned!

I figured an early screenshot was better than no screenshot at all, so bam!

19Dec/110

Ludum Dare 22 – Shadow

Ludum Dare, for those that don't know, is a competition to create a game in just 48 hours (for solo participants, teams can join the 72 hour competition). You have 48 hours to create a game from scratch but you can use publicly available libraries and personal code bases as long as they're open to everyone to use.

This was my first time entering and I wasn't real sure on how much I could get done in the time frame so I decided to start with something really simple and expand on that if I had more time. Overall, I'm pretty happy with how it turned out even though it has only a few sound effects and no music at all. I would've liked to get a story implemented but I just ran out of time. It was a good change of pace just being able to hack some code together without having to worry about cleanliness or robustness. :)

You can view the submission and play the game here: http://www.ludumdare.com/compo/ludum-dare-22/?action=preview&uid=5580

Here's a playthrough of the game below, don't watch if you're going to play the game!

Filed under: XNA No Comments
15Dec/110

Level Editor For Your XNA Platformer Based Games

When I first started out a level editor was beyond my abilities (or so I thought) but thanks to Nick Gravelyn's Tile Engine video series it's actually quite easy to get the basics of a level editor set up! It was also the first time I actually made something out of WinForms so it was a learning process along the way. The editor is very simple and comes with all of the source code so if you were ever wondering how you might tackle making one yourself  it's an excellent starting point to just tinker around and learn how the pieces fit together.

You can check out the project page on bitbucket to download and get more information but the general features of the editor are:

  • Open and Save .txt files (the format used for levels)
  • Paint/Erase/Fill tools so you can quickly change the appearance of your levels without editing them by hand
  • Tiles are displayed as images so you can easily see what you're editing with.

The project comes with a default XNA 4.0 version of the PSK so if you just want to check it out and play around with the editor you can do so (if you have Visual Studio).

Check out the Wiki Page if you want to get it working with your own PSK-based game.

I also made a video showing off just how easy it is to add it to your game (Nomis: Legacy Islands). I'm adding the Editor to my first game (which was based on the PSK) in the video.

Filed under: XNA No Comments