Saturday, February 27, 2010

About time!

I managed to get all the player mechanics and weapon collisions working! Now if I could get an artist & a music composer...

I can't believe I struggled for the last 2 days to get bouncing working correctly, only to find I made a mistake with the center of a rectangle! By 0.5 to be exact! The darn weapon kept going straight into the 2D terrain...

I really want to show some pictures..but only the mechanics are in working order, not the artwork. So once again..stay tuned! Hopefully a prototype will come under way, once I get enemy mechanics into it.

Tuesday, February 23, 2010

Basic 2D mechanics

Ah I solved my jumping problem, had to add a couple of booleans and update according to time instead of the actual states.

Now I will integrate the theory I mentioned in my second post. Stay tuned! (although I do hope no one is reading this.)

Monday, February 22, 2010

State machine roadblocks

Finding it difficult to get all the states to work together. The main issue is that if my character throws a weapon in the middle of a jump, the translation gets messed up.
Had an awkward cosine formula for the jump, but I redesigned the whole thing so I'd only need plus values and gravity values in the opposite direction, which is what I spent today doing. Quite pleased with the simplification. Probably easier to debug my problem now.
I'll make this short. It's 5am.

Sunday, February 21, 2010

Collision with sprite map, no tiles


This is the solution I have come up with to solve bouncing off slopes.
1) Create a bounding circle around the sprite (black circle).
2) Similarly, create a bounding rectangle the same size as the 'weapon' on the collision mask. All my collisions are done this way.
3) Per-pixel collision between circle and rectangle, if no collision, no bounce.
4) Check all pixels within the map's collision rectangle against the circle. If the pixels can be contained within the circle, store their locations.
5) Using those stored locations, form a best-fit rectangle around them (red lines). From this, find the center of the rectangle.
6) The vector formed between the center of the circle and the circle of that rectangle is the line of incidence (blue line).
7) Reflect the direction vector of the weapon around the incident vector. (black lines)

Woah, that's a long explanation, but its pretty logical (at least to me).

A few other solutions which came up to mind are (briefly)
1) Line map; a text file with a series of 'points' defining lines. From those points I could then find the gradient; if there is a collision (using ray-casting), use some physics to calculate bounce angle. But then I'd need to manually come up with all the points, and read them from the file!
2) Colour map; use RGB values to define gradients (in a collision mask). Most certainly not.

Friday, February 19, 2010

Very first post

Alright let's get things started!

Been building a game in XNA since November 2009, sorta drifted away from the idea, and have now reopened the project.
I've had a general game design in my head, but not one solid enough to put down on paper. Basically, its a 2D platformer where the player shoots off a weapon which bounces off the screen & walls like in Pong, and hits enemies above him as though you were playing Galaxian.
I've pretty much been handling the coding of the player's states, and the collisions. Been struggling to understand how I'm going to get a weapon to bounce off a 2D map. Currently, I'm using a separate collision map.
Only yesterday did I manage to get some headway with the player's character's collisions. The player can now jump, and land on a 2D map, as well as going up slopes, all while being affected by gravity. I shunned using a tilemap, it just doesn't look spiffy enough, as such it's not as easy to calculate collisions against inclined surfaces.

I'll conclude this post for now, hopefully I'll get somewhere by today.