
-----------------------------------
Master Programmer Dude
Fri Apr 22, 2005 10:34 am

Collision in Air Hockey Game
-----------------------------------
theres a prob i wanna change the colour in the maple leafs but the puck thinks that its a paddle whats wrong?



% Air Hockey V.3



View.Set ("graphics:800;600,title:Air Hockey, offscreenonly, nocursor")

var puckX, puckY : int := 0
var pad1X, pad1Y, button : int := 0
var pad2X, pad2Y : int := 0
var changeX, changeY := 10
var playerScore, compuScore : int := 0
var sign1X : int := 0
var sign2X : int := 480
var font1 : int := Font.New ("Courier New:40:bold")
var font2 : int := Font.New ("Courier New:20:bold")
var font3 : int := Font.New ("Courier New:10:bold")
var timeLeft : int := 6000
var keyPressed : string (1)
var signSwitch : boolean := false
var overTime : boolean := false

procedure Reset (restart : boolean)
    changeX := -10
    changeY := -10
    puckX := 650
    puckY := 300
    pad2X := 740
    pad2Y := 250
    if restart then
        playerScore := 0
        compuScore := 0
        timeLeft := 6000
        overTime := false
    end if
end Reset

procedure Intro
    loop
        Text.Cls
        Font.Draw ("Press any key to continue", 260, 25, font3, blue)
        Font.Draw ("Air Hockey", sign1X, 500, font1, blue)
        Font.Draw ("Air Hockey", sign2X, 100, font1, blue)
        Font.Draw ("Instructions", 350, 450, font3, blue)
        Font.Draw ("Move the mouse to block the puck", 250, 400, font3, blue)
        Font.Draw ("from entering your net", 250, 380, font3, blue)
        Font.Draw ("Keyboard:", 250, 325, font3, blue)
        Font.Draw ("p - Pauses the game", 250, 305, font3, blue)
        Font.Draw ("x - Exits current game and", 250, 275, font3, blue)
        Font.Draw ("    returns to this screen", 250, 255, font3, blue)
        Font.Draw ("r - Refreshs the screen", 250, 235, font3, blue)
        Font.Draw ("Each game lasts one minute", 250, 170, font3, blue)
        if sign1X = 460 then
            signSwitch := false
        end if
        if signSwitch then
            sign1X += 1
            sign2X -= 1
        elsif signSwitch = false then
            sign1X -= 1
            sign2X += 1
        end if
        View.Update
        exit when hasch
        Time.Delay (10)
    end loop
    Reset (true)
end Intro

loop
    Intro
    loop
        % Time
        timeLeft -= 2
        if timeLeft  compuScore then
                Font.Draw ("Player Wins", 300, 240, font2, black)
                View.Update
                getch (keyPressed)
                Intro
            elsif playerScore < compuScore then
                Font.Draw ("Computer Wins", 285, 240, font2, black)
                View.Update
                getch (keyPressed)
                Intro
            elsif playerScore = compuScore then
                timeLeft := 0
                overTime := true
            end if
        end if
        % Controls
        Mouse.Where (pad1X, pad1Y, button)
        if pad1X >= 365 then
            pad1X := 365
        elsif pad1X = 465 then
            pad1Y := 465
        elsif pad1Y = 0 then
            pad2X += 3
        elsif changeX = 0 then
            pad2Y += 3
        elsif changeY = 765 then
            pad2X := 765
        elsif pad2X = 465 then
            pad2Y := 465
        elsif pad2Y = maxx - 10 and puckY > 185 and puckY < 315 then
            Reset (false)
            playerScore += 1
            Font.Draw ("Goal", 355, 240, font2, black)
            View.Update
            getch (keyPressed)
        end if
        if puckX - 10  185 and puckY < 315 then
            Reset (false)
            compuScore += 1
            Font.Draw ("Goal", 355, 240, font2, black)
            View.Update
            getch (keyPressed)
        end if
        % Others
        View.Update
        Time.Delay (10)
    end loop
end loop

EDIT [Martin]: Fixed it up for you. Everybody gets one.

-----------------------------------
Martin
Fri Apr 22, 2005 10:37 am


-----------------------------------
Edit your post and give it a more descriptive title please. Also use [code] tags.

-----------------------------------
Mazer
Fri Apr 22, 2005 10:42 am


-----------------------------------
And posting in the right section never hurts.

-----------------------------------
StarGateSG-1
Fri Apr 22, 2005 10:46 am


-----------------------------------
What the H*** do you mean, I don't understand that questions at all.

-----------------------------------
Tony
Fri Apr 22, 2005 11:49 am


-----------------------------------
What the H*** do you mean, I don't understand that questions at all.
 :lol: 

Back to the question

if whatdotcolor (puckX + 11, puckY) = red then
            changeX := -changeX 

oh hey, guess what else on your screen is (or trying to be) red!

If you insist on using whatdotcolor(), then you have to use unique colours for everything.
