Page 1 of 3
Hexagonal rpg
Posted: Mon Jul 11, 2011 10:53 pm
by schael
Hello everyone
First, please don't mind about my bad english, I'm french .
Well ! This is my first project with Löve : I want to make a RPG with pokémon-like graphics but with one more dimension.
I never used POO languages before, only C, so
-Is my code strong and clean ?
-Is the "gameplay" intuitive for you ?
I think next release will include some obstacles.
controls are azeqsdwxc (azerty keyboard) or the numpad.
Re: Hexagonal rpg
Posted: Mon Jul 11, 2011 10:58 pm
by bartbes
I haven't looked at the source, but from what I ehm.. 'played', you sure got the grid movement down. I'd make sure you can't go off screen though. Oh, and you might want to disable the 8 and 2 keys on the numpad, as they make no sense. (Haven't played with letters because I don't have an azerty keyboard.)
EDIT: Oh, and before I forget, I suspect you mean OOP, not poo as in shit. Also, lua isn't traditionally seen as an OO language.
Re: Hexagonal rpg
Posted: Mon Jul 11, 2011 11:03 pm
by tentus
Source looks fine, very straightforward. You may want to bind Escape to quit the game.
Good luck!
Re: Hexagonal rpg
Posted: Mon Jul 11, 2011 11:22 pm
by schael
bartbes wrote:I haven't looked at the source, but from what I ehm.. 'played', you sure got the grid movement down. I'd make sure you can't go off screen though. Oh, and you might want to disable the 8 and 2 keys on the numpad, as they make no sense. (Haven't played with letters because I don't have an azerty keyboard.)
EDIT: Oh, and before I forget, I suspect you mean OOP, not poo as in shit. Also, lua isn't traditionally seen as an OO language.
I put 8, 2 and 5 key to choose more intuitive of them but I'm ok with you about them. And yes, the right acronym is OOP
Thank you Tentus, I was not sure about cleanness.
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 2:24 am
by Lafolie
I neither have a numerical pad or an azerty keyboard, so it was incredibly difficult to control for me, but you get plus points for the hex grid, which can be complicated. Loving the new programming paradigm also, heh.
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 3:49 pm
by linux-man
I played around a little with your code. See if you like it.
A good coordinate system is essential to this kind of games, so x,y (position) is printed.
To start to see how lua can be OO, study the nolove example (It was very useful to me).
Code: Select all
function love.load()
CelluleHexagonale = love.graphics.newImage("hexagone.png")
Link = love.graphics.newImage("link.png")
love.graphics.setBackgroundColor(131,192,240)
font = love.graphics.newFont(8)
love.graphics.setFont(font)
x, y = 0, 0
dx, dy = 0, 0
end
function love.draw()
for n = 0, love.graphics.getWidth() / 16 - 2 do
for m = 0, love.graphics.getHeight() / 24 - 2 do
if math.fmod(n + m, 2) == 0 then
love.graphics.draw(CelluleHexagonale ,n * 16 ,m * 24)
love.graphics.print(n..','..m,n * 16 + 8 ,m * 24 + 12)
end
end
end
love.graphics.draw(Link,(x - dx)* 16 ,(y - dy) * 24)
end
function love.keypressed(key, unicode)
if dx ~= 0 or dy ~= 0 then return end
if key == 'kp7' or key == 'q' then dx, dy = -1, -1
elseif key == 'kp4' or key == 'a' then dx, dy = -2, 0
elseif key == 'kp1' or key == 'z' then dx, dy = -1, 1
elseif key == 'kp3' or key == 'c' then dx, dy = 1, 1
elseif key == 'kp6' or key == 'd' then dx,dy = 2, 0
elseif key == 'kp9' or key == 'e' then dx, dy = 1, -1
end
x, y = x + dx, y + dy
end
function love.update(dt)
local v
if dy == 0 then v = 2 else v = 1 end
if dx > 0 then dx = dx - dt * v
elseif dx < 0 then dx = dx + dt * v
end
if dy > 0 then dy = dy - dt
elseif dy < 0 then dy = dy + dt
end
if math.abs(dx) < dt * v then dx = 0 end
if math.abs(dy) < dt then dy = 0 end
end
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 5:57 pm
by schael
You corrected al my code
thank you, it's really better (and really different).
In first time i didn't understood why some cells doesn't exist but i saw you used more columns and it will finaly be easier to use a map with.
The only strange thing is that it uses more cpu. Is it because of the text ?
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 6:03 pm
by Jasoco
I also have neither an AZERTY keyboard or a number pad. Please implement Arrow keys and WSAD. (Both. Not just one.)
Also, a hex grid is pretty easy in theory. It's just a normal grid with every other line shifted half the height of a tile then extra code for moving stuff in the two left and right directions instead of just straight left and right.
I don't have any ideas for a hex based game but have always wanted to play around with one. I already did some toying with an isometric grid. Never made anything with it, but the hardest part was translating where the tiles should be on screen and what tile the mouse was over if I moused over it.
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 7:58 pm
by schael
linux-man wrote:I played around a little with your code. See if you like it.
A good coordinate system is essential to this kind of games, so x,y (position) is printed.
To start to see how lua can be OO, study the nolove example (It was very useful to me).
Code: Select all
function love.load()
CelluleHexagonale = love.graphics.newImage("hexagone.png")
Link = love.graphics.newImage("link.png")
love.graphics.setBackgroundColor(131,192,240)
font = love.graphics.newFont(8)
love.graphics.setFont(font)
x, y = 0, 0
dx, dy = 0, 0
end
function love.draw()
for n = 0, love.graphics.getWidth() / 16 - 2 do
for m = 0, love.graphics.getHeight() / 24 - 2 do
if math.fmod(n + m, 2) == 0 then
love.graphics.draw(CelluleHexagonale ,n * 16 ,m * 24)
love.graphics.print(n..','..m,n * 16 + 8 ,m * 24 + 12)
end
end
end
love.graphics.draw(Link,(x - dx)* 16 ,(y - dy) * 24)
end
function love.keypressed(key, unicode)
if dx ~= 0 or dy ~= 0 then return end
if key == 'kp7' or key == 'q' then dx, dy = -1, -1
elseif key == 'kp4' or key == 'a' then dx, dy = -2, 0
elseif key == 'kp1' or key == 'z' then dx, dy = -1, 1
elseif key == 'kp3' or key == 'c' then dx, dy = 1, 1
elseif key == 'kp6' or key == 'd' then dx,dy = 2, 0
elseif key == 'kp9' or key == 'e' then dx, dy = 1, -1
end
x, y = x + dx, y + dy
end
function love.update(dt)
local v
if dy == 0 then v = 2 else v = 1 end
if dx > 0 then dx = dx - dt * v
elseif dx < 0 then dx = dx + dt * v
end
if dy > 0 then dy = dy - dt
elseif dy < 0 then dy = dy + dt
end
if math.abs(dx) < dt * v then dx = 0 end
if math.abs(dy) < dt then dy = 0 end
end
I don't understand in your code what are dx and dy and n and m
EDIT : I just understand that n and m are x and y coordinates of a cell in the grid
Re: Hexagonal rpg
Posted: Tue Jul 12, 2011 9:09 pm
by linux-man
Code: Select all
function love.load()
CelluleHexagonale = love.graphics.newImage("hexagone.png")
Link = love.graphics.newImage("link.png")
love.graphics.setBackgroundColor(131,192,240)
font = love.graphics.newFont(8)
love.graphics.setFont(font)
x, y = 0, 0 --initializing global variables
dx, dy = 0, 0
end
function love.draw()
for n = 0, love.graphics.getWidth() / 16 - 2 do
for m = 0, love.graphics.getHeight() / 24 - 2 do
if math.fmod(n + m, 2) == 0 then
-- a cell exists only when n + m is even, for example: (0, 0), (1, 1), (2, 0)
--This definition is not the only solution but is important to simplify the movement.
--if you want to go down-right you move (+1, +1). To jump right you move (2, 0)
love.graphics.draw(CelluleHexagonale ,n * 16 ,m * 24)
love.graphics.print(n..','..m,n * 16 + 8 ,m * 24 + 12)
end
end
end
love.graphics.draw(Link,(x - dx)* 16 ,(y - dy) * 24)
end
function love.keypressed(key, unicode)
if dx ~= 0 or dy ~= 0 then return end
if key == 'kp7' or key == 'q' then dx, dy = -1, -1
elseif key == 'kp4' or key == 'a' then dx, dy = -2, 0
elseif key == 'kp1' or key == 'z' then dx, dy = -1, 1
elseif key == 'kp3' or key == 'c' then dx, dy = 1, 1
elseif key == 'kp6' or key == 'd' then dx,dy = 2, 0
elseif key == 'kp9' or key == 'e' then dx, dy = 1, -1
end
x, y = x + dx, y + dy
-- dx and dy. Think of them as deltaX and deltaY (damn math!). They are the jump coordinates.
-- Now pay attention: If you delete love.update and do dx, dy = 0, 0 here (or remove them from love.graphics.draw(Link)) your player simply jump between cells.
--Instead, x and y are updated to the final position, but love.graphics.draw(Link) uses x-dx, y-dy. dx and dy are changed in love.update
end
function love.update(dt) --to make the player move between cells, dx and dy are decremented each step of update until = 0
local v
if dy == 0 then v = 2 else v = 1 end -- when jumping on x only player must move 2x faster.
if dx > 0 then dx = dx - dt * v
elseif dx < 0 then dx = dx + dt * v
end
if dy > 0 then dy = dy - dt
elseif dy < 0 then dy = dy + dt
end
if math.abs(dx) < dt * v then dx = 0 end
if math.abs(dy) < dt then dy = 0 end
end
To use permanent keypresses, you should change the key code to love.update.
Hope I could help with the comments.