📄 frmmvade.frm
字号:
giKilled = giKilled + 1
giScore = giScore + 5
'Speed up last invaders
If (giNumInvaders - giKilled) < 4 Then iDx = iDx + iDx \ 2
Else
'Remove the invader
SprDeactivateSprite i
giKilled = giKilled + 1
giScore = giScore + 5
'Speed up last invaders
If (giNumInvaders - giKilled) < 4 Then iDx = iDx + iDx \ 2
End If
'End of level/game test here
If giKilled = giNumInvaders Then
iDx = GamePrefs.iISpeed '1
giCurLevel = giCurLevel + 1
If giCurLevel > giNumLevels Then
iPaused = 50
iGameOver = True
Exit Sub
Else
i = iInitLevel(giCurLevel)
Exit Sub
End If
End If
End If
'Find an explosion
For j = FIRST_EXPLOSION_ID To LAST_EXPLOSION_ID
If Not gtSpr(j).iActive Then
'Activate it
SprActivateSprite j, gtSpr(i).lX + (gtSpr(i).lW \ 2) - (gtSpr(j).lW \ 2), gtSpr(i).lY
'Set its countdown, 5 frames @ 2 cycles/frame
gtSpr(j).iUsr1 = 5
Exit For
End If
Next j
End If
Next h
'Check if a players bullet is off screen & remove if so
For h = FIRST_PLAYER_BULLET_ID To LAST_PLAYER_BULLET_ID
If gtSpr(h).iActive Then
If gtSpr(h).lY < 0 Then SprDeactivateSprite h
End If
Next h
'Check if an invaders bullet has hit the player
If giShield = 0 Then
i = iSprCollisionRange(PLAYER_ID, FIRST_INVADER_BULLET_ID, LAST_INVADER_BULLET_ID)
If i Then
'Adjust to actual sprite ID
i = i - 1
'Remove bullet
SprDeactivateSprite i
'Play a 'Oh shit you killed me' sound!
PlayHitMe
'Find an explosion
For j = FIRST_EXPLOSION_ID To LAST_EXPLOSION_ID
If Not gtSpr(j).iActive Then
'Activate it
SprActivateSprite j, gtSpr(PLAYER_ID).lX + (gtSpr(PLAYER_ID).lW \ 2) - (gtSpr(PLAYER_ID).lW \ 2), gtSpr(PLAYER_ID).lY
'Set its countdown, 5 frames @ 2 cycles/frame
gtSpr(j).iUsr1 = 5
Exit For
End If
Next j
'If thats all lives gone, we finish the game
giLives = giLives - 1
If giLives = 0 Then
SprDeactivateSprite PLAYER_ID
iGameOver = True
iPaused = 50
Exit Sub
End If
'Enable the shield for approx 2 seconds
giShield = 2000 \ tmrGameLoop.Interval
SprActivateSprite SHIELD_ID, gtSpr(PLAYER_ID).lX, gtSpr(PLAYER_ID).lY
'Remove any power-up abilities
giFireRate = 10
giFirePower = FIRE_SINGLE
'Pause gameplay
iPaused = 50
End If
Else
giShield = giShield - 1
'Remove shield sprite when shield has expired
If giShield = 0 Then SprDeactivateSprite SHIELD_ID
End If
'Check if an invaders bullet has hit a barrier
For h = FIRST_BARRIER_ID To LAST_BARRIER_ID
i = iSprCollisionRange(h, FIRST_INVADER_BULLET_ID, LAST_INVADER_BULLET_ID)
If i Then
'Adjust to actual sprite ID
i = i - 1
'Remove bullet
SprDeactivateSprite i
'Find an explosion
For j = FIRST_EXPLOSION_ID To LAST_EXPLOSION_ID
If Not gtSpr(j).iActive Then
'Activate it
SprActivateSprite j, gtSpr(i).lX + (gtSpr(i).lW \ 2) - (gtSpr(j).lW \ 2), gtSpr(i).lY
'Set its countdown, 5 frames @ 2 cycles/frame
gtSpr(j).iUsr1 = 5
Exit For
End If
Next j
'Explode the barrier & remove when gone
If gtSpr(h).iFrame = gtSpr(h).iLastFrame Then
SprDeactivateSprite h
Else
SprAnimNextFrame h
End If
End If
Next h
'Check if a power-up has hit the player
i = iSprCollisionRange(PLAYER_ID, FIRST_POWER_UP_ID, LAST_POWER_UP_ID)
If i Then
'Adjust to actual sprite ID
i = i - 1
'Remove the power-up
SprDeactivateSprite i
Select Case gtSpr(i).iUsr1
Case 1 'Extra Life
giLives = giLives + 1
Case 2 '5 Seconds shield
giShield = 5000 \ frmMVaders.tmrGameLoop.Interval
If Not gtSpr(SHIELD_ID).iActive Then SprActivateSprite SHIELD_ID, gtSpr(PLAYER_ID).lX, gtSpr(PLAYER_ID).lY
Case 3 'Rapid Fire
giFireRate = 5
Case 4 'Twin Cannon
giFirePower = FIRE_DOUBLE
Case 5 'Restore Bases
iStep = GAME_WIDTH \ 3
iStart = (iStep - 60) \ 2
For i = FIRST_BARRIER_ID To LAST_BARRIER_ID
SprDeactivateSprite i
SprActivateSprite i, iStart, GAME_HEIGHT - 70
SprAnimSetFrame i, gtSprites(INIT_BARRIER_ID).iFirst
iStart = iStart + iStep
Next i
Case 6 'Extra points
giScore = giScore + 100
End Select
End If
'Check if a players bullet has hit the bonus ship
i = iSprCollisionRange(BONUS_SHIP_ID, FIRST_PLAYER_BULLET_ID, LAST_PLAYER_BULLET_ID)
If i Then
'Adjust to actual sprite ID
i = i - 1
'Remove the bonus ship & bullet
SprDeactivateSprite i
SprDeactivateSprite BONUS_SHIP_ID
'Bump score
giScore = giScore + giCurLevel * 10
'Reset bonus ship timer
giBonusTmr = 140
'Sound FX
PlayHitMe
'Find an explosion
For j = FIRST_EXPLOSION_ID To LAST_EXPLOSION_ID
If Not gtSpr(j).iActive Then
'Activate it
SprActivateSprite j, gtSpr(BONUS_SHIP_ID).lX + (gtSpr(BONUS_SHIP_ID).lW \ 2) - (gtSpr(j).lW \ 2), gtSpr(BONUS_SHIP_ID).lY
'Set its countdown, 5 frames @ 2 cycles/frame
gtSpr(j).iUsr1 = 5
Exit For
End If
Next j
End If
'Check if an explosion has run its course
For j = FIRST_EXPLOSION_ID To LAST_EXPLOSION_ID
If gtSpr(j).iActive Then
'Dec the countdown timer
gtSpr(j).iUsr1 = gtSpr(j).iUsr1 - 1
'If countdown expired then deactivate the sprite
If gtSpr(j).iUsr1 = 0 Then SprDeactivateSprite j
End If
Next j
'Move players sprite if key pressed
If giKeyStatus And KEY_CUR_LEFT_FLAG Then
If gtSpr(PLAYER_ID).lX - GamePrefs.iPSpeed > 0 Then
SprMoveSpriteRel PLAYER_ID, -1 * GamePrefs.iPSpeed, 0
Else
SprMoveSpriteRel PLAYER_ID, -1 * gtSpr(PLAYER_ID).lX, 0
End If
End If
If giKeyStatus And KEY_CUR_RIGHT_FLAG Then
If (gtSpr(PLAYER_ID).lX + gtSpr(PLAYER_ID).lW + GamePrefs.iPSpeed) < GAME_WIDTH Then
SprMoveSpriteRel PLAYER_ID, GamePrefs.iPSpeed, 0
Else
SprMoveSpriteRel PLAYER_ID, GAME_WIDTH - gtSpr(PLAYER_ID).lX - gtSpr(PLAYER_ID).lW, 0
End If
End If
'Move shield if active
If giShield Then SprMoveSprite SHIELD_ID, gtSpr(PLAYER_ID).lX, gtSpr(PLAYER_ID).lY
'Move players bullets if active
For h = FIRST_PLAYER_BULLET_ID To LAST_PLAYER_BULLET_ID
If gtSpr(h).iActive Then SprMoveSpriteRel h, 0, -1 * GamePrefs.iPBSpeed
Next h
'Move invaders bullets
For h = FIRST_INVADER_BULLET_ID To LAST_INVADER_BULLET_ID
If gtSpr(h).iActive Then SprMoveSpriteRel h, 0, GamePrefs.iIBSpeed
If gtSpr(h).lY > GAME_HEIGHT Then SprDeactivateSprite h
Next h
'Move power-ups
For h = FIRST_POWER_UP_ID To LAST_POWER_UP_ID
If gtSpr(h).iActive Then SprMoveSpriteRel h, 0, 5
If gtSpr(h).lY > GAME_HEIGHT Then SprDeactivateSprite h
Next h
'Move bonus ship if present, else decrease the counter
If gtSpr(BONUS_SHIP_ID).iActive Then
SprMoveSpriteRel BONUS_SHIP_ID, 7, 0
If gtSpr(BONUS_SHIP_ID).lX > GAME_WIDTH Then
gtSpr(BONUS_SHIP_ID).iActive = False
giBonusTmr = 140
End If
Else
giBonusTmr = giBonusTmr - 1
If giBonusTmr < 0 Then SprActivateSprite BONUS_SHIP_ID, 0, 1
End If
'Fire a players bullet if allowed, key pressed and bullet is free
If iFireDelay = 0 Then
If giKeyStatus And KEY_FIRE_FLAG Then
Select Case giFirePower
Case FIRE_SINGLE
For h = FIRST_PLAYER_BULLET_ID To LAST_PLAYER_BULLET_ID
If Not gtSpr(h).iActive Then
SprActivateSprite h, gtSpr(PLAYER_ID).lX + (gtSpr(PLAYER_ID).lW \ 2) - (gtSpr(h).lW \ 2), GAME_HEIGHT - gtSpr(PLAYER_ID).lH
iFireDelay = giFireRate
Exit For
End If
Next h
Case FIRE_DOUBLE
For h = FIRST_PLAYER_BULLET_ID To LAST_PLAYER_BULLET_ID
If Not gtSpr(h).iActive Then
SprActivateSprite h, gtSpr(PLAYER_ID).lX, GAME_HEIGHT - gtSpr(PLAYER_ID).lH
Exit For
End If
Next h
For h = FIRST_PLAYER_BULLET_ID To LAST_PLAYER_BULLET_ID
If Not gtSpr(h).iActive Then
SprActivateSprite h, gtSpr(PLAYER_ID).lX + gtSpr(PLAYER_ID).lW - gtSpr(h).lW, GAME_HEIGHT - gtSpr(PLAYER_ID).lH
iFireDelay = giFireRate
Exit For
End If
Next h
End Select
End If
Else
iFireDelay = iFireDelay - 1
End If
'Move invaders & do random shooting
If iDy Then
'Move invaders down, they are at the edge of the screen!
iYMax = -1
For i = FIRST_INVADER_ID To LAST_INVADER_ID
If gtSpr(i).iActive Then
gtSpr(i).lY = gtSpr(i).lY + iDy
If (gtSpr(i).lY + gtSpr(i).lH) > iYMax Then iYMax = gtSpr(i).lY + gtSpr(i).lH
End If
Next i
iDy = 0
Else
'Normal moving
iXMin = 9999
iXMax = -1
For i = FIRST_INVADER_ID To LAST_INVADER_ID
If gtSpr(i).iActive Then
gtSpr(i).lX = gtSpr(i).lX + iDx '* GamePrefs.iISpeed
If (gtSpr(i).lX + gtSpr(i).lW) > iXMax Then iXMax = gtSpr(i).lX + gtSpr(i).lW
If gtSpr(i).lX < iXMin Then iXMin = gtSpr(i).lX
'Random invader shooting
If Rnd > GamePrefs.fIBFreq Then
For j = FIRST_INVADER_BULLET_ID To LAST_INVADER_BULLET_ID
If gtSpr(j).iActive = False Then
SprActivateSprite j, gtSpr(i).lX, gtSpr(i).lY
SprActivateSprite j, gtSpr(i).lX + (gtSpr(i).lW \ 2) - (gtSpr(j).lW \ 2), gtSpr(i).lY + gtSpr(i).lH
Exit For
End If
Next j
End If
End If
Next i
'Test if we need to move down on next frame, sets iDy if so
If (iXMin <= 0) Or (iXMax >= (GAME_WIDTH - GamePrefs.iISpeed)) Then
iDx = iDx * -1
iDy = GamePrefs.iIDrop
'Debug.Print iXMin, iXMax
End If
End If
'End game if vaders have landed
If iYMax >= gtSpr(PLAYER_ID).lY Then
l = sndPlaySound(ByVal CStr(App.Path & "\landed.wav"), SND_ASYNC)
iPaused = 50
iGameOver = True
Exit Sub
End If
'Draw sprites
SprDraw
'Update the display
SprShowPlayDC frmMVaders.hdc, miTX, miTy
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -