Hexagonal rpg
Re: Hexagonal rpg
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...
Re: Hexagonal rpg
Woaw ! 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...
Re: Hexagonal rpg
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Hexagonal rpg
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.
Re: Hexagonal rpg
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!
Re: Hexagonal rpg
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.
In particular about tile-based scrolling because i want tu us it in this game.
I'm learning...
Re: Hexagonal rpg
Jasoco wrote:I also have neither an AZERTY keyboard or a number pad. Please implement Arrow keys and WSAD. (Both. Not just one.)
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Hexagonal rpg
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 113 times
Re: Hexagonal rpg
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 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...
Who is online
Users browsing this forum: No registered users and 3 guests