⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invaders.bas

📁 单片机 lcd 游戏 小蜜蜂 protus 仿真 源码 图
💻 BAS
📖 第 1 页 / 共 5 页
字号:
                    		Case INVADER_XPOS[INVADER_LOOP] to INVADER_XPOS[INVADER_LOOP] + INVADER_WIDTH
                    			INVADER_ENABLED[INVADER_LOOP] = FALSE
                    			MISSILE_HIT = TRUE							' Indicate the ship's missile has hit a target
                            	MISSILE_SOUND_ENABLE = 1
                                MISSILE_FREQ = 30
                            	Select INVADER_LOOP							' Decide on the score depending on which invader is hit
                            		Case 0 to 5								' Top layer of invaders score 20
                                		LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$42,$61,$51,$49,$46,$00,$3E,$51,$49,$45,$3E,$00]
                                		SCORE = SCORE + 20
                                	Case 6 to 11							' Middle layer of invaders score 10
                                		LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$42,$7F,$40,$00,$00,$3E,$51,$49,$45,$3E,$00]
                            			SCORE = SCORE + 10
                            		Case 12 to 17							' Bottom layer of invaders score 5
                            			LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$3E,$51,$49,$45,$3E,$00, $27,$45,$45,$45,$39,$00]
                                    	SCORE = SCORE + 5
                            	EndSelect
                                Delayms 10
                            	MISSILE_FREQ = 20
                                Delayms 10
                                MISSILE_FREQ = 10                              
                                Delayms 20
                            	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00] ' Erase the INVADER that was hit
                    			
                                
                                Dec INVADERS_ENABLED						' Decrement the hits counter
                    		
                            	If INVADERS_ENABLED = 1 Then				' Increase the speed substantially if only one invader left
                                	INVADER_SPEED = 5
                                Else if INVADERS_ENABLED = 2 Then
                                    INVADER_SPEED = 10						' Increase the speed to fast if there are only two invaders left
                                Else
                                
                                	If INVADER_SPEED >= 3 Then 					' Is the inveders speed greater than 3 ?
                						If INVADERS_ENABLED <= 4 Then			' Are there 4 or less invaders left ?
                							INVADER_SPEED = INVADER_SPEED - 3	' Yes.. So increase their speed by a factor of three
                						Else
                							Dec INVADER_SPEED					' Otherwise.. Increase the speed of the remaining invaders
                						Endif
                					Endif
                            	Endif
                                MISSILE_SOUND_ENABLE = 0					' Disable the missile's sound
                                Return										' And return from the subroutine prematurely
                    	Endselect
                	Endif
            	Endif
            	Inc INVADER_LOOP
        	Until INVADER_LOOP > 17
        Endif
        Return
'----------------------------------------------------------------------------
' Move the ship's missile
' The missile can only be fired if the flag MISSILE_FIRED is false, 
' otherwise there is already a missile in the air
'
MOVE_MISSILE:       
        If MISSILE_FIRED = TRUE Then  								' Don't enter the routine if the ship's missile is already flying       	                       
            If TIME_TO_MOVE_SHIP_MISSILE = TRUE Then				' Is it time to move the ship's missile ?
            	Gosub DRAW_MISSILE
            	Dec MISSILE_YPOS
                MISSILE_FREQ = 63 - MISSILE_YPOS
            Endif	     		       	     
        	If MISSILE_YPOS = 0 OR MISSILE_HIT = TRUE Then 			' Has the missile reached the top of the display or hit something ?
                MISSILE_SOUND_ENABLE = 0
                MISSILE_FIRED = FALSE								' Yes. So signal the missile is finished
        		Gosub CLEAR_MISSILE									' Clear the missile		
        		MISSILE_YPOS = 63 - 9       						' Reset the missile to the bottom of the display
            Endif
        Endif
        Return
'----------------------------------------------------------------------------
' Move the ship right
SHIP_RIGHT:
        If SHIP_XPOS > 117 Then Return
		Gosub DRAW_SHIP
		Inc SHIP_XPOS
		Return
'----------------------------------------------------------------------------
' Move the ship left
SHIP_LEFT:
        If SHIP_XPOS = 0 Then Return
		Gosub DRAW_SHIP
		Dec SHIP_XPOS
		Return 
'----------------------------------------------------------------------------
' Move the INVADERS down a line
' And check whether they have reached the bottom of the screen
' Flag INVADERS_REACHED_BOTTOM will be set if they have
MOVE_INVADERS_DOWN:
		INVADERS_REACHED_BOTTOM = FALSE									' Default to the invaders not at bottom of the screen
        TEMP_LOOP = 18
        Repeat      	
            Dec TEMP_LOOP
            If INVADER_ENABLED[TEMP_LOOP] = TRUE Then
            	LCDWRITE INVADER_YPOS[TEMP_LOOP],INVADER_XPOS[TEMP_LOOP],[$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00]
            	INVADER_YPOS[TEMP_LOOP] = INVADER_YPOS[TEMP_LOOP] + 1
                If INVADER_YPOS[TEMP_LOOP] = 6 Then 					' Have the invaders hit the bases ?
                	Str BASE_ENABLED = 0,0,0,0,0,0,0,0,0 				' Yes.. So disable them all
                    Str BASE_HITS = 5,5,5,5,5,5,5,5,5					' And move their hit counters to past their thresholds
                Endif
                If INVADER_YPOS[TEMP_LOOP] >= 7 Then INVADERS_REACHED_BOTTOM = TRUE ' Set a flag if the invaders have reached the bottom
                LCDWRITE INVADER_YPOS[TEMP_LOOP],INVADER_XPOS[TEMP_LOOP],[$00,$06,$0C,$9C,$EA,$36,$36,$EA,$9C,$0C,$06,$00]                             
            Endif
        Until TEMP_LOOP = 0 
        Inc INVADER_MISSILE_SPEED										' Slow down the invader's missile speed as they approach the bottom of the screen
        If INVADER_SPEED >= 3 Then Dec INVADER_SPEED					' Increase the speed of the invaders
        Return      
'----------------------------------------------------------------------------
' Reset the invaders positions
' Each element of the arrays hold coordinates for the invaders
' INVADER_XPOS holds the X position of the invader
' INVADER_YPOS holds the Y position of the invader
RESET_INVADERS:
        INVADER_LOOP = 0
        Repeat
        	INVADER_ENABLED[INVADER_LOOP] = TRUE						' Set all invaders to active and image 1
        	Select INVADER_LOOP
            	Case 0 to 5
                	INVADER_XPOS[INVADER_LOOP] = (INVADER_LOOP + 1) * 16
            		INVADER_YPOS[INVADER_LOOP] = 1
                Case 6 to 11
                	INVADER_XPOS[INVADER_LOOP] = (INVADER_LOOP - 5) * 16
            		INVADER_YPOS[INVADER_LOOP] = 2
                Case 12 to 17
                	INVADER_XPOS[INVADER_LOOP] = (INVADER_LOOP - 11) * 16
            		INVADER_YPOS[INVADER_LOOP] = 3
            End Select
        	Inc INVADER_LOOP
        Until INVADER_LOOP > 17
        Return
'----------------------------------------------------------------------------
' Move the INVADERS
MOVE_INVADERS:

		'If TIME_TO_MOVE_INVADERS = TRUE Then
         	TIME_TO_MOVE_INVADERS_DOWN = FALSE
            If INVADERS_DIRECTION = FORWARD Then 						' Are the invaders to move forward (right) ?         
                INVADER_LOOP = 0										' Yes.. So reset the invader loop
                Repeat													' Create a loop for all the invaders
                	If INVADER_ENABLED[INVADER_LOOP] = TRUE Then    	' Is this invader enabled ?          	
            			INVADER_XPOS[INVADER_LOOP] = INVADER_XPOS[INVADER_LOOP] + 1 ' Yes.. So increment its XPOS
            			If INVADER_XPOS[INVADER_LOOP] >= INVADER_RIGHT_LIMIT Then 	' Have we hit the right side of the screen ?
                            INVADERS_DIRECTION = BACKWARD				' Yes.. So indicate that we need to go backwards
                            SAUCER_ENABLED = TRUE
                            TIME_TO_MOVE_INVADERS_DOWN = TRUE			' and signal that we need to move the invaders down
         				Endif
         			Endif
         			Inc INVADER_LOOP
        		Until INVADER_LOOP > 17									' Close the loop after all the invader elements have been scanned
         	Else														' Otherwise we go backwards (left)
                INVADER_LOOP = 0										' Reset the invader loop
                Repeat													' Create a loop for all the invaders
         			If INVADER_ENABLED[INVADER_LOOP] = TRUE Then       	' Is this invader enabled ?        		
                		INVADER_XPOS[INVADER_LOOP] = INVADER_XPOS[INVADER_LOOP] - 1 ' Yes.. So decrement its XPOS
                        If INVADER_XPOS[INVADER_LOOP] <= 1 Then    		' Have we hit the left side of the screen ?                   
                            INVADERS_DIRECTION = FORWARD				' Yes.. So indicate that we need to go forwards
                            TIME_TO_MOVE_INVADERS_DOWN = TRUE			' and signal that we need to move the invaders down
                		Endif
        			Endif
        			Inc INVADER_LOOP
        		Until INVADER_LOOP > 17									' Close the loop after all the invader elements have been scanned
        	Endif
        If TIME_TO_MOVE_INVADERS_DOWN = TRUE Then Gosub MOVE_INVADERS_DOWN ' Do we need to move the invaders down ?
        'Endif
        ' Fall through to DRAW_THE_INVADERS
'----------------------------------------------------------------------------
' Draw the invaders
' Draws one of two invader shapes depending on the contents of BIT variable INVADER_CHARACTER
' Each row of invaders is a different character
'INVADER TOP ROW character 1 $00,$18,$4C,$2E,$5B,$2F,$2F,$5B,$2E,$4C,$18,$00
'INVADER TOP ROW character 2 $00,$08,$2C,$5E,$0B,$1F,$1F,$0B,$5E,$2C,$08,$00
                    
'INVADER MIDDLE ROW character 1 $00,$38,$0D,$3E,$5A,$1E,$1E,$5A,$3E,$0D,$38,$00
'INVADER MIDDLE ROW character 2 $00,$06,$48,$7F,$1A,$1E,$1E,$1A,$7F,$48,$06,$00
                    
'INVADER BOTTOM ROW character 1 $00,$4C,$6E,$3A,$1B,$2F,$2F,$1B,$3A,$6E,$4C,$00
'INVADER BOTTOM ROW character 2 $00,$0C,$0E,$3A,$4B,$1F,$1F,$4B,$3A,$0E,$0C,$00
DRAW_INVADERS:
		INVADER_LOOP = 0
        Repeat          
            If INVADER_ENABLED[INVADER_LOOP] = TRUE Then   	         
                If INVADER_CHARACTER = 0 Then
                	INVADER_SOUND_ENABLE = 0
                    INVADER_FREQ = 90             	                                    
                    Select INVADER_LOOP							' Decide on the score depending on which invader is hit
                    	Case 0 to 5								
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$18,$4C,$2E,$5B,$2F,$2F,$5B,$2E,$4C,$18,$00]
                    	Case 6 to 11							
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$38,$0D,$3E,$5A,$1E,$1E,$5A,$3E,$0D,$38,$00]
                    	Case 12 to 17							
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$4C,$6E,$3A,$1B,$2F,$2F,$1B,$3A,$6E,$4C,$00]
             		EndSelect
                              	
                	INVADER_SOUND_ENABLE = 1
                Else
                    INVADER_SOUND_ENABLE = 0
                    INVADER_FREQ = 105
            		Select INVADER_LOOP							' Decide on the score depending on which invader is hit
                    	Case 0 to 5								
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$08,$2C,$5E,$0B,$1F,$1F,$0B,$5E,$2C,$08,$00]
                    	Case 6 to 11							
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$06,$48,$7F,$1A,$1E,$1E,$1A,$7F,$48,$06,$00]
                    	Case 12 to 17							
                        	LCDWRITE INVADER_YPOS[INVADER_LOOP],INVADER_XPOS[INVADER_LOOP],[$00,$0C,$0E,$3A,$4B,$1F,$1F,$4B,$3A,$0E,$0C,$00]
             		EndSelect
                    INVADER_SOUND_ENABLE = 1
                Endif
            Endif 
        	Inc INVADER_LOOP
        Until INVADER_LOOP > 17
        Return  
'----------------------------------------------------------------------------
' Clear the saucer located at the top of the screen
CLEAR_SAUCER:
		Lcdwrite 0,SAUCER_XPOS,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        Return
'----------------------------------------------------------------------------
' Draw the saucer located at the top of the screen
DRAW_SAUCER:	
        Lcdwrite 0,SAUCER_XPOS,[$00,$04,$0E,$3A,$1B,$0F,$1B,$1B,$0F,$1B,$3A,$0E,$04,$00]
        Return
'----------------------------------------------------------------------------
' Move the saucer if it is not already flying
MOVE_SAUCER:
	
		If SAUCER_ENABLED = TRUE Then  								' Don't enter the routine if the saucer is already flying       	
            SAUCER_SOUND_ENABLE = 1									' Enable the saucer's sound channel
            If TIME_TO_MOVE_SAUCER = TRUE Then						' Is it time to move the saucer ?
                Dec SAUCER_XPOS										' Move the saucer accross the screen
                if SAUCER_XPOS // 2 = 0 Then
                	SAUCER_FREQ = 10
                Else
                	SAUCER_FREQ = 12
                Endif
                Gosub DRAW_SAUCER									' Display the saucer
            Endif	     		
        	If SAUCER_XPOS = 0 OR SAUCER_HIT = TRUE Then 			' Has the saucer reached the left of the display or been hit ?      		
                SAUCER_ENABLED = FALSE								' Yes. So signal the sacucer is finished
        		Gosub CLEAR_SAUCER									' Clear the saucer		
        		SAUCER_XPOS = 127 - SAUCER_WIDTH       				' Reset the saucer to the right of the display
        		Print at 0,0,Dec LEVEL, " ",Dec SCORE,at 0,20,LIVES	' And display the score because it was erased by the saucer
            Endif     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -