ASM: Space Invaders

 

This is my own version of space invaders programmed completely in x86 assembly. Everything, including font and number rendering, is done by hand. High scores between sessions are saved to a file to keep track of progress.

The full source code can be found here.

The main loop of the game looks like the following:

 

Start PROC NEAR
	CALL Init
	CALL Initial_Title
	CALL Instructions
	CALL Level1			;Init level 1
Main_Loop:				;Main game loop
	CALL Draw_FPS			;Draw the FPS (frames per second)
	CALL Get_Ticks
	MOV START_TICKS,EAX		;Ticks with which we start
	CALL Draw_Score
	CALL Render			;Draw the entire scene
	CALL Collisions			;Check if there are any collisions
	MOV AH,01h			;DOS Function: Check for characters in buffer
	INT 16h
	JZ No_Char
IS_Char:
	MOV AH,00			;DOS Function: Obtain character from buffer into AL
	INT 16h
	CMP AL,'q'
	JE End
	CMP AL,'Q'
	JE End
	CMP AH,77
	JE RShip
	CMP AH,75
	JE LShip
	CMP AL,32
	JE Shot
	JMP No_Char
RShip:
	INC SHIP_X
	JMP No_Char
LShip:
	DEC SHIP_X
	JMP No_Char
Shot:
	CALL Create_Ship_Shot

No_Char:
	CALL Update_World		;Update everything that needs to move.
	CALL Check_Limits		;Bound the ship to the limits of the screen.
	CALL Win_Condition		;Check if all the space invaders have been eliminated.
	MOV DELAY_TICKS,1		;Wait 1 hundredth of a second.
	CALL Delay			;Waist CPU cycles to cap the FPS.
	CALL Get_Ticks
	MOV END_TICKS,EAX
	JMP Main_Loop
End:
	CALL Stop 
Start ENDP