Hockey Puck in the net Game
Author |
Message |
Gackt
|
Posted: Tue Feb 17, 2009 10:52 am Post subject: Hockey Puck in the net Game |
|
|
Okay, I My Cannon Ball is the hockey puck, and the Target is the net.
The Cannon Ball (Puck) has to be in the lower left corner, and the target has to be in the bottom right corner.
I need to know how to arc the puck so it goes up and slowy comes down like it would in real life. Right now my coding makes no sense, it doesnt arc up and come down, it just keeps going up.
Is there any simpler coding to what I have. I know nothing about it, so explaining isn't really going to help. Im not asking you to write the whole program, just give me an arc coding that will help. I need to insert a power, and angle in the arc.
Heres my coding so far...
Turing: |
View.Set ("graphics:640;480")
randomize
var x, y, Randx, Randy : int
var POWER, ANGLE : int
var picID, picID2 : int
picID := Pic.FileNew ("Targets/HackeyPuckGood.jpg")
picID2 := Pic.FileNew ("Targets/HackeyNet.jpg")
x := 20
y := 5
Pic.Draw (picID, x, y, picCopy)
randint (Randx, 20, maxy - 100)
randint (Randy, 20, maxy - 100)
Pic.Draw (picID2, Randx, Randy, picCopy)
put "Enter the Power"
get POWER
put "Enter the Arc (Lower = Steep | Higher = Shallower"
get ANGLE
cls
Pic.Draw (picID2, Randx, Randy, picCopy)
loop
Pic.Draw (picID, x, y, picCopy)
delay (10)
exit when y>= maxy - 5
drawfilloval (x,y, 10, 15, white)
x := x + POWER
y := round (x ** 2 / ANGLE ) + 5
if x = Randx - 10 or x = Randx + 10 and y = Randy - 10 or y = Randy + 10 then
put "YOU WIN TADAH!!!!!"
POWER := 0
exit
elsif y >= maxy - 5 then
elsif x >= maxx - 5 then
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Gackt
|
Posted: Tue Feb 17, 2009 8:04 pm Post subject: Re: Hockey Puck in the net Game |
|
|
Alright, forgot all that coding up here. I Changed it,
Turing: | View.Set ("graphics:640;480")
randomize
var x, y, Randx, Tary : int
var POWER, ANGLE : int
var picID, picID2 : int
x := 20
y := 5
Tary := 10
randint (Randx, 150, maxx - 10)
put "Enter the Power"
get POWER
put "Enter the Arc (Lower = Steep | Higher = Shallower)"
get ANGLE
cls
drawfillbox (Randx, Tary, Randx + 60, Tary + 10, brightblue)
loop
drawfilloval (x,y, 5, 5, black)
delay (10)
exit when y>= maxy - 5
drawfilloval (x,y, 5, 5, white)
x := x + POWER
y := round (x ** 2 / ANGLE ) + 5
if x >= Randx and x <= Randx + 10 then
put "You Win"
POWER := 0
exit
elsif y >= maxy - 5 then
put "You Lose"
elsif x >= maxx - 5 then
put "You Lose"
end if
end loop
| [/syntax] |
|
|
|
|
|
Gackt
|
Posted: Wed Feb 18, 2009 4:28 pm Post subject: Re: Hockey Puck in the net Game |
|
|
Alright, Triple post.... >.>
Okay, Why doesnt this code run?
Turing: |
var x, y, x1, y1 : int
var velocity, gravity : int
var theta : int
gravity := 1
x := 10
y := 10
x1 := 10
y1 := 10
var Randx, Randx2 : int
randint (Randx, 160, maxx - 100)
drawfillbox (Randx, 2, Randx + 100, 12, brightred)
put " Enter The Velocity Between 1 and 30"
get velocity
put " Enter an Angle between 0 and 90 degress"
get theta
drawfillbox (Randx, 2, Randx + 100, 12, brightred)
loop
drawfilloval (x, y, 5, 5, black)
delay (10)
drawfilloval (x, y, 5, 5, white)
x := x1 + velocity * time * cosd (theta )
y := y1 + velocity * time * sind (theta ) - 0. 5 * gravity * time ** 2
end loop
|
|
|
|
|
|
|
saltpro15
|
Posted: Wed Feb 18, 2009 4:43 pm Post subject: RE:Hockey Puck in the net Game |
|
|
just use the edit button instead of triple posting, it's easier. and something is wrong with your main loop I think |
|
|
|
|
|
DemonWasp
|
Posted: Wed Feb 18, 2009 4:44 pm Post subject: RE:Hockey Puck in the net Game |
|
|
It won't run because "time" returns a string which cannot be used in multiplication. |
|
|
|
|
|
Gackt
|
Posted: Wed Feb 18, 2009 5:52 pm Post subject: RE:Hockey Puck in the net Game |
|
|
Its just the coding my Teacher gave me to use to make the ball arc.
I replaced time with 1 to see if it work and i got an error.
It highlighted the second bracket on theta and the 2 at the very end.
The error stated "Assigned Value is the wrong type" I have no clue what is wrong. |
|
|
|
|
|
Insectoid
|
Posted: Wed Feb 18, 2009 6:01 pm Post subject: RE:Hockey Puck in the net Game |
|
|
it means you're trying to put a string into an integer, or real into integer, or integer/real into string. For example,
var foo : string := 3.14
I assume x := x1 + velocity * time * cosd (theta) returns a decimal answer, which cannot fit into an integer variable. |
|
|
|
|
|
Gackt
|
Posted: Wed Feb 18, 2009 7:44 pm Post subject: RE:Hockey Puck in the net Game |
|
|
Well, from what my Assignment sheet says, time is sopossed to be a counter that increases by 1 each time through the loop. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Wed Feb 18, 2009 9:24 pm Post subject: RE:Hockey Puck in the net Game |
|
|
Well, then you need to declare a "time" variable - more specifically, you need to declare something like "loopCounter", as "time" is a reserved keyword used by Turing. Check the help (F10).
"counter that increases by 1 each time through the loop." means this:
code: |
var loopCounter : int := 0
loop
% Do your loop stuff here
loopCounter := loopCounter + 1
end loop
|
|
|
|
|
|
|
A.J
|
Posted: Wed Feb 18, 2009 10:21 pm Post subject: Re: Hockey Puck in the net Game |
|
|
time is already a predefined value used in turing...like DemonWasp mentioned, you can just make another counter and increase that by 1 every time in the loop |
|
|
|
|
|
Gackt
|
Posted: Thu Feb 19, 2009 7:38 pm Post subject: Re: Hockey Puck in the net Game |
|
|
Alright, before I Post my final coding for help. I just want to thank you guys for your help
I've worked on this for like an hour straight and can't figure how to have my target stay the same shape and get in a different random stop. It moves, but it like just shrinks or grows and I dont know why.
Turing: |
/********************************
* Cannon Ball Game *
* *
* *
* This is a simple game where *
* you just type in the power *
* and the angle of the cannon *
* ball and try to hit the *
* randomized target. The *
* program keeps track of number*
* of shots you take. *
********************************/
randomize
var x, y, ay, vx, vy : real; % These are The Variables for the ball, the angle and the power
var randx, randx2, x2, y2, county : int % Variables for the target and cannon
var ans : string % Variables for if you want to play again
var picID : int := Pic.FileNew ("Cannon.jpg")
ay := - 0. 2; % Cannon ball, power, angle variables
x := 115;
y := 98;
vx := 7;
vy := 7;
x2 := 5
y2 := 20
county := 0
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) % Picture of cannon
randint (randx, 400, maxx - 80) % Randomizing the target
randx2 := randx + 80;
drawfillbox (randx, 20, randx2, 30, brightred) % Drawing the target
colorback (53)
put "Enter the Speed" % Getting
get vx
put "Enter the Angle"
get vy
county := county + 1
loop
exit when (x > maxx) or (y < 0); %Exit when you miss
if (y - 5 <= 21) then
drawfillbox (0, 250, 200, maxy, 53) % easy way to erase the text
delay (500)
locatexy (5, maxy - 5)
put "You missed the target"
delay (500)
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
county := county
delay (10)
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred)
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off: " ..
put county
exit
end if
elsif x >= maxx or y <= 0 then %If you lose
put "YOU LOSE"
cls
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off " ..
put county
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
county := county
delay (10)
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred)
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off: " ..
put county
exit
end if
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
randx2 := randx + 80;
county := county
delay (10)
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred)
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off: " ..
put county
exit
end if
elsif x >= maxx or y <= 0 then %If you lose
cls
put "YOU LOSE"
delay (1000)
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
randx2 := randx + 80;
county := county
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred)
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off " ..
put county
exit
end if
end if
% THIS IS THE CODING TO MOVE THE BALL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfilloval (round (x ), round (y ), round (5), round (5), black); %Drawing cannonball
delay (10);
View.Update
drawfilloval (round (x ), round (y ), round (5), round (5), 53); %Erasing Cannonball
x + = vx; %Moving ball
y + = vy;
vy + = ay;
if (x >= randx ) and (x <= randx2 ) and (y >= 20) and (y <= 30) then %If you win
delay (1000)
put "You hit the target!"
delay (1000)
cls
vx := 0
vy := 0
delay (10)
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
county := county
delay (10)
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred)
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off " ..
put county
exit
end if
elsif x >= maxx or y <= 0 then %If you lose
put "YOU LOSE"
cls
delay (10)
put "Play Again(Y/N)" %Asking to play again
get ans
if ans = "Y" or ans = "y" then %If yes
cls
ay := - 0. 2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
county := county
drawfillbox (0, 20, maxx, maxy, 53) % Redrawing the Sky
drawfillbox (0, 0, maxx, 20, brightgreen) % Redrawing The Grass
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
randint (randx, 400, maxx - 80) % Randomizing the target
drawfillbox (randx, 20, randx2, 30, brightred) % The Target
put "Enter the angle" %Asking to enter the angle of shot
get vy
put "Enter the speed" %Asking to enter the speed of shot
get vx
county := county + 1
delay (10)
elsif ans = "N" or ans = "n" then
colorback (53) % THE counter in the top corner
locatexy (300, maxy - 5)
put "Number of times shot off: " ..
put county
exit
end if
end if
end loop
|
|
|
|
|
|
|
Ktomislav
|
Posted: Fri Feb 20, 2009 9:07 am Post subject: Re: Hockey Puck in the net Game |
|
|
code: | ...
if ans = "Y" or ans = "y" then %If yes
cls
ay := -0.2; %Variables for all the balls and cannon
x := 115;
y := 98;
x2 := 5
y2 := 20
vx := 7;
vy := 7;
county := county
delay (10)
drawfillbox (0, 20, maxx, maxy, 53)
drawfillbox (0, 0, maxx, 20, brightgreen)
Pic.Draw (picID, x2, y2, picCopy) %Drawing Cannon
[b]randint (randx, 400, maxx - 80) % Randomizing the target[/b]
[b]drawfillbox (randx, 20, randx2, 30, brightred)[/b]
... |
You have to change randx2, like you did before, because it contains position for old random position of target.
And one more thing vy is not angle, it's speed in y direction, and vx is just speed in x direction, not full speed.
You have to use trigonometry if you want to do it with angle. |
|
|
|
|
|
|
|