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.
Hexagonal rpg
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Hexagonal rpg
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.
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.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Hexagonal rpg
Source looks fine, very straightforward. You may want to bind Escape to quit the game.
Good luck!
Good luck!
Kurosuke needs beta testers
Re: Hexagonal rpg
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 OOPbartbes 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.
Thank you Tentus, I was not sure about cleanness.
I'm learning...
Re: Hexagonal rpg
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.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Re: Hexagonal rpg
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).
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
- Attachments
-
- hexagonal RPG.love
- (2.72 KiB) Downloaded 307 times
Last edited by linux-man on Tue Jul 12, 2011 6:14 pm, edited 1 time in total.
Re: Hexagonal rpg
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 ?
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 ?
I'm learning...
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Hexagonal rpg
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.
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
I don't understand in your code what are dx and dy and n and mlinux-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
EDIT : I just understand that n and m are x and y coordinates of a cell in the grid
I'm learning...
Re: Hexagonal rpg
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
Hope I could help with the comments.
Who is online
Users browsing this forum: No registered users and 1 guest