Finding decent *working* example code

BlitzMax Forums/BlitzMax Beginners Area/Finding decent *working* example code

Hi, Just purchased Blitzmax the other day and it looks great so far. Only thing im finding dissapointing is that whenever I find any code of interest to learn from like - tilemap/scroll demo or a space invaders code demo the thing wont compile. cause it has bugs in it. I have used blitzplus a little, but don't know enough about blitzmax to correct the errors im getting from the compilier. If someone out there could point me to some working code for either tilemap scroller, or simple space invader /pacman code to read and learn from, that would be greatly appreciated thanks.

Hi,

Its normaly not because the code has bugs in it, its normaly because the code is from a previous version.

Skid went through the code archieve the other week and changed things so that they work with 1.22

If you post the error messages you are getting on this thread, we can tell you how to change things for 1.22 normally its only the garbage collection, the import files and the GL commands

Oh ok, thanks mate. Well I'm using 1.22 and loaded a demo prog called maxinvaders by Jason Brasier.

First Error that is: Unable to convert from TStream to Int

Oh come on Play the game, at least post the line with the error.

Also I was under the impression that Maxinvaders was a finished product from http://www.sos-software.co.uk/ Were was the demo so I can download it and look?

i downloaded it again and but from another site (couldn't remeber first site i got it from) but it seems to work now, sorry for the bother, might have been a corrupted download or something or missing files.

Unable to convert from TStream to Int

Glad you got it working in that particular case, but you'll see this sort of thing with older code. It used to be permitted to have Int handles for images, streams, and such, but that became more strictly enforced when auto-garbage collection became possible.

If you see it in the future, just change the declaration of the variable to match what BlitzMax is complaining about and you should be fine. For example, an old program might have:
Strict
Local pic = LoadImage("somepic.jpg")
where pic defaults to Int and you get an "Unable to convert from 'TImage' to 'Int'" compile error. You can fix it with:
Strict
Local pic:TImage = LoadImage("somepic.jpg")

Another one that you'll sometimes run into is the use of "FlushMem." Just eliminate all uses of FlushMem and you should be fine (garbage collection now defaults to automatic, so FlushMem was eliminated).

You can find these changes and others in "Versions.doc" (in the "Program Files\BlitzMax" folder for Windows). Maybe not the most exciting reading ever, but useful. :)

Ehehehehe........ I should have asked about this too, as I ran into this a lot
when importing BB files from the code archives.

Learn something new everyday :-)

-Garrett

Ahh yes, have seen flushmem in some examples and have deleted it before and the code worked fine. Thanks for the 'Unable to convert from timage to Int tip. Now that I have got this space invaders code working, it should keep me busy for a while, and hopefully come up with my own first space invaders version sometime soon:)

Ahh btw another one I come across in samples is: Unable to calculate tex size

Ahh btw another one I come across in samples is: Unable to calculate tex size


What kind of machine/video card are you using?

It could be that:

1) The program is trying to run in full screen mode and your video card doesn't do full screen OpenGL
2) The program is trying to run in windowed mode and your video card doesn't do windowed OpenGL
3) The program is trying to run in windowed mode and your video card doesn't support 3D accelerating in the bitdepth used by your desktop
4) The program is trying to run in full screen mode and your video card doesn't support 3D acceleration in the bitdepth requested by the program
5) could be that either your DirectX or OpenGL drivers are broken

...for starters.

yeah the bugs are due to the code being written in previous versions and can usually be fixed easily - just post here and people will help you. My BlitzMax Game Framework has working source code for an entire game called Attack of the Mutant Greys, checkout the dmeo if you have time.

Oh ok, thanks mate. Well I'm using 1.22 and loaded a demo prog called maxinvaders by Jason Brasier.

First Error that is: Unable to convert from TStream to Int


Hmm, I thought I changed all of my code examples to work on versions after the removal FlushMem, etc. Looks like something else changed without me realising.

The offending line that gave you the error above is
Local configFile=ReadFile("config.ini")
..which should be
Local configFile:TStream=ReadFile("config.ini")
in the latest build of BlitzMax.

I'll check through my other stuff and upload any updates over the weekend.

Unable to calculate tex size


This is very often because you are Creating a graphic Object but not selecting it

If you use CreateGraphics then you must also use Setgraphics

An example
SetGraphic (CreateGraphics( 640,480,0,60,GRAPHICS_BACKBUFFER | BGL_DEPTHBUFFER ))

I wrote a space invaders when I first got BMAX about a year ago to learn it. It uses graphics from different arcade games. It is not complete but is playable. if anybody is interested, I can email the source code. It is not well documented but I don't think its that hard to follow. you can download the executable from here:
http://www.gamedev.net/community/gds/viewentry.asp?projectid=411660

Unable to calculate tex size

This can also happen with Intel drivers.

xlsior: yes, it seems that after running a couple more programs it does seem I have some opengl issues. The computer im running is a bucket -a celeron 730mhz with an old tnt2 card (It's my girlfriends computer) so i dont expect wonders from it.

H&k: thanks, it will take me a while to learn what all the errors mean.

grey: great little game, tried your demo works great, but if I select opengl, the game has a shitfit and takes me back to windows.

So it seems until I can afford to update this pc, or better yet get a new pc, I should stick to projects that use directx.

jesse: I just downloaded and tried your space invaders game and got 'Unable to calc text size' and it shut down, so im guessing it was written in opengl.

thanks for your input guys, appreciate it. :)

I updated the version in directX
and modified it a little I made two version the original
and the updated version.
I am working on creating a high score table
it will show up in the game but it is not implemented yet.
here is the source code of the updated version
if you are interested:
Framework BRL.D3D7Max2D
Import BRL.FileSystem
Import BRL.StandardIO
Import BRL.Retro
Import BRL.PNGLoader
Import BRL.BMPLoader
Import BRL.FreeAudioAudio
Import BRL.WAVLoader

SetGraphicsDriver D3D7Max2DDriver()

Const  ScreenWidth =  480
Const  screenHeight = 360
Const  MAXBULLETS = 2
Const  FIREDELAY = 25
Const  WALLDELAY = 50
Const  ufoSPEED = 1
Const  ALIENSPEED# = 1.5
Const  FORWARD# = ALIENSPEED
Const  BACKWARD# = -ALIENSPEED
Const  NUMBEROFALIENS = 10
Const  BOMBSPEED = 3
Const  MAXBOMBS = 3
Const  DROP = 7
Global inwave = False
Global settingup=False
Global option = 0
Global bullet_image:timage
Global bullet_sound:timage
Global Wall_image:timage
Global wall_sound:timage
Global alien_image:timage
Global ingame = False
Global score = 0

Type Tuser
	Field name$
	Field score:Int
EndType

Type TScoreTable
	Field player:Tuser[]
	Global Score_TableExists 
	Global Max_Names = 10
	Method makeFile:TStream(fileName:String)
		If Not ReadDir(ExtractDir(fileName)) CreateDir(ExtractDir(fileName)) 
		If -1 = FileSize(filename) Then
			Local file=CreateFile(filename)
			If file 
				Score_TableExists = True 
			Else 
				Score_TableExists = False
				RuntimeError "invalid file: Unable to create scoretable"
			EndIf
		EndIf
		
		Score_TableExists = True
	End Method
	Method Read:Int(fileName:String)
		Local file:TStream
		Local size = FileSize(fileName)
		Print size
		player = Null
		If size = -1 
			Score_TableExists = False
		Else 
			If size >= 0  
				file=OpenFile(fileName)
			Else
				Score_TableExists = False
			EndIf
			Local index = 0
			While Not Eof(file)
				player = player[..player.length+1]
				player[index] = New Tuser
				player[index].name = ReadString(file,20)
				player[index].score = ReadInt(file) 
				index=index+1
			Wend
			Score_TableExists = True
		EndIf
	End Method
	Method Write(filename:String)
		Local file:TStream
		Local size = FileSize(filename)
		If player.length > 0 Then 
			score_TableExists = True
			File = OpenFile(filename)
			If file 
				If player.length > Max_Names Then
					player = player[..Max_Names]
				EndIf  
				For Local index = 0 To player.length-1
					player[index].name = LSet(player[index].name,20)
					WriteString file,player[index].name$
					WriteInt file,player[index].score
				Next
				CloseFile(file)
			Else
				RuntimeError("unable to store names")
				End
			EndIf	
			
		EndIf
		
	End Method
	
	Method Add_Player(can:Tuser)
		Local user:Tuser = New Tuser
		user.name = can.name
		user.score = can.score
		If player.length > 0 Then
			player=player[..player.length+1]
			Local temp:Tuser=user 
			Local index	
			For index = 0 To player.length-1
				If player[index] <> Null 
					If player[index].score < user.score
						temp = player[index] 
						player[index] = user
						user = temp
					EndIf
				Else
					player[index]=user	
				EndIf 
			Next
			If player.length > Max_names  Then 
				player = player[..Max_Names]
			EndIf
		Else
			player=player[..1]
			player[0]= user
		EndIf		
	End Method
	Method clear()
	
	EndMethod
	
End Type

Type Tbackground
	
	Field x,y
	Field sy1#
	Field sy2#
	Field sy3#
	Field stars1:timage
	Field stars2:timage
	Field stars3:timage 
	Field world:timage
	Field scoreboard
	Field worldindex
	Field timer
	Global ship:timage
	Global shipcount
	Global background:Tbackground
	
	Function create()
		background = New Tbackground
		background.x = 0
		background.y = 0
		background.stars1 = LoadImage("outerspace1.png",FILTEREDIMAGE|DYNAMICIMAGE)
		background.stars2 = LoadImage("stars2.png",FILTEREDIMAGE|DYNAMICIMAGE)
		background.stars3 = LoadImage("stars3.png",FILTEREDIMAGE|DYNAMICIMAGE)
		background.world  = LoadAnimImage("world1.bmp",90,90,0,18)
		ship = LoadAnimImage("game.bmp",15,16,4,1)
	End Function		
	
	Function move()
		background.sy1 = (background.sy1 + 0.1) Mod 200
		background.sy2 = (background.sy2 + 0.2) Mod 200
		background.sy3 = (background.sy3 + 0.5) Mod 200
		background.timer = (background.timer+1) Mod 10
	End Function	
	
	Function Display()
		SetMaskColor(0,0,0)
		SetBlend(MASKBLEND)
		DrawImage background.stars1,0,0
		SetScale .7,.7
		If Not background.timer Then background.worldindex =(background.worldindex + 1) Mod 18  
		DrawImage(background.world,100,100,background.worldindex)
		SetScale 1.0,1.0
		SetBlend(LIGHTBLEND)
		TileImage (background.stars2,background.x,background.sy2)
		TileImage (background.stars3,background.x,background.sy3)
		SetColor 255,255,255
		SetBlend(MASKBLEND)
		If ingame
			For Local n = 1 To shipcount
				DrawImage ship,screenwidth-80+16*n,1
			Next
		EndIf
		DrawText " score :" + score,10,0
		SetColor 255,255,255
	End Function
	Function cycle(s)
		shipcount = s
		If background Then
			Display()
			move()
		Else
			create()
		EndIf
	End Function
End Type

Type ParticleType

	Field x#,Y#   				' not true physics but it works for this game
	Field Xspeed#,Yspeed#
	Field active
	Field index
	Field angle#=0.0
	Global exploding = False
	Global image:timage
	Global gravity#			= 0.15						
	Global friction#		= .981
	Global elasticity#      = 0.7						
	Global list:TList
	Global Particle:ParticleType
	Method initialize() image = LoadAnimImage("shippieces.png",4,4,1,13) EndMethod

	Function create(xr#,yr#)
		Local angle,index,cell
		SeedRnd MilliSecs()
		RestoreData shipdata
		For cell = 0 To 12
			particle=New ParticleType
			ReadData particle.x,particle.y
			particle.x=particle.x+xr
			particle.y=particle.y+yr
			angle = 10+Rnd(160)								
			particle.xspeed = 20*Cos(angle)				
			particle.yspeed = 20*Sin(angle)				
			particle.index =	cell						
			DrawImage(image,particle.x,particle.y,cell)
			If Not list Then list = CreateList()
			list.AddLast(particle)	
		Next
	End Function

	Method animate()
	    Local count = 0
		For particle = EachIn list 
			particle.x = particle.x + particle.xspeed
			particle.y = particle.y + particle.yspeed
			If particle.y>(screenheight-4)
				If particle.yspeed>0  particle.yspeed=-(particle.yspeed)*elasticity
				particle.y = (screenheight-4)
			EndIf
			If particle.x>=screenwidth 
				If particle.xspeed>0 particle.xspeed=-particle.xspeed*elasticity
				particle.x = screenwidth
			EndIf
		
			If particle.y <=0 And  particle.yspeed<0 particle.yspeed=-particle.yspeed
			If particle.x<=0 And  particle.xspeed<0 particle.xspeed=-particle.xspeed
			If particle.yspeed >=0 Then particle.yspeed =particle.yspeed+gravity
			If particle.yspeed <0 Then particle.yspeed =(particle.yspeed+gravity)*friction
			If Abs(particle.yspeed) <=0.4 And particle.y >= (screenheight-4)  
				particle.yspeed = 0
				If Abs(particle.xspeed) < 0.1 Then ListRemove(list,particle) Else particle.xspeed = particle.xspeed*(friction/1.1)
			EndIf
			SetRotation(-angle)
			DrawImage(image,particle.x,particle.y,particle. index)
			count=count+1
			angle=(angle+1.0)Mod 360
			SetRotation(0.0)
		Next
		If Not count exploding = False		
	End Method

End Type

#shipdata
DefData 5,0,9,0,3,4,7,4,11,4,0,8,4,8,8,8,12,8
DefData 1,12,5,12,9,12,13,12 


Type Twall
	Field active
	Field x,y
	Field speed
	Field life
	Field timer
	Field Count
	Field index
	Field frames
	Global list:TList
	Global wall:Twall
	Global Image:timage
	Function initialize()
		Image = LoadAnimImage("game.bmp",8,20,27,5)
	End Function
	Function create(x,y)
		wall = New Twall
		wall.active = True
		wall.x = x+4
		wall.y = y+8
		wall.index = 0
		wall.life = 900
		wall.timer = 15
		wall.timer = 0
  		If Not list Then list = CreateList()
		list.AddLast(wall)
	End Function
	
	Function animate()
		If wall Then  
    		For wall = EachIn list
				wall.life = wall.life -1
				If wall.life < 100 Then 
					If Not (wall.life Mod 25) Then wall.index = wall.index + 1
				End If 
				If wall.y < (screenHeight - 18) Then 
					wall.y =wall.y+1 
			    	DrawImage(wall.Image,wall.x,wall.y,wall.index)
				Else 
					If Not wall.life Then 
						wall.active = False
						DrawImage(wall.Image,wall.x,wall.y,wall.index)
						ListRemove(list,wall)	
					Else		
	    				DrawImage(wall.Image,wall.x,wall.y,wall.index)
					EndIf			
				EndIf
			Next
		EndIf	  
	End Function

End Type  


Type Tufo
	
	Field x
	Field y
	Field active
	Field life
	Field sound:TSound
	Field Channel:TChannel
	Field weapon
	Field speed
	Field direction
	Field counter
	Field timer
	Field index
	Field frames
	
	Global Image:timage
	Global triggerdelay
	Global ufo:Tufo

	Function create:Tufo()
 		ufo = New Tufo
 		ufo.y = 25
		ufo.active = False
		ufo.frames = 4
 		ufo.Image = LoadAnimImage("game.bmp",15,15,8,4)
		ufo.sound = LoadSound("ufo.wav")
		ufo.Channel = AllocChannel()
		Return ufo
  	End Function
	
	Function activate()
		If  ufo.active = False And  (Rand(300)-1) = 0 Then
 			ufo.direction = (Rand(3) & 2) - 1
 			ufo.speed = ufoSPEED * ufo.direction
        	ufo.x = (screenwidth/2)-(ufo.direction*((screenwidth/2)+12))
 			ufo.active = True 
 			ufo.index =  0
 			ufo.life = 0
 			ufo.timer= 0
			ufo.triggerdelay = 0
        	ufo.Channel = PlaySound(ufo.sound,ufo.Channel)
		EndIf 
	End Function
	
	Function animate()
		If ufo.active Then
			If Not ChannelPlaying(ufo.Channel) PlaySound(ufo.sound,ufo.Channel) 
			If ufo.x>10 And ufo.x < (screenwidth-10) Then
				If Not (Rand(100)-1) And triggerdelay = 0 Then 
					Twall.create(ufo.x,ufo.y)
					triggerdelay = WALLDELAY
				End If
				If triggerdelay Then triggerdelay = triggerdelay-1
			End If 
			If ufo.direction = 1 Then
				If ufo.x < (screenwidth) Then  
					ufo.x = ufo.x + ufo.speed 
				Else 
					ufo.active = False 
					If ChannelPlaying(ufo.Channel) Then StopChannel(ufo.Channel)
				EndIf
			Else
				If ufo.x >=-12 Then
					ufo.x=ufo.x+ufo.speed
				Else 
					ufo.active = False 
					If ChannelPlaying(ufo.Channel) Then StopChannel(ufo.Channel)
				EndIf
			EndIf
		EndIf
	End Function
		
	Function Display()
		If ufo.active Then
			ufo.timer =(ufo.timer+1)Mod 20
			If ufo.timer Then
				DrawImage(ufo.Image,ufo.x,ufo.y,ufo.index)
			Else
				ufo.index=(ufo.index+1)Mod 4
		      	DrawImage(ufo.Image,ufo.x,ufo.y,ufo.index)
			EndIf
		EndIf
	End Function	

End Type


 
Type TPlayer
	Field active
	Field life
	Field x#,y#
	Field weapon
	Field speed
	Field direction
	Field counter
	Field timer
	Field index
	Field frames
	Global Image:timage
	Global exploding = False
	Global player:TPlayer
	Global triggerdelay = 0
	Global sound:TSound
	Global soundchannel:TChannel
	Global explodesound:TSound
	Global explodechannel:TChannel
	Global bulletsound:TSound
	Global bulletchannel:TChannel
	Function initialize()
		Image = LoadAnimImage("game.bmp",15,16,4,1)
		explodesound = LoadSound("deadship.wav")
		explodechannel = AllocChannel()
		bulletsound = LoadSound( "bullet.wav" )
		bulletchannel = AllocChannel()
	End Function
	Function create:TPlayer()
 		player = New TPlayer
		
 		player.x = (screenwidth/2)- 7
 		player.y = screenHeight-16
 		player.speed = 1.5
		player.direction = 1
		player.life = 3
		Return player
	End Function
	
	Function trigger(B:Tammo)
		Local bullets = 0
		If B.list Then bullets = CountList(b.list)
		
		If bullets < MAXBULLETS And KeyDown(KEY_LCONTROL) And Not triggerdelay Then
				PlaySound(bulletsound,bulletchannel) 
				B.create(player)
	   	  		triggerdelay=FIREDELAY
		EndIf
		If triggerdelay Then triggerdelay = triggerdelay-1
		

	End Function

	Function move(wall:Twall)  
    	Local overlapleft,overlapright

		If wall.list Then 
       		
			overlapleft = False
			overlapright = False
			For wall = EachIn wall.list
				If (ImagesCollide(player.Image, player.x-6,player.y,0,wall.Image,wall.x,wall.y,wall.index)) Then 
				overlapleft = True
				EndIf
				If (ImagesCollide(player.Image,player.x+player.speed,player.y,0,wall.Image,wall.x,wall.y,wall.index)) Then
					overlapright = True
				EndIf
			Next
			If (overlapleft = False) And KeyDown(KEY_LEFT) And  (player.x > player.speed) Then player.x = player.x - player.speed
			If (overlapright= False) And KeyDown(KEY_RIGHT) And  (player.x < (screenwidth-(player.speed+15))) Then player.x =player.x + player.speed
		Else
			If KeyDown(KEY_LEFT) And player.x > player.speed Then player.x = player.x - player.speed
    		If KeyDown(KEY_RIGHT) And player.x < (screenwidth-(player.speed+15)) Then player.x =player.x + player.speed
		EndIf
	 

	End Function 

	Method Display()
		SetBlend(MASKBLEND)
		DrawImage(player.Image,player.x,player.y)
	EndMethod

End Type

Type Tammo
	Field x,y
	Field speed_x
	Field speed_y
	Field speed
	Global Image:timage
	Global bullet:Tammo
	Global Kazzapsound:TSound
	Global babysound:TSound
	Global kazzapchannel:TChannel
	Global babychannel:TChannel
	Global list:TList
	Global BULLETSPEED = 5
	Global startpattern = True

	Function initialize()
		Image = LoadAnimImage("game.bmp",6,10,34,1)
		Kazzapsound = LoadSound( "deadbee.wav" )
		kazzapchannel = AllocChannel()
		babysound = LoadSound( "deadbaby.wav")
		babychannel = AllocChannel()
	End Function

	Function create(p:TPlayer)
		bullet = New Tammo
  		bullet.x = p.x + 4
  		bullet.y = p.y-11
  		bullet.speed_y = -1
  		If Not list Then list = CreateList()
		list.AddLast(bullet)
	End Function

	Function move()
		If bullet  Then 
			For bullet = EachIn list
				bullet.y = bullet.y - BULLETSPEED
				If bullet.y < 10.0 ListRemove(list,bullet)	
			Next
		EndIf
	End Function

	Function Hit(alien:Talien,ufo:Tufo,wall:Twall,explosion:Texplosion)
		Local done=False
		Local increasespeed = False
		If bullet.list Then
		For bullet = EachIn list
     		If alien.list Then 
				For alien = EachIn alien.list
        			If ImagesCollide(bullet.Image,bullet.x,bullet.y,0,alien.Image,alien.x,alien.y,0) Then 
		   				If alien.class  Then 
		      				PlaySound (Kazzapsound,kazzapchannel)
		      				score=score + 20  
		   				Else 
			  				PlaySound (babysound,babychannel)
			  				score = score + 10
		   				EndIf 
						explosion.create(alien.x,alien.y)
						ListRemove(alien.list,alien)
						ListRemove(bullet.list,bullet)
						alien.speed :+ 0.03
						If alien.timer > 1 Then alien.timer:-1
						done = True
						Exit
					Else
						If ImagesCollide(Image,bullet.x,bullet.y,0,ufo.Image,ufo.x,ufo.y,0)  And ufo.active Then
							explosion.create(ufo.x,ufo.y)
							ufo.active = False
							score = score + 50
							StopChannel(ufo.Channel)
							ListRemove(bullet.list,bullet)
			  				Exit
						EndIf
					EndIf
	 			Next
			EndIf
			If done Then Exit
			If wall.list Then
				For wall = EachIn wall.list
					If ImagesCollide(Image,bullet.x,bullet.y,0,wall.Image,wall.x,wall.y,0) Then 
		    			score = score + 10
						explosion.create(wall.x,wall.y)
						ListRemove(wall.list,wall)
		    			ListRemove(bullet.list,bullet)
						done = True
		    			Exit
	    			EndIf
				Next
				If done Then Exit
			EndIf
		Next
		EndIf	 
		If CountList(alien.list)= 0 
			reset(wall,explosion)
			settingup= False
			inwave = False
		EndIf
		
	End Function

	Function reset(wall:twall,explosion:texplosion)
			If wall.list ClearList(wall.list)
			If bullet.list ClearList(bullet.list)
			If explosion.list ClearList(explosion.list)
			
	End Function
	
	Function Display()
    	If list Then
			If Not ListIsEmpty(bullet.list)  Then
				For bullet = EachIn list
         			SetBlend(MASKBLEND)
					DrawImage Image,bullet.x,bullet.y
	 			Next 
 		End If
		EndIf
	End Function
End Type


Type Talienammo
	Field x,y
	Field speed_x
	Field speed_y
	Field speed
	Global sound:TSound
	Global Channel:TChannel
	Global Image:timage
	Global bombs
	Global list:TList
	Global bomb:Talienammo

	Function initialize:Talienammo()
 		bombs = 0
		Image = LoadAnimImage("game.bmp",8,8,40,1)
		sound = LoadSound("ufo.wav")
		Channel = AllocChannel()
		Return bomb
	End Function

	Function create(x,y)
		bomb:Talienammo = New Talienammo
		bomb.x = x+6
		bomb.y = y+6
		bomb.speed_y = BOMBSPEED
		If Not list Then list = CreateList()
		list.AddLast(bomb)
	End Function

	Function move()
		If list Then 
			For bomb = EachIn list
				bomb.y = bomb.y + BOMBSPEED
		    	If bomb.y> screenHeight Then ListRemove(list,bomb)
			Next
		EndIf 
		bombHit(TPlayer.player,wall:Twall)
	End Function
	
	Function Display()
		If list  Then 
       		For bomb = EachIn list
           		DrawImage Image,bomb.x,bomb.y
	   		Next
		EndIf
	End Function

	Function bombHit(player:TPlayer,wall:twall)
		If list And particle.exploding = False Then 
	   		For bomb = EachIn list
	       		If ImagesCollide(Image,bomb.x,bomb.y,0,player.Image,player.x,player.y,0) Then 
					PlaySound (player.explodesound,player.explodechannel)
					ListRemove(list,bomb)
					If wall.list ClearList(wall.list)
					particle.create(player.x,player.y)
					particle.exploding = True
					player.life = player.life - 1
				EndIf
       		Next
    	EndIf
	End Function 

End Type

Type Talien
	Field x#,y#
	Field shield
	Field button
	Field Count
	Field class
	Field index
	Field frames
	Global timer
	Global speed#
	Global Image:timage
	Global bombsound:TSound
	Global bombchannel:TChannel
	Global alien:Talien
	Global list:TList
	Global link:TLink
	Global liningup
	Global direction#
	Global startpattern
	
	Function initialize()
		Image = LoadAnimImage ("invaders.png",32,32,0,6)'("game.bmp",13,10,6,4)
		bombsound =LoadSound( "bomb.wav")
		bombchannel = AllocChannel()
	End Function
	
	Function create()
		speed = 0.2
		For Local b = 1 To 5
			For Local t = 1 To NUMBEROFALIENS
 				alien = New Talien
				alien.x = 40+(30*t)
 				alien.y = 30 +(20*b)
 				timer = NUMBEROFALIENS*5
 				alien.Count = 0
 				direction = FORWARD
 				alien.button= Rand(10)
 				alien.class = Rand(2)-1
 				alien.frames= 2
 				alien.index = Rand(2)-1
 				If Not list Then list = CreateList()
				list.AddLast(alien)
				startpattern = True
			Next
		Next
	End Function

	Function move()  
		Local downshift
  			Local b:TList
			For alien = EachIn list
				If direction = FORWARD And   alien.x > (screenwidth-image.width) Then 
					direction = BACKWARD
					downshift = True 
					Exit
				End If
        		If direction = BACKWARD And  alien.x < 0 Then 
					direction = FORWARD
					downshift=True
					Exit
				EndIf
			Next
			
			If Not ListIsEmpty(list) Then 
				alien = Talien(list.Last())
				If alien.y> (screenHeight - 40) Then downshift = False
				For alien = EachIn list
        			If ingame And  downshift alien.y = alien.y + DROP
        			alien.x = alien.x + (direction * speed) 
     				trigger()
				Next
			EndIf
	End Function 
	
	
	Function Display()
  		For alien = EachIn list 	
			
			DrawImage( Image,alien.x,alien.y,(alien.class*2)+alien.index)
	   		
			alien.Count = (alien.Count + 1) Mod alien.timer
			If Not alien.Count Then alien.index = (alien.index+1)Mod alien.frames
  		Next
	End Function
	
	Function trigger()
		Local alienshots
		Local AliensLeft
		If list Then
			AliensLeft = CountList(list)
			If Talienammo.list Then alienshots = CountList(Talienammo.list)
			For alien = EachIn list
				If alien.button = Rand(40*AliensLeft) And alienshots < MAXBOMBS And Not particle.exploding Then 
            		If ChannelPlaying(bombchannel) Then
				   		StopChannel(bombchannel)
				   		PlaySound(bombsound,bombchannel)                                 
					Else
				   		PlaySound(bombsound,bombchannel)
					EndIf 
	        		Talienammo.create(alien.x,alien.y)
			 	End If
     		Next
		End If
	End Function 	
	
	Function setpattern()
		Local done
		done = False
		If startpattern 
			alien = Talien(list.Last())
			startpattern = False
		Else
			link = ListFindLink(list,alien).PrevLink()
		    If link
				alien = Talien(link.Value())
			Else 
				done = True
			EndIf
		EndIf
		If done Then Return done
		Local current:TList = list
		Local calien:Talien = alien
		While link
			DrawImage(Image,alien.x,alien.y,(alien.class*2)+alien.index)
			link= ListFindLink(list,alien).NextLink()
			If link Then alien = Talien(link.Value())
		Wend
		list = current
		alien = calien	
		Return done
	End Function
		
End Type

Type Texplosion
	Field index
	Field hold
	Field Hcounter
	Field x,y
	Global Image:timage
    Global list:TList
	Global explosion:Texplosion
	
	Function initialize() 
		Image = LoadAnimImage("game.bmp",15,15,17,4)
	End Function

	Function create(x,y)
        explosion = New Texplosion
        explosion.x = x
		explosion.y = y
        explosion.index = 0
        explosion.hold = 5
        explosion.Hcounter=0
 		If Not list Then list = CreateList()
		list.AddLast(explosion)
	End Function         
             
	Function Display()
		If list Then
	   		For explosion = EachIn list
	       		DrawImage Image,explosion.x,explosion.y,explosion.index
	       		explosion.Hcounter = (explosion.Hcounter + 1) Mod explosion.hold
	       		If Not explosion.Hcounter Then explosion.index=explosion.index+1
	       		If explosion.index>3 Then ListRemove(list,explosion)
	   		Next
		EndIf
	End Function

End Type

Type Twindow
	Field width
	Field Height
	Global alphabet:timage
	Global backed = False
	Global window:Twindow
	
	Function initialize:Twindow()
		window = New Twindow
		alphabet = LoadAnimImage("alphabit1.bmp",30,30,0,36)
		Return window
	End Function
	
	Function option(a$,x,y)
		Local r,g,b,alpha#,blend#
		If a$ = Null Then Return
		a$ = Upper$(a$)
    	alpha = GetAlpha()
		blend = GetBlend()
		GetColor r,g,b
		SetBlend LIGHTBLEND 
		SetAlpha 0.95
		If backed Then
			SetColor (0,0,255)
			DrawRect(x,y,Len(a$)*25,30)
		EndIf
		SetColor 200,0,0
		For Local c = 1 To Len(A$)
			Local d$= Mid$(a$,c,1)
			SetBlend LIGHTBLEND
			SetAlpha 1
			If Asc(d$) >=65 And Asc(d$)<=90 Then DrawImage(alphabet,x+(c-1)*25,y,Asc(d$)-65)
			If Asc(d$) >=48 And Asc(d$)<=57 Then DrawImage(alphabet,x+(c-1)*25,y,Asc(d$)-22)
		Next
		SetColor r,g,b
		SetAlpha alpha
		SetBlend blend
	End Function

	Function getinput()
		Local x,y,m
		x = MouseX()
		y = MouseY()
		m = -1
		backed = False
		option("space invaders",50,50)
		If x>100 And x<300 And y>200 And y<300 Then
			m = ((y-200)/30)+1
			Select m		
				Case 1
					backed = True
					option("new game",110,200)
					backed = False
					option("High Scores",100,230)
					option("exit game",100,260)
					
					If MouseDown(1) Then Return m
					Return -1
				Case 2				
					backed = False
					option("new Game",110,200)
					backed = True
					option("High Scores",100,230)
					backed = False
					option("Exit Game",100,260)
					If MouseDown(1) Then Return m
					Return -1
				Case 3
					backed = False
					option("new Game",110,200)
					option("High Scores",100,230)
					backed = True
					option("Exit Game",100,260)
					If MouseDown(1) Then Return m
					Return -1
					
				Default
					backed = False
					option("new game",110,200)
					option("High Score",100,230)
					option("exit game",100,260)
					If MouseDown(1) Then Return m
					Return -1
			EndSelect
		Else
					backed = False
					option("new game",110,200)
					option("High Scores",100,230)
					option("exit game",100,260)
		EndIf 
		Return m
	End Function
	

End Type
If GraphicsModeExists(screenwidth,screenheight,16,60)
	Graphics (screenwidth,screenheight,16,60)  
Else
	Graphics screenwidth,screenHeight,0
	
EndIf
Local player:TPlayer = TPlayer.create() 
Local bullet:Tammo = New Tammo
Local background:Tbackground = New Tbackground
Local wall:Twall = New Twall
Local aliens:Talien = New Talien
Local bomb:Talienammo = New Talienammo
Local explosion:Texplosion= New Texplosion
Local ufo:Tufo = New Tufo
Local selection:Twindow = Twindow.initialize()
Global particle:particletype = New particletype
wall.initialize()
explosion.initialize()
bomb.initialize()
bullet.initialize()
player.initialize()
aliens.initialize()
ufo = ufo.create()
particle.initialize()

Global picture = 0 

While Not KeyDown(KEY_ESCAPE) And option <> 2
	Cls
	background.cycle(player.life)
	If ingame 
		If inwave
			ufo.activate()
			aliens.move()
			If particle.exploding
				particle.animate()
			Else
				player.move(wall)
				player.Display()
				player.trigger(bullet)
			EndIf
			bullet.Hit(aliens,ufo,wall,explosion)
			bullet.move()
			bomb.move()
 			ufo.animate()
			wall.animate()
			ufo.Display()
			bullet.Display()
			explosion.Display()
			bomb.Display()
			aliens.Display()
			If Not player.life 
				bullet.reset(wall,explosion)
				ClearList(aliens.list)
				ClearList(bullet.list)
				ClearList(bomb.list)
				If particle.exploding ClearList(particle.list);particle.exploding = False 
				inwave = False
				ingame = False
				settingup = False
				GCCollect()
			EndIf
		Else
			If settingup = False 
				aliens.create()
 				settingup = True
			Else
				If aliens.setpattern() settingup = False; inwave = True
			EndIf
		EndIf
	Else
		If option = 1 And settingup = False 
			aliens.create()
 			settingup = True
			option = 0
			
		Else
			If settingup Then
				If aliens.setpattern() settingup = False; ingame = True; inwave = True
			Else
				
				Local a = selection.getinput()	
				If a =1 
					option = a
					player.life = 3
					score = 0
				EndIf
				If a = 3 Then option = 2 
				If a = 2 Then 
				EndIf
				
			EndIf
		EndIf
	EndIf	
	If KeyHit(KEY_P) And KeyDown(KEY_LCONTROL) Then
	    Local p:TPixmap = GrabPixmap(0,0,GraphicsWidth(),GraphicsHeight())
		picture=(picture+1) Mod 10 
		Local file$ = "spaceinvader"+Chr$(48+picture)+".png"
		SavePixmapPNG(p,file$)
	EndIf


	Flip
Wend

End


but you have to download the updated version from here for it to work:
www.gamedev.net/community/gds/viewentry.asp?projectid=411660

Jesse: thanks for the update, I put the new source code into the game directory and it works a treat now. Cool game btw :)

Rydan77: thanks. Yeah it switches to OpenGL and has various protections in place for PCs with no OpenGL, but guess what, none of them work, it just bombs back to windows ho hum. I'll look into more protction soon.