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

Re: Hexagonal rpg

Post by schael »

Thank you, it really helps me, I now understand the entire code. do you have a link to nolove ? I can't find it, I saw the main of adaptive invaders instead.
I'm learning...
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Hexagonal rpg

Post by linux-man »

no.love
(285.6 KiB) Downloaded 181 times
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post by schael »

Woaw :o ! Are color, fonts, graphics music and sound the objects or are they simply tables ?

Code: Select all

function love.load()

	-- Resources
	color =	 {	background = {240,243,247},
				main = {63,193,245},
			text = {76,77,78},
				overlay = {255,255,255,235} }
	font = {	default = love.graphics.newFont(24),
				large = love.graphics.newFont(32),
				huge = love.graphics.newFont(72),
				small = love.graphics.newFont(22) }
	graphics = {logo = love.graphics.newImage("media/logo.png"),
				fmas = love.graphics.newImage("media/fmas.png"),
				set = love.graphics.newImage("media/set.png"),
				notset = love.graphics.newImage("media/notset.png") }
	music =	{	default = love.audio.newSource("media/sawng.ogg") }
	sound =	{	click = love.audio.newSource("media/click.ogg", "static"),
				shush = love.audio.newSource("media/shh.ogg", "static"),
				pling = love.audio.newSource("media/pling.ogg", "static") }
	
	-- Variables
	size = 6				-- size of the grid
	audio = true			-- whether audio should be on or off
	state = Menu.create()	-- current game state
	
	-- Setup
	love.graphics.setBackgroundColor(unpack(color["background"]))
	love.audio.play(music["default"], 0)

end
I'm learning...
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hexagonal rpg

Post by Kadoba »

All data structures in lua are tables. If you ever see someone mention objects in lua they are simply tables that behave like objects, which is less confusing than it sounds.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Hexagonal rpg

Post by Robin »

Functions in the form of love.x.newY (for example love.graphics.newImage), return userdata, which is not the same as a table.
Help us help you: attach a .love.
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Hexagonal rpg

Post by linux-man »

Just open lua/states.lua and lua/button.lua and see how Menu, Instructions and other tables are created. You are looking at tables with functions connected to events: Objects!
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post by schael »

I thing that I will go to read more tutorials than only callback functions before continue this project...
In particular about tile-based scrolling because i want tu us it in this game.
I'm learning...
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Hexagonal rpg

Post by T-Bone »

Jasoco wrote:I also have neither an AZERTY keyboard or a number pad. Please implement Arrow keys and WSAD. (Both. Not just one.)
linux-man
Citizen
Posts: 67
Joined: Thu Apr 28, 2011 4:51 pm

Re: Hexagonal rpg

Post by linux-man »

Just to help a little your conversion, here is the Hexagonal code (this time only for cursor keys), and the same code in a OOP way.

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.update(dt)
	local v
	if dx == 0 and dy == 0 then
		if love.keyboard.isDown('left') and love.keyboard.isDown('up') then
			dx, dy = -1, -1
		elseif love.keyboard.isDown('left') and love.keyboard.isDown('down') then
			dx, dy = -1,  1
		elseif love.keyboard.isDown('right') and love.keyboard.isDown('up') then
			dx, dy =  1, -1
		elseif love.keyboard.isDown('right') and love.keyboard.isDown('down') then
			dx, dy =  1,  1
		elseif love.keyboard.isDown('left') then
			dx, dy = -2,  0
		elseif love.keyboard.isDown('right') then
			dx, dy =  2,  0
		end
		x, y = x + dx, y + dy
	end
	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

Code: Select all

function love.load()
	CelluleHexagonale = love.graphics.newImage("hexagone.png")
	love.graphics.setBackgroundColor(131,192,240)
	font = love.graphics.newFont(8)
	love.graphics.setFont(font)
	player = object:create()
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
	player:draw()
end

function love.update(dt)
	player:update(dt)
end

object = {}
object.__index = object
function object.create()
	local temp = {}
	setmetatable(temp, object)
	temp.x, temp.y = 0, 0
	temp.dx, temp.dy = 0, 0
	temp.link = love.graphics.newImage("link.png")
	return temp
end
function object:update(dt)
	local v
	if self.dx == 0 and self.dy == 0 then
		if love.keyboard.isDown('left') and love.keyboard.isDown('up') then
			self.dx, self.dy = -1, -1
		elseif love.keyboard.isDown('left') and love.keyboard.isDown('down') then
			self.dx, self.dy = -1,  1
		elseif love.keyboard.isDown('right') and love.keyboard.isDown('up') then
			self.dx, self.dy =  1, -1
		elseif love.keyboard.isDown('right') and love.keyboard.isDown('down') then
			self.dx, self.dy =  1,  1
		elseif love.keyboard.isDown('left') then
			self.dx, self.dy = -2,  0
		elseif love.keyboard.isDown('right') then
			self.dx, self.dy =  2,  0
		end
		self.x, self.y = self.x + self.dx, self.y + self.dy
	end
	if self.dy == 0 then v = 2 else v = 1 end
	if self.dx > 0 then self.dx = self.dx - dt * v
	elseif self.dx < 0 then self.dx = self.dx + dt * v
	end
	if self.dy > 0 then self.dy = self.dy - dt
	elseif self.dy < 0 then self.dy = self.dy + dt
	end
	if math.abs(self.dx) < dt * v then self.dx = 0 end
	if math.abs(self.dy) < dt then self.dy = 0 end
end
function object:draw()
	love.graphics.draw(self.link,(self.x - self.dx)* 16 ,(self.y - self.dy) * 24)
end
Attachments
hexagonal RPG.love
(2.82 KiB) Downloaded 102 times
User avatar
schael
Prole
Posts: 27
Joined: Mon Jul 11, 2011 5:13 pm
Location: France

Re: Hexagonal rpg

Post by schael »

Thank for the translation, I found a tutorial on C++. I red C tutorials from the same author and I think I will understand after reading this http://www.siteduzero.com/tutoriel-3-11 ... #ss_part_1.

I'm actualy adapting the example in the löve tutorials on tile scrolling for my game so I have two questions :
- Have I to use http://love2d.org/wiki/Quad:setViewport with a tileset ?
- How can I use .XML file made by Tiled map editor ?
I'm learning...
Post Reply

Who is online

Users browsing this forum: No registered users and 59 guests