Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Hockey Problem...still
Author Message
@DRI@N

Posted: Mon May 31, 2004 6:32 pm   Post subject: Hockey Problem...still

For god sakes this aint workin ..if I shoot from somewhere on the right side of the screen it goes down...BUT Y always returns positive

(get puck and press shift to shoot)
 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 cur_x,cur_y:int     var totalspeed:int:=2     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 function X_Velocity_Calculate(px:int,py:int):real var xvelocity, yvelocity : real var angle : real var ylength : int var xlength : int xlength := 400-px ylength := 620-py if ylength = 0 then        angle := 0 else     angle := arctand (ylength/xlength) end if    xvelocity := totalspeed*cosd(angle) if puckx>400 then xvelocity := xvelocity *-1   end if result xvelocity end X_Velocity_Calculate function Y_Velocity_Calculate(px:int,py:int):real var xvelocity, yvelocity : real var angle : real var ylength : int var xlength : int xlength := 400-px ylength := 620-py if ylength = 0 then        angle := 0 else     angle := arctand (ylength/xlength) end if yvelocity := totalspeed*sind(angle) result yvelocity end Y_Velocity_Calculate function Collision(x:real,y:real,xwall1:int,xwall2:int,ywall1:int,ywall2:int):boolean if x < xwall2 and x >xwall1 and y > ywall2 and y =puckx then puckxchange:=puckxchange*-1 puckychange:=puckychange*-1 end if if puckx>550 and pucky>650 and (1250-pucky)<=puckx then puckxchange:=puckxchange*-1 puckychange:=puckychange*-1 end if if puckx<250 and pucky<150 and (350-pucky)>=puckx then puckxchange:=puckxchange*-1 puckychange:=puckychange*-1 end if if puckx>550 and pucky<150 and (pucky+450)<=puckx then puckxchange:=puckxchange*-1 puckychange:=puckychange*-1 end if %%%%Player Corners if (RD_Y+2-450)>=RD_X-30 then RD_Y:=RD_Y-10 RD_X:=RD_X+10 end if if RD_X+52>550 and RD_Y+32>650 and (1250-RD_Y+32)<=RD_X+52 then RD_Y:=RD_Y-10 RD_X:=RD_X-10 end if if RD_X-40<250 and RD_Y-16<150 and (350-RD_Y-16)>=RD_X-40 then RD_Y:=RD_Y+10 RD_X:=RD_X+10 end if if RD_X+6>550 and RD_Y-11<150 and (RD_Y-11+450)<=RD_X+6 then RD_Y:=RD_Y+10 RD_X:=RD_X-10 end if %%%Collison if Collision(puckx,pucky,RD_X-34,RD_X+18,RD_Y+16,RD_Y-15)=true and puckxchange<2 and puckychange<2 and Player_Has_Puck(puckx,pucky,RD_X-25,RD_Y-2)=false then puckx:=RD_X-25 pucky:=RD_Y-2 end if if chars(KEY_ENTER)and puckx < RD_X+18 and puckx >RD_X-34 and pucky > RD_Y-15 and pucky 380 and cur_x <420 and cur_y >600 and cur_y <640 and puckx not=RD_X-25 and pucky not=RD_Y-2  then %%%Faceoff%%%% randint(puckychange,-1,1) if puckychange=0 then loop randint(puckychange,-1,1) exit when puckychange not=0 end loop end if %%%%%Faceoff%%% score:=score+1 puckx:=400 pucky:=400 puckxchange:=1 RD_X:=500 RD_Y:=200 player_score:=intstr(score) end if %%% View.Update end loop end loop

rhomer

Posted: Mon May 31, 2004 6:42 pm   Post subject: (No subject)

Sorry i can;t help...Your code is quite confusing...

just a suggestion...use comments so other users will understan whats happenind where easier and what some variables stand for.
Tony

Posted: Mon May 31, 2004 6:44 pm   Post subject: (No subject)

i agree with rhomer, code is quite confusing to read.

ether way - I think the problem lies in the fact that player doesn't have to be really close to "grab" the puck. This way when you shot, the puck moves one frame but is still within the player's "grab the puck" range and gets pulled back in on the next loop.
Tony's programming blog. DWITE - a programming contest.
SuperGenius

Posted: Mon May 31, 2004 7:01 pm   Post subject: (No subject)

while playing your game the puck got outside the arena somwhow.
rhomer

Posted: Mon May 31, 2004 7:07 pm   Post subject: (No subject)

ya i noticed that too...if you shoot from the left side at a sharp angle then it will bounce off the top right corner and go out the left side of the rink...very annoying!
guruguru

Posted: Mon May 31, 2004 7:16 pm   Post subject: (No subject)

I think Tony's nailed it. As soon as you shoot, you should make a counter that is assigned how far away the puck is. Only when the distance away is greater than... say 50... is the player allowed receive the puck again.

 code: var distanceAway : real var canGetPuck : boolean := false loop     distanceAway := sqrt ((puckX - playerX)**2 + (puckY - playerY)**2)     if distanceAway > 50 then         canGetPuck := true     end if     if canGetPuck then         % check to see if puck is in reach     end if     if puckIsShot then         % move puck         canGetPuck := false     end if end loop

That's the basic outline and order of what should happen.
@DRI@N

Posted: Mon May 31, 2004 9:11 pm   Post subject: (No subject)

Believe me I've already tried it with the boolean variable...and its only going back to the stick when the slope is 1 so I need smarter way to shoot. THe problem is that whole trig thing Tony gave me with cosd and sind I dont exactly understand. If I did I could fix it..
Tony

Posted: Mon May 31, 2004 10:35 pm   Post subject: (No subject)

i'm afraid you'd just have to try to make the flags work again

the player should be able to pick up the puck only when the boolean variable is marked the right way. And it gets marked only when the puck is out of player's "pick up" range. Once the shot is made, the variable remains false untill is it far away to escape "pick up".

another solution would be to increase the strength of puck shot so that it would escape that pickup zone on the first frame (that'd be quite fast unless you lower that distance.
Tony's programming blog. DWITE - a programming contest.

@DRI@N

Posted: Tue Jun 01, 2004 6:57 pm   Post subject: (No subject)

Yes fast shots will work.. I plan to make slapshots and wristshots. I'm sure slapshots will work because they are like 10x faster than the wrist. As for wrist do u think I could just set the puck x and ys to the corner of the collision zone and then shoot as opposed to shooting from within it or using if statements for slope. I tried making it go to the stick when slope is less than 2, but on 45 degree angles....
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: