Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with Turing platforms Please (Urgent)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mohammad033




PostPosted: Sat Jun 09, 2018 3:06 pm   Post subject: Need help with Turing platforms Please (Urgent)

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>

i am trying to make platforms where i could jump and stay on when i am at a certain x coordinate

What is the problem you are having?
<Answer Here>

whenever the program is started it does not on the platform and falls to the floor

Describe what you have tried to solve this problem
<Answer Here>

i have tried many things but do not know how to describe what i am doing since i started Turing 1 mount ago

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

setscreen ("graphics:1211, 607")

const GROUND_HEIGHT := 63
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2.0

var chars : array char of boolean

% player position and velocity
var posx, posy : int
var velx, vely : real

posx := 20
velx := 0
posy := 400
vely := 0

loop
Input.KeyDown (chars)
if chars ('q') then
exit
end if

% to make the player move
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if

% remember, in order to jump you MUST be on the ground when pressing UP
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT or posy = 148 or posy = 231 or posy = 314 or posy = 397 then
vely := JUMP_SPEED
end if

% subtract your "gravity" constant from the velocity EACH frame
vely -= GRAVITY
posx += round (velx)
posy += round (vely)

% simple "collision" check. just makes sure the player stays above ground
if posy < GROUND_HEIGHT then
vely := 0
elsif posy = 148 then
posy := 148
vely := 0
elsif posy = 231 then
posy := 231
vely := 0
elsif posy = 314 then
posy := 314
vely := 0
elsif posy = 397 then
posy := 397
vely := 0
end if


% different colours just to illustrate whether or not you may jump
if posy = 63 or posy = 148 or posy = 231 or posy = 314 or posy = 397 then
drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
else
drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
end if
drawbox (104, 21, 559, 63, brightred)
drawbox (1100, 21, 646, 63, brightred)

drawbox (104, 135, 559, 148, brightred)
drawbox (1100, 135, 646, 148, brightred)

drawbox (104, 218, 559, 231, brightred)
drawbox (1100, 218, 646, 231, brightred)

drawbox (104, 301, 559, 314, brightred)
drawbox (1100, 301, 646, 314, brightred)

drawbox (104, 384, 559, 397, brightred)
drawbox (1100, 384, 646, 397, brightred)

drawbox (24, 1, 1180, 527, brightred)
drawline (104, GROUND_HEIGHT, 1100, GROUND_HEIGHT, blue)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if whatdotcolor (posx, posy) = 3 then
posy := 220
vely := 1
end if

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View.Update
delay (85)
cls
end loop

<Answer Here>

Turing:


<setscreen ("graphics:1211, 607")

const GROUND_HEIGHT := 63
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2.0

var chars : array char of boolean

% player position and velocity
var posx, posy : int
var velx, vely : real

posx := 20
velx := 0
posy := 400
vely := 0

loop
    Input.KeyDown (chars)
    if chars ('q') then
        exit
    end if

    % to make the player move
    if chars (KEY_LEFT_ARROW) then
        velx := -RUN_SPEED
    elsif chars (KEY_RIGHT_ARROW) then
        velx := RUN_SPEED
    else
        velx := 0
    end if

    % remember, in order to jump you MUST be on the ground when pressing UP
    if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT or posy = 148 or posy = 231 or posy = 314 or posy = 397 then
        vely := JUMP_SPEED
    end if

    % subtract your "gravity" constant from the velocity EACH frame
    vely -= GRAVITY
    posx += round (velx)
    posy += round (vely)

    % simple "collision" check. just makes sure the player stays above ground
    if posy < GROUND_HEIGHT then
        vely := 0
    elsif posy = 148 then
        posy := 148
        vely := 0
    elsif posy = 231 then
        posy := 231
        vely := 0
    elsif posy = 314 then
        posy := 314
        vely := 0
    elsif posy = 397 then
        posy := 397
        vely := 0
    end if


    % different colours just to illustrate whether or not you may jump
    if posy = 63 or posy = 148 or posy = 231 or posy = 314 or posy = 397 then
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
    else
        drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
    end if
    drawbox (104, 21, 559, 63, brightred)
    drawbox (1100, 21, 646, 63, brightred)

    drawbox (104, 135, 559, 148, brightred)
    drawbox (1100, 135, 646, 148, brightred)

    drawbox (104, 218, 559, 231, brightred)
    drawbox (1100, 218, 646, 231, brightred)

    drawbox (104, 301, 559, 314, brightred)
    drawbox (1100, 301, 646, 314, brightred)

    drawbox (104, 384, 559, 397, brightred)
    drawbox (1100, 384, 646, 397, brightred)

    drawbox (24, 1, 1180, 527, brightred)
    drawline (104, GROUND_HEIGHT, 1100, GROUND_HEIGHT, blue)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if whatdotcolor (posx, posy) = 3 then
        posy := 220
        vely := 1
    end if

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    View.Update
    delay (85)
    cls
end loop
>



Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Jun 10, 2018 7:25 am   Post subject: RE:Need help with Turing platforms Please (Urgent)

Your code only registers the platforms when the character is exactly on them. How often is that going to happen when you're moving by 20 or more pixels at a time?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: