📄 invaders.bas
字号:
Else
BASE_ENABLED#6 = FALSE ' Disable the base element
Endif
Case 96 to 101 ' Has the missile XPOS hit BASE 3, ELEMENT 7
If BASE_HITS#7 < 5 AND BASE_ENABLED#7 = TRUE Then ' Is the base element enabled, and has had less than 5 hits ?
Inc BASE_HITS#7 ' Increment the amount of hits the base element has sustained
BASE_HIT = TRUE ' Indicate a missile has hit a target
Else
BASE_ENABLED#7 = FALSE ' Disable the base element
Endif
Case 102 to 107 ' Has the missile XPOS hit BASE 3, ELEMENT 8
If BASE_HITS#8 < 5 AND BASE_ENABLED#8 = TRUE Then ' Is the base element enabled, and has had less than 5 hits ?
Inc BASE_HITS#8 ' Increment the amount of hits the base element has sustained
BASE_HIT = TRUE ' Indicate a missile has hit a target
Else
BASE_ENABLED#8 = FALSE ' Disable the base element
Endif
End Select
If BASE_HIT = TRUE Then Gosub UPDATE_BASES ' Update the base shapes if a hit was detected
Return
'----------------------------------------------------------------------------
' Move the invader's missile
' The missile can only be fired if the flag INVADER_MISSILE_FIRED is false,
' otherwise there is already a missile in the air
MOVE_INVADER_MISSILE:
If INVADER_MISSILE_FIRED = TRUE Then ' Don't enter the routine if the invader's missile is already flying
If TIME_TO_MOVE_INV_MISSILE = TRUE Then ' Is it time to move the invader's missile ?
Gosub DRAW_INVADER_MISSILE
Inc INVADER_MISSILE_YPOS
Endif
If INVADER_MISSILE_YPOS >= 63 OR INVADER_MISSILE_HIT = TRUE Then ' Has the invader's missile reached the bottom of the display or hit something ?
INVADER_MISSILE_FIRED = FALSE ' Yes. So signal the invader's missile is finished
Gosub CLEAR_INVADER_MISSILE ' Clear the invader's missile
INVADER_MISSILE_HIT = FALSE
Endif
Endif
Return
'----------------------------------------------------------------------------
' Move the invader's second missile
' The missile can only be fired if the flag INVADER_MISSILE2_FIRED is false,
' otherwise there is already a missile in the air
MOVE_INVADER_MISSILE2:
If INVADER_MISSILE2_FIRED = TRUE Then ' Don't enter the routine if the invader's missile is already flying
If TIME_TO_MOVE_INV_MISSILE2 = TRUE Then ' Is it time to move the invader's missile ?
Gosub DRAW_INVADER_MISSILE2
Inc INVADER_MISSILE2_YPOS
Endif
If INVADER_MISSILE2_YPOS >= 63 OR INVADER_MISSILE2_HIT = TRUE Then ' Has the invader's missile reached the bottom of the display or hit something ?
INVADER_MISSILE2_FIRED = FALSE ' Yes. So signal the invader's missile is finished
Gosub CLEAR_INVADER_MISSILE2 ' Clear the invader's missile
INVADER_MISSILE2_HIT = FALSE
Endif
Endif
Return
'----------------------------------------------------------------------------
' Fire an invader missile if possible
' The logic is: -
' Make sure a missile is not already in flight.
' Scan all the invaders...
' If the invader is enabled, then check if it is over the ship.
' If it is then enable a missile to be fired.
FIRE_INVADER_MISSILE:
If INVADER_MISSILE_FIRED = FALSE Then ' Is it OK to fire an invader missile ?
INVADER_LOOP = 0
Repeat ' Create a loop for all the invaders
If INVADER_ENABLED[INVADER_LOOP] = TRUE Then ' Is this invader enabled ?
Select INVADER_XPOS[INVADER_LOOP] + 5
Case SHIP_XPOS to SHIP_XPOS + 8 ' Is the invader over the ship ?
INVADER_MISSILE_FIRED = TRUE ' Signal that an invader's missile is in the air
INVADER_MISSILE_XPOS = INVADER_XPOS[INVADER_LOOP] + 5 ' Move missile XPOS to the middle of the invader
INVADER_MISSILE_YPOS = (INVADER_YPOS[INVADER_LOOP] * 8) + 8 ' Move missile YPOS to below the invader
End Select
Endif
Inc INVADER_LOOP
Until INVADER_LOOP > 17 ' Close the loop when all invaders have been scanned
Endif
Return
'----------------------------------------------------------------------------
' Fire an invader second missile if possible
' The logic is: -
' Make sure a missile is not already in flight.
' Scan all the invaders...
' If the invader is enabled, then check if it is over the ship.
' If it is then enable a missile to be fired.
Dim RANDOM_VALUE as Byte
FIRE_INVADER_MISSILE2:
If INVADER_MISSILE2_FIRED = FALSE Then ' Is it OK to fire an invader second missile ?
'If INVADER_MISSILE_XPOS < SHIP_XPOS Then
Select SHIP_XPOS
Case > INVADER_MISSILE_XPOS + RANDOM_VALUE , < INVADER_MISSILE_XPOS - RANDOM_VALUE
INVADER_LOOP = 0
Repeat ' Create a loop for all the invaders
If INVADER_ENABLED[INVADER_LOOP] = TRUE Then ' Is this invader enabled ?
Select INVADER_XPOS[INVADER_LOOP] + 5
Case SHIP_XPOS to SHIP_XPOS + 8 ' Is the invader over the ship ?
INVADER_MISSILE2_FIRED = TRUE ' Signal that an invader's missile is in the air
INVADER_MISSILE2_XPOS = INVADER_XPOS[INVADER_LOOP] + 5 ' Move missile XPOS to the middle of the invader
INVADER_MISSILE2_YPOS = (INVADER_YPOS[INVADER_LOOP] * 8) + 8 ' Move missile YPOS to below the invader
End Select
Endif
Inc INVADER_LOOP
Until INVADER_LOOP > 17 ' Close the loop when all invaders have been scanned
EndSelect
Endif
Return
'----------------------------------------------------------------------------
' Check if the invader's missile has hit something
' Returns with INVADER_MISSILE_HIT set if the invader's missile has hit something
CHECK_FOR_INVADER_MISSILE_HIT:
INVADER_MISSILE_HIT = FALSE ' Default to not hit
If INVADER_MISSILE_FIRED = TRUE Then ' First make sure that a missile is actually launched
' Check if the invader's missile has hit a BASE
If INVADER_MISSILE_YPOS >= 45 Then
BASE_XPOS_TEST = INVADER_MISSILE_XPOS ' Transfer the invader's missile XPOS for testing
Gosub CHECK_BASE_HIT ' Check if a base was hit
If BASE_HIT = TRUE Then
INVADER_MISSILE_HIT = TRUE ' Transfer the hit detector into the invader's missile detector
Return ' Return from the subroutine prematurely
Endif
Endif
' Check if the invader's missile has hit the ship
If INVADER_MISSILE_YPOS >= 56 Then
Select INVADER_MISSILE_XPOS
Case SHIP_XPOS - 1 To SHIP_XPOS + SHIP_WIDTH
Gosub DRAW_SHIP
INVADER_MISSILE_HIT = TRUE ' Indicate the invader's missile has hit something
SHIP_HIT = TRUE ' Indicate that it is the ship that has been hit
End Select
Endif
Endif
Return
'----------------------------------------------------------------------------
' Check if the invader's second missile has hit something
' Returns with INVADER_MISSILE2_HIT set if the invader's missile has hit something
CHECK_FOR_INVADER_MISSILE2_HIT:
INVADER_MISSILE2_HIT = FALSE ' Default to not hit
If INVADER_MISSILE2_FIRED = TRUE Then ' First make sure that a second missile is actually launched
' Check if the invader's second missile has hit a BASE
If INVADER_MISSILE2_YPOS >= 45 Then
BASE_XPOS_TEST = INVADER_MISSILE2_XPOS ' Transfer the invader's second missile XPOS for testing
Gosub CHECK_BASE_HIT ' Check if a base was hit
If BASE_HIT = TRUE Then
INVADER_MISSILE2_HIT = TRUE ' Transfer the hit detector into the invader's second missile detector
Return ' Return from the subroutine prematurely
Endif
Endif
' Check if the invader's missile has hit the ship
If INVADER_MISSILE2_YPOS >= 56 Then
Select INVADER_MISSILE2_XPOS
Case SHIP_XPOS - 1 To SHIP_XPOS + SHIP_WIDTH
Gosub DRAW_SHIP
INVADER_MISSILE2_HIT = TRUE ' Indicate the invader's second missile has hit something
SHIP_HIT = TRUE ' Indicate that it is the ship that has been hit
End Select
Endif
Endif
Return
'----------------------------------------------------------------------------
' Draw or clear the Ship's missile
CLEAR_MISSILE:
UnPlot MISSILE_YPOS, MISSILE_XPOS
UnPlot MISSILE_YPOS, MISSILE_XPOS + 1
UnPlot MISSILE_YPOS + 1, MISSILE_XPOS
UnPlot MISSILE_YPOS + 1, MISSILE_XPOS + 1
UnPlot MISSILE_YPOS + 2, MISSILE_XPOS
UnPlot MISSILE_YPOS + 2, MISSILE_XPOS + 1
Return
DRAW_MISSILE:
Plot MISSILE_YPOS, MISSILE_XPOS
Plot MISSILE_YPOS, MISSILE_XPOS + 1
Plot MISSILE_YPOS + 1, MISSILE_XPOS
Plot MISSILE_YPOS + 1, MISSILE_XPOS + 1
UnPlot MISSILE_YPOS + 2, MISSILE_XPOS
UnPlot MISSILE_YPOS + 2, MISSILE_XPOS + 1
Return
'----------------------------------------------------------------------------
' Draw the ship
DRAW_SHIP:
LCDWRITE 7,SHIP_XPOS,[$00,$E0,$F0,$F0,$F8,$FC,$F8,$F0,$F0,$E0,$00]
Return
'----------------------------------------------------------------------------
' Check if the ship's missile has hit something
' Returns with MISSILE_HIT set if the ship's missile has hit something
CHECK_FOR_MISSILE_HIT:
MISSILE_HIT = FALSE ' Default to not hit
SAUCER_HIT = FALSE ' Default to saucer not hit
If MISSILE_FIRED = TRUE Then ' First make sure a missile is actually launched
' Check if the ship's missile has hit a BASE
If MISSILE_YPOS = 53 Then
BASE_XPOS_TEST = MISSILE_XPOS ' Transfer the ship's missile XPOS for testing
Gosub CHECK_BASE_HIT ' Check if a base was hit
If BASE_HIT = TRUE Then
MISSILE_SOUND_ENABLE = 0 ' Disable the missile's sound
MISSILE_HIT = TRUE ' Transfer the hit detector into the missile detector
Return ' And return from the subroutine prematurely
Endif
Endif
' Check if the ship's missile has hit an invader's missile
If MISSILE_XPOS = INVADER_MISSILE_XPOS Then If MISSILE_YPOS = INVADER_MISSILE_YPOS Then
MISSILE_SOUND_ENABLE = 0 ' Disable the missile's sound
MISSILE_HIT = TRUE ' Indicate the ship's missile has hit a target
INVADER_MISSILE_HIT = TRUE ' Indicate the invader's missile has also been hit
Inc SCORE ' Increment the score by one
Return ' And return from the subroutine prematurely
Endif
' Check if the ship's missile has hit the saucer
If SAUCER_ENABLED = TRUE Then
If MISSILE_YPOS < 7 Then
Select MISSILE_XPOS
Case SAUCER_XPOS To SAUCER_XPOS + SAUCER_WIDTH
MISSILE_HIT = TRUE ' Indicate the ship's missile has hit a target
SAUCER_HIT = TRUE
SAUCER_SOUND_ENABLE = TRUE
SAUCER_FREQ = 30
LCDWRITE 0,SAUCER_XPOS,[$8C,$C5,$6B,$36,$0C,$20,$68,$CC,$96,$33,$69,$CC,$86,$02]
Delayms 10
LCDWRITE 0,SAUCER_XPOS,[$7F,$08,$08,$08,$7F,$00,$00,$41,$7F,$41,$00,$00,$01,$01,$7F,$01,$01] ' Display text HIT
SAUCER_FREQ = 20
Delayms 5
SAUCER_FREQ = 10
Delayms 10
SCORE = SCORE + (100 + SAUCER_XPOS) ' Add 100 + xpos to the score for hitting the saucer
SAUCER_SOUND_ENABLE = FALSE
Return
EndSelect
Endif
Endif
' Check if the ship's missile has hit an INVADER
INVADER_LOOP = 0
Repeat
If INVADER_ENABLED[INVADER_LOOP] = TRUE Then ' Only check if the invader is enabled
If INVADER_YPOS[INVADER_LOOP] = MISSILE_YPOS / 8 Then
Select MISSILE_XPOS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -