Second character and camera

This commit is contained in:
Entarno54 2025-05-29 09:53:44 +07:00
parent 0d31c90532
commit 2e96933c7a
8 changed files with 2772 additions and 16 deletions

View File

@ -173,7 +173,7 @@
350
],
"healthicon": "bf",
"flip_x": true,
"flip_x": false,
"healthbar_colors": [
49,
176,

144
characters/tankman.json Normal file
View File

@ -0,0 +1,144 @@
{
"animations": [
{
"offsets": [
0,
0
],
"loop": false,
"fps": 24,
"anim": "idle",
"indices": [],
"name": "Tankman Idle Dance "
},
{
"offsets": [
54,
49
],
"loop": false,
"fps": 24,
"anim": "singUP",
"indices": [],
"name": "Tankman UP note "
},
{
"offsets": [
81,
-105
],
"loop": false,
"fps": 24,
"anim": "singDOWN",
"indices": [],
"name": "Tankman DOWN note "
},
{
"offsets": [
89,
-12
],
"loop": false,
"fps": 24,
"anim": "singLEFT",
"indices": [],
"name": "Tankman Right Note "
},
{
"offsets": [
-23,
-31
],
"loop": false,
"fps": 24,
"anim": "singRIGHT",
"indices": [],
"name": "Tankman Note Left "
},
{
"offsets": [
-14,
-8
],
"loop": false,
"fps": 24,
"anim": "singUP-alt",
"indices": [],
"name": "TANKMAN UGH "
},
{
"offsets": [
2,
16
],
"loop": false,
"fps": 24,
"anim": "singDOWN-alt",
"indices": [],
"name": "PRETTY GOOD tankman "
},
{
"offsets": [
3,
8
],
"loop": false,
"fps": 24,
"anim": "dodge",
"indices": [],
"name": "Tankman Dodg"
},
{
"loop": false,
"offsets": [
126,
117
],
"anim": "die",
"fps": 20,
"name": "Tankman Die",
"indices": []
},
{
"offsets": [
0,
0
],
"indices": [],
"fps": 24,
"anim": "",
"loop": false,
"name": ""
},
{
"offsets": [
0,
0
],
"indices": [],
"fps": 24,
"anim": "prettygood",
"loop": false,
"name": "PRETTY GOOD tankman "
}
],
"no_antialiasing": false,
"image": "sprites/tankmanCaptain",
"position": [
0,
240
],
"healthicon": "tankman",
"flip_x": true,
"healthbar_colors": [
225,
225,
225
],
"camera_position": [
-200,
-5000
],
"sing_duration": 4,
"scale": 1
}

View File

@ -76,11 +76,18 @@ local holded = {
false
}
local receptors = {
}
function love.load()
characters.bf = myTypes.character("bf")
characters.bf.stagePosition = myTypes.Vector2(stage.boyfriend[1], stage.boyfriend[2])
characters.dad = myTypes.character("tankman")
characters.dad.stagePosition = myTypes.Vector2(stage.opponent[1], stage.opponent[2])
for index, section in next, chart.notes do
for index, note in next, section.sectionNotes do
local newNote = myTypes.note(note, section.mustHitSection)
@ -89,12 +96,16 @@ function love.load()
end
for i = 0, 3 do
local receptor = myTypes.Rect("sprites/NOTE_assets.png", "sprites/NOTE_assets.json")
receptor:Frame("arrow"..directions[i+1], 0)
local receptor = myTypes.Sprite("sprites/NOTE_assets.png", "sprites/NOTE_assets.json", false)
receptor:PlayAnimation("arrow"..directions[i+1], 25, false)
receptor.position = myTypes.Vector2(100 + (65 * i), 0)
end
receptor.ui = true -- So it doesnt move with the camera.
receptors[i + 1] = receptor
end
inst:play()
voices:play()
@ -107,6 +118,9 @@ local function checkNote(dir)
if pressed[dir] or holded[dir] then
pressed[dir] = false
holded[dir] = true
if receptors[dir].animation ~= string.lower(directions[dir]).." confirm" then
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." press", 25, false)
end
return -- You dont check if you are already holding and not just pressing
end
pressed[dir] = true
@ -115,6 +129,7 @@ local function checkNote(dir)
if note.mustPress and not note.pressed and note.direction == dir then
characters.bf:PlayAnimation("sing"..directions[note.direction])
note.pressed = true
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." confirm", 25, false)
table.remove(notes, index)
note:destroy()
end
@ -197,17 +212,43 @@ function love.update(dt)
note:spawn()
table.remove(unspawnedNotes, index)
table.insert(notes, note)
elseif note.position - elapsed < 600 and not note.mustPress then
table.remove(unspawnedNotes, index)
table.insert(notes, note)
end
end
for index, note in next, notes do
note.sprite.position = myTypes.Vector2(100 + 65 * (note.direction - 1), note.position - elapsed - 100)
if note.position - elapsed < -150 then
note:destroy()
table.remove(notes, index)
if note.spawned then
note.sprite.position = myTypes.Vector2(100 + 65 * (note.direction - 1), note.position - elapsed - 100)
if note.position - elapsed < -150 then
note:destroy()
table.remove(notes, index)
end
else
if note.position - elapsed < 0 then
table.remove(notes, index)
characters.dad:PlayAnimation("sing"..directions[note.direction])
note = nil
end
end
end
for index, receptor in next, receptors do
if receptor.ended and receptor.animation ~= "arrow"..directions[index] and receptor.animation ~= "" then
receptor:PlayAnimation("arrow"..directions[index], 25, false)
end
end
local section = chart.notes[math.floor(step / 16) + 1]
if section.mustHitSection then
myTypes.cameraTarget = myTypes.Vector2(-stage.camera_boyfriend[1], -stage.camera_boyfriend[2]):Add(characters.bf.stageCamera:Negate())
else
-- When i add DAD he will be here too
myTypes.cameraTarget = myTypes.Vector2(-stage.camera_opponent[1], -stage.camera_opponent[2]):Add(characters.dad.stageCamera:Negate())
end
if not inst:isPlaying() then
love.event.quit()
end

View File

@ -24,8 +24,16 @@ function Vector2:Get()
return self.x, self.y
end
function Vector2:Negate()
return module.Vector2(-self.x, -self.y)
end
function Vector2:Add(addVector2)
return module.Vector2(self.x + addVector2.x, self.y + addVector2.y)
end
function module.Vector2(x, y)
return setmetatable({x = x, y = y}, Vector2)
return setmetatable({x = x or 0, y = y or 0}, Vector2)
end
function module.Sprite(image, sheet)
@ -49,7 +57,7 @@ function module.Sprite(image, sheet)
elapsed = 0,
fps = 10,
animation = nil,
frame = 1,
frame = 0,
position = module.Vector2(200, 100), -- changeable
looping = false,
extraOffset = module.Vector2(0,0),
@ -130,18 +138,29 @@ function module.updateSprites(dt)
::continue:: -- At the end. always.
end
end
module.draws = {}
if not module.cameraPosition then
module.cameraPosition = module.Vector2()
end
module.cameraPosition = module.cameraPosition:Lerp(module.cameraTarget or module.Vector2(0,0), .2)
end
function module.drawSprites()
for index, sprite in next, Sprites do
if not sprite.animation then goto continue end -- For some reason OG LUA doesnt have continue
if not sprite.animation or not sprite.quads or not sprite.quads[sprite.animation] then goto continue end -- For some reason OG LUA doesnt have continue
-- So im forced to use goto ::continue:: since it goes straight to the last point of the cycle
local quad = sprite.quads[sprite.animation][sprite.frame] or sprite.quads[sprite.animation][0]
if not quad then goto continue end
love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x)), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y)), 0, quad.resize.x, quad.resize.y)
if quad.offset.x == 0 and quad.offset.y == 0 and sprite.quads[sprite.animation][0].offset.x ~= 0 then
quad.offset.x = sprite.quads[sprite.animation][0].offset.x
quad.offset.y = sprite.quads[sprite.animation][0].offset.y
end
local cameraOffset = sprite.ui and module.Vector2() or module.cameraPosition
love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x) + cameraOffset.x), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (sprite.flipX and -1 or 1), quad.resize.y)
::continue:: -- Point itself
end
@ -150,7 +169,9 @@ function module.drawSprites()
local quad = rect.quads[rect.animation][0]
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x)), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y)), 0, quad.resize.x, quad.resize.y)
local cameraOffset = rect.ui and module.Vector2() or module.cameraPosition
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x) + cameraOffset.x), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (rect.flipX and -1 or 1), quad.resize.y)
::continue::
end
end

View File

@ -28,13 +28,17 @@ function module.character(name)
local sprite = module.myTypes.Sprite(image, sheet)
sprite.position = module.myTypes.Vector2(parsed.position[1], parsed.position[2])
sprite.flipX = parsed.flip_x
local newCharacter = setmetatable({
scale = parsed.scale,
animations = {},
animInfo = {},
sprite = sprite,
singing = false,
stagePosition = module.myTypes.Vector2(0,0) -- Changeable
stagePosition = module.myTypes.Vector2(0,0), -- Changeable
stageCamera = module.myTypes.Vector2(parsed.camera_position[1], parsed.camera_position[2]),
flipX = parsed.flip_x
}, CharacterClass)
for index, alias in next, parsed.animations do

View File

@ -31,6 +31,8 @@ function NoteClass:spawn()
sprite:Frame(sprites[self.direction], 0)
sprite.ui = true -- so it doesnt move with the camera
self.spawned = true
end

2544
sprites/tankmanCaptain.json Normal file

File diff suppressed because it is too large Load Diff

BIN
sprites/tankmanCaptain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB