
-----------------------------------
@DRI@N
Wed May 26, 2004 9:08 pm

Trigonometry Help, Hockey Game, Shooting
-----------------------------------
Can anyone spot what's wrong here because I can't see it. YOu press shift to shoot. Works alright from pretty close but if u shoot from far only the xchange increases. What I did was find the angle using Tan(opp/adj) and then multiplied my angle by the movement(2) and divided it by 90 to get x velocity. For Y i did the same but did (90-angle)...please help...

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
    const movement:=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(puckx:int,pucky:int):real
var xvelocity, yvelocity : real 
var angle : real 
var Opposite : int 
var Adjacent : int 


Adjacent := 400-puckx
Opposite := 620-pucky

if Opposite = 0 then       
angle := 0 
else 
    angle := arctand (Opposite/Adjacent) 
end if 


xvelocity := angle * movement / 90 

result xvelocity
end X_Velocity_Calculate

function Y_Velocity_Calculate(puckx:int,pucky:int):real
var xvelocity, yvelocity : real 
var angle : real 
var Opposite : int 
var Adjacent : int 


Adjacent := 400-puckx
Opposite := 620-pucky

if Opposite = 0 then       
angle := 0 
else 
    angle := arctand (Opposite/Adjacent) 
end if 



yvelocity := (90-angle)* movement / 90 
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)650 and (1250-RD_Y+32)380 and cur_x 600 and cur_y  are not switched, and that you are testing the right coordinates. As well, like I said before, check the directin of the current velocity and adjust it so that it goes up/dow/left/right.

-----------------------------------
@DRI@N
Thu May 27, 2004 5:42 pm


-----------------------------------
How do I check it..If its left of centre then go right
                           If its right of centre go left
                           If in the middle just go straight

-----------------------------------
guruguru
Thu May 27, 2004 5:56 pm


-----------------------------------
It shoould be based on last velocity and where it was hit. If it was going down and was hit up, or vice versa- velocityY := -velocityY. If it was going left and was hit up, or vice versa- velocityX := -veclocityX. Just check the direction of the x and y puck changes. Adjust those. If they are positive and need to be negative, make them negative.

-----------------------------------
@DRI@N
Fri May 28, 2004 8:46 pm


-----------------------------------
Collision thing wont work..the way you put, I have to set collision to false. Collision is a boolean function not a variable...so I cant assign a value to it

-----------------------------------
guruguru
Fri May 28, 2004 9:49 pm


-----------------------------------
Then you can make a new  boolean variable. Then your collision function can change the new variable. Or it can just return a local variable in itself that determines if the puck should be drawn toward the stick or not.

-----------------------------------
@DRI@N
Sat May 29, 2004 9:18 pm


-----------------------------------
I think I already tried that.....I was thinking to move the puck to the edge of the collision box and then shooting it as opposed to the whole collision variable thing..

-----------------------------------
guruguru
Sun May 30, 2004 12:14 am


-----------------------------------
Try what you might, both ways should work. It may be simpler your way I dont know.

-----------------------------------
@DRI@N
Sun May 30, 2004 7:03 pm


-----------------------------------
Or I could just say if the slope is 1 then, and only then go to the stick otherwise just shoot or if ur blocking a shot...bounce off
