Game Like Pacman

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
en_ef
Prole
Posts: 4
Joined: Wed Oct 19, 2011 4:36 am
Location: Jakarta, Indonesia
Contact:

Game Like Pacman

Post by en_ef »

Hy all.
I want to make a game like a pacman. I can't make collision with wall, my hero always stop if collision with wall and can't moving again. But my hero work finely if collision with coin. Any idea?
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Game Like Pacman

Post by Taehl »

My first guess would be that you're penetrating the wall - you're moving inside it (probably so little you can't see it). And since you're now inside it, your collision detection algorithm is reporting a collision every frame, so you can't move along or back out of it. To fix that, you need to make sure your Pacman is "pushed back out" of the wall when you collide with it.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
en_ef
Prole
Posts: 4
Joined: Wed Oct 19, 2011 4:36 am
Location: Jakarta, Indonesia
Contact:

Re: Game Like Pacman

Post by en_ef »

can you give me an example?
can i do it if i don't use "Physics" function?
I just use "graphics" function for make this game.

thanks.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Game Like Pacman

Post by coffee »

Somewhat off-topic. Just for fun and "inspiration" :)
http://www.royal-paw.com/games/netpack/
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Game Like Pacman

Post by Taehl »

You have to post your .love before I can tell you how to fix it.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Game Like Pacman

Post by Jasoco »

So many people are trying to make Pac-Man. A game that looks like Pac-Man is easy to make. A game that functions exactly like Pac-Man however, is not as easy.

I'll leave this here for your future use...
http://home.comcast.net/~jpittman2/pacm ... ssier.html
User avatar
en_ef
Prole
Posts: 4
Joined: Wed Oct 19, 2011 4:36 am
Location: Jakarta, Indonesia
Contact:

Re: Game Like Pacman

Post by en_ef »

this is my .love
JeblehMan.love
(11.46 KiB) Downloaded 381 times
thanks for all.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Game Like Pacman

Post by Taehl »

Alright, reviewing your code:

- First off, note that Pacman didn't use free movement, rather, it had a tile-based movement system. A free movement system like yours is fine, though. My primary warning would be to make sure it's easy to move the jebleh through "doorway" formations (and not get stuck on the blok corners)
- Part of your collision oddity is due to you using circular collision (checking only the distance between objects) on a grid-based world. The other part is due to the distance you move the jebleh when you touched a wall. The distance you should move back it is half of the size of jebleh plus half of the size of a blok.
- Here's revised collision code which works much more like what you're looking for. Simply replace what you have with this. It's a little bit odd still, but that's due to things like how you draw your graphics off-center. It's fixable with some number tweaking.

Code: Select all

if love.keyboard.isDown('up') then
	fungsijebleh.Posisi.y = fungsijebleh.Posisi.y - jeblehspeed * dt
	if fungsijebleh.Posisi.y < 25 then
		fungsijebleh.Posisi.y = 25
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.y = b.y + as + bs
		end
	end
end
if love.keyboard.isDown('down') then
	fungsijebleh.Posisi.y = fungsijebleh.Posisi.y + jeblehspeed * dt
	if fungsijebleh.Posisi.y > height - 35 then
		fungsijebleh.Posisi.y = height - 35 
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.y = b.y - as - bs
		end
	end
end	
if love.keyboard.isDown('left') then
	fungsijebleh.Posisi.x = fungsijebleh.Posisi.x - jeblehspeed * dt
	if fungsijebleh.Posisi.x < 25 then
		fungsijebleh.Posisi.x = 25
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.x = b.x + as + bs
		end
	end
end
if love.keyboard.isDown('right') then
	fungsijebleh.Posisi.x = fungsijebleh.Posisi.x + jeblehspeed * dt
	if fungsijebleh.Posisi.x > width - 35 then
		fungsijebleh.Posisi.x = width - 35
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.x = b.x - as - bs
		end
	end
end
PS) Indonesian? Your English is pretty good. Not perfect, but quite understandable.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
en_ef
Prole
Posts: 4
Joined: Wed Oct 19, 2011 4:36 am
Location: Jakarta, Indonesia
Contact:

Re: Game Like Pacman

Post by en_ef »

Taehl wrote:Alright, reviewing your code:

- First off, note that Pacman didn't use free movement, rather, it had a tile-based movement system. A free movement system like yours is fine, though. My primary warning would be to make sure it's easy to move the jebleh through "doorway" formations (and not get stuck on the blok corners)
- Part of your collision oddity is due to you using circular collision (checking only the distance between objects) on a grid-based world. The other part is due to the distance you move the jebleh when you touched a wall. The distance you should move back it is half of the size of jebleh plus half of the size of a blok.
- Here's revised collision code which works much more like what you're looking for. Simply replace what you have with this. It's a little bit odd still, but that's due to things like how you draw your graphics off-center. It's fixable with some number tweaking.

Code: Select all

if love.keyboard.isDown('up') then
	fungsijebleh.Posisi.y = fungsijebleh.Posisi.y - jeblehspeed * dt
	if fungsijebleh.Posisi.y < 25 then
		fungsijebleh.Posisi.y = 25
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.y = b.y + as + bs
		end
	end
end
if love.keyboard.isDown('down') then
	fungsijebleh.Posisi.y = fungsijebleh.Posisi.y + jeblehspeed * dt
	if fungsijebleh.Posisi.y > height - 35 then
		fungsijebleh.Posisi.y = height - 35 
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.y = b.y - as - bs
		end
	end
end	
if love.keyboard.isDown('left') then
	fungsijebleh.Posisi.x = fungsijebleh.Posisi.x - jeblehspeed * dt
	if fungsijebleh.Posisi.x < 25 then
		fungsijebleh.Posisi.x = 25
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.x = b.x + as + bs
		end
	end
end
if love.keyboard.isDown('right') then
	fungsijebleh.Posisi.x = fungsijebleh.Posisi.x + jeblehspeed * dt
	if fungsijebleh.Posisi.x > width - 35 then
		fungsijebleh.Posisi.x = width - 35
	end
	for z,i in pairs(fungsiblok) do
		local a,b,as,bs = fungsijebleh.Posisi, i.Posisi, jeblehsize/2, bloksize/2
		if a.x-as < b.x+bs and a.x+as > b.x-bs and a.y-as < b.y+bs and a.y+as > b.y-bs then
			fungsijebleh.Posisi.x = b.x - as - bs
		end
	end
end
PS) Indonesian? Your English is pretty good. Not perfect, but quite understandable.

Hey it's work. thanks Taehl.

Nice to have shared with you.

It's first time i used Lua and Love Emulator, and maybe i love it. LOL

Oh yeah i'm Indonesian. I'm so sorry about my English. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests