Computer Science Canada

Issues with whatdotcolor in platformer

Author:  Tsa [ Sun May 29, 2011 12:17 pm ]
Post subject:  Issues with whatdotcolor in platformer

What is it you are trying to achieve?
Create a simple platform game.


What is the problem you are having?
I am trying to use whatdotcolor in order to make sure the shape can only jump when it is in the air.


Describe what you have tried to solve this problem
Read a few tutorials on whatdotcolor as well as trying to change the whatdotcolor locations. I have also used put velocityY so that I am almost certain the issue is around whatdotcolor.


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

code:

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


Please specify what version of Turing you are using
4.1.1

Author:  goroyoshi [ Mon May 30, 2011 6:07 pm ]
Post subject:  RE:Issues with whatdotcolor in platformer

you use the color detection after the cls

Author:  Tsa [ Tue May 31, 2011 9:19 am ]
Post subject:  Re: Issues with whatdotcolor in platformer

Thank you for pointing that out, I ended up restarting my program and kept in mind the placement of whatdotcolour and now everything is working!


: