Skip to content

Commit

Permalink
tiles testing/template
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin452 committed Mar 4, 2024
1 parent 32e56e4 commit 3f8c59c
Show file tree
Hide file tree
Showing 60 changed files with 141 additions and 90 deletions.
18 changes: 9 additions & 9 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require("src/menus/gameplayingpausemenu")
require("src/menus/playinggamesettings")
require("src/menus/worldcreationmenu")
--blocks
require("src/blocks/TileEntities/tiledata")
require("src/blocksandtiles/tiledata")
--utils
require("src/utils/things")
require("src/utils/math")
Expand Down Expand Up @@ -97,12 +97,12 @@ function love.resize(w, h)

local scaleX = w / GraphicsWidth
local scaleY = h / GraphicsHeight
love.graphics.scale(scaleX, scaleY)
local newCanvas = love.graphics.newCanvas(w, h)
lovegraphics.scale(scaleX, scaleY)
local newCanvas = lovegraphics.newCanvas(w, h)

love.graphics.setCanvas(newCanvas)
love.graphics.draw(Scene.twoCanvas)
love.graphics.setCanvas()
lovegraphics.setCanvas(newCanvas)
lovegraphics.draw(Scene.twoCanvas)
lovegraphics.setCanvas()

Scene.twoCanvas = newCanvas

Expand Down Expand Up @@ -137,8 +137,8 @@ function love.draw()

DrawGame()
if hudMessage ~= nil then
local width, height = love.graphics.getDimensions()
local font = love.graphics.getFont()
local width, height = lovegraphics.getDimensions()
local font = lovegraphics.getFont()

-- Calculate the width and height of the text
local textWidth = font:getWidth(hudMessage)
Expand All @@ -148,7 +148,7 @@ function love.draw()
local x = (width - textWidth) / 2
local y = (height - textHeight) / 2 + 280

love.graphics.print(hudMessage, x, y)
lovegraphics.print(hudMessage, x, y)
end
if enablePROFIProfiler then
ProFi:stop()
Expand Down
Binary file removed resources/assets/texture.png
Binary file not shown.
Binary file removed resources/assets/textures/blocks/Stone.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/assets/textures/debug/defaulttexture.png
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
-- Define tile enumeration
tileTexturesCache = {}
tileModelCache = {}
tile2DCache = {}
lightSourceCache = {}
transparencyCache = {}

Tiles = {
AIR_Block = 0,
STONE_Block = 1,
Expand Down Expand Up @@ -26,8 +31,15 @@ Tiles = {
STONE_BRICK_Block = 45,
GLOWSTONE_Block = 89,
}

-- Define light source enumeration
local transparencyLookup = {
[Tiles.AIR_Block] = 0,
[Tiles.YELLO_FLOWER_Block] = 0,
[Tiles.ROSE_FLOWER_Block] = 0,
[Tiles.OAK_SAPPLING_Block] = 0,
[Tiles.OAK_LEAVE_Block] = 1,
[Tiles.GLASS_Block] = 2,
[Tiles.GLOWSTONE_Block] = 2,
}
LightSources = {
[0] = 0,
[1] = 1,
Expand All @@ -46,8 +58,6 @@ LightSources = {
[14] = 14,
[15] = 15,
}

-- Define tile collisions
function TileCollisions(n)
local nonCollidableTiles = {
Tiles.AIR_Block,
Expand All @@ -69,20 +79,6 @@ function TileCollisions(n)
return true
end

-- Define a lookup table for tile transparency values
local transparencyLookup = {
[Tiles.AIR_Block] = 0,
[Tiles.YELLO_FLOWER_Block] = 0,
[Tiles.ROSE_FLOWER_Block] = 0,
[Tiles.OAK_SAPPLING_Block] = 0,
[Tiles.OAK_LEAVE_Block] = 1,
[Tiles.GLASS_Block] = 2,
[Tiles.GLOWSTONE_Block] = 2,
}

local transparencyCache = {}

-- Define function to get tile transparency
function TileTransparency(n)
if transparencyCache[n] then
return transparencyCache[n]
Expand All @@ -93,78 +89,84 @@ function TileTransparency(n)
end
end

-- Define function to get tile light source
function TileLightSource(n)
if lightSourceCache[n] ~= nil then
return lightSourceCache[n]
end
local result
if n == Tiles.GLOWSTONE_Block then
return LightSources[15]
result = LightSources[15]
else
result = LightSources[0]
end

return LightSources[0]
lightSourceCache[n] = result
return result
end

-- Define function to check if tile is lightable
function TileLightable(n)
local t = TileTransparency(n)
return t == 0 or t == 2
end

-- Define function to check if tile is semi-lightable
function TileSemiLightable(n)
local t = TileTransparency(n)
return t == 0 or t == 1 or t == 2
end

local tileTexturesCache = {}

-- Define function to get tile textures
local list = {
[Tiles.AIR_Block] = { 0 },
[Tiles.STONE_Block] = { 1 },
[Tiles.GRASS_Block] = { 3, 0, 2 },
[Tiles.DIRT_Block] = { 2 },
[Tiles.COBBLE_Block] = { 16 },
[Tiles.OAK_PLANK_Block] = { 4 },
[Tiles.OAK_SAPPLING_Block] = { 15 },
[Tiles.BEDROCK_Block] = { 17 },
[Tiles.WATER_Block] = { 14 },
[Tiles.STATIONARY_WATER_Block] = { 14 },
[Tiles.LAVA_Block] = { 63 },
[Tiles.STATIONARY_LAVA_Block] = { 63 },
[Tiles.SAND_Block] = { 18 },
[Tiles.GRAVEL_Block] = { 19 },
[Tiles.GOLD_Block] = { 32 },
[Tiles.IRON_Block] = { 33 },
[Tiles.COAL_Block] = { 34 },
[Tiles.OAK_LOG_Block] = { 20, 21, 21 },
[Tiles.OAK_LEAVE_Block] = { 52 },
[Tiles.SPONGE_Block] = { 48 },
[Tiles.GLASS_Block] = { 49 },
[Tiles.ROSE_FLOWER_Block] = { 13 },
[Tiles.YELLO_FLOWER_Block] = { 12 },
[Tiles.STONE_BRICK_Block] = { 7 },
[Tiles.GLOWSTONE_Block] = { 105 },
}
function TileTextures(n)
if tileTexturesCache[n] then
return tileTexturesCache[n]
end

local list = {
[Tiles.AIR_Block] = { 0 },
[Tiles.STONE_Block] = { 1 },
[Tiles.GRASS_Block] = { 3, 0, 2 },
[Tiles.DIRT_Block] = { 2 },
[Tiles.COBBLE_Block] = { 16 },
[Tiles.OAK_PLANK_Block] = { 4 },
[Tiles.OAK_SAPPLING_Block] = { 15 },
[Tiles.BEDROCK_Block] = { 17 },
[Tiles.WATER_Block] = { 14 },
[Tiles.STATIONARY_WATER_Block] = { 14 },
[Tiles.LAVA_Block] = { 63 },
[Tiles.STATIONARY_LAVA_Block] = { 63 },
[Tiles.SAND_Block] = { 18 },
[Tiles.GRAVEL_Block] = { 19 },
[Tiles.GOLD_Block] = { 32 },
[Tiles.IRON_Block] = { 33 },
[Tiles.COAL_Block] = { 34 },
[Tiles.OAK_LOG_Block] = { 20, 21, 21 },
[Tiles.OAK_LEAVE_Block] = { 52 },
[Tiles.SPONGE_Block] = { 48 },
[Tiles.GLASS_Block] = { 49 },
[Tiles.ROSE_FLOWER_Block] = { 13 },
[Tiles.YELLO_FLOWER_Block] = { 12 },
[Tiles.STONE_BRICK_Block] = { 7 },
[Tiles.GLOWSTONE_Block] = { 105 },
}

tileTexturesCache[n] = list[n]

return tileTexturesCache[n]
end

-- Define function to get tile model
function TileModel(n)
if tileModelCache[n] then
return tileModelCache[n]
end
local result
if n == Tiles.YELLO_FLOWER_Block or n == Tiles.ROSE_FLOWER_Block or n == Tiles.OAK_SAPPLING_Block then
return 1
result = 1
else
result = 0
end

return 0
tileModelCache[n] = result
return result
end

-- Define function to check if tile is 2D
function Tile2D(n)
return n == Tiles.YELLO_FLOWER_Block or n == Tiles.ROSE_FLOWER_Block or n == Tiles.OAK_SAPPLING_Block
if tile2DCache[n] then
return tile2DCache[n]
end
local result = n == Tiles.YELLO_FLOWER_Block or n == Tiles.ROSE_FLOWER_Block or n == Tiles.OAK_SAPPLING_Block
tile2DCache[n] = result
return result
end
Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions src/init/!init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function initWorldGenerationVariables()
end

function InitializeGame()
_JPROFILER.push("InitializeAssets")
InitializeAssets()
_JPROFILER.pop("InitializeAssets")
_JPROFILER.push("InitializeGame")
_JPROFILER.push("SettingsHandlingInit")
SettingsHandlingInit()
Expand All @@ -42,9 +45,6 @@ function InitializeGame()
_JPROFILER.pop("InitializeWindowSettings")
LogicAccumulator = 0
PhysicsStep = true
_JPROFILER.push("InitializeAssets")
InitializeAssets()
_JPROFILER.pop("InitializeAssets")
_JPROFILER.push("InitializeGuisAndHud")
InitializeGuisAndHud()
_JPROFILER.pop("InitializeGuisAndHud")
Expand Down
77 changes: 63 additions & 14 deletions src/init/assetsinit.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
--Backgrounds
mainMenuBackground = nil
mainMenuSettingsBackground = nil
gameplayingpausemenu = nil
playinggamesettings = nil
worldCreationBackground = nil
function InitializeAssets()
DefaultTexture = love.graphics.newImage("resources/assets/texture.png")
if DefaultTexture == nil then
error("Erreur lors du chargement de la texture.")
end
TileTexture = love.graphics.newImage("resources/assets/terrain.png")
GuiSprites = love.graphics.newImage("resources/assets/gui.png")
BlockTest = lovegraphics.newImage("resources/assets/textures/debug/defaulttexture.png")
DefaultTexture = lovegraphics.newImage("resources/assets/textures/debug/defaulttexture.png")
GuiSprites = lovegraphics.newImage("resources/assets/gui.png")
mainMenuBackground = lovegraphics.newImage("resources/assets/backgrounds/MainMenuBackground.png")
mainMenuSettingsBackground = lovegraphics.newImage("resources/assets/backgrounds/Mainmenusettingsbackground.png")
gameplayingpausemenu = lovegraphics.newImage("resources/assets/backgrounds/gameplayingpausemenu.png")
playinggamesettings = lovegraphics.newImage("resources/assets/backgrounds/playinggamesettings.png")
worldCreationBackground = lovegraphics.newImage("resources/assets/backgrounds/WorldCreationBackground.png")
TileTexture = lovegraphics.newImage("resources/assets/terrain.png")
ChunkBorders = lovegraphics.newImage("resources/assets/textures/debug/chunkborders.png")

BlockTest = love.graphics.newImage("resources/assets/textures/blocks/Stone.png")
ChunkBorders = love.graphics.newImage("resources/assets/textures/debug/chunkborders.png")
-- Blocks/Tiles/liquids
grassTopTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/grass/grass_top.png")
grassBottomTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/grass/grass_side.png")
grassSideTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/grass/grass_botton.png")

airTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/air.png")

bedrockTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/bedrock.png")

coalTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/coal.png")

cobbleTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/cobble.png")

dirtTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/dirt.png")

glassTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/glass.png")

glowstoneTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/glowstone.png")

goldTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/gold.png")

gravelTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/gravel.png")

ironTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/iron.png")

oak_leavesTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/oak_leaves.png")

oak_logsTopTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/oak_logs/oak_top.png")
oak_logsBottomTexture =
lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/oak_logs/oak_botton.png")
oak_logsSideTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/oak_logs/oak_side.png")

oak_planksTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/oak_planks.png")

sandTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/sand.png")

spongeTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/sponge.png")

stoneTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/stone.png")

stone_brickTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/stone_brick.png")

bedrockTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/blocks/bedrock.png")

lavaTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/liquid/lava.png")

lavastationaryTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/liquid/lava_stationary.png")

waterTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/liquid/water.png")

waterstationaryTexture =
lovegraphics.newImage("resources/assets/textures/blocksandtiles/liquid/water_stationary.png")

oak_sapplingsTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/tiles/oak_sapplings.png")

roseflowerTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/tiles/rose_flower.png")

yellowflowerTexture = lovegraphics.newImage("resources/assets/textures/blocksandtiles/tiles/yellow_flower.png")
end

0 comments on commit 3f8c59c

Please sign in to comment.