This challenge sounded like a lot of fun when I read about it, and so far it has been. It's also the first challenge I've ever participated in
. I've posted my work so far below. You can't shoot yet, and you don't die when you hit an asteroid.
Rotate your ship with the mouse, and move it with the "w" key. Let me know what you think! (even if it's negative
)
rem constants
numberofstars=200
shiprotatespeed#=0.5
shipacceleration#=0.1
shipmaximumspeed#=3.0
rem setup
sync on
sync rate 60
set display mode 1024,768,32
hide mouse
null=make vector2(1)
null=make vector2(2)
rem make the stars
ink rgb(255,255,200),rgb(0,0,0)
for x=1 to numberofstars
dot rnd(1024),rnd(768)
next x
stars=1 : get image stars,0,0,1024,768
ink rgb(255,255,255),rgb(0,0,0)
rem object arrays
type pointtype
x as float
y as float
tx as float
ty as float
endtype
type objecttype
points as integer
size as float
xpos as float
ypos as float
rotation as float
xvel as float
yvel as float
spin as float
endtype
global dim object() as objecttype
global dim objectpoint(26,50) as pointtype
empty array object(0)
rem make the ship
array insert at bottom object(0)
object(0).points=5
object(0).size=10
object(0).xpos=500
object(0).ypos=300
object(0).rotation=0
object(0).xvel=0
object(0).yvel=0
object(0).spin=0
objectpoint(0,0).x=0
objectpoint(0,0).y=-10
objectpoint(0,1).x=-6
objectpoint(0,1).y=6
objectpoint(0,2).x=0
objectpoint(0,2).y=3
objectpoint(0,3).x=6
objectpoint(0,3).y=6
objectpoint(0,4).x=0
objectpoint(0,4).y=-10
rem make asteroids
makeasteroid(3,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
makeasteroid(3,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
makeasteroid(2,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
makeasteroid(2,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
makeasteroid(1,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
makeasteroid(1,rnd(1024),rnd(768),rnd(359),rnd(30)*0.1,rnd(30)*0.1)
`===========================================================================================
do
rem stuff
time=timer()
paste image stars,0,0
rem control the ship
object(0).spin=mousemovex()*shiprotatespeed#
if keystate(17)
inc object(0).xvel,sin(object(0).rotation)*shipacceleration#
inc object(0).yvel,cos(object(0).rotation)*shipacceleration#
set vector2 1,object(0).xvel,object(0).yvel
endif
for x=1 to array count(object(0))
set vector2 1,object(0).xpos-object(x).xpos,object(0).ypos-object(x).ypos
if length vector2(1)<object(0).size+object(x).size then print "you died!"
next x
rem draw and update all objects
gosub _update_objects
rem print stuff and sync
set cursor 0,5
print "fps: "+str$(screen fps())
sync
loop
`==========================================================================================
rem draws and updates all objects
_update_objects:
for x=0 to array count(object(0))
rem rotation
dec object(x).rotation,object(x).spin
for y=0 to object(x).points-1
objectpoint(x,y).tx=cos(object(x).rotation)*objectpoint(x,y).x+sin(object(x).rotation)*objectpoint(x,y).y
objectpoint(x,y).ty=cos(object(x).rotation)*objectpoint(x,y).y-sin(object(x).rotation)*objectpoint(x,y).x
next y
rem movement
dec object(x).xpos,object(x).xvel
dec object(x).ypos,object(x).yvel
if object(x).xpos<0 then object(x).xpos=1024
if object(x).ypos<0 then object(x).ypos=768
if object(x).xpos>1024 then object(x).xpos=0
if object(x).ypos>768 then object(x).ypos=0
rem drawing
for y=0 to object(x).points-2
line objectpoint(x,y).tx+object(x).xpos,objectpoint(x,y).ty+object(x).ypos,objectpoint(x,y+1).tx+object(x).xpos,objectpoint(x,y+1).ty+object(x).ypos
next y
next x
return
rem makes a new asteroid
function makeasteroid(size,x#,y#,direction#,speed#,spin#)
array insert at bottom object(0)
num=array count(object(0))
select size
case 1
object(num).points=6
object(num).size=10
object(num).xpos=x#
object(num).ypos=y#
object(num).rotation=0
object(num).xvel=sin(direction#)*speed#
object(num).yvel=cos(direction#)*speed#
object(num).spin=spin#
objectpoint(num,0).x=0
objectpoint(num,0).y=-10
objectpoint(num,1).x=-7
objectpoint(num,1).y=-7
objectpoint(num,2).x=-10
objectpoint(num,2).y=0
objectpoint(num,3).x=0
objectpoint(num,3).y=10
objectpoint(num,4).x=10
objectpoint(num,4).y=0
objectpoint(num,5).x=0
objectpoint(num,5).y=-10
endcase
case 2
object(num).points=7
object(num).size=20
object(num).xpos=x#
object(num).ypos=y#
object(num).rotation=0
object(num).xvel=sin(direction#)*speed#
object(num).yvel=cos(direction#)*speed#
object(num).spin=spin#
objectpoint(num,0).x=0
objectpoint(num,0).y=-20
objectpoint(num,1).x=-20
objectpoint(num,1).y=-5
objectpoint(num,2).x=-20
objectpoint(num,2).y=5
objectpoint(num,3).x=0
objectpoint(num,3).y=20
objectpoint(num,4).x=20
objectpoint(num,4).y=5
objectpoint(num,5).x=20
objectpoint(num,5).y=-5
objectpoint(num,6).x=0
objectpoint(num,6).y=-20
endcase
case 3
object(num).points=9
object(num).size=30
object(num).xpos=x#
object(num).ypos=y#
object(num).rotation=0
object(num).xvel=sin(direction#)*speed#
object(num).yvel=cos(direction#)*speed#
object(num).spin=spin#
objectpoint(num,0).x=0
objectpoint(num,0).y=-30
objectpoint(num,1).x=-17
objectpoint(num,1).y=-17
objectpoint(num,2).x=-30
objectpoint(num,2).y=0
objectpoint(num,3).x=-17
objectpoint(num,3).y=17
objectpoint(num,4).x=0
objectpoint(num,4).y=30
objectpoint(num,5).x=17
objectpoint(num,5).y=17
objectpoint(num,6).x=30
objectpoint(num,6).y=0
objectpoint(num,7).x=17
objectpoint(num,7).y=-17
objectpoint(num,8).x=0
objectpoint(num,8).y=-30
endcase
endselect
endfunction
formerly xMik