Moles that bumble about the meadow leaving little hills of dirt, and tidy the old ones away.
| 1 | --!strict |
| 2 | -- Mole: bumbles about south of the Green leaving molehills, a few at a |
| 3 | -- time: when it has made enough, it flattens its oldest one again. |
| 4 | |
| 5 | local world = require("@potluck/world") |
| 6 | local tweak = require("@potluck/tweak") |
| 7 | local sound = require("@potluck/sound@0.1") |
| 8 | |
| 9 | local knobs = tweak { |
| 10 | hills = { 4, min = 0, max = 10, label = "Molehills each", order = 1 }, |
| 11 | fur = { "#4b4038", label = "Fur color", order = 2 }, |
| 12 | } |
| 13 | |
| 14 | local Mole = world.creature { |
| 15 | name = "Mole", |
| 16 | speed = 1.5, |
| 17 | count = 2, |
| 18 | home = "start", |
| 19 | body = { |
| 20 | { "body", size = { 0.5, 0.34, 0.66 }, at = { 0, 0.22, 0.04 }, color = knobs.fur }, |
| 21 | { "head", size = { 0.32, 0.26, 0.26 }, at = { 0, 0.24, -0.38 }, color = knobs.fur, head = true }, |
| 22 | { "nose", size = { 0.12, 0.1, 0.1 }, at = { 0, 0.24, -0.55 }, color = "#e7a0a8", head = true }, |
| 23 | { "paw_left", size = { 0.18, 0.08, 0.2 }, at = { -0.3, 0.06, -0.24 }, color = "#e7a0a8", leg = true }, |
| 24 | { "paw_right", size = { 0.18, 0.08, 0.2 }, at = { 0.3, 0.06, -0.24 }, color = "#e7a0a8", leg = true }, |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | function Mole:spawned() |
| 29 | self.dig_in = world.random(20, 45) |
| 30 | self.hills = {} |
| 31 | end |
| 32 | |
| 33 | function Mole:tick(dt: number) |
| 34 | self:wander() |
| 35 | self.dig_in -= dt |
| 36 | if self.dig_in > 0 or knobs.hills < 1 then |
| 37 | return |
| 38 | end |
| 39 | self.dig_in = world.random(30, 70) |
| 40 | local p = self.position |
| 41 | local x, z = math.floor(p.x), math.floor(p.z) |
| 42 | local y = world.top(x, z) |
| 43 | local above = vector.create(x, y + 1, z) |
| 44 | if world.block(vector.create(x, y, z)) ~= "Grass" or world.block(above) ~= "Air" then |
| 45 | return |
| 46 | end |
| 47 | -- one hill in each patch |
| 48 | if world.find_block(above, 4, "Dirt") then |
| 49 | return |
| 50 | end |
| 51 | world.set_block(above, "Dirt") |
| 52 | table.insert(self.hills, { x, y + 1, z }) |
| 53 | self:say("*sniff*") |
| 54 | sound.play("dig", { at = self, volume = 0.5 }) |
| 55 | -- flatten the oldest once there are enough |
| 56 | while #self.hills > knobs.hills do |
| 57 | local old = table.remove(self.hills, 1) |
| 58 | local at = vector.create(old[1], old[2], old[3]) |
| 59 | if world.block(at) == "Dirt" then |
| 60 | world.set_block(at, "Air") |
| 61 | end |
| 62 | end |
| 63 | end |
| 64 | |
| 65 | function Mole:hit(player) |
| 66 | self:hop(0.5) |
| 67 | self:say("Eep!") |
| 68 | sound.play("yip", { at = self, pitch = 1.5 }) |
| 69 | end |