Re: Hexagonal rpg
Posted: Wed Jul 13, 2011 10:17 am
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.
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
Jasoco wrote:I also have neither an AZERTY keyboard or a number pad. Please implement Arrow keys and WSAD. (Both. Not just one.)
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