Character Movement
Moderator:Moderators
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?
(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?
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.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
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.
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.
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;
}
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.