Canon simulator
Author |
Message |
Insectoid
|
Posted: Wed Dec 09, 2009 10:13 am Post subject: Canon simulator |
|
|
I've been messing around with velocity/trig and whatnot, and came up with this.
Controls:
Up/down arrow keys- change angle
press spacebar to start power-up
release to end power-up
press space again to fire!
code: |
var bulletX := 0.00
var bulletY := 0.00
var degrees := 0.00
var bulletVel : real := 0
var font := Font.New ("Times New Roman:10")
var keys : array char of boolean
View.Set ("offscreenonly")
loop
bulletVel := 0
bulletX := 25
bulletY := 25
delay (10)
loop
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees - 5), black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
View.Update
Input.KeyDown (keys)
if keys (KEY_UP_ARROW) then
degrees += 1
elsif keys (KEY_DOWN_ARROW) then
degrees -= 1
end if
exit when keys (' ')
delay (10)
cls
end loop
loop
Input.KeyDown (keys)
bulletVel += .25
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees - 5), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
View.Update
exit when bulletVel >= 100 or not keys (' ')
delay (15)
cls
end loop
loop
Input.KeyDown (keys)
exit when keys (' ')
end loop
var velX : real
var velY : real
loop
Draw.FillArc (round (bulletX), round (bulletY), 20, 20, round (degrees - 5), round (degrees + 5), black)
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees - 5), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
View.Update
velX := bulletVel * cosd (round (degrees))
velY := bulletVel * sind (round (degrees))
bulletX += velX
bulletY += velY
velY -= .1
degrees := arctand (velY / velX)
bulletVel := sqrt (velX ** 2 + velY ** 2)
delay (10)
cls
exit when bulletX > maxx or bulletX < 0 or bulletY < 0
end loop
end loop
|
Whadaya think? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Wed Dec 09, 2009 10:57 am Post subject: RE:Canon simulator |
|
|
just an idea, maybe reset the angle to the last fired (same with power) because firing at angles of 45.76747 is kinda wierd |
|
|
|
|
|
Insectoid
|
Posted: Wed Dec 09, 2009 11:43 am Post subject: RE:Canon simulator |
|
|
ah, gotcha. I'll be updating this with more features and stuff over time. Done the CS curriculum, nothing left to do but mess around with Turing. |
|
|
|
|
|
Insectoid
|
Posted: Wed Dec 09, 2009 11:59 am Post subject: Re: Canon simulator |
|
|
Now with bounce!
code: |
var bulletX := 0.00
var bulletY := 0.00
var degrees := 0.00
var bulletVel : real := 0
const elasticity := .3
const gravity := .1
var font := Font.New ("Times New Roman:10")
var keys : array char of boolean
View.Set ("offscreenonly")
loop
degrees := 0
bulletVel := 0
bulletX := 25
bulletY := 25
delay (10)
loop
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees - 5), black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
View.Update
Input.KeyDown (keys)
if keys (KEY_UP_ARROW) then
degrees += 1
elsif keys (KEY_DOWN_ARROW) then
degrees -= 1
end if
exit when keys (' ')
delay (10)
cls
end loop
loop
Input.KeyDown (keys)
bulletVel += .25
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees - 5), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
View.Update
exit when bulletVel >= 100 or not keys (' ')
delay (15)
cls
end loop
loop
Input.KeyDown (keys)
exit when keys (' ')
end loop
var velX : real
var velY : real
loop
Draw.FillArc (round (bulletX), round (bulletY), 20, 20, round (degrees - 5), round (degrees + 5), black)
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 185), round (degrees - 185), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
velX := bulletVel * cosd (round (degrees))
velY := bulletVel * sind (round (degrees))
if bulletY >= 20 then
Draw.Line (0, 20, maxx, 20, black)
velY -= gravity
else
Draw.Line (0, 20, round (bulletX), round (bulletY), red)
Draw.Line (round (bulletX), round (bulletY), maxx, 20, red)
velY *= .99
velY += elasticity
end if
View.Update
bulletX += velX
bulletY += velY
degrees := arctand (velY / velX)
bulletVel := sqrt (velX ** 2 + velY ** 2)
delay (10)
cls
exit when bulletX > maxx or bulletX < 0 %or bulletY < 0
end loop
end loop
|
Note that, while I hate physics with a passion, 95% of the math in this I learned in grade 12 physics. |
|
|
|
|
|
Insectoid
|
Posted: Wed Dec 09, 2009 1:06 pm Post subject: RE:Canon simulator |
|
|
I'm working on having the 'elastic' modify the X velocity of the 'cannonball' but I'm having trouble with the physics. Also, I don't know if my math is wrong or if this is a result of rounding error, but the X velocity is not constant in my latest posted version. Can anyone figure out why?
EDIT: The X velocity only changes by .1 at the most, so I'll attribute that to rounding error. |
|
|
|
|
|
GalacticVenus
|
Posted: Wed Dec 09, 2009 2:53 pm Post subject: RE:Canon simulator |
|
|
Canon or Cannon?
There is quite a large difference, ya know. |
|
|
|
|
|
Insectoid
|
Posted: Wed Dec 09, 2009 3:41 pm Post subject: RE:Canon simulator |
|
|
Both, I'm throwing printers and cameras from a cannon. |
|
|
|
|
|
SNIPERDUDE
|
Posted: Wed Dec 09, 2009 11:51 pm Post subject: Re: RE:Canon simulator |
|
|
insectoid @ December 9th 2009 wrote: Both, I'm throwing printers and cameras from a cannon.
In Canaan? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|