
-----------------------------------
Gackt
Tue Feb 17, 2009 10:52 am

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...


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


-----------------------------------
Gackt
Tue Feb 17, 2009 8:04 pm

Re: Hockey Puck in the net Game
-----------------------------------
Alright, forgot all that coding up here. I Changed it,


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 = maxy - 5 then 
    put "You Lose"
    elsif x >= maxx - 5 then
    put "You Lose" 
    end if 

end loop
[/syntax]

-----------------------------------
Gackt
Wed Feb 18, 2009 4:28 pm

Re: Hockey Puck in the net Game
-----------------------------------
Alright, Triple post.... >.>


Okay, Why doesnt this code run?



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
Wed Feb 18, 2009 4:43 pm

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
Wed Feb 18, 2009 4:44 pm

RE:Hockey Puck in the net Game
-----------------------------------
It won't run because "time" returns a string which cannot be used in multiplication.

-----------------------------------
Gackt
Wed Feb 18, 2009 5:52 pm

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
Wed Feb 18, 2009 6:01 pm

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
Wed Feb 18, 2009 7:44 pm

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.

-----------------------------------
DemonWasp
Wed Feb 18, 2009 9:24 pm

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:


var loopCounter : int := 0
loop
    % Do your loop stuff here
    loopCounter := loopCounter + 1
end loop


-----------------------------------
A.J
Wed Feb 18, 2009 10:21 pm

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
Thu Feb 19, 2009 7:38 pm

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. 



/********************************
 *       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 = maxx or y = maxx or y = randx) and (x = 20) and (y = maxx or y 