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

Username:   Password: 
 RegisterRegister   
 whatdotcolour Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bharath1000




PostPosted: Mon Dec 24, 2012 11:15 pm   Post subject: whatdotcolour Problem

I'm trying to use the whatdotcolour command and it is not working for me (Note: first time using this command) and i dont see what is wrong with what i did... im trying to make the character stop when it hits the white block

Turing:


View.Set ("graphics:800;600,offscreenonly,nobuttonbar")
%%%%%%%%%%%%%%%%%%%%%%%%%%%VARIABLES%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var chars : array char of boolean
var hossam, hossamm : int
var x : int := 10
var y : int := 0
var xsize : int := 23
var ysize : int := 80
var velx : int := 0
var vely : int := 0
var groundheight := 0
const gravity := 1
const runspeed := 5
const jumpspeed := 15
var brickcolour : int := white
%%%%%%%%%%%%%%%%%%%%%%%%%%%DECLARATIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hossam := Pic.FileNew ("hossam.BMP")
%%%%%%%%%%%%%%%%%%%%%%%%%%%INITIAL SCREEN%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pic.Draw (hossam, x, y, picMerge)
drawfillbox (500, 0, 510, 80, brickcolour)
colourback (black)
loop

    Pic.Draw (hossam, x, y, picMerge)
    drawfillbox (500, 0, 523, 80, brickcolour)

    View.Update
    delay (10)
    cls
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        vely := 5
    end if

    if chars (KEY_LEFT_ARROW) then
        velx := -3
    elsif chars (KEY_RIGHT_ARROW) then
        velx := +3
    else
        velx := 0
    end if
    if chars (KEY_UP_ARROW) then
        y += vely
        vely -= gravity
    else
        vely := 0
    end if
    x+=velx

    if chars (KEY_LEFT_ARROW) and whatdotcolor (round (x) - xsize - 1, round (y)) = brickcolour then
        x -= velx
    end if
    if chars (KEY_RIGHT_ARROW) and whatdotcolor (round (x) + xsize + 1, round (y)) = brickcolour then
        x -= velx
    end if
end loop




Please specify what version of Turing you are using
Turing 4.1.1



hossam.BMP
 Description:
If you want to try the program
 Filesize:  5.68 KB
 Viewed:  2437 Time(s)

hossam.BMP


Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue Dec 25, 2012 4:45 am   Post subject: RE:whatdotcolour Problem

code:
round (x) - xsize - 1


Where is this point?

Why do you check again if the left/right arrow keys are pressed before subtracting the velocity?

You're only checking if a 1-pixel-thick line at the top of Hossam's head and twice his width is hitting the brick. Can you figure out why?
bharath1000




PostPosted: Tue Dec 25, 2012 1:36 pm   Post subject: Re: whatdotcolour Problem

Thank you.. i got it too work but now there is another problem.... the character sinks through the ground every time he jumps from a certain height . is there any way to fix??


Turing:

View.Set ("graphics:800;600,offscreenonly,nobuttonbar")
%%%%%%%%%%%%%%%%%%%%%%%%%%%VARIABLES%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var chars : array char of boolean
var hossam, hossamm : int
var x : int := 10
var y : int := 250
var velx : int := 0
var vely : int := 0
var groundheight := false
const gravity := 5
const runspeed := 5
const jumpspeed := 40
%%%%%%%%%%%%%%%%%%%%%%%%%%%DECLARATIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hossam := Pic.FileNew ("hossam.BMP")
hossamm := Pic.FileNew ("hossammotion.BMP")
%%%%%%%%%%%%%%%%%%%%%%%%%%%INITIAL SCREEN%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure foreground
    drawfillbox (0, 0, 150, 150, green)
    drawfillbox (303, 0, maxx, 150, green)
    drawfillbox (210, 150, 250, 200, green)
end foreground
Pic.Draw (hossam, x, y, picMerge)
foreground
View.Update
%%%%%%%%%%%%%%%%%%%%%%%%%%%INTERFACE CONTROL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
    Pic.Draw (hossam, x, y, picMerge)
    View.Update
    cls
    if y > 0 then
        vely -= gravity
        y += vely
    end if
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and groundheight = true then
        vely := jumpspeed
        y += vely
    end if
    if chars (KEY_RIGHT_ARROW) and x not= 775 then
        velx := runspeed
        x += velx
    elsif chars (KEY_LEFT_ARROW) and x >= 0 then
        velx := -runspeed
        x += velx
    else
        velx := 0
    end if
    foreground
    drawfillbox (400, 150, 500, 200, green)
    if View.WhatDotColor (x + 20, y + 20) = green then
        velx := 0
        velx -= runspeed
        x += velx
    end if
    if View.WhatDotColor (x + 5, y + 20) = green then
        velx := 0
        velx += runspeed
        x += velx
    end if
    if View.WhatDotColor (x + 5, y + 5) = green then
        groundheight := true
        vely := 0
        vely += gravity
        y += vely
    else
        groundheight := false
    end if
    delay (50)
end loop
put "Game Over!"

[/list]
Insectoid




PostPosted: Tue Dec 25, 2012 1:47 pm   Post subject: RE:whatdotcolour Problem

If the character is below the ground, what can you do to put him on the ground again?

Also:

code:
vely := 0
        vely += gravity
        y += vely


You can reduce this part to one line.
bharath1000




PostPosted: Tue Dec 25, 2012 2:13 pm   Post subject: RE:whatdotcolour Problem

there is a ground height and it works but eveytime i jump i land a few units below the ground and float back up to the ground height again
Insectoid




PostPosted: Wed Dec 26, 2012 11:20 am   Post subject: RE:whatdotcolour Problem

You do not have a ground height. You have a boolean called ground height, but that does not represent the height of the ground. Ground height should be an integer, and if your character's y value is lower than that integer, you are underground.

code:
if View.WhatDotColor (x + 5, y + 5) = green then
        groundheight := true
        vely := 0
        vely += gravity
        y += vely
    else
        groundheight := false
    end if


What is this code doing?

You check if the character is underground, then you set vely to gravity (vely := 0, vely += gravity is equivalent to vely := gravity). Gravity is a positive value (5). Then you add vely (gravity) to y. So if your character is underground, he will float up at 5 pixels per second.

This issue is not easily solved with whatdotcolor. Not as easily as regular collision detection anyway. Actually, whatdotcolor is pretty bad overall. It will take a lot of work to switch over to a better system, but once you've done that everything becomes a lot easier.
bharath1000




PostPosted: Wed Dec 26, 2012 3:30 pm   Post subject: RE:whatdotcolour Problem

Can you explain what the better system is? or at least the idea of it?
Insectoid




PostPosted: Wed Dec 26, 2012 3:44 pm   Post subject: RE:whatdotcolour Problem

I could, but the Turing Walkthrough already did.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Wed Dec 26, 2012 9:25 pm   Post subject: RE:whatdotcolour Problem

I think he's referring to using actual objects for detection rather than colour. So instead of landing on a colour, you land on top of the range of an object. It makes it much more flexible, and you don't have to keep using the same colour.
Insectoid




PostPosted: Thu Dec 27, 2012 10:53 am   Post subject: RE:whatdotcolour Problem

Actually, whatdotcolor doesn't limit your pallet at all. Using View.Update, you draw your simple colors, do all your detection work, then draw the real image on top, then update the screen.
Raknarg




PostPosted: Thu Dec 27, 2012 12:12 pm   Post subject: RE:whatdotcolour Problem

So it reads the buffer, not the screen itself? I didn't know that
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  [ 11 Posts ]
Jump to:   


Style:  
Search: