📄 baspacsetup.bas
字号:
Attribute VB_Name = "basSetUp"
Option Explicit
Public Enum BitbltOps ' For bitblt function
SRCCOPY = &HCC0020 ' Dest = Source
SRCAND = &H8800C6 ' Dest = Dest AND Source
SRCINVERT = &H660046 ' Dest = Dest XOR Source
SRCPAINT = &HEE0086 ' Dest = Dest OR Source
SRCERASE = &H4400328 ' Dest = (XOR Dest) AND Source
WHITENESS = &HFF0062 ' Dest = vbWhite
BLACKNESS = &H42 ' Dest = vbBlack
End Enum
Public Enum SoundOps
SND_SYNC = &H0
SND_ASYNC = &H1
SND_NODEFAULT = &H2
SND_LOOP = &H8
SND_NOSTOP = &H10
SND_PURGE = &H40
SND_NOWAIT = &H2000
End Enum
' pac is a simple enumerated variable to tell what each square is in the level
Public Enum Pac
Wall = -1
Blank = 0
Pill = 1
PowerPill = 2
End Enum
' paclevel is an array which holds all the data for the level in it
Public Type UDTPacLevel
Junction As Boolean ' If a junction is here
JUp As Boolean ' if Ghost can move up at this junction
JDown As Boolean ' if Ghost can move down at this junction
Jleft As Boolean ' if Ghost can move left at this junction
Jright As Boolean ' if Ghost can move right at this junction
Block As Integer ' block type ( pac enum)
MemPlay As Integer
End Type
Public Type UDTGhost
InGame As Boolean ' if ghost is in the game (true) or in the box (false)
Eyesonly As Boolean ' if ghost is eyes only (true)
Xpos As Integer ' x position of the ghost
Ypos As Integer ' y position of the ghost
Direction As Integer ' direction the ghost is currently moving
Offset As Integer ' y offset until the next square to be flush with it
Xcounter As Integer ' not used
Ycounter As Integer ' counts how many times ghost has bounced up and down in the box
Speed As Integer ' speed the ghost moves at
PPTimer As Integer ' how long the ghost stays in eaten mode for
DelayTime As Integer ' this is to slow the ghost down in eaten mode by half
End Type
Public Type UDTSprites
OXpos As Integer ' old x position
OYpos As Integer ' old y position
NXpos As Integer ' new x position
NYpos As Integer ' new y position
XSprite As Integer ' with pcttiles, know where it's X position is
YSprite As Integer ' with pcttiles, know where it's Y position is
End Type
Public Type UDTPacman
FruitHere As Boolean ' if fruit is on the screen or not
FruitGone As Boolean ' if fruit has been eaten or not
Dead As Boolean ' if pacman is dead or not
DotGone As Boolean ' if a dot has been eaten
FirstGo As Boolean ' If it's the first go, play the music
Score As Long ' his score
TimeCount As Long ' counter for checking when to put and hide the fruit
Xpos As Integer ' x position of pacman
Ypos As Integer ' y position of pacman
Lives As Integer ' how many lives he has
Direction As Integer ' the direction he is going in
Offset As Integer '
Speed As Integer ' speed pacman is moving at
Level As Integer ' level pacman is on
GhostsEaten As Integer ' count how many ghosts he has eaten with one powerpill
FlashOkay As Integer ' ghosts will flash when eaten mode is nearly finished
DotsLeft As Integer ' keep track of how many dots left in the game
Mouth As Integer ' which mouth sprite to use
MouthDir As Integer ' tracks if mouth is now opening or shutting
MouthSpeed As Integer ' delay in how long each frame runs for
End Type
Public Type UDTGame
Enhanced As Boolean ' If pacman is in enhanced graphics mode or not
HiScore As Long ' the current hiscore
Coins As Integer ' how much money can I make. :)
Players As Integer ' how many players
CurrentPlay As Integer ' Which player is now playing the game
Speed As Integer ' Speed of the game. >:)
Started As Boolean ' if game is in progress or not
Cheat As Boolean
End Type
' set up the User Defined Type Variables
Public Pacman As UDTPacman
Public Ghost(1 To 4) As UDTGhost
Public Sprite(4) As UDTSprites
Public PacLevel(27, 33) As UDTPacLevel
Public Game As UDTGame
Public PacmanBackUp(1) As UDTPacman
' set up some game arrays
Public Rev(3) As Integer ' Reverse direction number
Public XD(3) As Integer ' Holds the X directions
Public YD(3) As Integer ' Holds the Y directions
Public GhostEat(4) As Long ' Holds the bonus points for each ghost eaten
Public OffDir(3) As Integer
' declare some functions :)
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
' -----------------------------------------------------------------------------------------
' miscellaneous subroutines
Sub ShowLives()
Dim nLoop As Integer ' number loop
Dim Xo As Integer ' X offset of fruit
Dim Yo As Integer ' Y offset of fruit
With frmPacMan
' clear the stats picturebox
.pctStats.Cls
' display all the pacmen
For nLoop = 1 To Pacman.Lives - 1
BitBlt .pctStats.hDC, nLoop * 32 - 32, 0, 32, 32, .pctTiles.hDC, 96, 224, BitbltOps.SRCCOPY
Next
' display all the fruit as to which level pacman is up to
For nLoop = 0 To Pacman.Level - 1
Xo = Int(nLoop Mod 4) * 32
Yo = Int(nLoop / 4) * 32 + 256
BitBlt .pctStats.hDC, 416 - nLoop * 32, 0, 32, 32, .pctTiles.hDC, Xo, Yo, BitbltOps.SRCCOPY
Next
frmPacMan.pctStats.Refresh
End With
End Sub
Sub ResetLevel()
Dim i As Integer ' x loop
Dim j As Integer ' y loop
Dim strData(30) As String ' level data strings
Dim ju As Integer ' junction binary number for working out directions
' load the walls pills and powerpills into an array via strings
strData(0) = "WWWWWWWWWWWWWWWWWWWWWWWWWWWW"
strData(1) = "W............WW............W"
strData(2) = "W.WWWW.WWWWW.WW.WWWWW.WWWW.W"
strData(3) = "WoWWWW.WWWWW.WW.WWWWW.WWWWoW"
strData(4) = "W.WWWW.WWWWW.WW.WWWWW.WWWW.W"
strData(5) = "W..........................W"
strData(6) = "W.WWWW.WW.WWWWWWWW.WW.WWWW.W"
strData(7) = "W.WWWW.WW.WWWWWWWW.WW.WWWW.W"
strData(8) = "W......WW....WW....WW......W"
strData(9) = "WWWWWW.WWWWW WW WWWWW.WWWWWW"
strData(10) = " W.WWWWW WW WWWWW.W "
strData(11) = " W.WW WW.W "
strData(12) = " W.WW WWWWWWWW WW.W "
strData(13) = "WWWWWW.WW W W WW.WWWWWW"
strData(14) = " . W W . "
strData(15) = "WWWWWW.WW W W WW.WWWWWW"
strData(16) = " W.WW WWWWWWWW WW.W "
strData(17) = " W.WW WW.W "
strData(18) = " W.WW WWWWWWWW WW.W "
strData(19) = "WWWWWW.WW WWWWWWWW WW.WWWWWW"
strData(20) = "W............WW............W"
strData(21) = "W.WWWW.WWWWW.WW.WWWWW.WWWW.W"
strData(22) = "W.WWWW.WWWWW.WW.WWWWW.WWWW.W"
strData(23) = "Wo..WW....... .......WW..oW"
strData(24) = "WWW.WW.WW.WWWWWWWW.WW.WW.WWW"
strData(25) = "WWW.WW.WW.WWWWWWWW.WW.WW.WWW"
strData(26) = "W......WW....WW....WW......W"
strData(27) = "W.WWWWWWWWWW.WW.WWWWWWWWWW.W"
strData(28) = "W.WWWWWWWWWW.WW.WWWWWWWWWW.W"
strData(29) = "W..........................W"
strData(30) = "WWWWWWWWWWWWWWWWWWWWWWWWWWWW"
Pacman.DotsLeft = 0 ' set the counter to 0
' extra the walls, pills and powerpills from the string
For j = 0 To 30
For i = 0 To 27
With PacLevel(i, j)
Select Case Mid(strData(j), i + 1, 1)
Case "W"
.Block = Pac.Wall
Case "."
.Block = Pac.Pill
Pacman.DotsLeft = Pacman.DotsLeft + 1
Case "o"
.Block = Pac.PowerPill
Pacman.DotsLeft = Pacman.DotsLeft + 1
End Select
End With
Next
Next
' calc all the junctions in the game in the loop-up table so that
' the program doesn't have to keep calculating it
For j = 1 To 29
For i = 1 To 26
ju = 0
With PacLevel(i, j)
If .Block <> Pac.Wall Then
If PacLevel(i, j - 1).Block <> Pac.Wall Then ju = ju Or 1: .JUp = True
If PacLevel(i, j + 1).Block <> Pac.Wall Then ju = ju Or 2: .JDown = True
If PacLevel(i - 1, j).Block <> Pac.Wall Then ju = ju Or 4: .Jleft = True
If PacLevel(i + 1, j).Block <> Pac.Wall Then ju = ju Or 8: .Jright = True
If ju < 5 Or ju = 8 Or ju = 12 Then
.Junction = False ' delete straights & dead ends
Else
.Junction = True
End If
End If
End With
Next
Next
' draw all the dots
RefreshLevel
End Sub
Sub ShowBlit(ByVal X As Integer, ByVal Y As Integer, _
ByVal XP As Integer, ByVal YP As Integer, ByVal pos As Integer)
Dim maskOffset As Integer
With frmPacMan
' copy info behind the sprite into a buffer
BitBlt .pctBack.hDC, 0, pos * 32, 32, 32, .pctScreen.hDC, X, Y, BitbltOps.SRCCOPY
If pos = 0 Or pos = 5 Then ' pacman or fruit only
maskOffset = XP + 128
Else
If Ghost(pos).Eyesonly = False Then
maskOffset = 192 ' normal ghost mask
Else
maskOffset = 224 ' eyes mask
End If
End If
BitBlt .pctScreen.hDC, X, Y, 32, 32, .pctTiles.hDC, maskOffset, YP, BitbltOps.SRCAND
BitBlt .pctScreen.hDC, X, Y, 32, 32, .pctTiles.hDC, XP, YP, BitbltOps.SRCPAINT
End With
End Sub
Sub HideBlit(X As Integer, Y As Integer, pos As Integer)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -