So, for anyone who's ever done this, any ideas how to change it so I can implement new functions, like letting my character shoot at the ghosts?
If anyone could just tell me where to begin that would be ace.
Rem Project: Pacman_Tut
Rem Created: 01/05/2007 21:03:49
Rem ***** Main Source File *****
Sync On
Sync Rate 60
Set Display Mode 1024,768,32
Ink Rgb(255,255,255),0
Cls
Global ImageNumber
Global Dim Maze(21,22)
Global PenX, PenY, Pills
Global MazeCount = 2
Global ThisMaze
Global Dim MazeInventory$(MazeCount)
Global Dim Cast(5,12)
Global PlayerX, PlayerY
Global GateTimer, GhostTimer, GhostFlash
Global Toggle
Global HiScore, Score, Level, Lives
Global GhostScore
Global NewGame
Global SirenSound
Global ItemTimer, ItemOn, ItemImage
Global MazeOffsetX, MazeOffsetY
Global NextNewLife
NextNewLife = 20000
MazeOffsetX = 197
MazeOffsetY = 108
NewGame = 1
HiScore = 0
Toggle = 0
Rem
Rem Set initial maze
Rem
ThisMaze = 0
Rem
Rem Declare our maze inventory
Rem
_Declare_Mazes()
Rem
Rem Load Media
Rem
_Load_Media()
Do
Rem
Rem New Game
Rem
_New_Game()
Repeat
Cls
Paste Image 101, 0, 0, 0
Sync
Sync
Wait Key
Until SpaceKey() = 1
Do
Rem
Rem New Level
Rem
_New_Level()
Rem
Rem Load maze
Rem
_Load_Maze()
Rem
Rem Initialise Cast
Rem
_Initialise_Cast()
Rem
Rem Reset timer
Rem
GateTimer = Timer()
Rem
Rem Main program loop
Rem
Repeat
Cls
Inc Toggle
If Toggle = 2
Toggle = 0
Endif
_Draw_Maze()
_Update_HUD()
_Animate_Cast()
_Draw_Cast()
_Check_Input()
_Ghost_AI()
_Wall_Check()
_Move_Cast()
_Check_Timers()
_Check_Collisions()
Sync
If Not Sound Playing(SirenSound)
Loop Sound SirenSound
Endif
If Score >= NextNewLife
If Lives < 6
Inc Lives
NextNewLife = NextNewLife + 20000
Play Sound 8
Endif
Endif
Until Pills = 0 Or Lives = 0
If Sound Playing(SirenSound)
Stop Sound SirenSound
SirenSound = 4
Endif
Inc Level
If Lives > 0
Play Sound 7
Endif
If Lives = 0
_Game_Over()
Exit
Endif
Loop
Loop
Function _Load_Media()
Load Sound "Soundsgathers.wav", 1
Load Sound "Soundseat_ghost.wav", 2
Load Sound "Soundsbegin.wav", 3
Load Sound "Soundsbgm.wav", 4
Load Sound "Soundsweakened.wav", 5
Load Sound "Soundsitem.wav", 6
Load Sound "Soundsnewlevel.wav", 7
Load Sound "Soundsextra_life.wav", 8
Load Sound "Soundsdeath.wav", 9
Rem
Rem Get Maze pieces from bitmap
Rem
Load Bitmap "Graphicsmazeparts2.bmp",1
ImageNumber = 2
For Row = 0 To 90 Step 30
For Col = 0 To 90 Step 30
Inc ImageNumber
Get Image ImageNumber, Col, Row, Col + 30, Row + 30, 1
Next Col
Next Row
Delete Bitmap 1
Rem
Rem Get Ghosts and additional maze pieces from bitmap
Rem
Load Bitmap "Graphicsgeth.bmp",1
ImageNumber = 59
For Row = 0 To 60 Step 30
For Col = 0 To 90 Step 30
Inc ImageNumber
If ImageNumber <= 69
Get Image ImageNumber, Col, Row, Col + 30, Row + 30, 1
Endif
Next Col
Next Row
Get Image 2, 60, 60, 90, 90, 1
Get Image 1, 90, 60, 120, 90, 1
Delete Bitmap 1
Rem
Rem Get Ghost Pen
Rem
Load Bitmap "Graphicsghostpen.bmp", 1
Get Image 19, 0, 0, 150, 120, 1
Delete Bitmap 1
Rem
Rem Load Player
Rem
Load Bitmap "Graphicsplayerxman23.bmp",1
ImageNumber = 19
For Row = 0 To 108 Step 36
For Col = 0 To 252 Step 28
Inc ImageNumber
Get Image ImageNumber, Col, Row, Col + 28, Row + 36, 1
Next Col
Next Row
Delete Bitmap 1
Rem
Rem Backdrop
Rem
Load Bitmap "Graphicshudt.tga",1
Get Image 100, 0, 0, 1024, 768, 1
Delete Bitmap 1
Rem
Rem Items
Rem
Load Bitmap "Graphicsitems.bmp",1
ImageNumber = 109
For Row = 0 To 60 Step 30
For Col = 0 To 90 Step 30
Inc ImageNumber
Get Image ImageNumber, Col, Row, Col + 30, Row + 30, 1
Next Col
Next Row
Delete Bitmap 1
Rem
Rem Intro screen
Rem
Load Bitmap "Graphicsintscreen1.bmp", 1
Get Image 101, 0, 0, 1024, 768, 1
Delete Bitmap 1
Rem
Rem Scores
Rem
Load Bitmap "Graphicsscores1.bmp",1
ImageNumber = 119
For Col = 0 To 400 Step 100
Inc ImageNumber
Get Image ImageNumber, Col, 0, Col + 100, 50, 1
Next Col
Delete Bitmap 1
Rem
Rem Numbers
Rem
Load Bitmap "Graphicsnumbers2.bmp",1
ImageNumber = 129
For Col = 0 To 225 Step 25
Inc ImageNumber
Get Image ImageNumber, Col, 0, Col + 25, 20, 1
Next Col
Delete Bitmap 1
Rem
Rem Game Over
Rem
Load Bitmap "Graphicsgameover.bmp",1
Get Image 140, 0, 0, 320, 25, 1
Delete Bitmap 1
Rem
Rem Player Death
Rem
Load Bitmap "Graphicsasplode.bmp",1
ImageNumber = 149
For Row = 0 To 30 Step 30
For Col = 0 To 150 Step 30
Inc ImageNumber
Get Image ImageNumber, Col, Row, Col + 30, Row + 30, 1
Next Col
Next Row
Delete Bitmap 1
Endfunction
Function _Load_Maze()
Local TheFile$, TheCell, X, Y
Local TheLine$
Local LinesRead, C, TheChar$, ThePart$
Rem
Rem Determine filename of maze to load
Rem
Inc ThisMaze
If ThisMaze > MazeCount
ThisMaze = 1
Endif
TheFile$ = MazeInventory$(ThisMaze)
Rem
Rem Reset pills counter
Rem
Pills = 0
Rem
Rem Open maze file
Rem
Open To Read 1, "mazes" + TheFile$
LinesRead = 0
Repeat
Inc LinesRead
Read String 1, TheLine$
Rem
Rem Player cell
Rem
If LinesRead = 1
PlayerX = Val(Left$(TheLine$,2))
PlayerY = Val(Right$(TheLine$,2))
Endif
Rem
Rem Pen cell
Rem
If LinesRead = 2
PenX = Val(Left$(TheLine$,2))
PenY = Val(Right$(TheLine$,2))
Endif
Rem
Rem Rest of maze
Rem
If LinesRead >= 3
Y = LinesRead - 2
X = 0
ThePart$ = ""
For C = 1 To Len(TheLine$)
TheChar$ = Mid$(TheLine$,C)
If TheChar$ = ","
Inc X
TheCell = Val(ThePart$)
Maze(Y,X) = TheCell
If TheCell = 1
Inc Pills
Endif
ThePart$ = ""
Else
ThePart$ = ThePart$ + TheChar$
Endif
Next C
Inc X
TheCell = Val(ThePart$)
Maze(Y,X) = TheCell
If TheCell = 1
Inc Pills
Endif
Endif
Until File End(1)
Close File 1
Endfunction
Function _Draw_Maze()
Local TheCell, X, Y
Local ThisX, ThisY
Paste Image 100, 0, 0, 0
ThisY = MazeOffsetY
For Y = 1 To 22
ThisX = MazeOffsetX
For X = 1 To 21
TheCell = Maze(Y, X)
If TheCell >= 1 And TheCell <= 18
Paste Image TheCell, ThisX, ThisY,0
Endif
ThisX = ThisX + 30
Next X
ThisY = ThisY + 30
Next Y
Rem
Rem Paste Pen
Rem
Paste Image 19, MazeOffsetX + (PenX - 1) * 30, MazeOffsetY + (PenY - 1) * 30, 0
If Maze(PenX, PenY +2) <> 0
Paste Image 18, MazeOffsetX + (PenX + 1) * 30, MazeOffsetY + (PenY - 1) * 30, 0
Endif
If NewGame = 1
Sync
Sync
Play Sound 3
Wait 1100
NewGame = 0
Endif
Endfunction
Function _Declare_Mazes
MazeInventory$(1) = "0003.maz"
MazeInventory$(2) = "0003.maz"
Endfunction
Function _Initialise_Cast()
Rem
Rem Player
Rem
Cast(1,1) = MazeOffsetX + (PlayerX - 1) * 30
Cast(1,2) = MazeOffsetY + (PlayerY - 1) * 30
Cast(1,3) = 30
Cast(1,4) = 30
Cast(1,5) = 30
Cast(1,6) = 0
Cast(1,7) = 1
Cast(1,8) = 0
Cast(1,9) = 0
Rem
Rem Red
Rem
Cast(2,1) = MazeOffsetX + (PenX * 30)
Cast(2,2) = MazeOffsetY + (PenY * 30)
Cast(2,3) = 60
Cast(2,4) = 60
Cast(2,5) = 60
Cast(2,6) = 1
Cast(2,7) = 0
Cast(2,8) = 0
Cast(2,9) = 1
Rem
Rem Blue
Rem
Cast(3,1) = MazeOffsetX + (PenX + 1) * 30
Cast(3,2) = MazeOffsetY + (PenY * 30)
Cast(3,3) = 61
Cast(3,4) = 61
Cast(3,5) = 61
Cast(3,6) = 1
Cast(3,7) = 0
Cast(3,8) = 0
Cast(3,9) = 1
Rem
Rem Green
Rem
Cast(4,1) = MazeOffsetX + (PenX + 2) * 30
Cast(4,2) = MazeOffsetY + (PenY * 30)
Cast(4,3) = 62
Cast(4,4) = 62
Cast(4,5) = 62
Cast(4,6) = 1
Cast(4,7) = 0
Cast(4,8) = 0
Cast(4,9) = 1
Rem
Rem Pink
Rem
Cast(5,1) = MazeOffsetX + (PenX + 1) * 30
Cast(5,2) = MazeOffsetY + (PenY + 1) * 30
Cast(5,3) = 63
Cast(5,4) = 63
Cast(5,5) = 63
Cast(5,6) = 1
Cast(5,7) = 0
Cast(5,8) = 0
Cast(5,9) = 1
Endfunction
Function _Draw_Cast()
Local n
For n = 1 To 5
Sprite n, Cast(n,1), Cast(n,2), Cast(n,3)
Set Sprite n,0,1
If Cast(n,8) = 1
Hide Sprite n
Show Sprite n + 4
Else
Show Sprite n
Endif
Next n
For n = 6 To 9
If Cast(n-4,7) = 0
Sprite n, Cast(n-4,1), Cast(n-4,2), (63 + Cast(n-4,6))
Show Sprite n
Set Sprite n, 0, 1
Else
If Cast(n-4,8) = 0
Hide Sprite n
Endif
Endif
Next n
Rem
Rem Item
Rem
If ItemOn = 1
Sprite 110, MazeOffsetX + (PlayerX - 1) * 30, MazeOffsetY + (PlayerY - 1) * 30, ItemImage
Sprite 112, 60, 250, ItemImage
Show Sprite 110
Show Sprite 112
Else
If Sprite Exist(110)
Hide Sprite 110
Hide Sprite 112
Endif
Endif
Endfunction
Function _Animate_Cast()
Local n
Rem
Rem Check player's animation frames match direction
Rem
If Cast(1,6) = 1
Cast(1,4) = 20
Cast(1,5) = 29
Endif
If Cast(1,6) = 2
Cast(1,4) = 30
Cast(1,5) = 39
Endif
If Cast(1,6) = 3
Cast(1,4) = 40
Cast(1,5) = 49
Endif
If Cast(1,6) = 4
Cast(1,4) = 50
Cast(1,5) = 59
Endif
Rem
Rem Check for vulnerable ghosts
Rem
For n = 2 To 5
If Cast(n,7) = 1
Cast(n,4) = 68
Cast(n,5) = 68
Cast(n,3) = 68
Endif
Next n
For n = 1 To 5
If Cast(n,3) < Cast(n,4)
Cast(n,3) = Cast(n,4) - 1
Endif
If n = 1 Or Cast(n,7) <> 2
Inc Cast(n, 3)
Else
If Toggle = 1
Inc Cast(n, 3)
Endif
Endif
If Cast(n,3) > Cast(n,5)
Cast(n,3) = Cast(n,4)
Endif
Next n
Endfunction
Function _Move_Cast()
Local n, Distance
For n = 1 To 5
Distance = 2
If n <> 1
If Cast(n,7) <> 0
If Toggle = 0
If Cast(n,8) = 0
Distance = 0
Endif
Endif
Endif
Endif
If Cast(n,6) <> 0
If Cast(n,6) = 1
Cast(n,2) = Cast(n,2) - Distance
Endif
If Cast(n,6) = 2
Cast(n,1) = Cast(n,1) + Distance
Endif
If Cast(n,6) = 3
Cast(n,2) = Cast(n,2) + Distance
Endif
If Cast(n,6) = 4
Cast(n,1) = Cast(n,1) - Distance
Endif
Endif
Next n
Endfunction
Function _Wall_Check()
Local n, BaseX, BaseY, XtoCheck, YtoCheck
Local RealBaseX#, RealBaseY#
For n = 1 To 5
If _Check_Wall(n) = 1
Cast(n,6) = 0
Endif
Next n
Endfunction
Function _Check_Input()
Local LastDir
LastDir = Cast(1,6)
If _Can_Turn(1) = 1
If UpKey()
Cast(1,6) = 1
Endif
If RightKey()
Cast(1,6) = 2
Endif
If DownKey()
Cast(1,6) = 3
Endif
If LeftKey()
Cast(1,6) = 4
Endif
Else
If LastDir = 1 And DownKey()
Cast(1,6) = 3
Endif
If LastDir = 2 And LeftKey()
Cast(1,6) = 4
Endif
If LastDir = 3 And UpKey()
Cast(1,6) = 1
Endif
If LastDir = 4 And RightKey()
Cast(1,6) = 2
Endif
Endif
If _Check_Wall(1) = 1
Cast(1,6) = LastDir
Endif
Endfunction
Function _Can_Turn(n)
Local BaseX, BaseY
Local RealBaseX#, RealBaseY#
Local Result, NowTime
BaseY = Cast(n,1) - MazeOffsetX
BaseX = Cast(n,2) - MazeOffsetY
RealBaseY# = Cast(n,1) - MazeOffsetX
RealBaseX# = Cast(n,2) - MazeOffsetY
BaseX = 1 + BaseX / 30
BaseY = 1 + BaseY / 30
RealBaseX# = 1 + RealBaseX# / 30
RealBaseY# = 1 + RealBaseY# / 30
If BaseX < 0
BaseX = 0
Endif
If BaseY < 0
BaseY = 0
Endif
If BaseY = 1
Cast(n,1) = 767
Else
If BaseY = 21
Cast(n,1) = 227
Endif
Endif
If (RealBaseX# = BaseX) And (RealBaseY# = BaseY)
Result = 1
Else
Result = 0
Endif
If Result = 1 And n = 1
If Maze(BaseX, BaseY) = 1
Play Sound 1
Pills = Pills - 1
Maze(BaseX, BaseY) = 0
Score = Score + 10
If Score > HiScore
HiScore = Score
Endif
Endif
Endif
If Result = 1 And n = 1
If Maze(BaseX, BaseY) = 2
If Sound Playing(SirenSound)
Stop Sound SirenSound
Endif
SirenSound = 5
Maze(BaseX, BaseY) = 0
NowTime = Timer()
If (NowTime - GateTimer) > 10000
GhostTimer = Timer()
GhostFlash = Timer()
For n = 2 To 5
If Cast(n,8) = 0
If Cast(n,7) = 0
Cast(n,7) = 1
Endif
Endif
Next n
Endif
Endif
If ItemOn = 1
If Maze(BaseX, BaseY) = -1
Maze(BaseX, BaseY) = 0
ItemOn = 0
If Sprite Exist(110)
Hide Sprite 110
Endif
Play Sound 6
Hide Sprite 1
Score = Score + 1000
If Score > HiScore
HiScore = Score
Endif
_Show_Score(1000, Cast(n,1), Cast(n,2), 1000)
Show Sprite 1
Endif
Endif
Endif
Endfunction Result
Function _Check_Wall(n)
Local BaseX, BaseY
Local Result
Result = 0
BaseY = Cast(n,1) - MazeOffsetX
BaseX = Cast(n,2) - MazeOffsetY
BaseX = 1 + BaseX / 30
BaseY = 1 + BaseY / 30
If BaseX < 0
BaseX = 0
Endif
If BaseY < 0
BaseY = 0
Endif
If _Can_Turn(n) = 1
If Cast(n,6) <> 0
If Cast(n,6) = 1
XtoCheck = BaseX - 1
YtoCheck = BaseY
Endif
If Cast(n,6) = 2
XtoCheck = BaseX
YtoCheck = BaseY + 1
Endif
If Cast(n,6) = 3
XtoCheck = BaseX + 1
YtoCheck = BaseY
Endif
If Cast(n,6) = 4
XtoCheck = BaseX
YtoCheck = BaseY - 1
Endif
Endif
If Maze(XtoCheck,YtoCheck) > 2
Result = 1
Else
If XtoCheck = PenX And YtoCheck = PenY + 2
Rem
Rem If cast member isn't dead and at this coordinate, set their "in pen" flag to 0
Rem
If Cast(n,8) = 0
Cast(n,9) = 0
Endif
If Cast(n,6) = 3
If Cast(n,8) = 0
Result = 1
Endif
Endif
Endif
Endif
Endif
Endfunction Result
Function _Ghost_AI()
Local n, LastDir
Local Dim Directions(4)
Local D, Chosen
Local Bias, GateCellX, GateCellY
Local ToTry
Local XDistance, YDistance
Randomize Timer()
GateCellY = MazeOffsetY + ((PenY - 2) * 30)
GateCellX = MazeOffsetX + ((PenX + 1) * 30)
For n = 2 To 5
LastDir = Cast(n, 6)
Directions(1) = 0
Directions(2) = 0
Directions(3) = 0
Directions(4) = 0
If _Can_Turn(n) = 1
Bias = 0
If Cast(n,8) = 0 And Cast(n,9) = 0
Rem
Rem Determine which is larger gap
Rem
XDistance = Abs(Cast(n,1) - Cast(1,1))
YDistance = Abs(Cast(n,2) - Cast(1,2))
If YDistance > XDistance
Rem
Rem Get direction to try
Rem
If Cast(n,2) < Cast(1,2)
If Cast(n,7) = 0
ToTry = 3
Else
ToTry = 1
Endif
Endif
If Cast(n,2) > Cast(1,2)
If Cast(n,7) = 0
ToTry = 1
Else
ToTry = 3
Endif
Endif
Else
If Cast(n,1) < Cast(1,1)
If Cast(n,7) = 0
ToTry = 2
Else
ToTry = 4
Endif
Endif
If Cast(n,1) > Cast(1,1)
If Cast(n,7) = 0
ToTry = 4
Else
ToTry = 2
Endif
Endif
Endif
Cast(n,6) = ToTry
If _Check_Wall(n) = 0
Bias = ToTry
Endif
Endif
If Cast(n,8) = 1
Rem
Rem Check up and down first
Rem
If Cast(n,2) < GateCellY
Cast(n,6) = 3
If _Check_Wall(n) = 0
Bias = 3
Endif
Endif
Rem
Rem If level with gate entrance row
Rem
If Cast(n,2) = GateCellY
If Cast(n,1) < GateCellX
Cast(n,6) = 2
If _Check_Wall(n) = 0
Bias = 2
Endif
Endif
If Cast(n,1) > GateCellX
Cast(n,6) = 4
If _Check_Wall(n) = 0
Bias = 4
Endif
Endif
If Cast(n,1) = GateCellX
Bias = 3
Endif
Endif
If Cast(n,2) > GateCellY
Cast(n,6) = 1
If _Check_Wall(n) = 0
Bias = 1
Endif
Endif
Rem
Rem If cannot go up or down, check left or right bias
Rem
If Bias = 0
If Cast(n,1) < GateCellX
Cast(n,6) = 2
If _Check_Wall(n) = 0
Bias = 2
Endif
Endif
If Cast(n,1) > GateCellX
Cast(n,6) = 4
If _Check_Wall(n) = 0
Bias = 4
Endif
Endif
Endif
If Cast(n,1) = GateCellX
If Cast(n,2) = GateCellY + 60
Cast(n,8) = 0
Cast(n,3) = 58 + n
Cast(n,4) = 58 + n
Cast(n,5) = 58 + n
Endif
Endif
Endif
D = 0
If LastDir <> 3
Rem
Rem Try Up
Rem
Cast(n,6) = 1
If _Check_Wall(n) = 0
D = D + 1
Directions(D) = 1
Endif
Endif
If LastDir <> 4
Rem
Rem Try Right
Rem
Cast(n,6) = 2
If _Check_Wall(n) = 0
D = D + 1
Directions(D) = 2
Endif
Endif
If LastDir <> 1
Rem
Rem Try Down
Rem
Cast(n,6) = 3
If _Check_Wall(n) = 0
D = D + 1
Directions(D) = 3
Endif
Endif
If LastDir <> 2
Rem
Rem Try Left
Rem
Cast(n,6) = 4
If _Check_Wall(n) = 0
D = D + 1
Directions(D) = 4
Endif
Endif
Rem
Rem Restore Direction
Rem
Cast(n,6) = LastDir
If _Check_Wall(n) = 1 Or D >= 2
Cast(n,6) = 0
Endif
Rem
Rem If ghost already been this way last three direction changes, set it to 0
Rem
If _Has_Turned(n, Cast(n,6)) = 1
If Cast(n,7) = 0 And Cast(n,8) = 0
Cast(n,6) = 0
Endif
Endif
Rem
Rem If Ghost stopped
Rem
If Cast(n,6) = 0
If Bias <> 0
If Bias = 1 And LastDir <> 3
Cast(n,6) = Bias
Endif
If Bias = 2 And LastDir <> 4
Cast(n,6) = Bias
Endif
If Bias = 3 And LastDir <> 1
Cast(n,6) = Bias
Endif
If Bias = 4 And LastDir <> 2
Cast(n,6) = Bias
Endif
Endif
If Cast(n,6) = 0
Chosen = Int(Rnd(D))
If Chosen = 0
Chosen = 1
Endif
Cast(n,6) = Directions(Chosen)
Endif
Endif
Endif
Rem
Rem Store direction chosen in history
Rem
Cast(n,12) = Cast(n,11)
Cast(n,11) = Cast(n,10)
Cast(n,10) = Cast(n,6)
Next n
Endfunction
Function _Check_Timers()
Local NowTime
Rem
Rem Get timer as it is now
Rem
NowTime = Timer()
Rem
Rem Ghost pen gate timer
Rem
If (NowTime - GateTimer) > 10000
Rem
Rem Remove gate
Rem
Maze(PenX, PenY + 2) = 0
Endif
Rem
Rem Ghost vulnerability timer
Rem
If (NowTime - GhostTimer) > 10000
If Sound Playing(5)
Stop Sound 5
Endif
SirenSound = 4
GhostScore = 0
For n = 2 To 5
If Cast(n,7) <> 0
Cast(n,7) = 0
Cast(n,3) = 58 + n
Cast(n,4) = 58 + n
Cast(n,5) = 58 + n
Endif
Next n
Endif
Rem
Rem Ghost flash timer
Rem
If (NowTime - GhostTimer) > 8000
For n = 2 To 5
If Cast(n,7) = 1
Cast(n,7) = 2
Cast(n,3) = 68
Cast(n,4) = 68
Cast(n,5) = 69
Endif
Next n
Endif
Rem
Rem Item timer
Rem
If (NowTime - ItemTimer) > 20000
If ItemOn = 0
ItemOn = 1
ItemImage = (109 + Rnd(10))
If ItemImage = 109
ItemImage = 110
Endif
If ItemImage = 120
ItemImage = 119
Endif
Maze(PlayerY, PlayerX) = -1
Else
ItemOn = 0
Maze(PlayerY, PlayerX) = 0
Endif
ItemTimer = Timer()
Endif
Endfunction
Function _Check_Collisions()
For n = 2 To 5
Rem
Rem If ghost is not dead already
Rem
If Cast(n,8) = 0
If _Check_Collision(1, n) = 1
Rem
Rem If ghost is vulnerable, set it to dead
Rem
If Cast(n,7) <> 0
Play Sound 2
Cast(n,8) = 1
Cast(n,7) = 0
GhostScore = GhostScore + 200
If GhostScore > 1000
GhostScore = 1000
Endif
Hide Sprite n
Hide Sprite 1
_Show_Score(GhostScore, Cast(n,1), Cast(n,2), 1000)
Show Sprite n
Show Sprite 1
Score = Score + GhostScore
If Score > HiScore
HiScore = Score
Endif
Endif
Rem
Rem If ghost is alive and kicking, player dies
Rem
If Cast(n,7) = 0 And Cast(n,8) = 0
Cast(1,8) = 1
Dec Lives
_Player_Die()
Endif
Endif
Endif
Next n
Endfunction
Function _Check_Collision(P1, P2)
Local P1X, P1Y, P2X, P2Y
Local DifferenceX, DifferenceY
Local HasCollided
P1X = Cast(P1, 1)
P1Y = Cast(P1, 2)
P2X = Cast(P2, 1)
P2Y = Cast(P2, 2)
HasCollided = 0
DifferenceX = Abs(P1X - P2X)
DifferenceY = Abs(P1Y - P2Y)
If DifferenceX <= 5 And DifferenceY <= 5
HasCollided = 1
Endif
Endfunction HasCollided
Function _New_Game()
Lives = 3
Level = 1
Score = 0
GhostScore = 0
SirenSound = 4
ItemOn = 0
ItemTimer = Timer()
Endfunction
Function _New_Level()
GhostScore = 0
SirenSound = 4
ItemOn = 0
ItemTimer = Timer()
Endfunction
Function _Show_Score(TheScore, XPos, YPos, Duration)
Local ScoreImage
If TheScore = 200
ScoreImage = 120
Endif
If TheScore = 400
ScoreImage = 121
Endif
If TheScore = 600
ScoreImage = 122
Endif
If TheScore = 800
ScoreImage = 123
Endif
If TheScore = 1000
ScoreImage = 124
Endif
Sprite 111, XPos - 20, YPos - 20, ScoreImage
Show Sprite 111
Sync
Sync
Wait Duration
Hide Sprite 111
Endfunction
Function _Update_HUD()
Local StringVersion$, Char$, Count
Local NumberImage, XPosition, YPosition
Rem
Rem Score
Rem
XPosition = 360
YPosition = 22
StringVersion$ = Str$(Score)
For Count = 1 To Len(StringVersion$)
Char$ = Mid$(StringVersion$, Count)
If Val(Char$) > 0
Paste Image 129 + Val(Char$), XPosition, YPosition, 0
Else
Paste Image 139, XPosition, YPosition, 0
Endif
XPosition = XPosition + 20
Next Count
Rem
Rem High Score
Rem
XPosition = 360
YPosition = 72
StringVersion$ = Str$(HiScore)
For Count = 1 To Len(StringVersion$)
Char$ = Mid$(StringVersion$, Count)
If Val(Char$) > 0
Paste Image 129 + Val(Char$), XPosition, YPosition, 0
Else
Paste Image 139, XPosition, YPosition, 0
Endif
XPosition = XPosition + 20
Next Count
Rem
Rem Lives
Rem
XPosition = 790
YPosition = 22
If Lives <= 3
For Count = 1 To Lives
Paste Image 5, XPosition, YPosition, 0
XPosition = XPosition - 31
Next Count
Else
For Count = 1 To 3
Paste Image 36, XPosition, YPosition, 0
XPosition = XPosition - 31
Next Count
XPosition = 728
YPosition = 72
For Count = 4 To Lives
Paste Image 36, XPosition, YPosition, 0
XPosition = XPosition + 31
Next Count
Endif
Rem
Rem Level
Rem
StringVersion$ = Str$(Level)
XPosition = 60 - (Len(StringVersion$)-1) * 12
YPosition = 150
For Count = 1 To Len(StringVersion$)
Char$ = Mid$(StringVersion$, Count)
If Val(Char$) > 0
Paste Image 129 + Val(Char$), XPosition, YPosition, 0
Else
Paste Image 139, XPosition, YPosition, 0
Endif
XPosition = XPosition + 20
Next Count
Endfunction
Function _Has_Turned(n, DirectionToTest)
Local Result = 0
If Cast(n,10) = DirectionToTest
Result = 1
Endif
If Cast(n,11) = DirectionToTest
Result = 1
Endif
If Cast(n,12) = DirectionToTest
Result = 1
Endif
Endfunction Result
Function _Player_Die()
Local n, DieFrame
Stop Sound SirenSound
For n = 2 To 5
Hide Sprite n
If Cast(n,7) = 0
Hide Sprite n+4
Endif
Next n
Play Sound 9
DieFrame = 150
Repeat
Cls
_Draw_Maze()
_Update_Hud()
Hide Sprite 1
Sprite 10, Cast(1,1), Cast(1,2), DieFrame
Show Sprite 10
Inc DieFrame
Sync
Sync
Wait 100
Until Sound Playing(9) = 0
Hide Sprite 10
_Initialise_Cast()
ItemOn = 0
ItemTimer = Timer()
GhostTimer = Timer()
Endfunction
Function _Game_Over()
Local n
For n = 1 To 9
If Sprite Exist(n)
Hide Sprite n
Endif
Next n
If Sprite Exist(110)
Hide Sprite 110
Endif
Cls
_Draw_Maze()
_Update_Hud()
Paste Image 140, MazeOffsetX + (PlayerX - 6) * 30, MazeOffsetY + (PlayerY - 1) * 30, 0
Sync
Sync
Wait 3000
Endfunction