uh yeah i keep forgetting ab pushing these. sorry.

This commit is contained in:
lustlion 2022-01-18 00:14:54 +01:00
parent dd2debc0bd
commit 5a266d6b3a
73 changed files with 405 additions and 274 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 B

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 B

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 920 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 922 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 919 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 918 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 919 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 917 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 916 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 919 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 918 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 890 B

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 914 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 915 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 917 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 919 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 913 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 916 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
assets/ui/heonian.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -2,15 +2,13 @@ return {
name = "level1",
tileset = tileset.library,
tiles = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
{ },
{ 0, 0, 0, 0, 0, 0, 5,25,26, 6,25,26, 7, 0, 5,25,26, 7},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7},
{ 0, 0, 0, 0, 0, 0, 5,49,50, 6,49,50, 7, 0, 5,49,50, 7},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}
}

View File

@ -16,4 +16,5 @@ require "data/scripts/lights"
require "data/scripts/objects"
-- UI functions
require "data/scripts/debug"
require "data/scripts/keybind"
require "data/scripts/pause"

View File

@ -34,8 +34,8 @@ function Animation:DrawFrame(frame, x, y, rotate, sx, sy)
local sy = sy or 1
love.graphics.draw(
self.imgs[frame],
x - Camera.pos.x,
y - Camera.pos.y,
math.floor(x - Camera.pos.x),
math.floor(y - Camera.pos.y),
rotate,
sx,
sy
@ -66,8 +66,8 @@ function Animation:Draw(x, y, rotate, sx, sy)
local sy = sy or 1
love.graphics.draw(
self.imgs[self.frame],
x,
y,
math.floor(x),
math.floor(y),
rotate,
sx,
sy

View File

@ -37,12 +37,13 @@ function DebugEntities()
love.graphics.setColor(0,1,0)
love.graphics.circle("fill", -Camera.pos.x + enty.pos.x, -Camera.pos.y + enty.pos.y, 1)
-- draw collision box PURPLE
love.graphics.setColor(0,1,1)
love.graphics.points(
-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.from.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.to.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.to.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.from.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.to.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.to.y
love.graphics.setColor(1,0,1)
love.graphics.rectangle(
"line",
-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x,
-Camera.pos.y + enty.pos.y + enty.boxCollision.from.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.to.x -(-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x),
-Camera.pos.y + enty.pos.y + enty.boxCollision.to.y -(-Camera.pos.y + enty.pos.y + enty.boxCollision.from.y)
)
end
end

View File

@ -28,13 +28,7 @@ function Arrow:Smart()
end
function Arrow:HandleAnimation()
self.body:Draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
self:Draw(self.body)
end
function Arrow:DoPhysics()

View File

@ -0,0 +1,33 @@
Decoration = Entity:New(x,y)
function Decoration:New(x,y,animation,lightRange)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
-- animations
o.body = Animation:New(animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if lightRange ~= nil then
o.lightRange = lightRange
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,nil,60/6)
end
setmetatable(o, self)
self.__index = self
return o
end
function Decoration:Smart()
end
function Decoration:HandleAnimation()
self.body:Animate()
self:Draw(self.body)
end
function Decoration:DoPhysics()
end

View File

@ -0,0 +1,64 @@
Fairy = Entity:New(x,y)
function Fairy:New(x,y)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = 0.23
o.range = 20
o.target = {x = x, y = y}
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
o.lightRange = 1155
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
setmetatable(o, self)
self.__index = self
return o
end
function Fairy:Smart()
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y - 10
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y)
if distance < self.range then
self.vel.x = 0
self.vel.y = 0
else
self.vel.x = math.cos(angle)*self.speed*distance/(8*game.scale)
self.vel.y = math.sin(angle)*self.speed*distance/(8*game.scale)
end
end
function Fairy:HandleAnimation()
self.body:Animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:Draw(self.body)
end
function Fairy:DoPhysics()
local random_x = math.random(-0.04,0.04)
local random_y = math.random(-0.04,0.04)
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
-- move
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
end
end

View File

@ -25,7 +25,7 @@ Kupo = Entity:New(x,y)
o.bow_aim_frames = 8
o.hostile = true
o.lightRange = o.range/10
o.lightRange = o.range/2
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
setmetatable(o, self)
@ -35,23 +35,17 @@ Kupo = Entity:New(x,y)
end
function Kupo:Smart()
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = math.atan(distance_y/distance_x)
local angle = GetAngleFromVector(distance_x,distance_y)
self.draw_bow = false
if distance <= self.range then
if distance_x > 0 then
self.sprite_flip.x = 1
else
angle = angle + math.rad(180)
self.sprite_flip.x = -1
end
if self.hostile == true then
self.draw_bow = true
-- fix so it can rotate from 0 to 360
@ -133,17 +127,20 @@ function Kupo:Smart()
end
function Kupo:HandleAnimation()
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
if distance_x > 0 then
self.sprite_flip.x = 1
else
self.sprite_flip.x = -1
end
-- flip sprite to look in the direction is moving
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
self.body:Animate()
self.body:Draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
self:Draw(self.body)
if self.draw_bow == true then
self.bow:DrawFrame(

View File

@ -7,15 +7,33 @@
Player.coins = 0
-- physics
o.moveSpeed = 1.5
o.moveSpeed = 1.3
o.zeroSpeed = 0.01
o.move_x = 0
o.airFriction = 0.01
o.groundFriction = 0.3
o.jumpImpulse = 3.5
o.dashCooldownTime = 0.1
o.dashCooldownTimer = 0
o.dashTimer = 0
o.dashTime = 0.15
o.dashDistance = 40
o.dashSpeed = o.dashDistance / (o.dashTime*60)
o.dashCount = 1
o.boxCollision = {
from = {x = -8, y = -16},
to = {x = 8, y = 0}
}
o.lightRange = 32
o.lightRange = 0--32
-- status
o.isDashing = false
o.isJumping = false
o.isOnGround = 0
o.coyoteValue = 5
@ -26,10 +44,11 @@
o.maskType = animation.moth_mask
-- sprite
o.sprite_offset = {x = 8, y = 16}
o.target_offset = {x = 0, y = 12}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
o:centerOffset(o.body)
o:getBoundingBox(o.body, 3,-3,0,-1)
-- lights
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
@ -41,25 +60,100 @@
end
function Player:Smart()
if love.keyboard.isDown("a") then self.vel.x = -self.moveSpeed
elseif love.keyboard.isDown("d") then self.vel.x = self.moveSpeed
else self.vel.x = 0 end
if love.keyboard.isDown("w") then self.vel.y = -self.moveSpeed
elseif love.keyboard.isDown("s") then self.vel.y = self.moveSpeed
else self.vel.y = 0 end
end
function Player:DoPhysics()
self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y
end
function Player:HandleAnimation()
-- light
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
else
self.vel.x = self.vel.x * (1-self.airFriction)
end
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
if love.keyboard.isDown(keybind.moveLeft) then
self.move_x = -self.moveSpeed
elseif love.keyboard.isDown(keybind.moveRight) then
self.move_x = self.moveSpeed
else
self.move_x = 0
end
self.vel.x = self.vel.x
if love.keyboard.isDown(keybind.moveJump) then
if self.isOnGround then
self.vel.y = -self.jumpImpulse
end
end
end
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
if love.keyboard.isDown(keybind.moveDash) then
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
self.dashCount = self.dashCount - 1
self.isDashing = true
local vertical = 0
if love.keyboard.isDown(keybind.moveDown) then vertical = vertical + 1 end
if love.keyboard.isDown(keybind.moveUp) then vertical = vertical - 1 end
local horizontal = 0
if love.keyboard.isDown(keybind.moveRight) then horizontal = horizontal + 1 end
if love.keyboard.isDown(keybind.moveLeft) then horizontal = horizontal - 1 end
if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x
end
self.dashDirection = GetAngleFromVector(horizontal, vertical)
self.dashTimer = self.dashTime
end
else
self.isDashing = false
end
end
function Player:DoPhysics()
self.isOnGround = false
self.dashTimer = self.dashTimer - current_dt
if self.dashTimer > 0 then
self.dashCooldownTimer = self.dashCooldownTime
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
else
self.dashTimer = 0
self.vel.y = self.vel.y + gravity
end
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x + self.move_x
else
self.vel.x = 0
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
else
if self.vel.y > 0 then
self.isOnGround = true
self.dashCount = 1
self.vel.y = 0
end
end
end
function Player:HandleAnimation()
if self.dashTimer > 0 then
self.sprite_tint = {1,1,0}
else
self.sprite_tint = {1,1,1}
end
-- flip sprite to look in the direction is moving
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
if self.move_x ~= 0 then self.sprite_flip.x = math.sign(self.move_x) end
-- animation priority
if self.vel.y > 1.25 then
@ -68,7 +162,7 @@ function Player:HandleAnimation()
elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump)
elseif self.vel.x ~= 0 then
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
else
@ -82,18 +176,8 @@ function Player:HandleAnimation()
end
self.body:Animate()
self.body:Draw(
math.floor(self.pos.x) - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
math.floor(self.pos.y)- Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
self.mask:Draw(
math.floor(self.pos.x) - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
math.floor(self.pos.y)- Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
self:Draw(self.body)
if self.dashCount > 0 then
self:Draw(self.mask)
end
end

View File

@ -1,5 +1,4 @@
Entity = {
}
Entity = {class = "Entity"}
function Entity:New(x,y)
o = {}
@ -8,14 +7,14 @@ function Entity:New(x,y)
o.boxCollision = {
from = {x = x, y = y},
to = {x = x, y = y}
to = {x = x, y = y},
}
o.class = "Entity"
o.target_offset = {x = 0, y = 0}
o.sprite_offset = {x = 0, y = 0}
o.sprite_scale = {x = 1, y = 1}
o.sprite_rotation = math.rad(0)
o.sprite_tint = {1,1,1}
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
@ -24,14 +23,45 @@ function Entity:New(x,y)
return o
end
function Entity:centerOffset(animation,x,y)
local x = x or 0
local y = y or 0
self.sprite_offset.x = animation.imgs[1]:getWidth()/2 + x
self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y
end
function Entity:getBoundingBox(animation,left,right,top,bottom)
local left = left or 0
local right = right or 0
local top = top or 0
local bottom = bottom or 0
self.boxCollision.from.x = -animation.imgs[1]:getWidth()/2 + left
self.boxCollision.to.x = animation.imgs[1]:getWidth()/2 + right
self.boxCollision.from.y = -animation.imgs[1]:getHeight()/2 + top
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom
end
function Entity:Draw(animation)
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3])
animation:Draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
love.graphics.setColor(c1,c2,c3,a)
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object)
local result = false
for _, col in pairs(object) do
result = self.pos.x + self.boxCollision.from.x < col.to.x
and self.pos.x + self.boxCollision.to.x > col.from.x
and self.pos.y + self.boxCollision.from.y < col.to.y
and self.pos.y + self.boxCollision.to.y > col.from.y
result = x + self.boxCollision.from.x < col.to.x
and col.from.x < x + self.boxCollision.to.x
and y + self.boxCollision.from.y < col.to.y
and col.from.y < y + self.boxCollision.to.y
if result == true then break end
end
return result
@ -39,9 +69,9 @@ end
function Entity:isCollidingWith(entity)
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
and self.pos.x + self.boxCollision.to.x > entity.pos.x + entity.boxCollision.from.x
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
and self.pos.y + self.boxCollision.to.y > entity.pos.y + entity.boxCollision.from.y
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y
end
function Entity:isCollidingAtAll(x,y)
@ -58,131 +88,8 @@ function Entity:isCollidingAtAll(x,y)
return result
end
--[[function Entity:Draw()
if self.sprite ~= nil then
local relative_position_x = self.pos.x - Camera.pos.x
local relative_position_y = self.pos.y - Camera.pos.y
local origin_compensation_x = - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation))
local origin_compensation_y = - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation))
local dimensions_x = self.sprite_scale.x * self.sprite_flip.x
local dimensions_y = self.sprite_scale.y * self.sprite_flip.y
love.graphics.draw(
self.sprite,
relative_position_x + origin_compensation_x * dimensions_x,
relative_position_y + origin_compensation_y * dimensions_y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
if debug_collision then
love.graphics.setColor(1, 0, 0)
love.graphics.circle( "line", relative_position_x, relative_position_y, 2 )
love.graphics.setColor(0, 1 ,0)
love.graphics.circle( "line",
relative_position_x + origin_compensation_x * dimensions_x,
relative_position_y + origin_compensation_y * dimensions_y,
2
)
end
love.graphics.setColor(1, 1 ,1)
end
end
function Entity:NewAnimation(anim,frames,speed)
local anim_data = {
frame = 1,
subframe = 1,
path = anim.path,
frames = anim.frames,
speed = anim.speed,
imgs = anim.imgs
}
self.animations[#self.animations+1] = anim_data
return self.animations[#self.animations]
end
function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy)
local x = x or 0
local y = y or 0
local sx = sx or 1
local sy = sy or 1
love.graphics.draw(
animation.imgs[frame],
x - Camera.pos.x,
y - Camera.pos.y,
rotate,
sx,
sy
)
end
function DrawAnimation(animation, x, y, rotate, sx, sy)
local x = x or 0
local y = y or 0
local sx = sx or 1
local sy = sy or 1
if game_paused ~= true then
-- try to animate
animation.subframe = animation.subframe + current_dt
if animation.subframe >= animation.speed then
animation.frame = animation.frame + 1
animation.subframe = animation.subframe - animation.speed
end
-- cycle
if animation.frame >= animation.frames+1 then
animation.frame = animation.frame - animation.frames
end
end
love.graphics.draw(
animation.imgs[animation.frame],
x - Camera.pos.x,
y - Camera.pos.y,
rotate,
sx,
sy
)
end
function Entity:Animate()
if game_paused ~= true and self.anim.path ~= nil then
-- try to animate
self.anim.subframe = self.anim.subframe + current_dt
if self.anim.subframe >= self.anim.speed then
self.anim.frame = self.anim.frame + 1
self.anim.subframe = self.anim.subframe - self.anim.speed
end
-- cycle
if self.anim.frame >= self.anim.frames+1 then
self.anim.frame = self.anim.frame - self.anim.frames
end
-- change
self.sprite = self.anim.imgs[self.anim.frame]
end
end
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
self.anim.frames = frames or 4
self.anim.speed = speed or frames
else
self.anim.path = anim.path
self.anim.frames = anim.frames
self.anim.speed = anim.speed
end
self.anim.imgs = anim.imgs
end
end
]]--
require "data/scripts/entities/kupo"
require "data/scripts/entities/arrow"
require "data/scripts/entities/decoration"
require "data/scripts/entities/player"
require "data/scripts/entities/fairy"

View File

@ -1,6 +1,20 @@
-- animationsç
-- all these are linear animations, maybe in the future make proper animations?
animation = {
fairy = {
flying = {
path = "assets/characters/fairy/flying",
frames = 2,
speed = 1/30
}
},
decoration = {
candelabra = {
path = "assets/characters/decoration/candelabra",
frames = 8,
speed = 1/6
}
},
kupo = {
body = {
path = "assets/characters/kupo/kupo",

View File

@ -1,9 +1,3 @@
function doOutput(table)
local file = io.open("map.json", "w")
io.output(file)
io.write(json.encode(table))
io.close(file)
end
function getInput(filename)
local file = io.open(filename, "r")

9
data/scripts/keybind.lua Normal file
View File

@ -0,0 +1,9 @@
keybind = {}
keybind.moveLeft = "left"
keybind.moveRight = "right"
keybind.moveUp = "up"
keybind.moveDown = "down"
keybind.moveJump = "z"
keybind.moveAttack = "x"
keybind.moveDash = "c"

View File

@ -8,8 +8,6 @@ function LevelLoadTiles()
overlay = render another tile id or, if multiple tiles {id, id, id,} or
overlay_depth = foreground/background overlay depth
type = collision type
]]
LevelData = dofile("Mothback/data/levels/"..currLevel..".lua")

View File

@ -2,7 +2,7 @@ Lights = {}
LightTimer = 0
function CreateDarkness()
return love.graphics.newCanvas(game.width, game.height)
return love.graphics.newCanvas(game.width/game.scale, game.height/game.scale)
end
function CreateLight(x,y,range,lum,flicker)
@ -13,10 +13,10 @@ function CreateLight(x,y,range,lum,flicker)
}
o.range = range
o.lum = lum or 1
o.flicker_value = flicker or 1
o.flicker_value = flicker or 2
o.flicker = 0
o.dim = 0
o.flicker_speed = flicker_speed or 10
o.flicker_speed = flicker_speed or 60/12
o.flicker_time = 0
table.insert(Lights,o)
return o
@ -34,37 +34,30 @@ function DoLights()
if light.flicker_time >= light.flicker_speed then
light.flicker_time = light.flicker_time - light.flicker_speed
light.flicker = 0 + math.random(-1,1)
light.flicker = 0 + math.random(0,1)
light.flicker = math.min(math.max(light.flicker, -light.flicker_value),light.flicker_value)
end
end
--[[
-- first, border
love.graphics.setColor(1,1,1)
love.graphics.setBlendMode("replace")
love.graphics.setColor(1,1,1,1)
for _, light in pairs(Lights) do
if light.range ~= 0 then
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
light.range + light.flicker + 1
(light.pos.x - Camera.pos.x) / game.scale,
(light.pos.y - Camera.pos.y) / game.scale,
(light.range + light.flicker + 1) / game.scale
)
end
]]
love.graphics.setBlendMode("replace")
for _, enty in pairs(LoadedEntities) do
end
local shades = 200
for i=1, shades do
love.graphics.setColor(0,0,0,0)
for _, light in pairs(Lights) do
local luminosity = shades*light.lum/100
love.graphics.setColor(0,0,0,math.min(1,math.max(0,(shades-i-luminosity+1)/(shades-luminosity+1))))
if light.range ~= 0 then
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
(light.range + light.flicker)*(shades-i+1)/shades
(light.pos.x - Camera.pos.x) / game.scale,
(light.pos.y - Camera.pos.y) / game.scale,
(light.range + light.flicker) / game.scale
)
end
end
@ -75,5 +68,5 @@ function DoBorder()
end
function DrawDarkness()
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 0.5, 0.5)
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 2/game.scale)
end

View File

@ -7,3 +7,11 @@ function math.sign(x)
return 0
end
end
function GetAngleFromVector(x,y)
local reduce = 0
if x < 0 then
reduce = math.rad(180)
end
return math.atan(y/x) - reduce
end

View File

@ -1,21 +1,28 @@
function love.load()
do_pause = false
debug = false
debug_collision = false
editor_mode = false
textScale = 1
fps_count = 0
fps_second = 0
fps_draw = 0
fps_total = 0
love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel
game = {
scale = 2,
width = love.graphics.getWidth(),
height = love.graphics.getHeight(),
paused = false
}
require "data/scripts"
Canvas = {
Darkness = CreateDarkness()
@ -23,19 +30,25 @@ function love.load()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
Camera.width = game.width
Camera.height = game.height
levelList = {"level1","2","3","ewae","tileset"}
levelNum = 1
currLevel = levelList[levelNum]
LoadedEntities = {}
LevelLoadTiles()
main_Player = Player:New(0,20)
main_Player = Player:New(75,50)
table.insert(LoadedEntities,main_Player)
table.insert(LoadedEntities,Kupo:New(700,150))
table.insert(LoadedEntities,Kupo:New(800,150))
CreateLight(200,64,80,nil,5,{1,0,0})
main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png")
table.insert(LoadedEntities,Decoration:New(200,89,animation.decoration.candelabra,80))
table.insert(LoadedEntities,Fairy:New(200,88))
gravity = 0.2
end
function love.update(dt)
@ -50,6 +63,12 @@ function love.update(dt)
fps_count = fps_count + 1
current_dt = dt
if editor_mode then
AnimateTiles()
else
-- GAME STEP
if not do_pause then
SetCollisionFlags(main_Player)
@ -62,6 +81,19 @@ function love.update(dt)
--camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
end
end
end
function love.wheelmoved(_, y)
if editor_mode then
if palette then
p_scroll = p_scroll + y
else
local oscale = game.scale
game.scale = math.max(0.1,game.scale + y/16)
end
end
end
function love.keypressed(key)
@ -86,19 +118,23 @@ function love.keypressed(key)
end
if key == "f2" then
main_Player.pos.x, main_Player.pos.y = -16,-0.1
if editor_mode then
else
main_Player.pos.x, main_Player.pos.y = 16,-10
end
end
if key == "f3" then
LoadLevel()
end
if key == "f5" then
levelNum = levelNum + 1
if levelNum > #levelList then levelNum = levelNum - #levelList end
currLevel = levelList[levelNum]
LevelLoadTiles()
main_Player.pos.x, main_Player.pos.y = 0,-0.1
if key == "f4" then
if editor_mode then
editor_mode = false
else
editor_mode = true
end
end
end