
-----------------------------------
hossack
Tue Feb 17, 2009 10:53 am

cannonball game
-----------------------------------
I need to know how to make my arc go up and then down. This is what i've gotten so far

View.Set ("graphic:640;480")

var x, y, angle, power : int

x := 20
y := 5

put "Enter Gun Powder"
get power
put "Enter the arc |Lower = Steep | Higher = Shallower"
get angle
delay (100)
cls


loop
    drawfillbox (580, 0, 480, 20, brightred)
    drawfilloval (x, y, 5, 5, blue)
    delay (10)
    if x = 600 + 20 or x = 600 - 20 and y = 360 - 20 or y = 360 -20 then
    x := x
    y := y
    cls
    locatexy (300,200)
    put "YOU WIN!!!"
    elsif x = maxx or y = maxy then
    locatexy (300,200)
    put "YOU LOSE!!!!"
    end if
    drawfilloval (x, y, 5, 5, 0)
    x := x + power
    y := round (x ** 2 / angle) + 5
end loop

-----------------------------------
Ktomislav
Tue Feb 17, 2009 11:23 am

Re: cannonball game
-----------------------------------
It's simple physics. You just have to set speed in x direction an in y direction and acceleration. And after that you just increase your x coordinate for x speed and y coordinate for y speed and increase your y speed for acceleration. You repeat that until x reaches maxx or y reaches 0.

procedure arc
    var x, y, ay, vx, vy: real;
    ay := -0.2;
    x := 0;
    y := 0;
    vx := 10;
    vy := 10;
    loop
        exit when (x > maxx) or (y < 0);
        Draw.Dot (round(x), round(y), blue);
        x += vx;
        y += vy;
        vy += ay;
        delay (100);
    end loop
end arc

-----------------------------------
hossack
Tue Feb 17, 2009 8:47 pm

Re: cannonball game
-----------------------------------
We haven't learned Procedures yet. Is there any other way to do it?

-----------------------------------
DemonWasp
Tue Feb 17, 2009 9:22 pm

RE:cannonball game
-----------------------------------
Learn procedures.

If you want to just run his code, copy everything between "procedure arc" and "end arc" and run that as a Turing program. You should see what he's talking about.

Learn procedures anyway.

-----------------------------------
hossack
Wed Feb 18, 2009 9:30 am

RE:cannonball game
-----------------------------------
I got it work. Thanks

edit nvm

-----------------------------------
hossack
Wed Feb 18, 2009 10:06 am

Re: cannonball game
-----------------------------------
How do i get it so like when it hits the target you win/ if you miss you lose? Also how do you get it so the target is the same size each time?

var x, y, ay, vx, vy: real; 
 var randx, randx2: int
    ay := -0.2; 
    x := 0; 
    y := 0; 
    vx := 7; 
    vy := 7; 
    
   randint (randx, 125, maxx-125)
   randint (randx2, 125, maxx-125)
    
    drawfillbox (randx, 0, randx2, 20, brightred)
    put "Enter the angle"
    get vy
    put "Enter the speed"
    get vx
    delay(10)
    
   
    loop 
        exit when (x > maxx) or (y < 0); 
        drawfilloval (round(x), round(y), round(5), round (5), blue); 
        delay (10); 
        View.Update
        drawfilloval (round(x), round(y), round(5), round (5), white); 
        x += vx; 
        y += vy; 
        vy += ay; 
        if x 