My Lander program in RB
Sept 3, 2018 15:37:17 GMT -5
Post by Gordon on Sept 3, 2018 15:37:17 GMT -5
'Lander program for RunBASIC aug 2018 adapted from
'Lander mod 2.txt for JB v2 B+ 2018年05月29日
'Lander by Carl mod Rod mod B+.bas for JB v2 started 2018年05月26日
'from Rod's mod of
'written by Carl Gundel
'carlg@world.std.com
'Needs at least Liberty BASIC v2.0 ????
'This file is contributed to the public domain
'Use the left or right arrows on screen to rotate left or right
'Use the up arrows to increase thrust
'You must make a VERY gentle and level landing
'on one of the flat areas!
[start]
call setCSS
xmax = 800
ymax = 600
pi = acs(-1)
d2r = pi/180
'fuel = 500
Gfuel = 250 :Yfuel = 125 :Rfuel = 125
tG = 130 : tG$=str$(130) :hG$ =str$(250)
tY = 380 : tY$=str$(380) :hY$ =str$(125)
tR = 505 : tR$=str$(505) :hR$ =str$(125)
lzx1 =120: lzx2 = 305 :lzy = 555 '(555-40+30)
'vda is vehicle degree angle = orientation of the vehicle, mainly it's thrusters
vda = 4 'the vehicle is traveling right across screen due East = 0 degrees = 0 Radians
speed = 3 'this is the speed the vehicle is moving in the vda direction
vx = 65 'this is current x position of vehicle 50 pixels from left side
vy = 45 'this is current y position of vehicle 10 pixels down from top of screen
'd stands for delta with stands for change dx = change in x, dy = change in y
'dg is change due to gravity (vertical)
'dat is change of acceleration due to thrust
dx = speed * cos(d2r * (360-vda*22.5)) 'this is the horizontal x change on screen due to speed and angle
dy = (0-speed) * sin(d2r * (360-vda*22.5)) 'this is the vertical y change on screen due to speed and angle
'LBx = r * cos(d2r * (360-vda))
'LBy = 0-r * sin(d2r * (360-vda))
dg = .1 'this is the constant acceleration gravity applies to the vehicle (was .1)
dat = 2 'this is burst of acceleration a thrust or reverse thrust will apply to speed and angle
gosub [mars]
gosub [imgbut]
gosub [fuel]
'wait
link #timer, "", [timer]
Call TimeoutLink 500, "#timer"
wait
[timer]
gosub [mars]
'vehicle falls faster and faster, because gravity effects the vertical speed
dy = dy + dg 'speed up falling due to gravity acceleration
'new position = last position plus the horizontal and vertical changes from momentum
vx = vx + dx
vy = vy + dy
if vx < 10 or vx > xmax - 10 or vy < 10 then
crash$ = "Lander out of control ! !":goto [NoControl]
end if
if vy <= lzy - 4 and Rfuel > 0 then
goto [fuelOk]
else
crash$ = ""
if vda <> 4 then crash$ = "Vehicle not upright. "+chr$(13)
if dy > 4 then crash$ = crash$ + "Came down too fast. "+chr$(13)
if dx > 4 then crash$ = crash$ + "Still moving horizontally too fast. "+chr$(13)
if Rfuel <= 0 then crash$ = crash$ + "Ran out of fuel. "
if vx < lzx1 or vx > lzx2 then crash$ = crash$ + "Did not land on level site. "
if crash$ <> "" then
cause$ = "You crashed!" + chr$(13) + crash$
crash$ = cause$ :goto [NoControl]
else
crash$ = "Successful landing!" ':goto [NoControl]
goto [reconfirm]
end if
end if
gosub [lander]
gosub [imgbut]
gosub [fuel]
wait
[control]
gosub [mars]
if EventKey$ = "#R10" and vx<780 then
vda = vda + 1
if vda = 16 then vda = 0
fuelUsed = 10
end if
if EventKey$ = "#L10" and vx>20 then
vda = vda - 1
if vda = -1 then vda = 15
fuelUsed = 10
end if
if EventKey$ = "#U10" and vy>20 then fuelUsed = 10
if EventKey$ = "#U8" and vy>20 then fuelUsed = 8
if EventKey$ = "#U6" and vy>20 then fuelUsed = 6
if EventKey$ = "#U4" and vy>20 then fuelUsed = 4
if EventKey$ = "#U2" and vy>20 then fuelUsed = 2
'here is the vertical and horizontal change from a burst of fuel for thrust
thrustx = dat * cos(d2r * (360-vda*22.5)) '* cos(d2r * vda*22.5 + pi)
thrusty = 0-dat * sin(d2r * (360-vda*22.5)) '* sin(d2r * vda*22.5 + pi)
'LBx = r * cos(d2r * (360-vda))
'LBy = 0-r * sin(d2r * (360-vda))
thrustx = 0-thrustx
thrusty = 0-thrusty
'now change the horizontal and vertical momentums from the thrust
dx = dx + thrustx
dy = dy + thrusty
'update the position
vx = vx + dx
vy = vy + dy
'fuelUsed = val(a$)
[Gfuel]
if Gfuel = 0 then goto [Yfuel]
if fuelUsed > Gfuel then
hG$ =str$(0):tG = tY : tG$ = str$(tG):fuelUsed =abs(fuelUsed-Gfuel)
Gfuel = 0 : goto [Yfuel]
end if
Gfuel = Gfuel - fuelUsed
hG$ =str$(Gfuel):tG = tG + fuelUsed :tG$ = str$(tG)
goto [fuelOk]
[Yfuel]
if Yfuel = 0 then goto [Rfuel]
if fuelUsed > Yfuel then
hY$ =str$(0):tY = tR : tY$ = str$(tR):fuelUsed =abs(fuelUsed-Yfuel)
Yfuel = 0 : goto [Rfuel]
end if
Yfuel = Yfuel - fuelUsed
hY$ =str$(Yfuel):tY = tY + fuelUsed :tY$ = str$(tY)
goto [fuelOk]
[Rfuel]
if Rfuel <= 0 then hR$ = "0": tR$ = "505": goto [noFuel]
if Rfuel > 0 then Rfuel = Rfuel - fuelUsed
hR$ =str$(Rfuel):tR = tR + fuelUsed :tR$ = str$(tR)
goto [fuelOk]
wait
[fuelOk]
gosub [mars]
gosub [lander]
gosub [imgbut]
gosub [fuel]
wait
[noFuel]
wait
[NoControl]
[reconfirm]
cls
loadimage "warn1","public\raket\marsland.png"
graphic #txt1, 800, 600
#txt1 drawimage("warn1",10,10)
#txt1 color("black")
#txt1 place(250,250)
#txt1 font("times",20)
#txt1 "\";crash$
'#txt1 "\ dy = ";dy
'#txt1 "\ vy = ";vy
div reconf
imagebutton #start,"\raket\startbutt1.gif",[start]
end div
render #txt1
wait
'------------------------------------------
[mars]
html "<img src='/raket/marsland.jpg' style=' width:800px; height:600px; position:absolute; left:20px; top:30px'>"
RETURN
[lander]
img$ = "lem"+str$(vda)+".gif" :tp$ = " top:"+str$(vy)+"px;" :lp$ = " left:"+str$(vx)+"px;"
html "<img src='/raket/"+img$+"' style=' width:40px; height:40px; position:absolute;"+lp$+tp$+ "'>"
RETURN
[fuel]
html "<img src='/raket/fuelG0.jpg' style=' width:10px; height:"+hG$+"px; position:absolute; top:"+tG$+"px;left:58px;'>"
html "<img src='/raket/fuelY0.jpg' style=' width:10px; height:"+hY$+"px; position:absolute; top:"+tY$+"px;left:58px;'>"
html "<img src='/raket/fuelR0.jpg' style=' width:10px; height:"+hR$+"px; position:absolute; top:"+tR$+"px;left:58px;'>"
RETURN
[imgbut]
div nav1
imagebutton #L10, "\raket\CC.gif",[control] 'pijlL.gif", [control]
end div
div nav2
imagebutton #R10, "\raket\CW.gif",[control] 'pijlR.gif", [control]
end div
div U10
imagebutton #U10, "\raket\U10.gif", [control]
end div
div U8
imagebutton #U08, "\raket\U8.gif", [control]
end div
div U6
imagebutton #U06, "\raket\U6.gif", [control]
end div
div U4
imagebutton #U04, "\raket\U4.gif", [control]
end div
div U2
imagebutton #U02, "\raket\U2.gif", [control]
end div
RETURN
Sub TimeoutLink msec, linkId$
html "
<script type=""text/javascript"">
<!--
var a = document.getElementById('"+linkId$+"');
if (a) window.setTimeout('window.location = a.href', "+Str$(msec)+");
//-->
</script>"
End Sub
Sub setCSS
cssid #mainBG,"{position:absolute; left:50px ; top:180px;}"
cssid #nav1, "{position:absolute; left:620px; top:520px;}"
cssid #nav2, "{position:absolute; left:720px; top:520px;}"
cssid #U10, "{position:absolute; left:670px; top:472px;}"
cssid #U8, "{position:absolute; left:685px; top:427px;}"
cssid #U6, "{position:absolute; left:688px; top:392px;}"
cssid #U4, "{position:absolute; left:690px; top:362px;}"
cssid #U2, "{position:absolute; left:692px; top:337px;}"
cssid #reconf,"{position:absolute; left:360px; top:430px;}"
end sub
wait
'#R setid("Ibutton1")
wait
'pi = acs(-1)
'd2r = pi/180
'[start] X1,Y1 105,554 and X2,Y2 315,555
'print MouseX,MouseY
'input vda
'r = 20
'dx = r * cos(d2r * vda)
'dy = r * sin(d2r * vda)
'LBx = r * cos(d2r * (360-vda))
'LBy = 0-r * sin(d2r * (360-vda))
'print "dx ";dx;" LBx = ";LBx
'print "dy ";dy;" LBy = ";LBy
'goto [start]