Character Movement

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator:Moderators

Post Reply
User avatar
ghosstt
Senior Member
Posts:1551
Joined:Mon Feb 26, 2007 4:14 pm
Character Movement

Post by ghosstt » Wed Nov 21, 2007 10:32 am

ok, so i don't have VB.net installed right now, so i can't run any code(its dloading now). But i would like to know how to get a character moving via WSAD, or the arrow keys.

(no animation yet)

render bmp

check if 1px above bmp is open

delete bmp, rerender it

would that work? or is there an easier way?

myersn024
Posts:212
Joined:Mon Dec 11, 2006 2:34 pm

Post by myersn024 » Wed Nov 21, 2007 12:45 pm

you've got the general idea. the standard technique is the following.
- read keys to check for movement
- update character position variables and do collision detection
- clear screen
- draw background if necessary
- draw character
- flip the screen
- repeat

User avatar
Skyone
Moderator
Posts:6390
Joined:Tue Nov 29, 2005 8:35 pm
Location:it is a mystery
Contact:

Post by Skyone » Wed Nov 21, 2007 5:30 pm

myersn024 wrote:you've got the general idea. the standard technique is the following.
- read keys to check for movement
- update character position variables and do collision detection
- clear screen
- draw background if necessary
- draw character
- flip the screen
- repeat
Well, you should generally proceed through collision detection before updating coordinates. Otherwise, I highly doubt he's using DirectX, so it's unnecessary to flip the buffer screen.

User avatar
ghosstt
Senior Member
Posts:1551
Joined:Mon Feb 26, 2007 4:14 pm

Post by ghosstt » Wed Nov 21, 2007 6:32 pm

nope. not using DX. does anyone have some example code for collision detecting? (just so i can get a base)

myersn024
Posts:212
Joined:Mon Dec 11, 2006 2:34 pm

Post by myersn024 » Wed Nov 21, 2007 6:53 pm

That was just the general technique that I use. In reality, there's a lot more to it.

@ghosstt: I can post up some simple bounding box collision detection code when I get back to my computer. It's all in C++, and I don't know any vb.

User avatar
ghosstt
Senior Member
Posts:1551
Joined:Mon Feb 26, 2007 4:14 pm

Post by ghosstt » Wed Nov 21, 2007 6:57 pm

i could try and convert it to vb.net

myersn024
Posts:212
Joined:Mon Dec 11, 2006 2:34 pm

Post by myersn024 » Wed Nov 21, 2007 10:25 pm

Alright, here's my bounding box collision code. In spite of the fact that it's in C++, you still may have a hard time understanding what I'm doing since I actually use my if statements to test for the lack of collision. My philosophy is that your sprites take up very small portions of the screen, and therefore it is more likely that they aren't colliding, and as such it takes less tests to determine whether or not collision has taken place, which leads to a quicker running program. Anyway, on to the code.

Code: Select all

bool collide(float bx, float by, float bw, float bh, float gx, float gy, float gw, float gh)
{
	if((bx + bw) < gx || (gx + gw)) return false;
	if((by + bh) < gy || (gy + gh)) return false;
	return true;
}
bx is the x position of object b and gx is the x position of object g. by and gy are b's and g's heights respectively. bw and gw are b's and g's widths.

If I had any clue as to how to program in vb.net, I'd convert it to something you're more familiar with. Maybe someone else here will be able to do it for you.

User avatar
ghosstt
Senior Member
Posts:1551
Joined:Mon Feb 26, 2007 4:14 pm

Post by ghosstt » Wed Nov 21, 2007 11:51 pm

what are b and g

User avatar
Skyone
Moderator
Posts:6390
Joined:Tue Nov 29, 2005 8:35 pm
Location:it is a mystery
Contact:

Post by Skyone » Wed Nov 21, 2007 11:53 pm

ghosstt wrote:what are b and g
...your character and its collision.

myersn024
Posts:212
Joined:Mon Dec 11, 2006 2:34 pm

Post by myersn024 » Thu Nov 22, 2007 7:49 pm

Skyone wrote:
ghosstt wrote:what are b and g
...your character and its collision.
yeah, b ang g are the objects that I'm checking for collisiong between. Just think of b as badguy and g as good-guy.

Post Reply