Quote: "And was the repeat-until loop with a sync a good or bad thing?"
Bad sorry - 1 sync per loop.
I've re-written my code and dropped the use of udt's (user defined types). But realy you should be using them. When you've got to grips with this code I'd highly recomend reading up on the use of types and arrays.
Anyway here's the code highly commented and sticking to your variable names as much as possible (just copy and paste):
rem initial set-up stuff
sync on
rem set the refresh rate to 60 fps. As your knowledge improves you may want to experiment
rem with timer based movement so that you can set the sync rate at 0. But for now locking the
rem refresh rate is the best way to ensure program runs equal on all machines.
sync rate 60
hide mouse
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
rem variables
rem I have dropped the user defined types for now, as its the basic principle of structured
rem code is I want to demonstrate.
rem Now variables can either be local or global. Local is the default scope of any vaiable.
rem this means it can be seen and manipulated only by the function that created it, look at
rem your main program as a kind of function too.
rem so when you wrote: SSX=480
rem You were creating a local variable and assigning 480 to it. This variable could only be
rem seen and manipulated in your main program. Any function you call would not see the ssx
rem variable, and could not alter it.
rem If you wish to be able to see and manipulate a variable from anywhere then declare them
rem as GLOBAL.
rem There are some good tutorials stickied in the newcomers board, I think at least one of these
rem covers variables. TDK's tutorials are very well written.
rem the ship's x and y:
global ssx
global ssy
rem the lasers x and y:
global lx
global ly
rem a variable to tell us if the laser is fired or not:
global lalive
rem other variables:
global score
global level
global lives
rem set up game - put all initialisation in a function
initialise()
rem *******************
rem *****MAIN LOOP*****
rem *******************
rem main game loop - now we want to keep this loop nice and neat and very easy to read
rem all the coding is in seperate functions, which makes coding and debugging much easier
rem as your code grows. When your game grows to 10000 lines of code you'll be very happy
rem your code is well structured.
do
cls ` this cls command won't be needed when you are using sprites, just while i use text.
rem infact, replace cls with this - paste image 1,0,0
controlship()
updatelaser()
printscores()
sync `one sync per loop - everything moves a bit, sync, everything moves a bit, sync and so on.....
loop
rem all functions go at end of program:
rem *******************
rem **** FUNCTIONS ****
rem *******************
function initialise()
rem initialise all variables
rem you would also load you media here
score=0
level=1
lives=3
ssx=480
ssy=650
endfunction
function controlship()
rem moves the ship - this is exactly as you coded it
if leftkey()=1 and ssx>0 then dec ssx,1
if rightkey()=1 and ssx<960 then inc ssx,1
if upkey()=1 and ssy>400 then dec ssy,1
if downkey()=1 and ssy<650 then inc ssy,1
rem position a X where ship is, you will replace this with your sprite command
text ssx,ssy,"X"
endfunction
function updatelaser()
rem in this function we look to see if the laser is in action (is lalive=1)
if lalive=1
rem if it is alive then whe move it up the screen 5 pixels (ie decrease ly by 5)
dec ly,5
rem if its y position is off the screen (smaller than -15) then it is no longer
rem considered to be in action so we set lalive to 0
if ly<-15 then lalive=0
else
rem if it isn't alive then we see if spacekey (fire) is pressed
if spacekey()
rem if fire pressed...
rem set the lasers initial positions so that it comes from the ship
lx=ssx
ly=ssy-10
rem the laser is now in action so set lalvive to 1
lalive=1
endif
endif
rem position laser - again you will place your sprite command here
text lx,ly,"|"
endfunction
function printscores()
rem print the scores,lives,level
text 1,1,"SCORE:"+str$(score)+" LEVEL:"+str$(level)+" LIVES:"+str$(lives)
endfunction
And just to show udt's and arrays in action here is a ship that can fire lots of lasers - each laser has its own data and can be individualy checked for collisions etc (again just copy & paste):
sync on
sync rate 60
hide mouse
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
rem user defined types
type shipinfo
x
y
endtype
type laserinfo
x
y
alive
endtype
type playerinfo
score
level
lives
lastfired
endtype
rem variables - must be global to access in functions
global ship as shipinfo
dim laser(20) as laserinfo
global player as playerinfo
rem set up game
initialise()
rem main game loop
do
cls
controlship()
updatelaser()
printscores()
sync
loop
rem *** FUNCTIONS ***
function initialise()
player.score=0
player.level=1
player.lives=3
ship.x=480
ship.y=650
endfunction
function controlship()
if leftkey()=1 and ship.x>0 then dec ship.x,1
if rightkey()=1 and ship.x<960 then inc ship.x,1
if upkey()=1 and ship.y>400 then dec ship.y,1
if downkey()=1 and ship.y<650 then inc ship.y,1
text ship.x,ship.y,"X"
endfunction
function updatelaser()
if timer()>player.lastfired
if spacekey()
for i=1 to 20
if laser(i).alive=0
laser(i).alive=1
laser(i).x=ship.x
laser(i).y=ship.y-5
player.lastfired=timer()+150
exit
endif
next i
endif
endif
for i=1 to 20
if laser(i).alive
dec laser(i).y,5
if laser(i).y<-15 then laser(i).alive=0
endif
text laser(i).x,laser(i).y,"|"
next i
endfunction
function printscores()
text 1,1,"SCORE:"+str$(player.score)+" LEVEL:"+str$(player.level)+" LIVES:"+str$(player.lives)
endfunction

The word "Gullible" cannot be found in any English Dictionary.