uh yeah i keep forgetting ab pushing these. sorry.
This commit is contained in:
@@ -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()
|
||||
|
||||
33
data/scripts/entities/decoration.lua
Normal file
33
data/scripts/entities/decoration.lua
Normal 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
|
||||
64
data/scripts/entities/fairy.lua
Normal file
64
data/scripts/entities/fairy.lua
Normal 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
|
||||
@@ -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,26 +127,29 @@ function Kupo:Smart()
|
||||
end
|
||||
|
||||
function Kupo:HandleAnimation()
|
||||
-- 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
|
||||
local distance_x = self.target.x - self.pos.x
|
||||
local distance_y = self.target.y - self.pos.y
|
||||
|
||||
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
|
||||
)
|
||||
if distance_x > 0 then
|
||||
self.sprite_flip.x = 1
|
||||
else
|
||||
self.sprite_flip.x = -1
|
||||
end
|
||||
|
||||
if self.draw_bow == true then
|
||||
self.bow:DrawFrame(
|
||||
math.min(self.bow_frame,self.bow_frames),
|
||||
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
|
||||
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
|
||||
self.bow_rotation
|
||||
)
|
||||
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:Draw(self.body)
|
||||
|
||||
if self.draw_bow == true then
|
||||
self.bow:DrawFrame(
|
||||
math.min(self.bow_frame,self.bow_frames),
|
||||
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
|
||||
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
|
||||
self.bow_rotation
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function Kupo:DoPhysics()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user