kupo nice now

bow nice
aim nice
arrow nice

all nice
This commit is contained in:
lustlion
2021-10-25 01:41:40 +02:00
parent 5b7924fe4e
commit 1e1f9edb45
22 changed files with 348 additions and 82 deletions

View File

@@ -0,0 +1,57 @@
Arrow = Entity:New(x,y)
function Arrow:New(x,y,rotation,speed)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = speed or 0
o.sprite_rotation = rotation or 0
o.vel = {
x = o.speed * math.cos(o.sprite_rotation),
y = o.speed * math.sin(o.sprite_rotation)
}
o.sprite_offset = {x = 13, y = 1}
o.stuck = false
setmetatable(o, self)
self.__index = self
table.insert(LoadedEntities,o)
return o
end
function Arrow:Smart()
end
function Arrow:HandleAnimation()
self:LoadAnimation(animation.kupo.arrow)
end
function Arrow: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
else
while not isThereCollisionAt(self.pos.x + math.sign(self.vel.x), self.pos.y) do
self.pos.x = self.pos.x + math.sign(self.vel.x)
end
self.stuck = true
end
-- vertical collision
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
self.pos.y = self.pos.y + self.vel.y
else
while not isThereCollisionAt(self.pos.x, self.pos.y + math.sign(self.vel.y)) do
self.pos.y = self.pos.y + math.sign(self.vel.y)
end
self.stuck = true
end
-- stuck into collisions
if self.stuck then
--lets allow the arrow to tip a bit into the thing
self.pos.x = self.pos.x + self.vel.x / 5
self.pos.y = self.pos.y + self.vel.y / 5
self.vel.x = 0
self.vel.y = 0
end
end

View File

@@ -5,22 +5,148 @@ Kupo = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = 20
o.range = 1000
o.range = 200
o.target = {x = x, y = y}
o.sprite_offset = {x = 8, y = 5}
-- kupo bow
o.bow = self:NewAnimation(animation.kupo.bow)
o.bow_flip = 1
o.bow_rotation = 0
o.bow_frame = 1
o.bow_subframe = 1
o.bow_aim_frame = 0
o.bow_speed = 1/10
o.bow_frames = 6
o.bow_extraframes = 18
o.bow_aim_frames = 8
setmetatable(o, self)
self.__index = self
return o
end
function Kupo:DoInput()
function Kupo:Smart()
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)
if distance <= self.range then
self.draw_bow = true
if distance_x > 0 then
self.sprite_flip.x = 1
else
angle = angle + math.rad(180)
end
-- fix so it can rotate from 0 to 360
if math.deg(self.bow_rotation - angle) < 0 then
self.bow_rotation = self.bow_rotation + math.rad(360)
end
-- fix so it can rotate from 360 to 0
if math.deg(self.bow_rotation - angle) > 180 then
self.bow_rotation = self.bow_rotation - math.rad(360)
end
-- actual rotation
if self.bow_rotation < angle then
self.bow_rotation = self.bow_rotation + math.rad(2)
else
self.bow_rotation = self.bow_rotation - math.rad(2)
end
--set in place
if math.abs(math.deg(self.bow_rotation) - math.deg(angle)) < 2 then
self.bow_rotation = angle
end
-- holding tight dispersion -- also affets arrows
if self.bow_rotation == angle then
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2))
end
-- AIMING AI
self.bow_subframe = self.bow_subframe + current_dt
if self.bow_subframe > self.bow_speed then
self.bow_subframe = self.bow_subframe - self.bow_speed
if self.bow_frame == 3 then
self.bow_aim_frame = self.bow_aim_frame + 1
if self.bow_aim_frame > self.bow_aim_frames then
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
self.bow_frame = self.bow_frame + 1
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,30)
end
else
self.bow_frame = self.bow_frame + 1
end
if self.bow_frame > self.bow_frames + self.bow_extraframes then
self.bow_frame = self.bow_frame - self.bow_frames - self.bow_extraframes
end
end
else
self.bow_frame = 6
self.draw_bow = true
-- rest bow animation
if distance_x > 0 then
if self.bow_rotation > math.rad(45) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(45) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 45) < 3 then
self.bow_rotation = math.rad(45)
end
self.sprite_flip.x = 1
else
if self.bow_rotation > math.rad(135) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(135) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 135) < 3 then
self.bow_rotation = math.rad(135)
end
self.sprite_flip.x = -1
end
end
self.angle = angle
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
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
self:LoadAnimation(animation.kupo.body)
if self.draw_bow == true then
DrawAnimationFrame(
self.bow,
math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)) * game.scale,
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)) * game.scale,
self.bow_rotation
)
end
if debug_collision then
love.graphics.setColor(1,0,0)
love.graphics.line(
self.pos.x - Camera.pos.x,
self.pos.y - Camera.pos.y,
self.target.x - Camera.pos.x,
self.target.y - Camera.pos.y
)
love.graphics.circle( "line", self.pos.x - Camera.pos.x, self.pos.y - Camera.pos.y, self.range )
love.graphics.setColor(1,1,1)
love.graphics.print(self.bow_rotation, self.pos.x, self.pos.y+30)
love.graphics.print(self.angle, self.pos.x, self.pos.y+50)
end
end
function Kupo:DoPhysics()

View File

@@ -1,6 +1,44 @@
Player = Entity:New(x,y)
function Player:DoInput()
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.sprite_offset = {x = 8, y = 16}
o.target_offset = {x = 4, y = 12}
setmetatable(o, self)
self.__index = self
return o
end
function Player:Smart()
-- PLATFORMER INPUT
if self.isOnGround > 0 then
-- apply friction
@@ -42,7 +80,7 @@ end
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
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
-- animation manager
if self.isOnLadder then
@@ -163,40 +201,3 @@ function Player:DoPhysics()
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/20, 1))
end
end
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
return o
end