[syntax="turing"]
var playerX, playerY, velocityX, velocityY : int
var move : array char of boolean
setscreen ("graphics:1200;600, offscreenonly")
% Set variables and constants
playerX := 100
playerY := 50
const XSpeed := 4
const YSpeed := 20
const gravity := 2
% Draw player original position
drawfillbox (playerX - 10, playerY, playerX + 10, playerY + 30, brightgreen)
loop
velocityX := 0
velocityY := 0
% Draw platforms
drawfillbox (0, 0, maxx, 5, black)
drawline (0, 150, 150, 150, black)
drawfillbox (playerX - 10, playerY, playerX + 10, playerY + 20, brightgreen)
View.Update
cls
% Movement
Input.KeyDown (move)
if move (KEY_LEFT_ARROW) then
velocityX := -XSpeed
end if
if move (KEY_RIGHT_ARROW) then
velocityX := XSpeed
end if
% Collision detection
if whatdotcolor (playerX, playerY) not= 0 or whatdotcolor (playerX, playerY - 5) not= 0 then
if move (KEY_UP_ARROW) then
velocityY := YSpeed
end if
else
velocityY := -gravity
end if
if playerY <= 5 then
playerY := 6
end if
% Subtract gravity and calculate new player position
velocityY -= gravity
playerX += velocityX
playerY += velocityY
delay (25)
end loop
[/syntax]
|