Help With Platfromer Gravity
Author |
Message |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Wed Jan 06, 2010 11:07 am Post subject: Help With Platfromer Gravity |
|
|
I am trying to get my gravity to work, it doesnt seemt o work when you just roll of platfroms, i know why, i just have trouble figuring out where to place this one line of code. They code that needs to be put in is:
Here is the rest of the program.
Turing: |
%MAKE A JUMPING GAME
%BEN *******
class platform
export all
type aPlatform :
record
x1, x2, y, clr : int
end record
var pform : aPlatform
proc drawplatform (X1, X2, Y, CLR : int)
pform.x1 := X1 % RIGHT SIDE
pform.x2 := X2 % LEFT SIDE
pform.y := Y % HEIGHT
pform.clr := CLR % COLOUR
drawline (pform.x1, pform.y, pform.x2, pform.y, pform.clr )
end drawplatform
proc generate
end generate
end platform
%SET UP PLATFORM VARIABLE
var aplatform : flexible array 1 .. 1 of ^platform
new platform, aplatform (upper (aplatform ))
class player
import Input, aplatform, platform, Math
export all
const gravity := 1
const radius := 5
const movespeed := 3
const jumpspeed := 15
const maxvelocity := - 7
type aPlayer :
record
x, y, xsp, ysp : real
end record
var user : aPlayer
var ground : boolean := false
user.xsp := 0
user.ysp := 0
user.x := maxx div 2
user.y := 0
var chars : array char of boolean
var t1 := 0
proc move
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) and ground and Time.Elapsed - t1 > 500 then %JUMP
t1 := Time.Elapsed
user.ysp := jumpspeed
ground := false
end if
if chars (KEY_LEFT_ARROW) then %MOVER LEFT
user.xsp := -movespeed
elsif chars (KEY_RIGHT_ARROW) then %MOVE RIGHT
user.xsp := movespeed
else
user.xsp := 0
end if
%MOVE THE PLAYER
if user.ysp > maxvelocity and ground = false then
user.ysp - = gravity
end if
user.x + = user.xsp
user.y + = user.ysp
end move
proc draw
drawoval (round (user.x ), round (user.y ), radius, radius, black)
end draw
proc detect
%SET BOUNDERIES
%RIGHT AND LEFT
if user.x + radius > maxx then
user.x := maxx - radius
elsif user.x - radius < 0 then
user.x := radius
end if
%UP AND DOWN
if user.y + radius > maxy then
user.y := maxy - radius
elsif user.y - radius <= 0 then
user.y := radius
user.ysp := 0
ground := true
end if
%PLATFROM DETECTION
for o : 1 .. (upper (aplatform ))
for decreasing i : - 1 .. - round (abs (user.ysp ))
if user.y + i = platform (aplatform (o )).pform.y + radius and user.x >= platform (aplatform (o )).pform.x1 and
user.x <= platform (aplatform (o )).pform.x2 and user.ysp < 0 then
user.y := platform (aplatform (o )).pform.y + radius
user.ysp := 0
ground := true
end if
end for
end for
end detect
end player
%PROGRAM
setscreen ("offscreenonly")
%SET UP PLAYER VARIABLE
var aplayer : ^player
new player, aplayer
%INITIATE PLATFORMS
for i : 1 .. 4
new aplatform, (upper (aplatform ) + 1)
new platform, aplatform (upper (aplatform ))
end for
loop
aplayer -> move
aplayer -> draw
%PLATFROMS
aplatform (1) -> drawplatform (50, 100, 120, 255)
aplatform (2) -> drawplatform (120, 170, 50, 255)
aplatform (3) -> drawplatform (120, 170, 190, 255)
aplatform (4) -> drawplatform (50, 100, 260, 255)
aplatform (5) -> drawplatform (120, 170, 310, 255)
aplayer -> detect
%JUST FOR TEST PURPOSES
locate (1, 1)
put "X: ", player (aplayer ).user.x, " Y: ", player (aplayer ).user.y - player (aplayer ).radius, " YSP: ", player (aplayer ).user.ysp
View.Update
cls
Time.DelaySinceLast (10)
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed Jan 06, 2010 1:44 pm Post subject: RE:Help With Platfromer Gravity |
|
|
You need to check if the player is still on the platform. Prolly in the 'move' procedure, check against platform and floor coordinates and set it to false if the player isn't on a platform |
|
|
|
|
![](images/spacer.gif) |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Wed Jan 06, 2010 8:39 pm Post subject: Re: RE:Help With Platfromer Gravity |
|
|
insectoid @ Wed Jan 06, 2010 1:44 pm wrote: You need to check if the player is still on the platform. Prolly in the 'move' procedure, check against platform and floor coordinates and set it to false if the player isn't on a platform
yeah but if im already cheking if its ON a platfrom, why dont i just put an:
Turing: | else
ground := false
end if
|
but this doesnt work. |
|
|
|
|
![](images/spacer.gif) |
|
|