Ajout des derniers développement #1

Merged
kazhnuz merged 68 commits from chronicles-cbs into master 2020-08-02 11:14:18 +02:00
3 changed files with 69 additions and 131 deletions
Showing only changes of commit 1ec185cc3a - Show all commits

View file

@ -1,24 +1,26 @@
local Map = Object:extend() local ParallaxBackground = Object:extend()
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local HEIGHT = 5 function ParallaxBackground:new(scene, height, bottomBorder, type)
local BOTTOM_BORDER = 1 self.scene = scene
self.assets = self.scene.assets
function Map:new(world, type, terrain)
self.world = world
self.assets = self.world.assets
self.scene = self.world.scene
self.datas = {} self.datas = {}
self.datas.type = type or "forest" self.datas.type = type or "forest"
self.height = height
self.bottomBorder = bottomBorder
local zones = require "datas.gamedata.maps.shoot.zones" local zones = require "datas.gamedata.maps.shoot.zones"
local datas = zones[self.datas.type] local datas = zones[self.datas.type]
self.datas.background = datas.background self.datas.background = datas.background
self.datas.tiles = datas.tiles self.datas.tiles = datas.tiles
self.datas.borders = datas.borders self.datas.borders = datas.borders
self.assets:addTileset("normaltiles", "assets/backgrounds/normaltile")
self.assets:addTileset("borders", "assets/backgrounds/borders")
local backpath = "assets/backgrounds/parallax/" .. self.datas.background local backpath = "assets/backgrounds/parallax/" .. self.datas.background
self.assets:addImage("back1", backpath .. "-back.png") self.assets:addImage("back1", backpath .. "-back.png")
self.assets:addImage("back2", backpath .. "-fore.png") self.assets:addImage("back2", backpath .. "-fore.png")
@ -31,27 +33,27 @@ end
-- GET FUNCTIONS -- GET FUNCTIONS
-- Get information from the map -- Get information from the map
function Map:getTotalHeight() function ParallaxBackground:getTotalHeight()
return HEIGHT + BOTTOM_BORDER; return self.height + self.bottomBorder;
end end
function Map:getTerrain(x, y) function ParallaxBackground:getTerrain(x, y)
if (y <= HEIGHT) then if (y <= self.height) then
return 0 return 0
else else
return nil return nil
end end
end end
function Map:isInGrid(x, y) function ParallaxBackground:isInGrid(x, y)
return ( self:getTerrain(x, y) ~= nil ) return ( self:getTerrain(x, y) ~= nil )
end end
function Map:getStartY() function ParallaxBackground:getStartY()
return 240 - (self:getTotalHeight() * 20) - 10 return 240 - (self:getTotalHeight() * 20) - 10
end end
function Map:gridToPixel(x, y, center) function ParallaxBackground:gridToPixel(x, y, center)
local pixelx, pixely local pixelx, pixely
local center = center or false local center = center or false
local x, y = x, y local x, y = x, y
@ -70,7 +72,7 @@ end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- Draw the battle map -- Draw the battle map
function Map:generateFloor(tile) function ParallaxBackground:generateFloor(tile)
local canvas = love.graphics.newCanvas(31*16, self:getTotalHeight() * 20) local canvas = love.graphics.newCanvas(31*16, self:getTotalHeight() * 20)
local tile = tile or 1 local tile = tile or 1
@ -99,14 +101,24 @@ function Map:generateFloor(tile)
return texture return texture
end end
function ParallaxBackground:draw()
function Map:draw() self:drawParallax(0, -self:getStartY(), 424, 240)
self:drawBackgrounds()
self:drawBorders()
love.graphics.draw(self.texture.floor, maputils.CONST.STARTX, self:getStartY())
end end
function Map:drawBackgrounds() function ParallaxBackground:drawParallax(x, y, w, h)
self:drawBackground(x, y, w, h)
self:drawForeground(x, y, w, h)
--love.graphics.draw(self.texture.floor, maputils.CONST.STARTX, self:getStartY())
local w2, _ = self.texture.floor:getDimensions()
for i=1, 2 do
local x2 = x % w2
love.graphics.draw(self.texture.floor, ((i-1)*31*16)-x2, -y)
end
self:drawBorders(x, y, w, h)
end
function ParallaxBackground:drawBackgrounds()
local w, _ = core.screen:getDimensions() local w, _ = core.screen:getDimensions()
local w2, h2 = self.assets.images["back1"]:getDimensions() local w2, h2 = self.assets.images["back1"]:getDimensions()
@ -123,12 +135,31 @@ function Map:drawBackgrounds()
end end
function Map:drawBorders() function ParallaxBackground:drawBackground(x, y, w, h)
local border = self.datas.borders + 1 local w2, h2 = self.assets.images["back1"]:getDimensions()
for i=1, 7 do local imax = math.ceil(w / w2) + 1
self.assets.tileset["borders"]:drawTile(border, (i-1)*80, self:getStartY()-10 , 0, 1, 1) for i=1, imax do
self.assets.tileset["borders"]:drawTile(border, (i-1)*80, 240-10, 0, 1, 1) local x1 = (x / 5) % w2
self.assets.images["back1"]:draw((i-1)*w2 - x1, 0, 0, 1, 1, 0, 0)
end end
end end
return Map function ParallaxBackground:drawForeground(x, y, w, h)
local w2, h2 = self.assets.images["back2"]:getDimensions()
local imax = math.ceil(w / w2) + 1
for i=1, imax do
local x1 = (x / 2) % w2
self.assets.images["back2"]:draw((i-1)*w2 - x1, -y, 0, 1, 1, 0, h2)
end
end
function ParallaxBackground:drawBorders(x, y)
local border = self.datas.borders + 1
for i=1, 7 do
local x2 = x % 80
self.assets.tileset["borders"]:drawTile(border, (i-1)*80 - x2, -y, 0, 1, 1, 0, 10)
self.assets.tileset["borders"]:drawTile(border, (i-1)*80 - x2, -(y-self:getTotalHeight()*20), 0, 1, 1)
end
end
return ParallaxBackground

View file

@ -5,12 +5,14 @@ local TILESIZE = 31
local TESTZONE = "forest" local TESTZONE = "forest"
local zoneDatas = require "datas.gamedata.maps.shoot.zones" local zoneDatas = require "datas.gamedata.maps.shoot.zones"
local Background = require "game.modules.drawing.parallaxBackground"
function ShootMap:new(world, maptype, mapname) function ShootMap:new(world, maptype, mapname)
ShootMap.super.new(self, world) ShootMap.super.new(self, world)
self:setPadding(0, 0, 0, 0) self:setPadding(0, 0, 0, 0)
self:generateTextures(2, "tunnel") self.parallaxBackground = Background(world.scene, 5, 1, "tunnel")
end end
function ShootMap:loadCollisions() function ShootMap:loadCollisions()
@ -34,112 +36,14 @@ function ShootMap:loadActors()
-- Empty Placeholder function -- Empty Placeholder function
end end
function ShootMap:generateTextures(tile, background)
self.texture = {}
self.texture.floor = self:generateFloor(tile)
self.texture.border = love.graphics.newImage("assets/backgrounds/borders.png")
self.quads = {}
local w, h = self.texture.border:getDimensions()
self.quads.borders = love.graphics.newQuad(0, tile*10, 80, 10, w, h)
self:addParallax(background)
end
function ShootMap:generateFloor(tile)
local canvas = love.graphics.newCanvas(31*16, 100)
local tile = tile or 1
local tileTexture = love.graphics.newImage("assets/backgrounds/normaltile.png")
local tileQuad = {}
local w, h = tileTexture:getDimensions()
tileQuad[1] = love.graphics.newQuad( 0, tile*24, 40, 24, w, h)
tileQuad[2] = love.graphics.newQuad(40, tile*24, 40, 24, w, h)
love.graphics.setCanvas( canvas )
for i=1, 5 do
for j=0, 18 do
local tiley = (i-1)*20 - 4
local tilex = (j-2)*31 + (i-1)*10
local variant = 1 + ((i + j) % 2)
love.graphics.draw(tileTexture, tileQuad[variant], tilex, tiley)
end
end
love.graphics.setCanvas( )
local imagedata = canvas:newImageData()
local texture = love.graphics.newImage( imagedata )
imagedata:release()
canvas:release()
return texture
end
function ShootMap:draw() function ShootMap:draw()
for i=1, 10 do for i=1, 10 do
--love.graphics.draw(self.texture.floor, ((i-1)*31*16), 0) --love.graphics.draw(self.texture.floor, ((i-1)*31*16), 0)
end end
end end
function ShootMap:addParallax(filename)
-- Empty Placeholder function
local filename = filename or "forest"
local backfolder = "assets/backgrounds/parallax/"
filename = backfolder .. filename
self.texture.back1 = love.graphics.newImage(filename .. "-back.png")
self.texture.back2 = love.graphics.newImage(filename .. "-fore.png")
self.texture.cliff = love.graphics.newImage(filename .. "-cliff.png")
end
function ShootMap:drawParallax(x, y, w, h) function ShootMap:drawParallax(x, y, w, h)
self.parallaxBackground:drawParallax(x, y, w, h)
self:drawBackground(x, y, w, h)
self:drawForeground(x, y + 10, w, h)
local w2, _ = self.texture.floor:getDimensions()
for i=1, 2 do
local x2 = x % w2
love.graphics.draw(self.texture.floor, ((i-1)*31*16)-x2, -y)
end
self:drawBorder(x, y + 10)
self:drawBorder(x, y - 100)
self:drawCliff(x, y - 110, w, h)
end end
function ShootMap:drawBackground(x, y, w, h)
local w2, h2 = self.texture.back1:getDimensions()
local imax = math.ceil(w / w2) + 1
for i=1, imax do
local x1 = (x / 5) % w2
love.graphics.draw(self.texture.back1, (i-1)*w2 - x1, 0, 0, 1, 1, 0, 0)
end
end
function ShootMap:drawForeground(x, y, w, h)
local w2, h2 = self.texture.back2:getDimensions()
local imax = math.ceil(w / w2) + 1
for i=1, imax do
local x1 = (x / 2) % w2
love.graphics.draw(self.texture.back2, (i-1)*w2 - x1, -y, 0, 1, 1, 0, h2)
end
end
function ShootMap:drawBorder(x, y)
for i=1, 7 do
local x2 = x % 80
love.graphics.draw(self.texture.border, self.quads.borders, (i-1)*80 - x2, -y, 0, 1, 1)
end
end
function ShootMap:drawCliff(x, y, w, h)
local w2, h2 = self.texture.cliff:getDimensions()
local imax = math.ceil(w / w2) + 1
for i=1, imax do
local x1 = (x) % w2
love.graphics.draw(self.texture.cliff, (i-1)*w2 - x1, -y, 0, 1, 1, 0, 0)
end
end
return ShootMap return ShootMap

View file

@ -1,7 +1,7 @@
local World = Object:extend() local World = Object:extend()
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local Map = require "scenes.battlesystem.map" local Map = require "game.modules.drawing.parallaxBackground"
local TweenManager = require "game.modules.tweenmanager" local TweenManager = require "game.modules.tweenmanager"
@ -11,6 +11,9 @@ local POSITIONS = {
{x = 2, y = 6}, {x = 2, y = 6},
} }
local HEIGHT = 5
local BORDER_BOTTOM = 2
local gui = require "game.modules.gui" local gui = require "game.modules.gui"
-- INIT FUNCTIONS -- INIT FUNCTIONS
@ -25,7 +28,7 @@ function World:new(scene, battlefile)
self.actors = {} self.actors = {}
self.globalID = 0 self.globalID = 0
self.map = Map(self, "city") self.map = Map(scene, HEIGHT, BORDER_BOTTOM, "city")
self.isBattleActive = false self.isBattleActive = false
end end