Pacman Game

BlitzPlus Forums/BlitzPlus Beginners Area/Pacman Game

I've been trying to program a Pacman game but can't figure out how to get the small yellow dot to delete once pacman eats it (collides). I know I obiously need the "Delete" Command but I need a NewType for that. I know what types are and what a newtype is but don't know how to incorperate it into the situation. Any help would be most appriciated.

Well, you should make your dots into a type. For instance,

type food
   field x,y
end type

for f=1 to 100  ;make 100 foods
  dot.food=new food
next


Then, when it collides, just use DELETE dot.

hmm, thanks. I'll look into this.

This didn't seem to work, B+ is asking that dot be a NewType.
But I can probably fix this.

No, it's still saying it's a non-Newtype...

Type TypSmallBit
Field x#,y#
End Type

Function CreateSmallBits()
For f = 1 To 100
	SMbit.TypSmallBit = New TypSmallBit
	Next
End Function

Function UpdateCollision() 
For SMbit.TypSmallBit = Each TypSmallBit
Next
If ImagesCollide (imgplayerR,x,y,0,smallbit,bitx,bity,0)
	p1score = p1score + 10
	Delete TypSmallBit ;problem is here
End If

End Function


Why is you maze not just in an array? surely that's the simpler solution, and forget about using images collide, simply go by the snapped location of the pacman?

ie
Dim Maze(9)
Maze(0) = "XXXXXXXXX"
Maze(1) = "X.......X"
Maze(2) = "X.X.XXXXX" etc etc


Then if your pacman is say 32x32 then just take the x,y pos take away the offset of where the maze is onscreen and divide by 32.

Anyway... That's how I'd do it..

Ok, well in your code, your next needs to be after all of the collision checking, not before.

That way the program knows to handle ALL SMbit's, and then delete the one when there is a collision.

Yeah, but now it says "Next without For." ????????

OK... Just knocked this together to demonstrate my point:

You'll need:


Graphics 512,512,32,2

Data "MMGCCCCCCCCCCCCFGCCCCCCCCCCCCFMM"
Data "MMK............JK............JMM"
Data "MMK.ABBD.ABBBD.JK.ABBBD.ABBD.JMM"
Data "MMKOJMMK.JMMMK.JK.JMMMK.JMMKOJMM"
Data "MMK.ECCH.ECCCH.EH.ECCCH.ECCH.JMM"
Data "MMK..........................JMM"
Data "MMK.ABBD.AD.ABBBBBBD.AD.ABBD.JMM"
Data "MMK.ECCH.JK.ECCFGCCH.JK.ECCH.JMM"
Data "MMK......JK....JK....JK......JMM"
Data "MMLBBBBD.JLBBD.JK.ABBIK.ABBBBIMM"
Data "MMMMMMMK.JGCCH.EH.ECCFK.JMMMMMMM"
Data "MMMMMMMK.JK..........JK.JMMMMMMM"
Data "MMMMMMMK.JK.ABD  ABD.JK.JMMMMMMM"
Data "MMMCCCCH.EH.JGH  EFK.EH.ECCCCMMM"
Data "MMM     ....JK    JK....     MMM"
Data "MMMBBBBD.AD.JLBBBBIK.AD.ABBBBMMM"
Data "MMMMMMMK.JK.ECCCCCCH.JK.JMMMMMMM"
Data "MMMMMMMK.JK..........JK.JMMMMMMM"
Data "MMMMMMMK.JK.ABBBBBBD.JK.JMMMMMMM"
Data "MMGCCCCH.EH.ECCFGCCH.EH.ECCCCFMM"
Data "MMK............JK............JMM"
Data "MMK.ABBD.ABBBD.JK.ABBBD.ABBD.JMM"
Data "MMK.ECFK.ECCCH.EH.ECCCH.JGCH.JMM"
Data "MMKO..JK................JK..OJMM"
Data "MMLBD.JK.AD.ABBBBBBD.AD.JK.ABIMM"
Data "MMGCH.EH.JK.ECCFGCCH.JK.EH.ECFMM"
Data "MMK......JK....JK....JK......JMM"
Data "MMK.ABBBBILBBD.JK.ABBILBBBBD.JMM"
Data "MMK.ECCCCCCCCH.EH.ECCCCCCCCH.JMM"
Data "MMK..........................JMM"
Data "MMLBBBBBBBBBBBBBBBBBBBBBBBBBBIMM"

Img_Maze = LoadAnimImage("Maze.png",16,16,0,16)
Img_PacMan = LoadAnimImage("PacMan.png",32,32,0,16)
MaskImage Img_PacMan,58,37,75

Dim Maze(31,30)


For y=0 To 30
	Read m$

	For x=0 To 31
		Maze(x,y) = Asc(Mid(m$,x+1,1))
	Next
Next

px = 248
py = 368
d = 0
f = 0
fd = 1
fdel = 1

SetBuffer BackBuffer()

Repeat

	;Draw Maze
	For x=0 To 31
	For y=0 To 30
		T$ = Chr(maze(x,y))
		Tile = maze(x,y) - 65
		
		If T = " " Then DrawBlock Img_Maze,x*16,y*16,13
		If T = "." Then DrawBlock Img_Maze,x*16,y*16,14
		If T = "O" Then DrawBlock Img_Maze,x*16,y*16,15
		If Tile >= 0 And Tile <= 12 Then DrawBlock Img_Maze,x*16,y*16,Tile
		
	Next
	Next
	
	; Draw Pacman
	DrawImage Img_PacMan,px-8,py-8,(d*4)+f
	
	; Animation
	fdel = (fdel + 1) Mod 2
	If fdel = 0 Then f = f + fd
	If f = 3 And fd= 1 Then fd = -1
	If f = 0 And fd = -1 Then fd = 1
	
	; Control
	If KeyDown(205) Then d = 0
	If KeyDown(200) Then d = 3
	If KeyDown(208) Then d = 1
	If KeyDown(203) Then d = 2
	
	; Movement
	opx = px
	opy = py
	If d = 0 Then px = px + 1
	If d = 1 Then py = py + 1
	If d = 2 Then px = px - 1
	If d = 3 Then py = py - 1
	
	x = (px+8) / 16
	y = (py+8) / 16
	Current$ = Chr(maze(x,y))
	
	; Collision
	If Current <> "." And Current <> " " And Current <> "O" Then
		px = opx
		py = opy
	EndIf
	
	
	; Pill Eaten
	If Current ="." Then maze(x,y) = 32
	
	; Power Pill!
	If Current ="O" Then
		; OOOoooohh!
	EndIf
	
Flip
Until KeyHit(1)


this method is also handy in gauntlet clones
i myself would use 0-255 (well the hex equivelant) to define objects
00 in hex = floor FF wall
that then gives you 254 other values for bits inbetween
(optional) player start point (which is also a floor tile when not the start)
exit
monster a start points (also a floor tile when it moves)
monster b " " " "
monster c " " " "
monster d " " " "
monster a generator (and perhaps levels of degredation)
monster b generator etc
food
potions
heal packs

afaik in the olden days levels were kinda layed out like this, simple random looking chunks of ascii that the game understood as destructable wall

i doubt youd ever need to fill all 256 options, without counting i dont think gauntlet needed more than 32

edit:
im defining monster and hero starting squares in the maze data but you could have
level layer
object layer
monster layer
but i find it easier not to worry about a monster being one grid out and finding itself on a wall ;)

OK, neither of your posts really answered my questions... maybe I'm not reading carfully enough, but all I want to know is what's wrong with the code I provided and a straight out answer what I can do to delete the dot instead of all of this elaborate stuff you're giving me.

When I put NEXT just before END FUNCTION I don't get any error... but another issue is that you want to address is that you want to use "DELETE SMbit" because you're deleting that specific item of the type, not the type itself.

Hopefully that helps a bit.

All right, it's not even drawing the bit now...

OK, neither of your posts really answered my questions.
I've not answered your question because the way you're going about doing a pac man game in my opinion is seriously flawed and massively ineffeciant. I have given you an example of how to create a pac man game which is far from elaborate.

If you want to know about types and handling them then don't mention pac man, just ask a specific types question.

try this

Delete SMbit.TypSmallBit


I program in b3d but I would assume this would still work.

Well then someone coulda said something about how flawed my method is... however I'm not angry at you Rob. Thanks for showing me this code, I just didn't bother to look at it since I was too fustrated at the time. Thanks for providing me with the engine. :) :) :)