Hexagonal rpg

Show off your games, demos and other (playable) creations.
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Hexagonal rpg

Post by schael »

Hello everyone
First, please don't mind about my bad english, I'm french :3.

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.
Attachments
hexagonal RPG.love
V0.1a
(2.82 KiB) Downloaded 470 times
I'm learning...
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Hexagonal rpg

Post 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.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Hexagonal rpg

Post by tentus »

Source looks fine, very straightforward. You may want to bind Escape to quit the game.

Good luck!
Kurosuke needs beta testers
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post 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.
I'm learning...
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Hexagonal rpg

Post 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.
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.
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Hexagonal rpg

Post 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
Attachments
hexagonal RPG.love
(2.72 KiB) Downloaded 233 times
Last edited by linux-man on Tue Jul 12, 2011 6:14 pm, edited 1 time in total.
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post by schael »

You corrected al my code :shock: 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.
:crazy:
The only strange thing is that it uses more cpu. Is it because of the text ?
I'm learning...
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Hexagonal rpg

Post 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.
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post 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 :crazy:
I'm learning...
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Hexagonal rpg

Post 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.
Post Reply

Who is online

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