diff --git a/game/constants.lua b/game/constants.lua index 11b466e..e26dc39 100644 --- a/game/constants.lua +++ b/game/constants.lua @@ -7,6 +7,8 @@ _M.SoundName = { PlayerHurt = "PLAYER_HURT", MonsterHurt = "MONSTER_HURT", GameOver = "GAMEOVER", + HpRecover = "HPRECOVER", + PickupGun = "PickupGun", } _M.TileSize = 32 @@ -90,7 +92,7 @@ _M.RoleState = { Ice = 2, Fire = 3, } -_M.SupplyFalldownKillNum = 120 +_M.SupplyFalldownKillNum = 20 _M.SupplyType = { IceGun = 1, @@ -98,8 +100,8 @@ _M.SupplyType = { HpRecover = 3, } _M.SupplyItem = { - [_M.SupplyType.IceGun] = { num = 100 }, - [_M.SupplyType.FireGun] = { num = 100 }, + [_M.SupplyType.IceGun] = { num = 50}, + [_M.SupplyType.FireGun] = { num = 50}, [_M.SupplyType.HpRecover] = { recover = 50}, } diff --git a/game/content.lua b/game/content.lua index 9ca6b76..5e72cd1 100644 --- a/game/content.lua +++ b/game/content.lua @@ -34,11 +34,16 @@ _M.GameStateEnum = { Gaming = 3, } +_M.HpRecoverListAnim = {} + _M.GameState = _M.GameStateEnum.ShowLogo ---@type table _M.MonsterList = {} +---@type table +_M.MonsterCorpseList = {} + _M.MonsterBirthNum = 0 _M.MonsterBirthCountDown = 0 diff --git a/game/ecs.lua b/game/ecs.lua index 3ee6adb..b9cf67c 100644 --- a/game/ecs.lua +++ b/game/ecs.lua @@ -699,5 +699,4 @@ function _M.CreateSupply(type, pos) return entity end - return _M \ No newline at end of file diff --git a/game/main.lua b/game/main.lua index 5af8d48..5497471 100644 --- a/game/main.lua +++ b/game/main.lua @@ -71,6 +71,13 @@ local function updateMonster() end end +local function updateMonsterCropse() + ---@param v Entity + for _, v in pairs(content.MonsterCorpseList) do + v:Update() + end +end + local function updateSupply() ---@param v Entity for _, v in pairs(content.SupplyList) do @@ -101,7 +108,10 @@ local function collisionDeal() monsterBox.w, monsterBox.h) ---@type RolePropComponent local monsterRoleProp = monster:GetComponent(ECS.ComponentType.RoleProp) - if vmath.IsRectIntersect(playerColliBox, monsterColliBox) then + ---@type StateComponent + local mosnterState = monster:GetComponent(ECS.ComponentType.State):GetState() + + if mosnterState ~= constants.RoleState.Ice and vmath.IsRectIntersect(playerColliBox, monsterColliBox) then ---@type InvincibleComponent local playerInvincible = content.PlayerEntity:GetComponent(ECS.ComponentType.Invincible) if playerInvincible and not playerInvincible:IsInvincibleState() then @@ -155,6 +165,8 @@ local function collisionDeal() content.Score = content.Score + 1 helpfunc.IncKillNum() end + table.insert(content.MonsterCorpseList, monster) + content.MonsterList[km] = nil end end end @@ -173,8 +185,16 @@ local function collisionDeal() ---@type GunComponent local gun = content.PlayerEntity:GetComponent(ECS.ComponentType.Gun) local type = v:GetComponent(ECS.ComponentType.Supply).type - print(type) if type == constants.SupplyType.HpRecover then + local index = #content.HpRecoverListAnim + 1 + local hpRecoverAnim = animation.CreateAnimation(content.Tilesheet, { + {row = 12, col = 0, time = 0.5}, + }, function() + content.HpRecoverListAnim[index] = nil + end) + hpRecoverAnim:Play() + table.insert(content.HpRecoverListAnim, index, hpRecoverAnim) + hazel.Sound.Play(constants.SoundName.HpRecover) ---@type RolePropComponent local roleProp = content.PlayerEntity:GetComponent(ECS.ComponentType.RoleProp) roleProp.hp = roleProp.hp + constants.SupplyItem[type].recover @@ -184,9 +204,11 @@ local function collisionDeal() elseif type == constants.SupplyType.IceGun then gun:SetType(constants.BulletType.Ice) gun.bulletNum = gun.bulletNum + constants.SupplyItem[type].num + hazel.Sound.Play(constants.SoundName.PickupGun) elseif type == constants.SupplyType.FireGun then gun:SetType(constants.BulletType.Fire) gun.bulletNum = gun.bulletNum + constants.SupplyItem[type].num + hazel.Sound.Play(constants.SoundName.PickupGun) end end end @@ -218,6 +240,7 @@ end local function initGame() content.KillNum = 0 content.Score = 0 + content.HpRecoverListAnim = {} content.BulletList = {} content.MonsterList = {} content.SupplyList = {} @@ -297,6 +320,23 @@ local function drawNum(num, x, y) end end +local function updateHpRecoverAnim() + for _, ani in pairs(content.HpRecoverListAnim) do + if ani:IsPlaying() then + ani:Update() + ---@type TileSheet + local tilesheet = ani:GetTilesheet() + ---@type Frame + local frame = ani:GetCurFrame() + ---@type Point + local pos = content.PlayerEntity:GetComponent(ECS.ComponentType.Transform).position + tilesheet:Draw(frame.col, frame.row, + hazel.CreateRect(pos.x, pos.y - constants.TileSize - 5, + constants.TileSize, constants.TileSize)) + end + end +end + local function updateRoles() ---@param monster Entity for _, monster in pairs(content.MonsterList) do @@ -322,13 +362,15 @@ function GameStart() content.RestartHintTexture = hazel.LoadTexture("resources/RestartHint.png") content.LicensTexture = hazel.LoadTexture("resources/License.png") content.StartHintTexture = hazel.LoadTexture("resources/StartHint.png") - content.Tilesheet = hazel.CreateTileSheet(content.Texture, 3, 12) + content.Tilesheet = hazel.CreateTileSheet(content.Texture, 3, 13) content.NumberTexture = hazel.LoadTexture("resources/numbers.png") content.NumberTilesheet = hazel.CreateTileSheet(content.NumberTexture, 11, 1) hazel.Sound.Load("resources/gameover.wav", constants.SoundName.GameOver) hazel.Sound.Load("resources/player_hurt.wav", constants.SoundName.PlayerHurt) hazel.Sound.Load("resources/monster_hurt.wav", constants.SoundName.MonsterHurt) hazel.Sound.Load("resources/shoot.wav", constants.SoundName.Shoot) + hazel.Sound.Load("resources/hprecover.wav", constants.SoundName.HpRecover) + hazel.Sound.Load("resources/pickupgun.wav", constants.SoundName.PickupGun) initGame() @@ -373,6 +415,7 @@ function GameLoop() if content.GameState == content.GameStateEnum.WaitStart or content.GameState == content.GameStateEnum.Gaming then drawFloors() + updateMonsterCropse() updateSupply() updateMonster() content.PlayerEntity:Update() @@ -380,6 +423,7 @@ function GameLoop() collisionDeal() drawCurosr() updateRoles() + updateHpRecoverAnim() end ---@type RolePropComponent @@ -395,8 +439,18 @@ function GameLoop() ---@type GunComponent local gun = content.PlayerEntity:GetComponent(ECS.ComponentType.Gun) local x = hazel.GetCanvaSize().x - 128 + content.Tilesheet:Draw(2, 11, hazel.CreateRect(x - 64, 22, 50, 50)) drawNum(content.Score, x, 32) if gun then + ---@param type number + local type = gun.type + if type == constants.BulletType.Fire then + content.Tilesheet:Draw(1, 10, hazel.CreateRect(x - 64, 70, 50, 50)) + elseif type == constants.BulletType.Ice then + content.Tilesheet:Draw(0, 10, hazel.CreateRect(x - 64, 80, 50, 50)) + else + content.Tilesheet:Draw(1, 4, hazel.CreateRect(x - 64, 80, 50, 50)) + end drawNum(gun:GetBulletNum(), x, 80) end end diff --git a/game/resources/hprecover.wav b/game/resources/hprecover.wav new file mode 100644 index 0000000..0503bca Binary files /dev/null and b/game/resources/hprecover.wav differ diff --git a/game/resources/pickupgun.wav b/game/resources/pickupgun.wav new file mode 100644 index 0000000..0febf68 Binary files /dev/null and b/game/resources/pickupgun.wav differ diff --git a/game/resources/tilesheet.png b/game/resources/tilesheet.png index e23f347..b18a221 100644 Binary files a/game/resources/tilesheet.png and b/game/resources/tilesheet.png differ