
-----------------------------------
bharath1000
Mon Dec 24, 2012 11:15 pm

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 



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

-----------------------------------
Insectoid
Tue Dec 25, 2012 4:45 am

RE:whatdotcolour Problem
-----------------------------------
[code]round (x) - xsize - 1[/code]

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
Tue Dec 25, 2012 1:36 pm

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??



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
Tue Dec 25, 2012 1:47 pm

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 [/code]

You can reduce this part to one line.

-----------------------------------
bharath1000
Tue Dec 25, 2012 2:13 pm

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
Wed Dec 26, 2012 11:20 am

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 [/code]

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
Wed Dec 26, 2012 3:30 pm

RE:whatdotcolour Problem
-----------------------------------
Can you explain what the better system is? or at least the idea of it?

-----------------------------------
Insectoid
Wed Dec 26, 2012 3:44 pm

RE:whatdotcolour Problem
-----------------------------------
I could, but the Turing Walkthrough already did.

-----------------------------------
Raknarg
Wed Dec 26, 2012 9:25 pm

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
Thu Dec 27, 2012 10:53 am

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
Thu Dec 27, 2012 12:12 pm

RE:whatdotcolour Problem
-----------------------------------
So it reads the buffer, not the screen itself? I didn't know that
