Author Topic: Space shooter  (Read 5343 times)

B+

  • Guest
Space shooter
« on: August 14, 2016, 04:28:14 AM »
Here is a simple one:
« Last Edit: August 14, 2016, 03:44:13 PM by B+ »

Mopz

  • Guest
Re: Space shooter
« Reply #1 on: August 14, 2016, 09:57:21 AM »
Interesting and fun :)

Mike Lobanovsky

  • Guest
Re: Space shooter
« Reply #2 on: August 14, 2016, 01:59:47 PM »
Doesn't run for me. :(

It says it can't load some TrueType font...

B+

  • Guest
Re: Space shooter
« Reply #3 on: August 14, 2016, 03:04:06 PM »
Doesn't run for me. :(

It says it can't load some TrueType font...

Hmm... I did not load any special font, so there must be a default font floating around in SdlBasic files (or Windows?).

APPEND and EDIT: I have loaded a ttf font file (Ariel version) in with the zip package and setfont in program to that file and it seems to be working OK, so I have repackaged game in opening thread post.
« Last Edit: August 14, 2016, 03:49:00 PM by B+ »

cvirus

  • Guest
Re: Space shooter
« Reply #4 on: August 14, 2016, 03:44:23 PM »
well you can load a font in case of the default not loaded, just setfont("namoeofthefont.ttf"), this way it doesn't gives this error.

B+

  • Guest
Re: Space shooter
« Reply #5 on: August 14, 2016, 03:50:10 PM »
Thanks cvirus! I had figured out pretty quick thanks to good sdlBasic docs.

B+

  • Guest
Re: Space shooter
« Reply #6 on: August 14, 2016, 03:59:31 PM »
BTW, I should say: unless hit by target, use esc to quit game then high score will be updated for that level.

Mopz

  • Guest
Re: Space shooter
« Reply #7 on: August 14, 2016, 06:05:12 PM »
nisse.dat Are you Swedish?

B+

  • Guest
Re: Space shooter
« Reply #8 on: August 14, 2016, 06:16:45 PM »
I am not Swedish and never heard of nisse until:
Quote
https://en.wikipedia.org/wiki/Tomte

 :o perhaps one of us has offended a spirit?

The original download might have a Mark.dat file but nisse?  ;D

Mike Lobanovsky

  • Guest
Re: Space shooter
« Reply #9 on: August 14, 2016, 07:27:31 PM »
Oh, thanks for the font B+!

Damn, isn't that thingy just ... viral?! :D

B+

  • Guest
Escher Space shooter
« Reply #10 on: August 14, 2016, 08:49:42 PM »
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

Code: [Select]
'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)

Mopz

  • Guest
Re: Space shooter
« Reply #11 on: August 15, 2016, 08:54:25 AM »
Haha, sorry, didn't remember that I was required to enter a name the first time I started the game and that I then wrote "nisse". I thought it was a hardcoded filename :D

Rick3137

  • Guest
Re: Space shooter
« Reply #12 on: August 15, 2016, 02:09:32 PM »
 Nice work.

  Your new font works good on my computer.
 

B+

  • Guest
Re: Space shooter
« Reply #13 on: August 15, 2016, 05:41:36 PM »
Thanks for feedback, all!

Rick mentioned a speed problem at SdlBasic with just level 1. For my 5+ year old computer, level 1 is like shooting fish in a barrel but for newer faster computers it could be too much. Level 1 should be easy as pie, level 9 very challenging.

I will try an overhaul to make speed at steady fps rate.

n00b

  • Guest
Re: Space shooter
« Reply #14 on: August 16, 2016, 04:04:03 AM »
This game is pretty good. I did find a few things that could be polished. First thing is that if you aim at your ship the game crashes because of a divide by zero error. Next thing was something that I personally just thought was irritating and that was the sound effect for the blaster. If you hold the mouse down, the sound effect just drives you insane. But none of this takes a way from what is a fun little diversion. Its also kinda awesome to see what kind of games other people in this community are working on.