Thanks for your feedback!
For any brave captain who wants to fly into Escher Space for target practice, I have this code and these instructions:
Save the following code file as: Escher Space Shooter.sdlbas, in the same folder as Space Shooter.
Then rename the Space Shooter.exe file in that folder to: Escher Space Shooter.exe
And you are set to enjoy Escher Space target shooting.
If you don't like Escher Space so much, just rename the exe back to Space shooter.exe
'Escher Space Shooter.sdlbas [B+=MGA] 2016-08-10 modified from
' Space shooter.sdlbas (B+=MGA) 2016-08-13
xmax = 1200 : ymax = 700
setdisplay(xmax, ymax, 32, 1)
setcaption("Escher Space shooter")
setfont("ariblk.ttf")
autoback(-2)
randomize
' =========================== sound from Johnno's Prototype 5 data
loadsound("explode2.wav", 10)
loadsound("zap2.wav", 11)
cx = xmax / 2 : cy = ymax / 2 : pi = acos(-1) : highScore = "0" : level = 0 : fileName = ""
dim scores[8]
'sSpace setup
es = 50
xTiles = int(xmax / es) + 1
yTiles = int(ymax / es) + 1
dim eSpace[xTiles, yTiles]
function deg(rAngle)
deg = rAngle * 180 / pi
end function
function rad(dAngle)
rad = dAngle * pi / 180
end function
function rand(n1, n2) ' numbers between n1, n2 inclusive, no worries first and second argument
dim hi, lo
if n1 > n2 then
hi = n1 : lo = n2
else
hi = n2 : lo = n1
end if
rand = rnd(hi - lo + 2) + lo -1
end function
function textInput(x, y, sz, prompt, fc, bc)
ink(bc)
bar(0, y, screenwidth, y + 1.2 * sz) ' the bar has to be bigger than sz to clear the lower parts of y,p or q
ink(fc)
text(x, y, sz, prompt)
screenswap
k = 0 : rtn = ""
while k <> 13 ' until press enter
k = inkey
'wait(100)
while inkey = k : wait(10) : wend
if k > 31 and k < 127 then
rtn = rtn + chr(k)
elseif k=8 or k=127 then ' backspace and delete
rtn = left(rtn, len(rtn) - 1)
end if
ink(bc)
bar(0, y, screenwidth, y + 1.2 * sz)
ink(fc)
text(x, y, sz, prompt + rtn)
screenswap
wend
textInput = rtn
end function
sub instructions()
lvl = 0
ink(0xffffff)
name = textInput(300, 60, 18, "Hello captain, please type your name for the log and enter. > ", 0xffffff, 0)
fileName = name + ".dat"
if fileExists( fileName) then
open fileName for input as 1
for i=1 to 9
file input #1, hs
scores[i-1] = hs
next
close(1)
else
open fileName for output as 1
for i = 1 to 9
file output #1, str(0)
scores[i-1] = str(0)
next
close(1)
end if
text(300, 100, 18, name + ", you have unlimited power for phasers to shoot at targets.")
text(300, 120, 18, "Just lock in and click mouse button, zap... boom!")
text(300, 140, 18, "Get hit once by a target and the game is over!")
text(300, 170, 18, "You need to choose a level of play:")
text(300, 190, 18, "For every increase in level the targets go faster and the")
text(300, 210, 18, "likely-hood of getting hit by a target increases.")
screenswap
''' johnno's key version (mod MGA) works perfectly!!!!
text(350, 250, 18, "Press a number key 1 to 9 for your level.")
screenswap
while lvl = 0
if key(k_1) then : lvl = 1 : end if
if key(k_2) then : lvl = 2 : end if
if key(k_3) then : lvl = 3 : end if
if key(k_4) then : lvl = 4 : end if
if key(k_5) then : lvl = 5 : end if
if key(k_6) then : lvl = 6 : end if
if key(k_7) then : lvl = 7 : end if
if key(k_8) then : lvl = 8 : end if
if key(k_9) then : lvl = 9 : end if
wend
highScore = scores[lvl-1]
text(280, 320, 24, "Level " + str(lvl) + " chosen, your high score for that level is "+ highScore)
screenswap
wait(1500)
level = 2 * int(lvl)
cls
end sub
sub eTile1(xof, yof, dx, dy)
ink(rgb(0, 30, 30))
line( 0.2*dx+xof, 0.0*dy+yof, 0.0*dx+xof, 0.2*dy+yof)
line( 0.4*dx+xof, 0.0*dy+yof, 0.0*dx+xof, 0.8*dy+yof)
line( 0.6*dx+xof, 0.0*dy+yof, 0.2*dx+xof, 1.0*dy+yof)
line( 0.8*dx+xof, 0.0*dy+yof, 1.0*dx+xof, 0.2*dy+yof)
line( 0.0*dx+xof, 0.4*dy+yof, 1.0*dx+xof, 0.8*dy+yof)
line( 0.0*dx+xof, 0.6*dy+yof, 0.8*dx+xof, 1.0*dy+yof)
line( 1.0*dx+xof, 0.4*dy+yof, 0.4*dx+xof, 1.0*dy+yof)
line( 1.0*dx+xof, 0.6*dy+yof, 0.6*dx+xof, 1.0*dy+yof)
end sub
sub eTile2(xof, yof, dx, dy)
ink(rgb(0, 30, 30))
line( 0.2*dx+xof, 0.0*dy+yof, 1.0*dx+xof, 0.4*dy+yof)
line( 0.4*dx+xof, 0.0*dy+yof, 0.0*dx+xof, 0.4*dy+yof)
line( 0.6*dx+xof, 0.0*dy+yof, 0.0*dx+xof, 0.6*dy+yof)
line( 0.8*dx+xof, 0.0*dy+yof, 0.4*dx+xof, 1.0*dy+yof)
line( 0.0*dx+xof, 0.2*dy+yof, 1.0*dx+xof, 0.6*dy+yof)
line( 0.0*dx+xof, 0.8*dy+yof, 0.2*dx+xof, 1.0*dy+yof)
line( 1.0*dx+xof, 0.2*dy+yof, 0.6*dx+xof, 1.0*dy+yof)
line( 1.0*dx+xof, 0.8*dy+yof, 0.8*dx+xof, 1.0*dy+yof)
end sub
sub drawspace(moving)
ink(0)
bar(0, 0, xmax, ymax)
for yy = 0 to yTiles
for xx = 0 to xTiles
if eSpace[xx, yy] then
etile1( xx * es, yy * es, es, es)
else
eTile2( xx * es, yy * es, es, es)
end if
next
next
if moving then
for yy = 0 to yTiles - 1
for xx = 1 to xTiles - 1
eSpace[xx-1, yy] = eSpace[xx, yy]
next
next
for yy = 0 to yTiles -1
eSpace[xTiles - 1, yy] = rand(0, 1)
next
end if
end sub
sub method3(ex, ey, count) 'from explosions study combine method 1 and 2 = 2 sets of dots
max_dot = 400 : num_dots =401
dim dot_x[num_dots], dot_y[num_dots], dot_dx[num_dots], dot_dy[num_dots], dot_size[num_dots], dot_colr[num_dots]
playsound(10, 1)
dim dots[128,5]
for i = 0 to 127
dots[i, 0] = ex
dots[i, 1] = ey
angle = rnd(360)
dots[i, 2] = cos(angle)
dots[i, 3] = sin(angle)
dots[i, 4] = rand(65, 75)
next
for i = 0 to max_dot
dot_x[i] = ex
dot_y[i] = ey
angle = (rnd( 10000) / 10000) * 2 * pi
dot_dx[i] = (rnd(9500)/100) * cos(angle)
dot_dy[i] = (rnd(9500)/100) * sin(angle)
dot_size[i] = rnd(3)
shade = rnd(255)
dot_colr[i] = rgb(shade, shade, shade)
next
while key(27) =0
drawspace(0)
counter = counter + 1
for i = 0 to max_dot
if dot_x[i] > 0 and dot_x[i] < xmax and dot_y[i] > 0 and dot_y[i] < ymax then
counter = counter + 1
ink(dot_colr[i])
fillcircle(dot_x[i], dot_y[i], dot_size[i])
dot_x[i] = dot_x[i] + dot_dx[i]
dot_y[i] = dot_y[i] + dot_dy[i]
end if
next
for i = 0 to 127
if dots[i, 4] > 0 and dots[i,0] > 0 and dots[i,0] < xmax and dots[i,1] < ymax and dots[i,1] > -100 then 'added more checks
dots[i, 0] = dots[i, 0] + dots[i, 2] * dots[i, 4]
dots[i, 1] = dots[i, 1] + dots[i, 3] * dots[i, 4]
dots[i, 4] = dots[i, 4] - 0.04
shade = 64 + rnd(128)
ink(rgb(shade, shade, shade))
fillcircle(round(dots[i, 0]), round(dots[i, 1]), rnd(7)+1)
end if
next
screenswap
wait(2)
if counter >= count then
exit while
end if
wend
end sub
'set up eSpace
for y = 0 to yTiles-1
for x = 0 to xTiles-1
eSpace[x,y] = rand(0, 1)
next
next
r = .2 : g = .3 : b = .4 : looper = 0 : hits = 0 : active = 0 : xz = 0 : yz = 0 : hit = 0 : targets = 0 : beemer = 0
instructions()
hidemouse
while key(27) = 0
drawspace(1)
looper += 1 'count loops for new targets
'draw target
if looper mod 70 = 0 then ' new target
active = 1 : targets += 1
side = rand(1, 4)
select case side
case 1 'left
xz = 0 : yz =rand(100, ymax - 100) : dx = rand(3 + level, 6+ level) : dy = rand( (-1*5) - level, 5 + level)
case 2 'right
xz = xmax : yz =rand(100, ymax - 100) : dx = rand( (-1*3) - level, (-1*6) - level ) : dy = rand( (-1*5) - level, 5 + level)
case 3 ' top
xz = rand(100, xmax - 100) : yz = 0 : dx = rand( (-1*6) - level, 6 + level) : dy = rand(1 + level, 5 + level)
case 4 'bottom
xz = rand(100, xmax - 100) : yz = ymax : dx = rand( (-1*6) - level, 6 + level) : dy = rand( (-1*1) - level, (-1*5) - level)
end select
if looper > 1000000 then : looper = 0 : end if
else
if active then
for rz = 20 to 0 step -5
if rz mod 2 = 0 then : ink(0xff0000) : else : ink(0xffffff) : end if
fillcircle(xz, yz, rz)
next
xz = xz + dx : yz = yz + dy
end if
end if
'draw craft
ink(rgb(190, 40, 0))
fillcircle(cx, cy, 10)
ink(rgb(190, 150, 90))
fillellipse(cx, cy, 30, 5)
ink(0xffff88)
ls = rnd(6)
for light =1 to 12
circle(cx - 36 + 5 * light + ls, cy, 1)
next
'target sight
mx=mousex : my=mousey
ink(0xffffff)
circle(mx, my, 5)
circle(mx, my, 10)
circle(mx, my, 15)
line(mx, my - 20, mx, my + 20)
line(mx - 20, my, mx + 20, my)
'plasma beamer
r += .2 : g += .005 : b += .010
if r > .5 then : r = .02 : end if
if g > .5 then : g = .005 : end if
if b > .5 then : b = .01 : end if
if mousebutton = 1 then 'shoot ray
playsound(11, 0)
dist = ((mx - cx) ^ 2 + (my - cy) ^ 2) ^ .5
if dist > 20 then
if cx - mx = 0 then
if my > cy then
angle = 90
else
angle = 270
end if
else
angle = deg( atan( (cy - my) / (cx - mx) ) )
if mx < cx then : angle = angle + 180 : end if
end if
end if
ra = deg( atan(21/ dist) )
angle1 = angle - ra
angle2 = angle1 + 2 * ra
for ray =1 to dist
x1 = cx + ray * cos(rad(angle1) )
y1 = cy + ray * sin(rad(angle1) )
x2 = cx + ray * cos(rad(angle2) )
y2 = cy + ray * sin(rad(angle2) )
ink( rgb(127 + 127 * sin(r * ray), 127 + 127 * sin(g * ray), 127 + 127 * sin(b * ray) ) )
line(x1, y1, x2, y2)
line(x2, y2, x1, y1) 'get rid of some holes in beam
next
beemer = 1
end if
ink(0xffffff)
if targets <> 0 then
text(10, 10, 18, " Hits " + str(hits))
text(950, 10, 18, "Level "+ str(int(level/2) + " High Score "+ highScore))
text(10, 30, 18, " Targets " + str(targets))
text(10, 50, 18, " Percent " + str( int(100 * hits/targets) ))
end if
screenswap
wait(1)
'hits
if abs(mx-xz) < 15 and abs(my-yz) < 15 and beemer = 1 then
if active then
hits += 1
method3(xz, yz, 1000)
active = 0
hit = 1
end if
end if
'target crashes into ship
if abs(xz-cx) < 30 and abs(yz - cy) < 30 then ' game over
ink(0xffffff)
fillcircle(cx, cy, 60)
screenswap
wait(5)
method3(cx, cy, 2500)
ink(0xffee00)
text( 300, 300, 100, "Game Over!")
screenswap
wait(100)
exit while
end if
screenswap
beemer = 0
wend
'update scoring
sc = int(100 * hits/targets) : lv = level/2 - 1
if int( scores[lv] ) < sc then
scores[lv] = str(sc)
open fileName for output as 1
for i = 1 to 9
file output #1, scores[i-1]
next
close(1)
end if
waitkey(27)