new animations + images

This commit is contained in:
Juan 2025-08-26 17:53:17 -04:00
parent ede6bb6d91
commit 5077f3390f
27 changed files with 117 additions and 51 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 B

After

Width:  |  Height:  |  Size: 777 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 734 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 650 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 677 B

After

Width:  |  Height:  |  Size: 851 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 627 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

View file

@ -25,7 +25,7 @@ function love.load()
cursor = Cursor:new() cursor = Cursor:new()
-- Create a MeatFactory instance -- Create a MeatFactory instance
meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"}) meatFactory = MeatFactory:new(5, {"chicken"})
instances = {} instances = {}
instances.meats = {} instances.meats = {}
@ -37,6 +37,9 @@ end
function love.update(dt) function love.update(dt)
cursor:update(dt) cursor:update(dt)
meatFactory:update(dt) meatFactory:update(dt)
for _, meat in ipairs(instances.meats) do
meat:update(dt)
end
end end
function love.draw() function love.draw()

View file

@ -8,75 +8,111 @@ function Cleaver:new()
instance.timer = 0 instance.timer = 0
instance.score = 0 instance.score = 0
instance.images = {} instance.images = {}
instance.frame = 1
Cleaver.loadImages(instance) Cleaver.loadImages(instance)
return instance return instance
end end
function Cleaver:loadImages() function Cleaver:loadImages()
self.images.idle = love.graphics.newImage("assets/images/cleaver/cleaver-idle.png") self.images.idle = {love.graphics.newImage("assets/images/cleaver/cleaver-idle.png")}
self.images.windup = love.graphics.newImage("assets/images/cleaver/cleaver-windup.png") self.images.windup = {
self.images.charged = love.graphics.newImage("assets/images/cleaver/cleaver-charged.png") love.graphics.newImage("assets/images/cleaver/cleaver-windup-1.png"),
self.images.chop = love.graphics.newImage("assets/images/cleaver/cleaver-chop.png") love.graphics.newImage("assets/images/cleaver/cleaver-windup-2.png"),
self.currentImage = self.images.idle }
self.images.charged = {
love.graphics.newImage("assets/images/cleaver/cleaver-charged-1.png"),
love.graphics.newImage("assets/images/cleaver/cleaver-charged-2.png"),
love.graphics.newImage("assets/images/cleaver/cleaver-charged-3.png"),
}
self.images.chop = {
love.graphics.newImage("assets/images/cleaver/cleaver-chop.png"),
love.graphics.newImage("assets/images/cleaver/cleaver-chop-2.png"),
love.graphics.newImage("assets/images/cleaver/cleaver-chop-3.png"),
love.graphics.newImage("assets/images/cleaver/cleaver-retract.png"),
}
self.currentImage = self.images.idle[1]
end end
function Cleaver:update(dt) function Cleaver:update(dt)
if self.state == "windup" then if self.state == "windup" then
self.timer = self.timer + dt self.timer = self.timer + dt
if self.timer >= 0.2 then if self.timer >= 0.1 then
self.state = "charged" self.frame = self.frame + 1
self.currentImage = self.images.charged if self.frame > #self.images.windup then
self.state = "charged"
self.frame = 1
self.currentImage = self.images.charged[self.frame]
else
self.currentImage = self.images.windup[self.frame]
end
self.timer = 0
end end
elseif self.state == "charged" then elseif self.state == "charged" then
-- Stay in charged state until mouse is released self.timer = self.timer + dt
if self.timer >= 0.1 then
self.frame = self.frame + 1
if self.frame > #self.images.charged then
self.frame = 1
end
self.currentImage = self.images.charged[self.frame]
self.timer = 0
end
elseif self.state == "chop" then elseif self.state == "chop" then
self.timer = self.timer + dt self.timer = self.timer + dt
if self.timer >= 0.1 then if self.timer >= 0.1 then
self.frame = self.frame + 1
if self.frame > #self.images.chop then
self.state = "idle" self.state = "idle"
self.currentImage = self.images.idle self.frame = 1
self.timer = 0 self.currentImage = self.images.idle[self.frame]
else
self.currentImage = self.images.chop[self.frame]
end end
self.timer = 0
end end
end end
function Cleaver:draw(x,y)
love.graphics.draw(self.currentImage, x - self.currentImage:getWidth() / 2, y - self.currentImage:getHeight() / 2)
end end
function Cleaver:draw(x, y)
love.graphics.draw(self.currentImage, x - self.currentImage:getWidth() / 2, y - self.currentImage:getHeight() / 2)
end
function Cleaver:mousepressed(button) function Cleaver:mousepressed(button)
if button == 1 then -- Left mouse button if button == 1 then -- Left mouse button
self.state = "windup" self.state = "windup"
self.currentImage = self.images.windup self.frame = 1
self.currentImage = self.images.windup[self.frame]
self.timer = 0 self.timer = 0
end end
end end
function Cleaver:mousereleased(button) function Cleaver:mousereleased(button)
if button == 1 then -- Left mouse button if button == 1 then -- Left mouse button
if self.state == "charged" then if self.state == "charged" then
self.state = "chop" self.state = "chop"
self.currentImage = self.images.chop self.frame = 1
self.timer = 0 self.currentImage = self.images.chop[self.frame]
-- Check if the cleaver is hovering over a meat instance self.timer = 0
local x, y = love.mouse.getPosition() -- Check if the cleaver is hovering over a meat instance
for i, meat in ipairs(instances.meats) do local x, y = love.mouse.getPosition()
if x >= meat.x and x <= meat.x + meat.currentImage:getWidth() and y >= meat.y and y <= meat.y + meat.currentImage:getHeight() then for i, meat in ipairs(instances.meats) do
-- Remove the meat instance from the table if x >= meat.x and x <= meat.x + meat.currentImage:getWidth() and y >= meat.y and y <= meat.y + meat.currentImage:getHeight() then
table.remove(instances.meats, i) -- Remove the meat instance from the table
self.score = self.score + 1 meat.meatFactory.hasMeat = false
break table.remove(instances.meats, i)
self.score = self.score + 1
break
end
end
elseif self.state == "windup" then
self.state = "idle"
self.frame = 1
self.currentImage = self.images.idle[self.frame]
self.timer = 0
end end
end
elseif self.state == "windup" then
self.state = "idle"
self.currentImage = self.images.idle
self.timer = 0
end end
end
end end
function Cleaver:getScore() function Cleaver:getScore()
return self.score return self.score
end end

View file

@ -2,16 +2,21 @@
Meat = {} Meat = {}
Meat.__index = Meat Meat.__index = Meat
function Meat:new(x , y, meatType) function Meat:new(x, y, meatType, meatFactory)
local instance = setmetatable({}, Meat) local instance = setmetatable({}, Meat)
instance.meatFactory = meatFactory
instance.meatType = meatType instance.meatType = meatType
instance.images = {} instance.images = {}
instance.spawnImages = {}
instance.currentImage = "" instance.currentImage = ""
instance.scorePending = false instance.scorePending = false
instance.value = 1 instance.value = 1
instance.x = x instance.x = x
instance.y = y instance.y = y
instance.spawnFrame = 1
instance.spawnTimer = 0
Meat.loadImages(instance) Meat.loadImages(instance)
instance.currentImage = instance.spawnImages[instance.spawnFrame]
return instance return instance
end end
@ -19,22 +24,41 @@ function Meat:loadImages()
self.images.chicken = love.graphics.newImage("assets/images/meats/chicken.png") self.images.chicken = love.graphics.newImage("assets/images/meats/chicken.png")
self.images.pig = love.graphics.newImage("assets/images/meats/pig.png") self.images.pig = love.graphics.newImage("assets/images/meats/pig.png")
self.images.cow = love.graphics.newImage("assets/images/meats/cow.png") self.images.cow = love.graphics.newImage("assets/images/meats/cow.png")
if self.meatType == "chicken" then for i = 1, 6 do
self.currentImage = self.images.chicken table.insert(self.spawnImages, love.graphics.newImage("assets/images/meats/meat-spawn-" .. i .. ".png"))
end end
if self.meatType == "pig" then end
self.currentImage = self.images.pig
end function Meat:update(dt)
if self.meatType == "cow" then self.spawnTimer = self.spawnTimer + dt
self.currentImage = self.images.cow if self.spawnTimer >= 0.1 then
self.spawnFrame = self.spawnFrame + 1
if self.spawnFrame == 2 then
if self.meatType == "chicken" then
self.baseImage = self.images.chicken
elseif self.meatType == "pig" then
self.baseImage = self.images.pig
elseif self.meatType == "cow" then
self.baseImage = self.images.cow
end
self.currentImage = self.spawnImages[self.spawnFrame]
elseif self.spawnFrame > 2 and self.spawnFrame <= #self.spawnImages then
self.currentImage = self.spawnImages[self.spawnFrame]
end
self.spawnTimer = 0
end end
end end
function Meat:draw() function Meat:draw()
local tableImage = love.graphics.newImage("assets/images/env/newer_table.png") local tableImage = love.graphics.newImage("assets/images/env/newer_table.png")
local x = self.x + (tableImage:getWidth() - self.currentImage:getWidth()) - 15 local x = self.x + (tableImage:getWidth() - self.currentImage:getWidth())
local y = self.y + (tableImage:getHeight() - self.currentImage:getHeight()) - 30 local y = self.y + (tableImage:getHeight() - self.currentImage:getHeight()) - 30
love.graphics.draw(self.currentImage, x, y) if self.baseImage then
love.graphics.draw(self.baseImage, x, y)
end
if self.spawnFrame > 1 and self.spawnFrame <= #self.spawnImages then
love.graphics.draw(self.currentImage, x, y)
end
end end
return Meat return Meat

View file

@ -11,7 +11,8 @@ function MeatFactory:new(spawnRate, meatTypes)
instance.spawnTimer = 0 instance.spawnTimer = 0
instance.image = love.graphics.newImage("assets/images/env/newer_table.png") instance.image = love.graphics.newImage("assets/images/env/newer_table.png")
instance.x = (love.graphics.getWidth() - instance.image:getWidth()) / 2; instance.x = (love.graphics.getWidth() - instance.image:getWidth()) / 2;
instance.y = (love.graphics.getHeight() - instance.image:getHeight()) / 2; instance.y = (love.graphics.getHeight() - instance.image:getHeight()) / 2;
instance.hasMeat = false
return instance return instance
end end
@ -32,10 +33,12 @@ end
function MeatFactory:spawnMeat() function MeatFactory:spawnMeat()
local meatType = self.meatTypes[math.random(#self.meatTypes)] if not self.hasMeat then
local meat = Meat:new(self.x , self.y, meatType) local meatType = self.meatTypes[math.random(#self.meatTypes)]
table.insert(instances.meats, meat) local meat = Meat:new(self.x , self.y, meatType, self)
table.insert(instances.meats, meat)
self.hasMeat = true
end
end end
function MeatFactory:getMeatValue(meatType) function MeatFactory:getMeatValue(meatType)

0
src/upgrade_table.lua Normal file
View file