Get the latest Education e-news

 Game Career Guide Forums Game Programming Challenge 2: Scrolling Shooter
 Forum Home Register Members List Mark Forums Read

01-12-2009, 03:41 AM   #21
Kavity
Junior Member

I know I'm a little late to be trying this, but I've been trying to think of things I can work on for a while. I'm working offshore right now, so when I'm not working I can spend my spare time programming at this, and hopefully get it done before the deadline.

My only question is, can I use SDL/C++?

01-12-2009, 03:58 AM   #22
Claxon
Senior Member

Location: London

Yes providing it will run with little effort on the judges machines.

01-13-2009, 10:31 PM   #23
brainydexter
Member

Location: N. America

Rant time

Collision resolution is the one this time!

I have been scratching my head for quite some time now to make this work, but, gah!!

So, I am trying to get my character(which is no more than a square as of now) to move in the world. So, when there is a obstacle in front of him, he should not be able to move and when he jumps and lands on a height-tile, he should stop there...you get the idea!

Well, implementing it is not easy as it sounds (or maybe its just me over-engineering). So, here is what I did..

Depending on:
Code:
`(OriginX + velocity.X - CellCenterX)`
I decide which all squares can my character be in.
• OriginX = center of character's square
• velocity.X = velocity that is intended to be added if it is walkable
• cellcenterX = Center of the square on the map array grid

After I get that list, I see if all the squares are walkable. If they are, the character moves, else he doesn't.

Now, this works fine for the X axis, but when I get into the Y axis, things go for a toss I dont know whats messing up..my logic..my approach or what..please suggest me how should I solve it. I have done lots of headbanging...aaaa!

And ya, ignore the insanity @ display..radiation from my monitor with no output often leads me to this!

PS: Hit D to toggle debug info and P to pause/unpause
Attached Files

Last edited by brainydexter : 01-13-2009 at 11:04 PM.

01-14-2009, 01:51 AM   #24
Claxon
Senior Member

Location: London

Ah yes, I remember the days of battling with platform game collision detection. A more accurate name for what you need is "Collision Detection and Response", which means it's not enough to simply detect collision & forbid movement when it occurs, you also need to compensate by having the player 'bounce back' or slide along the surface so that they don't get stuck in a state of perpetual collision, and can never escape.

I've writen a method for you that you may find useful:

Code:
```private float FindGroundLevel(Vector2 pos)
{

Point checkPoint = Point.Zero;
float lastClearPoint = pos.Y;

checkPoint.X = (int)(pos.X) / Constants.TileWidth;

while (pos.Y < Constants.WindowHeight)
{
checkPoint.Y = (int)(pos.Y + objectSprite.Height) / Constants.TileHeight;

if (world.mapValueAt(checkPoint.X, checkPoint.Y) != 6 && world.mapValueAt(checkPoint.X, checkPoint.Y) != 0) // Non-empty space detected
break;

lastClearPoint = pos.Y;
pos.Y++;
}
return lastClearPoint;
}```
What this will do is find the closest ground level below a certain point of the level. I put this in your Player class, and called it from the player update method like this:

Code:
```/*
* Old collision code
*
if (velocity.Y < 0)
velocity.Y += 0.1f;
else if (velocity.Y > 0)
{
velocity.Y += 0.1f;
}
*/

float groundPos = findGroundLevel(new Vector2(position.X + (objectSprite.Width / 2), position.Y - (objectSprite.Height/2)));
if (position.Y < groundPos)
velocity.Y += 0.1f;
else if (position.Y > groundPos)
{
velocity.Y = 0.0f;
position.Y = groundPos;
}```
It could be improved, but I hope that's helped you out of your hole.

01-14-2009, 08:36 PM   #25
brainydexter
Member

Location: N. America

yaay! Thanks claxon, once again. I really appreciate your help and guess what, it works..yaaay

But, I have a question for you.. I dont understand how Findground(..) works between the range.. (player.posY - height/2) to (player.posY + height/2). Also, why do we choose to do this..
Quote:
 Originally Posted by Claxon Code: ```private float FindGroundLevel(Vector2 pos) { Point checkPoint = Point.Zero; float lastClearPoint = pos.Y; checkPoint.X = (int)(pos.X) / Constants.TileWidth; while (pos.Y < Constants.WindowHeight) { checkPoint.Y = (int)(pos.Y + objectSprite.Height) / Constants.TileHeight; if (world.mapValueAt(checkPoint.X, checkPoint.Y) != 6 && world.mapValueAt(checkPoint.X, checkPoint.Y) != 0) // Non-empty space detected break; lastClearPoint = pos.Y; pos.Y++; } return lastClearPoint; } float groundPos = findGroundLevel(new Vector2(position.X + (objectSprite.Width / 2), position.Y - (objectSprite.Height/2))); if (position.Y < groundPos) velocity.Y += 0.1f; else if (position.Y > groundPos) { velocity.Y = 0.0f; position.Y = groundPos; }``` It could be improved, but I hope that's helped you out of your hole.
I will soon add this to my FAQ, as soon as I completely understand it .

Anyways, next stop, I'm thinking to define my level.
Thanks a ton

Last edited by brainydexter : 01-14-2009 at 09:02 PM.

01-14-2009, 11:44 PM   #26
Claxon
Senior Member

Location: London

FindGroundLevel() is basically the code from one of your existing methods to test if it is a floor tile put into a loop. You pass it a world position and it will check to see if that position is a solid platform. If it is, it will return the position you passed (though the ground level may actually be higher, because it doesn't trace upwards), if however it is an empty tile, the loop will increment the Y position (move one pixel down) and run the check again. Basically it will check every pixel until it hits a platform, then it will return the last empty pixel.

When we call
float groundPos = findGroundLevel(new Vector2(position.X + (objectSprite.Width / 2), position.Y - (objectSprite.Height/2)));

it starts checking from the Top-Center point of your player sprite and then scans all the way down beyond the sprite's feet. I did it here rather than start at the sprite's feet because if the sprite happened to be just 1 pixel too far down, it would instantly collide with the floor, and would stop moving. Where you trace from is really up to you though.

01-15-2009, 08:02 AM   #27
Duckman
Member

Location: Tuckahoe, NY

I am working on this using DirectX and C++ and my progress is quite slow. I am basically learning as I go on this one, and as of now I have only have a ship that can move and fire bullets terribly. I am trying to establish a rate of fire as of now because the bullets collide and it doesn't look very nice. I am currently at work, but if you guys want me to zip up the code, I can do that from home tonight. I don't think I will be able to finish the game by the deadline to perfection, but might just enter it for criticism and complete it later on. I just need some direction on what to do next once I get collision detection down.
__________________
Mike M

01-15-2009, 08:27 AM   #28
dzeligman
Member

If you have a functional ship that can move back and forth, and shoot projectiles than thats a pretty solid start.

I'd work on whatever enemy mechanic you'd want to focus on in the game. How they spawn in the world... How they move... some pathing, or something similar along those lines

01-15-2009, 03:30 PM   #29
mordekai
Junior Member

Location: Seattle WA
just noticed this

Quote:
 Originally Posted by Claxon Judging on this competition will begin on the Sunday 27th January and Judges comment will be posted by the following weekend.
is the deadline on Sunday the 25th? or Tuesday the 27th?
__________________
my gamedev blog

01-16-2009, 12:08 AM   #30
Claxon
Senior Member

Location: London

Whoops! I was obviously looking at January 2008 instead of 2009! I've changed it to Sunday 25th January. Sorry for the confusion!

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off