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

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




PostPosted: Mon Dec 11, 2006 10:03 pm   Post subject: whatdotcolor help

How do i use whatdotcolor to detect color? For example 2 circles make paths both different colors and when one circle hits the other players path, then that person loses. i know whatdotcolor can detect collision between circles but how does it detect the collision between a circle and the other circles path?

code:
var window : int := Window.Open ("graphics:1000;668")
var chars : array char of boolean
var x1, y1, x2, y2, intX, intY : int
var intColor1, intColor2 : int
x1 := 200
y1 := 668 div 2
x2 := 800
y2 := 668 div 2

locatexy (420, 335)
put "*The colors cannot be the same*"
locatexy (395, 330)
put "Enter the color of Player 1 (1 to 255)"
locatexy (395, 310)
get intColor1
locatexy (395, 290)
put "Enter the color of Player 2 (1 to 255)"
locatexy (395, 270)
get intColor2
if intColor1 = intColor2 then
    quit
end if
cls

var gametime : int := Time.Sec
View.Set ("offscreenonly")

loop
    Input.KeyDown (chars)
    %Player 1
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 1
    end if
    %Boundary
    if (x1 + 10) >= maxx or (x1 - 10) <= -1 then
        x1 *= -1
    elsif (y1 + 10) >= maxy or (y1 - 10) <= -1 then
        y1 *= -1
    end if

    %Player 2
    if chars ('w') then
        y2 := y2 + 1
    end if
    if chars ('s') then
        y2 := y2 - 1
    end if
    if chars ('a') then
        x2 := x2 - 1
    end if
    if chars ('d') then
        x2 := x2 + 1
    end if

    %Boundary
    if (x2 + 10) >= maxx or (x2 - 10) <= -1 then
        x2 *= -1
    elsif (y2 + 10) >= maxy or (y2 - 10) <= -1 then
        y2 *= -1
    end if
    Draw.FillOval (x1, y1, 10, 10, intColor1)
    Draw.FillOval (x2, y2, 10, 10, intColor2)
    View.Update

    %Collision
    if whatdotcolor (x1, y1) = intColor2 then
        cls
        locatexy (420, 354)
        put "Your game lasted ", Time.Sec - gametime, " seconds."
        locatexy (465, 334)
        put "Player 1 Loses!"
        locatexy (465, 330)
        put "Player 2 Wins!"
        delay (1000)
        locatexy (480, 310)
        put "Game Over!"
        delay (2000)
        exit
    elsif whatdotcolor (x2, y2) = intColor1 then
        cls
        locatexy (420, 354)
        put "Your game lasted ", Time.Sec - gametime, " seconds."
        locatexy (465, 334)
        put "Player 2 Loses!"
        locatexy (465, 330)
        put "Player 1 Wins!"
        delay (1000)
        locatexy (480, 310)
        put "Game Over!"
        delay (2000)
        exit
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Dec 11, 2006 10:17 pm   Post subject: (No subject)

Simply check to see if the color of the pixel you are checking is the color of the "enemy" circle, if it is, that player loses, otherwise, theyre fine. Check out the whatdotcolor tutorial in the Turing Walkthrough for more.
StrikerZ




PostPosted: Mon Dec 11, 2006 10:37 pm   Post subject: whatdotcolor help

Thanks for your help, but i have one problem...intcolor1 and intcolor2 are both touching when they collide so player 1 always loses. How do i make the first player to collide lose?
TokenHerbz




PostPosted: Mon Dec 11, 2006 10:40 pm   Post subject: (No subject)

post your code please.

How do you want to determine which player loses?
Clayton




PostPosted: Mon Dec 11, 2006 10:51 pm   Post subject: (No subject)

TokenHerbz: Everything is in his first post, read it before you reply...

You'll need to keep track of wheter you cross the trailing color (ie, where the circle has been), so you have to check if you cross the tail, and if you do, whos crossing what tail. (If that makes any sense)
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  [ 5 Posts ]
Jump to:   


Style:  
Search: