Platform Jumping Help
Author |
Message |
evildaddy911
|
Posted: Thu Oct 27, 2011 7:42 am Post subject: Platform Jumping Help |
|
|
What is it you are trying to achieve?
simple platform jumping game
What is the problem you are having?
the character sinks into the platforms and sometimes goes through them
Describe what you have tried to solve this problem
altering the whatdotcpolor for loops to predict when the character will make contact:
Turing: | for i : x - 3 .. x + 3 %checks if you are in contact with gray walls
for j : y - 3+ yv .. y + 3
if whatdotcolor (i, j ) = grey then
move := false
yv := 0
elsif whatdotcolor (i, j ) not= grey then
move := true
end if
end for
end for |
insted of
Turing: | for j : y - 3 .. y + 3 |
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
if move = true then %for parabolic jumping
yv := yv - 1
end if
drawfillbox(x- 3,y- 3,x+ 3,y+ 3, black) %draws character
|
Please specify what version of Turing you are using
4.1.1.0
Description: |
heres the entire code if you want it |
|
Download |
Filename: |
basic game.t |
Filesize: |
1.49 KB |
Downloaded: |
84 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Zren
|
Posted: Thu Oct 27, 2011 7:38 pm Post subject: RE:Platform Jumping Help |
|
|
Your relative coordinate in your for loop seems to be a bit off.
for j : y - 3 + yv .. y + 3
y := 5
yv := 10
for j : 5 - 3 + 10 .. 5 + 3
for j : 12 .. 8
I'm also going to assume there is no change in position over the x plane.
~
Also, what happens when the pixel (i, -3) is grey, but (i, -2) isn't grey?
|
|
|
|
|
|
evildaddy911
|
Posted: Fri Oct 28, 2011 10:21 am Post subject: Re: Platform Jumping Help |
|
|
do you mean (i,y-3)?
also, i took out the i forloop and just used
then i put in another whatdotcolor forloop for the lateral movement:
Turing: | if whatdotcolor (x, y ) not= gray then
if chars ('a') and x > 29 then %moving left/right
x := x - 1
elsif chars ('d') and x < (maxx - 29) then
x := x + 1
end if
elsif whatdotcolor (x + 1, y ) = gray then
x := x - 1
elsif whatdotcolor (x - 1, y ) = gray then
x := x + 1
end if |
|
|
|
|
|
|
Zren
|
Posted: Fri Oct 28, 2011 11:09 am Post subject: RE:Platform Jumping Help |
|
|
I purposely put the range from -3 .. 3 in the for loop I copied from you. This was to simplify the thought process.
Bascially, -3 would be gray, and thus:
move = false
vy = 0
but then you keep running though the loop, and since -2 is not gray:
move = true.
But wait? vy = 0 so nothing should be happening right? Well, at least until you hit your 'gravity code', which does vy -= 1 when move is true.
~
Basically you were doing:
y + vy - (width/2) .. y + (width/2)
Your right side was missing the displacement of moving that frame (velocity_y). So the upper limit could be skimping on some areas to check. Or in the case I mentioned, not check at all.
~
You were on the right track before. You were (trying to) calculating collision detection on where you'd end up before moving.
dx = obj.x + obj.velocity_x
dy = obj.y + obj.velocity_y
Check collision on (dx,dy). If no collision -> move obj.
Your player should never end up in a wall to begin with, thus you shouldn't need to worry about 'pushing' him out of the wall.
~
Also, by removing that for loop (I'm assuming as I don't have your updated code), you're now only checking collision (above? and) below the box's (x,y). Essentially your collision detection is for a line now. So the box will overlay over your walls possibly.
|
|
|
|
|
|
|
|