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
|
|