- More cleanup

- Added kupos entity and sprites (body, bow)
- Finally understood my code
This commit is contained in:
lustlion
2021-10-22 18:23:05 +02:00
parent 966aebf046
commit 5b7924fe4e
157 changed files with 394 additions and 1159 deletions

1
data/levels/33.json Normal file
View File

@@ -0,0 +1 @@
[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,162,163,163,163,164,0,0,0,0,0,0,0,0,0],[154,155,0,0,0,0,144,145,145,146,176,176,176,144,145,145,146,0,0,0,0,152,153],[175,182,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,175,169,177],[0,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,165,0],[0,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,165,0],[0,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,165,0],[0,181,0,162,164,0,0,0,0,0,0,0,0,0,0,0,0,0,162,164,0,178,0],[0,0,0,175,177,0,0,0,0,0,0,0,0,0,0,0,0,0,175,177,0,0,0],[0,0,0,0,0,0,144,145,145,145,145,145,145,145,145,145,146,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]

View File

@@ -0,0 +1,30 @@
LevelProperties = {
pos = {
x = 0,
y = 0
},
offset = {
x = 0,
y = 0
}
}
TileProperties = {
width = 16,
height = 16,
scale = game.scale,
tileset = love.graphics.newImage("assets/terrain/tileset.png")
}
TileCollisions = {
whole = { 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 016, 018, 019, 020, 021, 022, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 049, 050, 051, 052, 054, 055, 056, 057, 061, 062, 063, 064, 065, 066, 067, 068, 069, 85, 086, 087, 088, 089, 090, 091, 092, 093, 094, 095, 096, 097, 098, 099, 100, 101, 102, 103, 104, 105, 106, 107, 108,113, 114, 115, 116, 125, 126, 127, 128, 133, 134, 135, 136, 137, 138, 139, 140, 145, 146, 147, 148, 149, 150, 151, 152 },
platform = { 046, 047, 048, 058, 059, 060 },
ramp_topright_bot = { 109, 161, 117, 157 },
ramp_topright_top = { 110, 162, 118, 158 },
ramp_topleft_top = { 111, 163, 119, 159 },
ramp_topleft_bot = { 112, 164, 120, 160 },
ramp_botright_bot = { 073, 077, 081, 121 },
ramp_botright_top = { 074, 078, 082, 122 },
ramp_botleft_top = { 075, 079, 083, 123 },
ramp_botleft_bot = { 076, 080, 084, 124 }
}

File diff suppressed because one or more lines are too long

1
data/levels/level2.json Normal file
View File

@@ -0,0 +1 @@
[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[202,202,202,202,202,202,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,202,0,202,202,202,202,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,106,106,106,106,106,106,106,106,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,119,119,119,119,119,119,119,119,130,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,119,119,119,119,119,119,119,119,119,130,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,119,119,119,119,119,119,119,119,119,119,130,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,119,119,119,119,119,119,119,119,119,119,119,130,106,106,106,106,106,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]

1
data/levels/level3.json Normal file

File diff suppressed because one or more lines are too long

View File

@@ -13,9 +13,11 @@ function Camera:CenterAt(x,y,cx,cy)
if self.pos.y < 0 then self.pos.y = 0 end
if self.pos.y > cy then self.pos.y = cy end
end
self.pos.x = math.floor(self.pos.x)
self.pos.y = math.floor(self.pos.y)
end
function Camera:ScreenAt(x,y,width,height)
self.pos.x = math.floor(x/width)*width
self.pos.y = math.floor(y/height)*height
function Camera:ScreenAt(x,y)
self.pos.x = math.floor(x/self.width)*self.width
self.pos.y = math.floor(y/self.height)*self.height
end

View File

@@ -25,7 +25,7 @@ Collision = {}
--]]
-- can also be called with only ox and oy, where they become the width and height instead
function Collision:new(ox,oy,tx,ty)
function Collision:New(ox,oy,tx,ty)
local o = {isColliding = false, isDisabled = false, isActive = false}
if tx ~= nil and ty ~= nil then

View File

@@ -3,12 +3,12 @@ love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..m
love.graphics.setColor(1,1,1)
-- lots of variables
love.graphics.print("[main_player]",10*textScale,40*textScale, 0, textScale)
love.graphics.print("position: {"..main_player.pos.x..", "..main_player.pos.y.."}",10*textScale,60*textScale, 0, textScale)
love.graphics.print("velocity: {"..main_player.vel.x..", "..main_player.vel.y.."}",10*textScale,80*textScale, 0, textScale)
love.graphics.print("scale: {"..main_player.scale.x..", "..main_player.scale.y.."}",10*textScale,100*textScale, 0, textScale)
love.graphics.print("sprite: "..tostring(main_player.sprite)..", anim_speed: "..main_player.anim_speed,10*textScale,120*textScale, 0, textScale)
love.graphics.print("booleans: \"isOnGround\": "..tostring(main_player.isOnGround),10*textScale,140*textScale, 0, textScale)
love.graphics.print("[main_Player]",10*textScale,40*textScale, 0, textScale)
love.graphics.print("position: {"..main_Player.pos.x..", "..main_Player.pos.y.."}",10*textScale,60*textScale, 0, textScale)
love.graphics.print("velocity: {"..main_Player.vel.x..", "..main_Player.vel.y.."}",10*textScale,80*textScale, 0, textScale)
love.graphics.print("scale: {"..main_Player.scale.x..", "..main_Player.scale.y.."}",10*textScale,100*textScale, 0, textScale)
love.graphics.print("sprite: "..tostring(main_Player.sprite)..", anim_speed: "..main_Player.anim_speed,10*textScale,120*textScale, 0, textScale)
love.graphics.print("booleans: \"isOnGround\": "..tostring(main_Player.isOnGround),10*textScale,140*textScale, 0, textScale)
love.graphics.print("[Camera]",10*textScale,160*textScale, 0, textScale)
love.graphics.print("position: {"..Camera.pos.x..", "..Camera.pos.y.."}",10*textScale,180*textScale, 0, textScale)
@@ -19,7 +19,7 @@ love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..m
-- player isOnGroundCheck
love.graphics.setColor(1,0,0)
love.graphics.points(-Camera.pos.x + main_player.pos.x, -Camera.pos.y + main_player.pos.y)
love.graphics.points(-Camera.pos.x + main_Player.pos.x, -Camera.pos.y + main_Player.pos.y)
end
function DebugColisions()

View File

@@ -0,0 +1,35 @@
Kupo = Entity:New(x,y)
function Kupo:New(x,y)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = 20
o.range = 1000
setmetatable(o, self)
self.__index = self
return o
end
function Kupo:DoInput()
end
function Kupo:HandleAnimation()
-- flip sprite to look in the direction is moving
if self.vel.x ~= 0 then self.flip.x = math.sign(self.vel.x) end
self:LoadAnimation(animation.kupo.body)
end
function Kupo:DoPhysics()
-- horizontal collisions
if not isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
self.pos.x = self.pos.x + self.vel.x
end
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
self.pos.y = self.pos.y + self.vel.y
end
end

View File

@@ -1,38 +1,8 @@
player = entity:newEntity(x,y)
Player = Entity:New(x,y)
function InitPlayer(id)
player.health = 3
player.coins = 0
-- physics
player.vel = {
x = 0,
y = 0
}
-- constants
player.acc = 90
player.friction = 20
player.gravity = 9.81
player.climbHeight = 3
player.jumpForce = 5
player.maxSpeed = 600
player.jumpMaxSpeed = 9.5
player.zeroSpeed = 0.001
-- bools
player.isJumping = false
player.isOnGround = false
player.isOnLadder = false
player.canJump = true
player.canFall = true
player.canFriction = true
-- sprite
player.offset = {x = -8, y = -16}
end
function player:DoInput()
function Player:DoInput()
-- PLATFORMER INPUT
if self.isOnGround then
if self.isOnGround > 0 then
-- apply friction
-- horizontal input (slide~~)
@@ -46,7 +16,7 @@ function player:DoInput()
-- vertical input (jump!)
if love.keyboard.isDown("up", "w") and self.isJumping ~= true then
self.vel.y = self.vel.y - self.jumpForce
self.isOnGround = false
self.isOnGround = 0
self.isJumping = true
end
end
@@ -65,11 +35,11 @@ function player:DoInput()
) and love.keyboard.isDown("down", "s")
then
self.pos.y = self.pos.y + tileProperties.height/3
self.isOnGround = false
self.isOnGround = 0
end
end
function player:HandleAnimation()
function Player:HandleAnimation()
-- flip sprite to look in the direction is moving
if self.vel.x ~= 0 then self.flip.x = math.sign(self.vel.x) end
@@ -77,9 +47,9 @@ function player:HandleAnimation()
-- animation manager
if self.isOnLadder then
self:LoadAnimation(animation.nancy.jump)
elseif not self.isOnGround and self.isJumping and self.vel.y > 1.25 then
elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then
self:LoadAnimation(animation.nancy.fall)
elseif not self.isOnGround and self.vel.y < 0 then
elseif self.isOnGround == 0 and self.vel.y < 0 then
self:LoadAnimation(animation.nancy.jump)
elseif self.vel.x ~= 0 then
self:LoadAnimation(animation.nancy.run)
@@ -93,13 +63,12 @@ function player:HandleAnimation()
end
end
function player:DoPhysics()
function Player:DoPhysics()
-- reset physics resolution
self.canFall = true
self.canJump = true
self.canFriction = true
-- reset flags
self.isOnGround = false
self.isOnLadder = false
-- truncate to max & min values
if math.abs(self.vel.x) > self.maxSpeed then
@@ -126,7 +95,7 @@ function player:DoPhysics()
self.pos.x,
self.pos.y + self.vel.y
) then
self.isOnGround = true
self.isOnGround = self.coyoteValue
self.isJumping = false
end
end
@@ -147,15 +116,15 @@ function player:DoPhysics()
self.canFriction = false
self.isOnLadder = true
self.isOnGround = true
self.isOnGround = self.coyoteValue
end
-- checks for slopes
for i = 1, self.climbHeight do
if not isThereCollisionAt(self.pos.x + self.vel.x, self.pos.y - i * game.scale)
and self.isOnGround then
and self.isOnGround > 0 then
self.pos.x = self.pos.x + self.vel.x
self.pos.x = self.pos.x + self.vel.x * 4/5
self.pos.y = self.pos.y - i * game.scale
self.canFriction = false
@@ -174,11 +143,12 @@ function player:DoPhysics()
-- vertical collision
if self.vel.y > 0
and isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
self.isOnGround = true
self.isOnGround = self.coyoteValue
self.isJumping = false
self.vel.y = 0
else
self.pos.y = self.pos.y + self.vel.y
self.isOnGround = math.max(self.isOnGround - 1, 0)
end
-- drop.
@@ -187,7 +157,7 @@ function player:DoPhysics()
end
-- friction hard in ground, soft in air
if self.isOnGround then
if self.isOnGround > 0 then
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction, 1))
else
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/20, 1))
@@ -195,9 +165,36 @@ function player:DoPhysics()
end
function player:newPlayer(x,y)
local o = entity:newEntity(x,y)
function Player:New(x,y)
local o = Entity:New(x,y)
Player.health = 3
Player.coins = 0
-- physics
o.vel = {
x = 0,
y = 0
}
-- constants
o.acc = 90
o.friction = 20
o.gravity = 9.81
o.climbHeight = 4
o.jumpForce = 5
o.maxSpeed = 600
o.jumpMaxSpeed = 9.5
o.zeroSpeed = 0.001
-- bools
o.isJumping = false
o.isOnGround = 0
o.coyoteValue = 10
o.isOnLadder = false
o.canJump = true
o.canFall = true
o.canFriction = true
-- sprite
o.offset = {x = -8, y = -16}
setmetatable(o, self)
self.__index = self

View File

@@ -1,19 +1,27 @@
entity = {class = "entity", anim_subframe = 0, anim_frame = 0, anim_imgs = {}, offset = {x = 0, y = 0}, scale = {x = 1, y = 1}, flip = { x = 1, y = 1}}
Entity = {
}
function entity:newEntity(x,y)
function Entity:New(x,y)
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.class = "Entity"
o.anim_subframe = 0
o.anim_frame = 0
o.anim_imgs = {}
o.offset = {x = 0, y = 0}
o.scale = {x = 1, y = 1}
o.flip = { x = 1, y = 1}
setmetatable(o, self)
self.__index = self
return o
end
function entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
end
function entity:Draw()
function Entity:Draw()
if self.sprite ~= nil then
love.graphics.draw(
self.sprite,
@@ -26,7 +34,7 @@ function entity:Draw()
end
end
function entity:Animate()
function Entity:Animate()
if game_paused ~= true then
-- try to animate
self.anim_subframe = self.anim_subframe + current_dt
@@ -46,7 +54,7 @@ function entity:Animate()
end
end
function entity:LoadAnimation(anim,frames,speed)
function Entity:LoadAnimation(anim,frames,speed)
if self.anim_path ~= anim and self.anim_path ~= anim.path then
if frames ~= nil and speed ~= nil then
self.anim_path = anim or nil
@@ -62,4 +70,5 @@ function entity:LoadAnimation(anim,frames,speed)
end
end
require "data/scripts/entities/kupo"
require "data/scripts/entities/player"

View File

@@ -1,41 +1,47 @@
image = {
background = love.graphics.newImage("assets/terrain/background.png"),
cartridge = {
nancy = love.graphics.newImage("assets/menu/nancy.png")
}
background = love.graphics.newImage("assets/terrain/background.png")
}
-- animations
animation = {
kupo = {
body = {
path = "assets/characters/kupo/kupo",
frames = 4,
speed = 1/8
},
bow = {
path = "assets/characters/kupo/kupo_bow",
frames = 6,
speed = 1/8
}
},
nancy = {
idle = {
path = "assets/characters/nancy/idle",
frames = 4,
speed = 1/8,
imgs = {}
speed = 1/8
},
run = {
path = "assets/characters/nancy/run",
frames = 6,
speed = 1/8,
imgs = {}
speed = 1/8
},
fall = {
path = "assets/characters/nancy/fall",
frames = 3,
speed = 1/8,
imgs = {}
speed = 1/8
},
jump = {
path = "assets/characters/nancy/jump",
frames = 3,
speed = 1/8,
imgs = {}
speed = 1/8
}
}
}
for _, object in pairs(animation) do
for _, anim in pairs(object) do
anim.imgs = {}
for i = 1, anim.frames do
table.insert(anim.imgs,love.graphics.newImage(anim.path..tostring(i)..".png"))
end

View File

@@ -1,4 +1,4 @@
function LoadTiles()
function LevelLoadTiles()
LevelInfo = {}
Tiles = dofile("Mothback/data/tiles.lua")
--[[
@@ -13,13 +13,17 @@ function LoadTiles()
]]
LevelTiles = json.decode(getInput("Mothback/data/levels/"..currLevel..".json"))
LevelInfo.Width = GetLevelWidth()
LevelInfo.Height = #LevelTiles * tileProperties.height
IndexLevelTiles()
LoadTileObjects()
LevelInfo.Width = LevelGetWidth()
LevelInfo.Height = LevelGetHeight()
LevelIndexTiles()
TileCreateObjects()
end
function GetLevelWidth()
function LevelGetHeight()
return #LevelTiles * tileProperties.height
end
function LevelGetWidth()
local width = 0
for i = 1, #LevelTiles do
if width < #LevelTiles[i] then width = #LevelTiles[i] end
@@ -27,7 +31,7 @@ function GetLevelWidth()
return width * tileProperties.width
end
function IndexLevelTiles()
function LevelIndexTiles()
TileIndex = {}
-- number of tiles in tileset!
@@ -79,12 +83,12 @@ function IndexLevelTiles()
end
end
function TilesDisplayFront()
function LevelDisplayForeground()
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
local depth = getTileDepth(LevelTiles[i][j])
local depth = TileGetDepth(LevelTiles[i][j])
DrawTile(
LevelTiles[i][j],
tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.width) - Camera.pos.x,
@@ -97,12 +101,12 @@ function TilesDisplayFront()
end
end
function TilesDisplayBack()
function LevelDisplayBackground()
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
local depth = getTileDepth(LevelTiles[i][j])
local depth = TileGetDepth(LevelTiles[i][j])
DrawTile(
LevelTiles[i][j],
tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.width) - Camera.pos.x,
@@ -116,7 +120,7 @@ function TilesDisplayBack()
end
function getTileType(tile_id)
function TileGetType(tile_id)
for _, properties in ipairs(Tiles) do
if properties.id == tile_id then
return properties.type
@@ -124,7 +128,7 @@ function getTileType(tile_id)
end
end
function getTileDepth(tile_id)
function TileGetDepth(tile_id)
for _, properties in ipairs(Tiles) do
if properties.id == tile_id then
return properties.depth
@@ -146,7 +150,7 @@ function GridDisplay()
end
end
function LoadTileObjects()
function TileCreateObjects()
objects.collisions = {}
objects.platforms = {}
objects.ladders = {}
@@ -155,13 +159,13 @@ function LoadTileObjects()
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
local type = getTileType(LevelTiles[i][j])
local type = TileGetType(LevelTiles[i][j])
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
if type == "whole" then
local col = Collision:new(
local col = Collision:New(
base_x,
base_y,
base_x + tileProperties.width * tileProperties.scale,
@@ -169,9 +173,9 @@ function LoadTileObjects()
)
table.insert(objects.collisions,col)
elseif type == "half" then
elseif type == "half_bottom" then
local col = Collision:new(
local col = Collision:New(
base_x,
base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -179,8 +183,38 @@ function LoadTileObjects()
)
table.insert(objects.collisions,col)
elseif type == "half_top" then
local col = Collision:New(
base_x,
base_y ,
base_x + tileProperties.width * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale
)
table.insert(objects.collisions,col)
elseif type == "half_right" then
local col = Collision:New(
base_x + tileProperties.height/2 * tileProperties.scale,
base_y,
base_x + tileProperties.width * tileProperties.scale,
base_y + tileProperties.height * tileProperties.scale
)
table.insert(objects.collisions,col)
elseif type == "half_left" then
local col = Collision:New(
base_x,
base_y,
base_x + tileProperties.height/2 * tileProperties.scale,
base_y + tileProperties.height * tileProperties.scale
)
table.insert(objects.collisions,col)
elseif type == "platform" then
local plat = Collision:new(
local plat = Collision:New(
base_x,
base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale,
@@ -191,7 +225,7 @@ function LoadTileObjects()
elseif type == "ramp2_bot_left_whole" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x,
base_y + k * tileProperties.scale - tileProperties.scale,
base_x + k * 2 * tileProperties.scale,
@@ -201,7 +235,7 @@ function LoadTileObjects()
end
-- fill lower half
local col = Collision:new(
local col = Collision:New(
base_x,
base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -212,7 +246,7 @@ function LoadTileObjects()
elseif type == "ramp2_bot_left_half" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x,
base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale - tileProperties.scale,
base_x + k * 2 * tileProperties.scale,
@@ -225,7 +259,7 @@ function LoadTileObjects()
elseif type == "ramp2_top_left_whole" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
@@ -235,7 +269,7 @@ function LoadTileObjects()
end
-- fill higher half
local col = Collision:new(
local col = Collision:New(
base_x,
base_y,
base_x + tileProperties.width * tileProperties.scale,
@@ -246,7 +280,7 @@ function LoadTileObjects()
elseif type == "ramp2_top_left_half" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x,
base_y - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
@@ -259,7 +293,7 @@ function LoadTileObjects()
elseif type == "ramp2_bot_right_whole" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x + (k-8) * -2 * tileProperties.scale,
base_y - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -269,7 +303,7 @@ function LoadTileObjects()
end
-- fill lower half
local col = Collision:new(
local col = Collision:New(
base_x,
base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -280,7 +314,7 @@ function LoadTileObjects()
elseif type == "ramp2_bot_right_half" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -293,7 +327,7 @@ function LoadTileObjects()
elseif type == "ramp2_top_right_half" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -306,7 +340,7 @@ function LoadTileObjects()
elseif type == "ramp2_top_right_whole" then
for k = 1, 8 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale,
@@ -316,7 +350,7 @@ function LoadTileObjects()
end
-- fill higher half
local col = Collision:new(
local col = Collision:New(
base_x,
base_y,
base_x + tileProperties.width * tileProperties.scale,
@@ -328,7 +362,7 @@ function LoadTileObjects()
for k = 1, 16 do
-- do ramp owo
local slope = Collision:new(
local slope = Collision:New(
base_x,
base_y + k * tileProperties.scale - tileProperties.scale,
base_x + k * tileProperties.scale,
@@ -340,7 +374,7 @@ function LoadTileObjects()
elseif type == "ladder_right" then
local ladder = Collision:new(
local ladder = Collision:New(
base_x + (tileProperties.width-4)* tileProperties.scale,
base_y,
base_x + tileProperties.width * tileProperties.scale,
@@ -350,7 +384,7 @@ function LoadTileObjects()
elseif type == "ladder_platform_right" then
local ladder = Collision:new(
local ladder = Collision:New(
base_x + (tileProperties.width-4)* tileProperties.scale,
base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale,
@@ -358,7 +392,7 @@ function LoadTileObjects()
)
table.insert(objects.ladders,ladder)
local plat = Collision:new(
local plat = Collision:New(
base_x,
base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale,
@@ -369,7 +403,7 @@ function LoadTileObjects()
elseif type == "ladder_left" then
local ladder = Collision:new(
local ladder = Collision:New(
base_x,
base_y,
base_x + tileProperties.scale * 4,
@@ -380,7 +414,7 @@ function LoadTileObjects()
elseif type == "ladder_platform_left" then
local ladder = Collision:new(
local ladder = Collision:New(
base_x,
base_y + tileProperties.scale * 2,
base_x + tileProperties.scale * 4,
@@ -388,7 +422,7 @@ function LoadTileObjects()
)
table.insert(objects.ladders,ladder)
local plat = Collision:new(
local plat = Collision:New(
base_x,
base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale,

File diff suppressed because it is too large Load Diff