_TITLE "Lander B+ started 2018-06-02" ' Lander update.bas SmallBASIC 0.12.11 (B+=MGA) 2018-06-01
'modified code from my 2nd mod of:
'Lander mod 2.txt for JB v2 B+ 2018-05-29 big mod of
'Lander by Carl mod Rod mod B+.txt for JB v2 started 2018-05-26
'where I rewired controls and changed physics of Lander Model.
'This will further depart from Carls's original by hand drawing Lander
'at different angles instead of using sprites and, alas, landscape will
'have to be updated each frame because there is no drawing on top of images
'in SmallBASIC.
' INSTRUCTIONS:
'Use the left or right arrow keys to rotate Lander left or right.
'Use the up arrow for thruster burst. These moves cost fuel!
'The Fuel Gage is Red Horizontal line below landscape.
'The fuel level is Yellow.
'You must make a VERY gentle and level landing
'on one of the flat areas!
'Horizontal location, speed in green.
' Vertical location, speed inblue
d2r = pi / 180
'stars
'terrain
'vehicle globals
DIM SHARED fuel
, vda
, speed
, vx
, vy
, dx
, dy
, dg
, dat
restart: ' ========================================= initialize Game
makeStars
makeTerra
fuel = 500 'this is the space vehicle's fuel
'vda is vehicle degree angle = orientation of the vehicle, mainly it's thrusters
vda = 0 'the vehicle is traveling right across screen due East = 0 degrees = 0 Radians
speed = 6 'this is the speed the vehicle is moving in the vda direction
vx = 50 'this is current x position of vehicle 10 pixles from left side
vy = 30 '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
* vda
) 'this is the horizontal x change on screen due to speed and angledy
= speed
* SIN(d2r
* vda
) 'this is the vertical y change on screen due to speed and angledg = .1 'this is the constant acceleration gravity applies to the vehicle
dat = 2 'this is burst of acceleration a thrust or reverse thrust will apply to speed and angle
'buttons
drwbtn 290, ymax - 80, "Rotate Left"
drwbtn 500, ymax - 80, "Forward Thrust"
drwbtn 710, ymax - 80, "Rotate Right"
'respond to button clicks
moveLeft
moveUp
moveRight
'respond to key press
scene
'fuel line
rgb 300
recf 10, ymax - 25, xmax - 10, ymax - 5
ff = fuel / 500 * (xmax - 20)
rgb 860
recf 10, ymax - 20, ff + 10, ymax - 10
'vehicle falls faster and faster, because gravity effects the vertical speed
dy = dy + dg 'speed up falling due to gravity acceleration
'new position = last postion plus the horizontal and vertical changes from momentum
vx = vx + dx
vy = vy + dy
Lander vx, vy, d2r * vda
IF vx
< 30 OR vx
> xmax
- 30 OR vy
< -50 THEN 'edit keep Lander legs inside boundries of terraH() _TITLE "You have drifted off screen. Press p to play again..."
crash$ = ""
crash$ = crash$ + "Ran out of fuel. "
IF vda
<> 270 THEN crash$
= crash$
+ "Vehicle not upright. " IF dy
> 4 THEN crash$
= crash$
+ "Came down too fast. " IF ABS(dx
) > 4 THEN crash$
= crash$
+ "Still moving hoizontally too fast. " IF terraH
(vx
- 10) <> terraH
(vx
+ 10) THEN crash$
= crash$
+ "Did not land on level site. " _TITLE "You crashed! because: " + crash$
+ " Press p to play again..." _TITLE "Nice job! Successful landing! Press p to play again..." k$ = ""
drwbtn 990, ymax - 80, "Restart"
k$ = "p"
rgb 101
recf 4, 4, xmax - 5, ymax - 85
fcirc sx(i), sy(i), sr(i)
rgb terraC(i) * 100 + terraC(i) * 10 + terraC(i)
ln i, terraH(i), i, ymax - 86
' arrow + esc key
'here is the vertical and horizontal change from a burst of fuel for thrust
thrustx
= dat
* COS(d2r
* vda
) thrusty
= dat
* SIN(d2r
* vda
)
'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
rgb 990
fcirc vx, vy, 5
'the thrust cost fuel
fuel = fuel - 10
x1
= vx
+ 10 * COS(d2r
* vda
+ .5 * pi
) y1
= vy
+ 10 * SIN(d2r
* vda
+ .5 * pi
) rgb 990
fcirc x1, y1, 5
vda = vda - 22.5
fuel = fuel - 10
x1
= vx
+ 10 * COS(d2r
* vda
- .5 * pi
) y1
= vy
+ 10 * SIN(d2r
* vda
- .5 * pi
) rgb 990
fcirc x1, y1, 5
vda = vda + 22.5
fuel = fuel - 10
SUB Lander
(x0
, y0
, rAngle
) 'rebuilt from ground up literally! 'x0, y0 are at the base of the lander, the rocket will point rAngle up when landing
rgb 333
x1
= x0
+ 10 * COS(rAngle
- .5 * pi
) y1
= y0
+ 10 * SIN(rAngle
- .5 * pi
) x2
= x0
+ 10 * COS(rAngle
+ .5 * pi
) y2
= y0
+ 10 * SIN(rAngle
+ .5 * pi
) x3
= x0
+ 10 * COS(rAngle
) y3
= y0
+ 10 * SIN(rAngle
) x4
= x0
+ 25 * COS(rAngle
) y4
= y0
+ 25 * SIN(rAngle
) 'legs/fins
ln x3, y3, x1, y1
ln x3, y3, x2, y2
ln x4, y4, x1, y1
ln x4, y4, x2, y2
pangle = 2 * pi / 5
x1
= x4
+ r
* COS(i
* pangle
+ rAngle
) y1
= y4
+ r
* SIN(i
* pangle
+ rAngle
) IF i
<> 0 THEN ln lx
, ly
, x1
, y1
lx = x1: ly = y1
LINE (x1
, y1
)-(x2
, y2
), , B
SUB recf
(x1
, y1
, x2
, y2
) LINE (x1
, y1
)-(x2
, y2
), , BF
SUB rgb
(n
) ' New (even less typing!) New Color System 1000 colors with up to 3 digits
'Steve McNeil's copied from his forum note: Radius is too common a name
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF
th
= 16: tw
= LEN(s$
) * 8 rgb 0
recf x, y, x + 200, y + 50
rgb 999
recf x, y, x + 198, y + 48
rgb 666
recf x + 2, y + 2, x + 198, y + 48
xoff = 100 - tw \ 2: yoff = 25 - th \ 2
sx
(i
) = RND * (xmax
- 16) + 8 sy
(i
) = RND * (ymax
- 96) + 8 sr(i) = 1
sr(i) = 2
sr(i) = 3
xstop = min(xmax - 5, x + 50)
terraH(lz) = y
terraC(lz) = c
x = lz - 1
xstop
= min
(xmax
- 5, x
+ RND * 25) y = min(ymax - 90, y + yd)
y = max(y, ymax - 240)
terraH(xx) = y
terraC(xx) = c
x = xx - 1