Calculator Community > The Axe Parser Project

Need Help With Collision

(1/2) > >>

Nathonion:
So I'm making a game and for the life of me, I can't figure out how to implement collision. It's a game inspired by counter-strike (and will eventually actually BE more like it later on) with a top-down view of a person with a gun, and when you press left or right, the player will rotate, and when you press forward or back, the world moves away, making it seem that the player is moving. I made it so that a tilemap will draw relative to the x,y of the player as well. Now all I need is collision with the walls. Every way I go about it doesn't work. So I need help, or some sort of tip or something. I'll include a file with the source code and game if you want to see it. Thanks!

Sorunome:
Mind adding the important parts in [code]-tags?

Nathonion:

--- Quote from: Sorunome on January 16, 2017, 05:58:27 pm ---Mind adding the important parts in [code]-tags?

--- End quote ---
Sure!
To draw the room (the data for the room layout/tile sprites are in prgmCSTILE):

--- Code: ---For(B,0,11
For(A,0,19
{B*20+A+GDB1}->T
If T
T--
Pt-On(A*8-(X//4)+44,B*8-(Y//4)+28,T*8+Pic2
End
End
End

--- End code ---
Moving/rotating:

--- Code: ---If getKey(55)            (Controls speed of movement/rotation)
11->S
Else
22->S
End
If getKey(2)              (Turn Left)
Z+S->Z
If Z>255
0->Z
End
End
If getKey(3)              (Turn Right)
Z-S->Z
If Z<<0
254->Z
End
End
If getKey(4)              (Move forward)
-sin(Z)//(264/S)+X->X
-cos(Z)//(264/S)+Y->Y
End
If getKey(1)             (Move backward (slower))
sin(Z)//(528/S)+X->X
cos(Z)//(528/S)+Y->Y
End

--- End code ---
Note: All this happens in a Repeat loop.

Sorunome:
So in drawing you have

--- Code: ---{B*20+A+GDB1}->T

--- End code ---
I guess that is to fetch the tile ID and if it is non-zero then it is a wall, so that only blank stuff is walkable?

The basic idea is to do those checks before moving, so maybe something like this: (Assuming A and B are free)

--- Code: ---If getKey(4)              (Move forward)
-sin(Z)//(264/S)+X->A
-cos(Z)//(264/S)+Y->B
{B*20+A+GDB1}->T
If T
A->X
B->Y
End
End

--- End code ---
The other movements would have to be adapted in the same way

Nathonion:
I tried to implement this, but it didn't seem to line up right. The player would stop moving in random spots, and in some places you could still walk through walls. Could you maybe explain what the code means exactly?

Navigation

[0] Message Index

[#] Next page

Go to full version