XNA “Platformer” added to the Silverlight community gallery

My conversion of the XNA starter kit to Silverlight, using SilverSprite, have been accepted into the Silverlight Community Gallery. This is really great and I hope it helps somebody out there. You can view it and download the source from the link above.

You can see my original post about the conversion here: http://laumania.net/post/Porting-XNA-starter-kit-Platformere2809d-to-Silverlight-(SilverSprite).aspx

– Enjoy!

Porting XNA starter kit “Platformer” to Silverlight (SilverSprite)

I read this post by Bill Reiss the other day and found out about this marketplace thing that Xbox have. (I don’t have an Xbox myself so didn’t knew anything about the community actually. I have a PS3). After reading this, I got a little interested in XNA and thereby SilverSprite, as I can see potential in this new “Xbox Live Independent Games” thing. I haven’t done any XNA or SilverSprite before, only knew very little about both.
So, I decided to take a look at it as it might be interesting to do my current game in XNA and Silverlight. So I started to do a little research.

First I started by follow be beginning of this guide and eventually got Xna game studio 3.1 installed. Then I downloaded the latest changeset for SilverSprite (which supported silverlight 3), so I had the source for that on my pc.
I created an default xna windows project 3.1, so I had something to try things on. The code that comes with this default project were pretty easy to understand and I quickly made a small “game” where a sprite were sliding around the screen and pressing the space button changed the background color. Pretty simple and easy. I got that working in Silverlight using SilverSprite pretty fast, so I thought I needed something a little more complex.

I saw that Xna Game Studio 3.1 comes with a starter kit “Platformer”, so I decided to give that a try. After about 4 hours I had a playable version of “Platformer” running in Silverlight and Windows with the exact same code base – wow! At first 4 hours might sound like much to you, but I needed to change stuff in the Platformer game code and in the SilverSprite core to make this work and if you keep in mind that I haven’t worked with either Xna or SilverSprite before, I think it pretty fast :)

image

Play
You can try out the game here (Warning: It’s the same assets as in the XNA version, so the game is about 9 MB) : http://silverlight.laumania.net/platformer/

Source
You can get the entire source from here: http://silverlight.laumania.net/platformer/platformer1.zip

Keep in mind that to be able to build the source, you need Xna Game Studio 3.1 and Silverlight 3 Tools installed.

To see all the things I have changed/implemented search for “laumania” in the entire solution. I have made minor comments. The SilverSprite version in this source, is a modified one as stated. I have submitted the changes as patches to the SilverSprite, so they will be in the original source too soon I guess.

My experience of using Xna and SilverSprite were actually really good and I decided to give my current project a try in Xna and SilverSprite :)

– Enjoy!

Little Longhorn – Part 3 – Collision, Detection and Selection (Help needed)

image 
As you might already know, I’m currently trying to get some of the basic stuff implemented for an “Tower defense”-genre (TD) game into Little Longhorn. I’m making progress, but have now run into a little problem. In this blog post I will try to explain which features that are coursing the trouble and hopefully, after I got some input/help from some of you guys out there, I can also post the solution for others to learn from and use.
Let me also make it clear that I’m not asking for complete code samples provided by one of you guys, I’m asking for a good dialog about this problem and different possible solutions for it. I will figure out the code myself, it’s the “thoughts behind” or what you want to call it I’m after here, some inspiration you could say. Hoping for some good input :)

WARNING: This post includes my own hand-made drawings! :)

Course of the problem(s)
Well, the main reason to this/these problems are that Little Longhorn is a little different than a normal TD. In normal TD games I see a lot of use of the mouse to interact with the game, Little Longhorn doesn’t use a mouse for anything. You are now thinking, “But how are you going to place towers, upgrade them etc?”. Instead of a mouse, you have an character you play in the game. This little guy is controlled by the arrow keys at the moment. This little player character will walk around, avoiding being hit by enemies, while he collect gold and build new towers, controlled by you of course. So you actually have to “walk” to where you want your tower and then build it there. It might sound weird to you, if you are use to play the standard online TD games, but believe me, this works and adds a hole different aspect to the game.
The above is what course the troubles I’m having here, but let me explain what I’m trying to archive and then you might see the problem.

The actual problem(s)
The following is what I need to have implemented in the game.

“Normal” collision
I need basic collision in the game. This is actually almost in place in the code and is actually working ok. My implementation is pretty similar to what Joel Neubeck describes in this article, I just have it all divided up in classes etc, but the basics are the same. This collision mechanism should be used to detect is the player is colliding with an enemy.

(Yes, I made this drawing myself :) Keep in mind that all graphics you see on screenshots, drawings etc, are all just “temp” graphics, so don’t get confused if an enemy looks like an alien in one image and a beetle in another one)

image

This is the most common collision (and maybe the mechanism that all the rest of the features can use? I’ll get back to that later). GameObject A intersect with GameObject B, and a “Collide()” method is called on both GameObject’s which they can act upon.

“Block” collision
At some point in the game, I need to be able to place objects that that player can’t go through, ex. a rock. This is essential the same collision as the “normal” one, I just can’t figure out how to implement it? All my “GameObjects” moves around using the normal “Vector/Velocity” approach (if you don’t know this approach Joel Neubeck describes this too in this article series). I have tried setting the Velocity equals to an “Zero” when the player hits a “rock” (actually i tried it on an enemy just for testing purpose), but it didn’t have the right effect :)

image

“Detection” of enemies
One of the basic features in a TD game, is the towers ability to detect enemies in a range and shoot at them. I have this implemented in the game right now actually, but it’s done by using the “normal” collision detection described above. This works “ok”, but is it the “right” way to do it? What I have done now is that I have given the towers a big “CollisionSphere”, which is actually a collision object, but act as a “range of sight” for the tower. Is this the right way to do it? I mean, at the moment, when the enemy is inside the towers “range” a collision is happening in every tick of the game. Is that wise or could this be done in another and better way?

image

“Selection” of elements
As stated earlier you don’t have a mouse in this game, all interaction is done through your player character. In the game you can only build towers on special elements that I (the level editor) put in there. This mean that when you want to build a tower to need to move your player character close to one of these “building” spots, hit “space” and a build-menu will show up. You choose the type of tower you want to build, and hit “space” again and your tower is build on that spot(this isn’t actually implemented in the game yet). The same approach is used when you want to delete or upgrade a tower. Move close to it and hit “space” and the options for this tower will appear.
The problem for me, at this point in time, is this “selection” mechanism. Basically, in my head that is, this is also a kind of “collision”, but at the same time it’s conceptually not, because nothing is actually colliding logically. 

image

 

Let’s sum it up
All the above can somehow to boiled down to being “collision” related. I just can’t figure out how I should implement these features. I have tried out different things but nothing seems to be “good”. In my mind all of the above should be able to be archived by using the same “intersection” algorithms that I use already and then adjust the behavior of the colliding objects properly, it’s just not that simple. I’m pretty empty on good idea for how to implement this, so all input are welcome. Please let me know if you need more information about something and I will gladly give it to you.

You can get the current source code of the game here. The game is not intended to be an open source game, but I have decided to share the code in this early stage, to give you guys the best possibility to help me out here. And then you can also see how I have build the game so far. Keep in mind that the source is very work-in-progress, which is why there are a lot stuff in there that isn’t used for anything.

Hope for great dialog and some good feedback/ideas.

Thanks in advance :)