PacMan 2D

Blitz3D Forums/Blitz3D Beginners Area/PacMan 2D

Ok Here is my code:

Graphics 640,480,0,2
SetBuffer BackBuffer()
AppTitle "PacMan V0.0 "

Global SUR, Food, tempscore
SX#=0
SY#=0

Load_Surround()
Create_Player(90,90,3,0)
Load_HUD()

For t=1 To 35
Create_food(20+(t*16),90)
Next

While Not KeyHit(1)
Cls

Update_Food()
Draw_Surround()
Update_Player()
Draw_Player()
Draw_Hud()
Color 255,0,0
Flip
Wend
End

Type Player
Field Img
Field HUD
Field X#,Y#
Field Lives%
Field Score%
Field Frame%
End Type

;Function to create player
Function Create_Player(X#,Y#,Lives%=3,Score%=0)
P.Player = New Player
P\Img=LoadAnimImage("PacMan.Png",32,32,0,4)
MidHandle P\Img
P\X#=X#
P\Y#=Y#
P\Lives%=Lives%
P\Score%=Score%
P\Frame%=0
End Function

;Function to update player
Function Update_Player()
For P.Player = Each Player

If P\X#<=40 Then P\X#=40
If P\Y#<=90 Then P\Y#=90
If P\X#=>600 Then P\X#=600
If P\Y#=>440 Then P\Y#=440

Next
End Function

;Function to draw player
Function Draw_Player()
For P.Player = Each Player

If KeyHit(208) Then
P\Frame%=2 ;Up
EndIf

If KeyHit(200) Then
P\Frame%=3 ;Down
Sx#=0
Sy#=Sy#+1
EndIf

If KeyHit(203) Then
P\Frame%=1 ;Left
Sx#=Sx#-1
Sy#=0
EndIf

If KeyHit(205) Then
P\Frame%=0 ;Right
Sx#=Sx#+1
Sy#=0
EndIf

If P\Frame%=2 Then Sy#=Sy#+1:Sx#=0
If P\Frame%=3 Then Sy#=Sy#-1:Sx#=0
If P\Frame%=1 Then Sy#=0:Sx#=Sx#-1
If P\Frame%=0 Then Sy#=0:Sx#=Sx#+1

P\X#=P\X#+SX#
P\Y#=P\Y#+SY#

DrawImage P\Img,P\X#,P\Y#,P\Frame%
Next
End Function

;Function to load HUD
Function Load_HUD()
For P.Player = Each Player
P\Hud=LoadImage("HUD.png")
Next
End Function

;Function to draw HUD
Function Draw_Hud()
For P.Player=Each Player
DrawImage P\HUD,0,0
Color 1,1,1
Text 55,18,P\Lives%
Text 90,18,P\Score%
Next
End Function

;Functions for surrounding border
Function Load_Surround()
SUR=LoadImage("Dec.png")
End Function

Function Draw_Surround()
DrawImage SUR,0,50
End Function

;food
Type Food
Field Img
Field X#,Y#
End Type

Function Create_Food(X#,Y#)
F.Food = New Food
F\Img = LoadImage("Food.png")
F\X# = X#
F\Y# = Y#
End Function

Function Update_Food()
For F.Food = Each Food
	For P.Player = Each Player
DrawImage F\Img,F\X#,F\Y#

If RectsOverlap(P\X#-15,P\Y#-15,32,32,F\X#,F\Y#,7,7)
tempscore=tempscore+10
P\Score%=P\Score%+10
Delete F.Food
EndIf

If Tempscore=100 Then
P\Lives%=P\Lives%+1
tempscore=0
EndIf

	Next
Next
End Function