'Double-clickingthemousefiresPlayer1'sgun.
PrivateSubForm_DblClick()
DimrcAsInteger
IfNotTimer1.EnabledThenExitSub
GunFired(1)=True
rc=sndPlaySound(App.Path&"/BANG.WAV",SND_ASYNC)
EndSub
'ThiseventhandlesPlayer0'sgameactionviathekeyboard.
PrivateSubForm_KeyDown(KeyCodeAsInteger,ShiftAsInteger)
DimrcAsInteger
StaticInKeyDownAsInteger
IfNotTimer1.EnabledThenExitSub
IfInKeyDownThenExitSub
InKeyDown=True
DoEvents
SelectCaseKeyCode
CaseKEY_UP
imgPlayer(0).Top=imgPlayer(0).Top-PlayerIncrement
IfimgPlayer(0).Top<0ThenimgPlayer(0).Top=0
CaseKEY_SPACE
GunFired(0)=True
rc=sndPlaySound(App.Path&"/BANG.WAV",SND_ASYNC)
CaseKEY_DOWN
imgPlayer(0).Top=imgPlayer(0).Top PlayerIncrement
IfimgPlayer(0).Top>(picDesert.ScaleHeight-
imgPlayer(0).Height)Then
imgPlayer(0).Top=picDesert.ScaleHeight-
imgPlayer(0).Height
EndIf
EndSelect
InKeyDown=False
EndSub
PrivateSubForm_Load()
DimiAsInteger
Timer1.Interval=22
Timer1.Enabled=False
MouseButtonDown=NO_BUTTON
Fori=1ToNUM_BULLETS-1
LoadimgLBullet(i)
LoadimgRBullet(i)
Next
EndSub
PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
MouseButtonDown=Button
EndSub
PrivateSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
MouseButtonDown=NO_BUTTON
EndSub
'Themaingametimer.
PrivateSubTimer1_Timer()
ConstCactusIncrement=30
ConstBulletIncrement=300
ConstNumCacti=2
DimiAsInteger
DimrcAsInteger
'Movetherovingcacti.
Fori=0ToNumCacti-1
imgCactus(i).Top=imgCactus(i).Top-CactusIncrement
IfimgCactus(i).Top<-imgCactus(i).HeightThen
imgCactus(i).Top=picDesert.Height
EndIf
Next
'Didplayer0fireabullet?
IfGunFired(0)Then
GunFired(0)=False
'Findaspare(invisible)bullet.
Fori=0ToNUM_BULLETS-1
IfNotimgLBullet(i).VisibleThen
imgLBullet(i).Top=imgPlayer(0).Top
imgLBullet(i).Left=imgPlayer(0).Left
(imgPlayer(0).Width/2)
imgLBullet(i).Visible=True
ExitFor
EndIf
Next
EndIf
'Didplayer1fireabullet?
IfGunFired(1)Then
GunFired(1)=False
'Findaspare(invisible)bullet.
Fori=0ToNUM_BULLETS-1
IfNotimgRBullet(i).VisibleThen
imgRBullet(i).Top=imgPlayer(1).Top
imgRBullet(i).Left=imgPlayer(1).Left-
(imgPlayer(1).Width/2)
imgRBullet(i).Visible=True
ExitFor
EndIf
Next
EndIf
'MoveVisibleBullets
Fori=0ToNUM_BULLETS-1
'Moveplayer0'sbullets.
IfimgLBullet(i).VisibleThen
imgLBullet(i).Left=imgLBullet(i).Left BulletIncrement
IfCollided(imgLBullet(i),imgCactus(0))Then
imgLBullet(i).Visible=False
ElseIfCollided(imgLBullet(i),imgCactus(1))Then
imgLBullet(i).Visible=False
ElseIfimgLBullet(i).Left>picDesert.ScaleWidthThen
imgLBullet(i).Visible=False
ElseIfCollided(imgLBullet(i),imgPlayer(1))Then
imgLBullet(i).Visible=False
imgPlayer(1).Picture=imgRIP.Picture
Timer1.Enabled=False
rc=sndPlaySound(App.Path&"/OH!!.WAV",SND_ASYNC)
EndIf
EndIf
'Moveplayer1'sbullets.
IfimgRBullet(i).VisibleThen
imgRBullet(i).Left=imgRBullet(i).Left-BulletIncrement
IfCollided(imgRBullet(i),imgCactus(0))Then
imgRBullet(i).Visible=False
ElseIfCollided(imgRBullet(i),imgCactus(1))Then
imgRBullet(i).Visible=False
ElseIfimgRBullet(i).Left<-imgRBullet(i).WidthThen
imgRBullet(i).Visible=False
ElseIfCollided(imgRBullet(i),imgPlayer(0))Then
imgRBullet(i).Visible=False
imgPlayer(0).Picture=imgRIP.Picture
Timer1.Enabled=False
rc=sndPlaySound(App.Path&"/OH!!.WAV",SND_ASYNC)
EndIf
EndIf
Next
EndSub
'HandlePlayer1'smovement(upanddown).
PrivateSubtmrMouseCntl_Timer()
IfNotTimer1.EnabledThenExitSub
SelectCaseMouseButtonDown
CaseRBUTTON
imgPlayer(1).Top=imgPlayer(1).Top-PlayerIncrement
IfimgPlayer(1).Top<0ThenimgPlayer(1).Top=0
CaseLBUTTON
imgPlayer(1).Top=imgPlayer(1).Top PlayerIncrement
IfimgPlayer(1).Top>(picDesert.ScaleHeight-
imgPlayer(1).Height)Then
imgPlayer(1).Top=picDesert.ScaleHeight-
imgPlayer(1).Height
EndIf
EndSelect
EndSub
文章的上述內容對射擊游戲中的各個實現功能進行了詳細的介紹,讀者朋友可以根據文章中的程序代碼自己動手實驗一下。本程序在Windows2000、VisualBasic6.0環(huán)境下編譯通過,運行正常。
|
新聞熱點
疑難解答