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

Username:   Password: 
 RegisterRegister   
 Hockey Game Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
@DRI@N




PostPosted: Sun May 23, 2004 4:25 pm   Post subject: Hockey Game Help

Hey I'm making a hockey game, but I'm having trouble with the scoreboard. You press "enter" to drop the puck and if it is in the box it should be 1:0 but the score is different every time. The corners as well, I don't know how to make the puck and player bounce off them

code:



setscreen("graphics:800;800")
View.Set("offscreenonly")   
 
colorback(black)
cls

    var crowd_colour:int
   
    var x1_crowd: int
    var y1_crowd: int

   
    var counter:int:=0
    var arena_x : array 1..8 of int := init (200, 200, 250, 550,
                                   600, 600, 550, 250)
    var arena_y : array 1..8 of int := init (150, 650, 700, 700,
                                   650, 150, 100, 100)
    var Score_font:int:=Font.New ("Garamond:30")
   
    var score:int:=0
    var player_score:string:=""
    var puckx,pucky:int:=400
    var puckychange,puckxchange:int:=1
    var RD_X:int:=500
    var RD_Y:int:=200
    var chars : array char of boolean
    var chars1 : array char of boolean   
    var cur_x,cur_y:int

procedure Arena
loop

counter:=counter+1


randint(crowd_colour,1,255)

randint(x1_crowd,1,800)
randint(y1_crowd,1,800)

drawfilloval(x1_crowd,y1_crowd,2,2,crowd_colour)

exit when counter=30000

end loop
end Arena

%%%Faceoff%%%%
randint(puckychange,-1,1)
if puckychange=0 then
loop
randint(puckychange,-1,1)
exit when puckychange not=0
end loop
end if
%%%%%Faceoff%%%



loop
cls
Arena
loop
Input.KeyDown (chars)

if chars (KEY_UP_ARROW) then
            RD_Y := RD_Y + 2
        elsif chars (KEY_DOWN_ARROW) then
            RD_Y := RD_Y - 2
        elsif chars (KEY_RIGHT_ARROW) then
            RD_X := RD_X + 2
        elsif chars (KEY_LEFT_ARROW) then
            RD_X := RD_X - 2
end if

if RD_X=586 then
RD_X:=RD_X-8
elsif  RD_X=224 then
RD_X:=RD_X+8
end if

if RD_Y=688 then
RD_Y:=RD_Y-8
elsif  RD_Y=112 then
RD_Y:=RD_Y+8
end if

%Arena
Draw.FillPolygon (arena_x, arena_y, 8, 100) 
delay(0)
puckx:=puckx+puckxchange
pucky:=pucky+puckychange

cur_x:=puckx
cur_y:=pucky
%Puck
Draw.FillOval(puckx,pucky,2,2,black)
if puckx=598 or puckx=202 then
puckxchange:=puckxchange*-1
end if

if pucky=698 or pucky=102 then
puckychange:=puckychange*-1
end if

%%%Collison
if puckx < RD_X+18 and puckx >RD_X-34 and pucky > RD_Y-15 and pucky <RD_Y+16 then
puckx:=RD_X-25
pucky:=RD_Y-2
end if

if chars(KEY_ENTER) then
puckx:=cur_x
pucky:=cur_y
puckxchange:=0
puckychange:=0
end if
%%%Target(Version1Only
Draw.Box(390,600,430,640,red)
%%%%User Right Defense
Draw.Line(RD_X+14,RD_Y+7,RD_X-25,RD_Y-5,black)
Draw.Line(RD_X-25,RD_Y-5,RD_X-30,RD_Y-2,black)

Draw.FillOval(RD_X,RD_Y,5,10,9)
Draw.FillOval(RD_X,RD_Y+12,4,4,66)

Draw.Line(RD_X+4,RD_Y+8,RD_X+14,RD_Y+8,9)
Draw.Line(RD_X-4,RD_Y+8,RD_X-14,RD_Y,9)

Draw.FillOval(RD_X-14,RD_Y,2,3,9)
Draw.FillOval(RD_X+14,RD_Y+8,2,3,9)

Draw.FillOval(RD_X-6,RD_Y-11,2,5,black)
Draw.FillOval(RD_X+6,RD_Y-11,2,5,black)
%%%%%%%%%%%%%%


%ScoreBox
Draw.FillBox(340,0,460,50,black)
player_score:=intstr(score)
Font.Draw(player_score,360,10,Score_font,40)
%Timebox

if puckxchange=0 and puckychange=0 and cur_x >390 and cur_x <430 and cur_y >600 and cur_y <640 and puckx not=RD_X-25 and pucky not=RD_Y-2  then

score:=score+1

player_score:=intstr(score)

end if


View.Update

end loop
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun May 23, 2004 5:04 pm   Post subject: (No subject)

see how you have
code:

        if w/e then

            score := score + 1

            player_score := intstr (score)

        end if


you add one to the score, but you do not move the puck out of the net. So next time though the loop the puck is still there and scores just keep on adding up.

After you count the score, you should move the puck out of the net
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
@DRI@N




PostPosted: Sun May 23, 2004 5:31 pm   Post subject: Corners

Thanks, so I'll just reset the puck x and y coordinates to what they were at the start of the loop. Same with the player, but do you have any ideas about those corners??
Paul




PostPosted: Sun May 23, 2004 6:55 pm   Post subject: (No subject)

The corners...
you can try using whatdotcolor, if you visualize your player as a rectangular picture, figure out the coordinate at the corners of your picture. And if you were pressing the left arrow key, instead just if chars(KEY_LEFT_ARROW), you go
code:

if chars(KEY_LEFT_ARROW) and whatdotcolor (lefttopcornerx-2, lefttopcornery) = rinkcolor then
RD_Y := RD_Y + 2
end if
 

Im sure u can figure it out using the corners.
Andy




PostPosted: Sun May 23, 2004 8:12 pm   Post subject: (No subject)

or you can use some math and just make sure the dot is within the triangle...
Paul




PostPosted: Sun May 23, 2004 8:33 pm   Post subject: (No subject)

Damn it dodge, you gave up whatdotcolor for Hyori Lee!
Andy




PostPosted: Mon May 24, 2004 10:56 am   Post subject: (No subject)

yes im sorry... cant resist... nah i'd never give up whatdotcolor... im just pissed off rite now cuz in c++ whatdotcolor is called getpixel... wtf is wit that??? blah... hes my friend and i told him how to do it already
@DRI@N




PostPosted: Mon May 24, 2004 7:04 pm   Post subject: (No subject)

Now how I am going to make him shoot Evil or Very Mad Mad I tried making a function to calculate slope and assign that value to puckxchange and puckychange but hey what do u know it doesnt work Embarassed Embarassed Embarassed
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: