Turing Mathematics
Author |
Message |
Witchcraft
|
Posted: Sun Oct 12, 2008 4:35 pm Post subject: Turing Mathematics |
|
|
Hey,
So I just started a nice big turing project to sum things up before I move onto learning Java. My idea is to make a pirate cannon game (kind of like the one from math circus). Well I'm just working on the rough stuff, and I got a ball to shoot up in a parabolic arc that has a vertical stretch depending on how long you hold down the mouse. Now my problem is that pictures can only be drawn on pixel values (which are always ints), but if I use a verticle stretch that is not an int, (such as 3/2) then I will get real numbers as the y values, and so the cannon ball cannont be drawn at that coordinate. This same problem would occur for vertical compression as well because division is even worse for giving you whole numbers as a result. How do I fix this problem? Do I convert a real to a int? The cod is posted below.
Turing: | %This is a pirate game, with several mini games in it
var cannonx, cannony, stretch, window : int %cannon x/y, and parabola vertical stretch
window := Window.Open ("graphics:800;800,position:center;center,nobuttonbar,offscreenonly")
cannonx := 0
cannony := 0
stretch := 0
loop
if Mouse.ButtonMoved ("down") then
stretch := 1
end if
exit when stretch = 1
end loop
loop
exit when Mouse.ButtonMoved ("up")
delay (500)
stretch := stretch + 1
end loop
for i : 30 .. 100
cls
cannonx := i + 1
cannony := - 1 * stretch * (cannonx - 50) ** 2 + (stretch * 400)
if cannony < 0 then
cannony := 0
end if
Draw.FillOval (cannonx, cannony, 5, 5, black)
View.Update
delay (50)
exit when cannony = 0
end for |
Mod edit: Working syntax tags added. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Witchcraft
|
Posted: Sun Oct 12, 2008 4:36 pm Post subject: RE:Turing Mathematics |
|
|
sorry I tried to get my code to appear as it would in turing, but I'm new to the forums so it didn't work out. How is it done? |
|
|
|
|
 |
The_Bean

|
Posted: Sun Oct 12, 2008 5:25 pm Post subject: Re: Turing Mathematics |
|
|
round() % rounds a number according to the one's column, should work for what you want
code: |
[syntax="turing"]
%code
[/syntax]
|
|
|
|
|
|
 |
Witchcraft
|
Posted: Sun Oct 12, 2008 5:56 pm Post subject: RE:Turing Mathematics |
|
|
thanks a lot, got it to work |
|
|
|
|
 |
Insectoid

|
Posted: Sun Oct 12, 2008 8:30 pm Post subject: RE:Turing Mathematics |
|
|
make sure you use 'perfect' collision detection, or if the ball is moving too fast, it will go through the walls. Look it up in the tutorials (it is rather complicated) |
|
|
|
|
 |
|
|