Page 2 of 2
Re: Question
Posted: Fri Oct 21, 2011 5:57 pm
by kikito
You must transform your main.lua a bit; this is the simplest thing you can do:
Code: Select all
-- main.lua
require('pacman')
function love.load()
loadPacman()
end
function love.update(dt)
updatePacman(dt)
end
function love.draw()
drawPacman()
end
And, inside pacman.lua, you only define pacman stuff; just rename the love.load, love.update and love.draw functions there with loadPacman, updatePacman & drawPacman
Code: Select all
-- pacman.lua
function loadPacman()
... -- same as before
end
function updatePacman(dt)
... -- same as before
end
function drawPacman()
... -- same as before
end
Once you have this, you can more or less easily extend it; you can have a ghosts.lua file with loadGhosts, updateGhosts and drawGhosts functions, and add them to main.lua, right after loadPacman, updatePacman and drawPacman.
Re: Question
Posted: Fri Oct 21, 2011 6:07 pm
by Acnesium
Jasoco wrote:Of course! Don't put multiple love.***() functions. You're going about it wrong. Instead, put the love.***() functions in main.lua and call the other individual update, draw, load functions with different names, from the originals.
Ah! now i get it, Thank you very much!
Re: Question
Posted: Sat Oct 22, 2011 5:44 pm
by Acnesium
Hello,
I am in kinda trouble. I want to create a menu, map, enemies and I want to have pacman move to the right automatically when I press Right.
However this is kinda of a big deal to ask to you guys, so do you guys know some sort of site or tutorials where I could find this kind of stuff. I already looked through the wiki and searched around the forums (still doing) but I don't seem to be finding anything.
Thanks anyway!
Re: Question
Posted: Sat Oct 22, 2011 6:31 pm
by Robin
You'll need to use the callback
love.keypressed or the function
love.keyboard.isDown for things like that.
Example usage:
Code: Select all
function love.keypressed(key)
if key == 'right' then
--move pacman right
end
end
Code: Select all
function love.update(dt)
if love.keyboard.isDown('right') then
--move pacman right
end
end
Re: Question
Posted: Sun Oct 23, 2011 10:56 am
by Acnesium
Robin wrote: SNIP
Yes, but I can't seem to figure out how I get the original pacman movement like this one:
http://www.pacman.nl/pacman.html.
This is what I got at the moment:
Code: Select all
function playerLoad()
playerUp = love.graphics.newImage("images/pacmanUp.png")
playerDown = love.graphics.newImage("images/pacmanDown.png")
playerRight = love.graphics.newImage("images/pacmanRight.png")
playerLeft = love.graphics.newImage("images/pacmanLeft.png")
player = {
animUp = newAnimation(playerUp, 32, 32, 0.1, 2);
animDown = newAnimation(playerDown, 32, 32, 0.1, 2);
animRight = newAnimation(playerRight, 32, 32, 0.1, 2);
animLeft = newAnimation(playerLeft, 32, 32, 0.1, 2);
x = 256;
y = 256;
s = 100;
}
playerAnim = player.animUp
dt = love.timer.getDelta()
end
function goUp(dt)
if player.y >= 0 then
player.y = player.y - (player.s * dt)
playerAnim = player.animUp
playerAnim:update(dt)
end
end
function playerUpdate(dt)
if love.keyboard.isDown("up") then
goUp(dt)
end
end
function playerDraw()
playerAnim:draw(player.x, player.y)
end
Thanks.
Re: Question
Posted: Sun Oct 23, 2011 3:34 pm
by Robin
The way you do that is you remember the direction pacman is going (that is, put it in a variable).
You change that variable only on a keypress (and when there is a collision).
Re: Question
Posted: Sun Oct 23, 2011 4:48 pm
by Jasoco
Pac-Man is complicated, but easy to figure out. I has been completely documented in how it works in the
Pac-Man Dossier.
I used that page to create my own clone of Pac-Man that works about 90% like the original complete with ghost AI. You can have this code to check out. Mind it's a few months old and I've learned new Lua tricks since then so it may not look optimized. In fact I haven't even looked at the code in months so...
- Pac-Man.love
- wokka wokka wokka wokka
- (7.32 KiB) Downloaded 107 times
The main things I didn't implement are collisions to kill, levels, score and "corner cutting". (You'll read about it in the Dossier. It's very integral to mastering the game. If you can't get cutting in, you fail! FAIL!! MUAHAHAHAHA!!!!! Fail.) And because of that, I do not suggest you use this code at all. Rather learn SOME things from it. It's buggy and not accurate 100%. Only 90%. Also, this was before I learned how to use framebuffers to scale the graphics so sorry for the 1:1 scale of pixels. Man, CRT's were low resolution back then.
READ THE DOSSIER!
Edit: Looking back, it's about 10 months old. Man, where did this year go? I made this in December! I had recently broken up with my girlfriend and was feeling good so I was able to concentrate.
Re: Question
Posted: Sun Oct 23, 2011 5:33 pm
by Acnesium
Jasoco wrote:--SNIP--
Thats awesome! I will definitely use this. Thanks you!
Re: Question
Posted: Sat Nov 26, 2011 10:39 pm
by McClane
I had a problem with the require command but people at #love helped me out
The problem was that the name of the "file.lua" can't be upper case.
Thanks!