From 3303c52fbce42facf506174a928f62111e283f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 29 Jun 2019 23:35:02 +0300 Subject: [PATCH] Have it be a coinflip whether you or a slime will die --- README | 2 +- bundle/main.lua | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README b/README index 87ac6dc..898fb5f 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ A dungeon crawler. That is, you are crawling around in a dungeon. Find the Orb of Èitmer hidden within the dungeon, and beware the slimes for -they will consume you if they catch up to you. +it is up to chance whether you or they will prevail should you meet. Movement: diff --git a/bundle/main.lua b/bundle/main.lua index 6c516f5..cb9c10e 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -602,7 +602,7 @@ function newGame() end function moveSlimes() - for i, slime in ipairs(slimes) do + for i, slime in pairs(slimes) do local dx = 0 local dy = 0 @@ -651,6 +651,17 @@ function moveSlimes() end end +function killSlime() + local body_x, body_y = getBodyLocation() + + for i, slime in pairs(slimes) do + if slime.x == player_x and slime.y == player_y or slime.x == body_x and slime.y == body_y then + cavern[slime.x][slime.y] = tiletypes.empty + slimes[i] = nil + end + end +end + function step(direction) if game_mode == gamemodes.normal then if last_direction_moved == direction then @@ -673,7 +684,11 @@ function step(direction) end if collidedPlayerSlime() then - newGame() + if math.random(0, 1) == 0 then + newGame() + else + killSlime() + end end end end