📄 invaders.bas
字号:
Else
SAUCER_SOUND_ENABLE = 0 ' Disable the saucer's sound channel
Endif
Return
'----------------------------------------------------------------------------
' Determine whether a missile, ship, saucer or base should move
' governed by their individual speed controls
GOVERN_SPEEDS:
' Advance the saucers's tick (governs its speed)
Dec SAUCER_SPEED
TIME_TO_MOVE_SAUCER = FALSE
If SAUCER_SPEED = 0 Then
TIME_TO_MOVE_SAUCER = TRUE
SAUCER_SPEED = 3
Endif
' Advance the ship's tick (governs its speed)
Dec SHIP_SPEED
TIME_TO_MOVE_BASE = FALSE
If SHIP_SPEED = 0 Then
TIME_TO_MOVE_BASE = TRUE
SHIP_SPEED = 3
Endif
' Advance the invader's missile tick (governs its speed)
Inc INVADER_MISSILE_TICK
TIME_TO_MOVE_INV_MISSILE = FALSE
If INVADER_MISSILE_TICK >= INVADER_MISSILE_SPEED Then ' Set the speed for the invader's missile
TIME_TO_MOVE_INV_MISSILE = TRUE
INVADER_MISSILE_TICK = 0
Endif
' Advance the invader's second missile tick (governs its speed)
Inc INVADER_MISSILE2_TICK
TIME_TO_MOVE_INV_MISSILE2 = FALSE
If INVADER_MISSILE2_TICK >= INVADER_MISSILE2_SPEED Then ' Set the speed for the invader's second missile
TIME_TO_MOVE_INV_MISSILE2 = TRUE
INVADER_MISSILE2_TICK = 0
Endif
' Advance the ship's missile tick (governs its speed)
Dec SHIP_MISSILE_TICK
TIME_TO_MOVE_SHIP_MISSILE = FALSE
If SHIP_MISSILE_TICK = 0 Then ' Set the speed for the ship's missile
TIME_TO_MOVE_SHIP_MISSILE = TRUE
SHIP_MISSILE_TICK = 2
Endif
Return
'----------------------------------------------------------------------------
' Display the spash screen
' The subroutine re-uses some of the variables
' TEMP_LOOP, LEVEL, and INVADER_LOOP
DISPLAY_SPASH_SCREEN:
Cls
SCORE = 0
TEMP_LOOP = 0
Repeat
INVADER_LOOP = 0
Repeat
LEVEL = CREAD INVADER_SPLASH_SCREEN + SCORE
LcdWrite TEMP_LOOP,INVADER_LOOP,[LEVEL]
Inc SCORE
Inc INVADER_LOOP
Until INVADER_LOOP > 127
Inc TEMP_LOOP
Until TEMP_LOOP > 7
Return
'----------------------------------------------------------------------------
MAIN_PROGRAM_LOOP:
Gosub DISPLAY_SPASH_SCREEN
Delayms 1000
Print at 4,1,"PRESS FIRE TO START"
While FIRE_BUTTON = 1 : Wend
While FIRE_BUTTON = 0 : Wend
Delayms 50
Cls
Print at 0,7,"Scoring"
Lcdwrite 2,0,[$00,$04,$0E,$3A,$1B,$0F,$1B,$1B,$0F,$1B,$3A,$0E,$04,$00]
Print at 2,2," = 100+ Points"
LCDWRITE 3,0,[$00,$18,$4C,$2E,$5B,$2F,$2F,$5B,$2E,$4C,$18,$00]
Print at 3,2," = 20 Points"
LCDWRITE 4,0,[$00,$38,$0D,$3E,$5A,$1E,$1E,$5A,$3E,$0D,$38,$00]
Print at 4,2," = 10 Points"
LCDWRITE 5,0,[$00,$4C,$6E,$3A,$1B,$2F,$2F,$1B,$3A,$6E,$4C,$00]
Print at 5,2," = 5 Points"
Print at 7,1,"PRESS FIRE TO START"
While FIRE_BUTTON = 1 : Wend
While FIRE_BUTTON = 0 : Wend
Delayms 50
LEVEL = 0 ' Start at level 0
LIVES = "3" ' Set the initial lives counter to 3
SHIP_SPEED = 3
SCORE = 0
SHIP_XPOS = 64
SAUCER_SPEED = 7 ' Speed of the saucer
INVADER_SPEED = 70 ' The initial speed of the invaders
DEFAULT_INVADER_SPEED = INVADER_SPEED
TEMP_LOOP = 0
Repeat
BASE_ENABLED[TEMP_LOOP] = TRUE
BASE_HITS[TEMP_LOOP] = 0
Inc TEMP_LOOP
Until TEMP_LOOP > 8
INTERRUPT_COUNTER1 = 0
NOTE_STATUS = 0
INVADER_SOUND_COUNTER = 0
MISSILE_SOUND_COUNTER = 0
SAUCER_SOUND_COUNTER = 0
INVADER_SOUND_DURATION_COUNTER = 0
INVADER_SOUND_ENABLE = 1 ' Enable the Invaders sound channel
INVADER_SOUND_DURATION = 20 ' Set the note duration to 20
' Main program loop starts here
' Jump to this location to implement a new sheet of invaders
NEW_SHEET:
Inc LEVEL
Cls
Gosub UPDATE_BASES ' Draw the bases (or what's left of them)
SHIP_HIT = FALSE ' Default to no hit on the ship by a missile
SAUCER_ENABLED = FALSE ' Disable the saucer
SAUCER_XPOS = 127 - SAUCER_WIDTH ' Position saucer at top tight of the screen
MISSILE_XPOS = 0
MISSILE_YPOS = 63 - 9
INVADER_MISSILE_XPOS = 0
INVADER_MISSILE_YPOS = 0
MISSILE_STATUS = 0
INVADER_MISSILE2_YPOS = 0 ' Y position of Invader's second MISSILE
INVADER_MISSILE2_XPOS = 0 ' X position of Invader's second MISSILE
TIME_TO_MOVE_INV_MISSILE2 = FALSE ' Indicate time to move the invader's second missile
INVADER_MISSILE2_FIRED = FALSE ' TRUE if Invader's second MISSILE in the air
INVADER_MISSILE2_HIT = FALSE ' Default to not hit anything
TIME_TO_MOVE_BASE = FALSE
Gosub CLEAR_INVADER_MISSILE
Gosub CLEAR_MISSILE
Gosub DRAW_SHIP ' Draw the initial ship
Dec DEFAULT_INVADER_SPEED ' Speed up the invaders every new sheet
INVADER_SPEED = DEFAULT_INVADER_SPEED ' Transfer the speed into the actual speed altering variable
Clear INVADER_TICK
Clear INVADER_MISSILE_TICK
Clear INVADER_MISSILE2_TICK
SHIP_MISSILE_TICK = 2
INVADERS_REACHED_BOTTOM = FALSE ' Default to the invaders not at the bottom of the screen
INVADER_CHARACTER = 0
INVADER_MISSILE_SPEED = 5 ' Default speed of the invader's missile
INVADER_MISSILE2_SPEED = 4
INVADERS_DIRECTION = FORWARD ' Default to the invaders moving right
INVADERS_ENABLED = 18 ' All 18 invaders are enabled
Gosub RESET_INVADERS ' Reset all the invaders positions
Gosub DRAW_INVADERS ' Place all the invaders on the screen
Print at 0,0,Dec LEVEL, " ",Dec SCORE,at 0,20,LIVES
While 1 = 1
RANDOM_VALUE = RANDOM
RANDOM_VALUE = RANDOM_VALUE & %00111000
Inc INVADER_TICK
TIME_TO_MOVE_INVADERS = FALSE
If INVADER_TICK > INVADER_SPEED Then
INVADER_TICK = 0
'TIME_TO_MOVE_INVADERS = TRUE
'If TIME_TO_MOVE_INVADERS = TRUE Then
Gosub MOVE_INVADERS
Gosub MOVE_INVADERS
INVADER_CHARACTER = ~INVADER_CHARACTER ' Use a new invader character
If INVADERS_REACHED_BOTTOM = TRUE Then GAME_OVER
Endif
Gosub MOVE_SAUCER ' Move the flying saucer (if required)
Gosub GOVERN_SPEEDS ' Check whether a piece should be moving
If L_BUTTON = 0 Then Gosub SHIP_LEFT ' Move ship left if LEFT button pressed
If R_BUTTON = 0 Then Gosub SHIP_RIGHT ' Move ship right if RIGHT button pressed
If FIRE_BUTTON = 0 Then If MISSILE_FIRED = FALSE Then ' Has the FIRE button been pressed and the ship's missile not already flying ?
SEED INVADER_SOUND_COUNTER
MISSILE_FIRED = TRUE ' Yes.. So signal we need the ship's missile FIRED
MISSILE_XPOS = SHIP_XPOS + 4 ' Place the ship's missile's xpos at the middle of the ship's shape
MISSILE_SOUND_ENABLE = 1 ' Enable the missile's sound
Endif
Gosub MOVE_MISSILE ' Move the ship's missile if OK to do so
Gosub CHECK_FOR_MISSILE_HIT ' Check if the ship's missile has hit anything
If MISSILE_HIT = TRUE OR SAUCER_HIT = TRUE Then
If BASE_HIT = FALSE Then
'Print at 0,19,Dec2 INVADERS_ENABLED," " ' Display the INVADER hits count
Print at 0,0,Dec LEVEL, " ",Dec SCORE,at 0,20,LIVES
Endif
Endif
If INVADER_CHARACTER = 1 Then
Gosub FIRE_INVADER_MISSILE ' Fire an invader missile is possible
Endif
Gosub MOVE_INVADER_MISSILE ' Move the invader's missile (if fired)
Gosub CHECK_FOR_INVADER_MISSILE_HIT ' Check if the invader's missile has hit anything
If INVADERS_ENABLED = 0 Then ' Have all the invaders been destroyed ?
INVADERS_ENABLED = 18 ' Yes.. So enable them all again
If INVADER_SPEED >= 3 Then Dec INVADER_SPEED ' Increase the speed of the invaders
Goto NEW_SHEET ' and start a new sheet
Endif
If LEVEL > 10 Then ' Add a second invader missile after level 10
If INVADER_CHARACTER = 0 then
Gosub FIRE_INVADER_MISSILE2 ' Fire an invader missile is possible
Endif
Gosub MOVE_INVADER_MISSILE2 ' Move the invader's missile (if fired)
Gosub CHECK_FOR_INVADER_MISSILE2_HIT ' Check if the invader's missile has hit anything
Endif
If SHIP_HIT = TRUE Then ' Has the ship been hit ?
SHIP_HIT = FALSE
SAUCER_SOUND_ENABLE = 1 ' Yes. So enable SAUCER sound channel
MISSILE_SOUND_ENABLE = 1 ' Enable MISSILE sound channel
MISSILE_FREQ = 70 ' Set MISSILE channel frequency to 70
SAUCER_FREQ = 90 ' Set SAUCER channel frequency to 90
LCDWRITE 7,SHIP_XPOS,[$10,$24,$AC,$F8,$F0,$E0,$F0,$F8,$AC,$24,$10] ' Draw first part of ship exploding
Delayms 40 ' Leave the graphic on the screen for 40ms
SAUCER_FREQ = 100 ' Increase the SAUCER channel's frequency
MISSILE_FREQ = 120 ' Increase the MISSILE channel's frequency
LCDWRITE 7,SHIP_XPOS,[$00,$20,$28,$F0,$A8,$C0,$E0,$F0,$28,$04,$00] ' Draw second part of ship exploding
Delayms 40 ' Leave the graphic on the screen for 40ms
SAUCER_FREQ = 150 ' Increase the SAUCER channel's frequency
MISSILE_FREQ = 135 ' Increase the MISSILE channel's frequency
LCDWRITE 7,SHIP_XPOS,[$00,$00,$30,$60,$80,$C0,$60,$30,$00,$00,$00] ' Draw third part of ship exploding
Delayms 100
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -