Wobbly jellies that bounce around the Green. Bop one and it splits in two little ones, who don't last long.
| 1 | --!strict |
| 2 | -- Jelly: wobbly jellies that bounce around the Green. Bop one and it |
| 3 | -- splits into two jellylets, who bounce about for a bit and then pop. |
| 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 | color = { "#6fd6b8", label = "Jelly color", order = 1 }, |
| 11 | bounce = { 1.1, min = 0.3, max = 3, label = "Bounce", order = 2 }, |
| 12 | last = { 40, min = 5, max = 120, label = "Seconds a jellylet lasts", order = 3 }, |
| 13 | } |
| 14 | |
| 15 | local Jelly = world.creature { |
| 16 | name = "Jelly", |
| 17 | speed = 1.8, |
| 18 | count = 2, |
| 19 | home = "green", |
| 20 | body = { |
| 21 | { "jelly", size = { 0.9, 0.7, 0.9 }, at = { 0, 0.35, 0 }, color = knobs.color }, |
| 22 | { "top", size = { 0.6, 0.16, 0.6 }, at = { 0, 0.78, 0 }, color = knobs.color }, |
| 23 | { "eye_left", size = { 0.24, 0.252, 0.04 }, at = { -0.18, 0.5, -0.46 }, color = "#f6f2e6", head = true }, |
| 24 | { "pupil_left", size = { 0.132, 0.168, 0.04 }, at = { -0.18, 0.493, -0.489 }, color = "#1b1b1b", head = true }, |
| 25 | { "eye_right", size = { 0.24, 0.252, 0.04 }, at = { 0.18, 0.5, -0.46 }, color = "#f6f2e6", head = true }, |
| 26 | { "pupil_right", size = { 0.132, 0.168, 0.04 }, at = { 0.18, 0.493, -0.489 }, color = "#1b1b1b", head = true }, |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | local Jellylet = world.creature { |
| 31 | name = "Jellylet", |
| 32 | speed = 2.4, |
| 33 | count = 0, |
| 34 | home = "green", |
| 35 | body = { |
| 36 | { "jelly", size = { 0.44, 0.36, 0.44 }, at = { 0, 0.18, 0 }, color = knobs.color }, |
| 37 | { "eye_left", size = { 0.135, 0.142, 0.03 }, at = { -0.09, 0.25, -0.23 }, color = "#f6f2e6", head = true }, |
| 38 | { "pupil_left", size = { 0.074, 0.095, 0.03 }, at = { -0.09, 0.246, -0.253 }, color = "#1b1b1b", head = true }, |
| 39 | { "eye_right", size = { 0.135, 0.142, 0.03 }, at = { 0.09, 0.25, -0.23 }, color = "#f6f2e6", head = true }, |
| 40 | { "pupil_right", size = { 0.074, 0.095, 0.03 }, at = { 0.09, 0.246, -0.253 }, color = "#1b1b1b", head = true }, |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | local MOST_LETS = 12 |
| 45 | |
| 46 | local function bounce(j, power: number, dt: number) |
| 47 | j.bounce_in -= dt |
| 48 | if j.bounce_in <= 0 then |
| 49 | j.bounce_in = world.random(0.9, 1.8) |
| 50 | j:hop(power) |
| 51 | end |
| 52 | end |
| 53 | |
| 54 | function Jelly:spawned() |
| 55 | self.bounce_in = world.random(0, 1) |
| 56 | end |
| 57 | |
| 58 | function Jelly:tick(dt: number) |
| 59 | self:wander() |
| 60 | bounce(self, knobs.bounce, dt) |
| 61 | end |
| 62 | |
| 63 | function Jelly:hit(player) |
| 64 | if #world.creatures(Jellylet) + 2 > MOST_LETS then |
| 65 | self:hop(knobs.bounce * 1.5) |
| 66 | self:say("Blorp!") |
| 67 | sound.play("boing", { at = self }) |
| 68 | return |
| 69 | end |
| 70 | local here = self.position |
| 71 | world.spawn(Jellylet, here + vector.create(-0.6, 0.5, 0)) |
| 72 | world.spawn(Jellylet, here + vector.create(0.6, 0.5, 0)) |
| 73 | self:remove() |
| 74 | end |
| 75 | |
| 76 | function Jellylet:spawned() |
| 77 | self.bounce_in = 0 |
| 78 | self.left = knobs.last |
| 79 | end |
| 80 | |
| 81 | function Jellylet:tick(dt: number) |
| 82 | self:wander(2.4) |
| 83 | bounce(self, knobs.bounce * 0.8, dt) |
| 84 | self.left -= dt |
| 85 | if self.left <= 0 then |
| 86 | self:remove() |
| 87 | end |
| 88 | end |
| 89 | |
| 90 | function Jellylet:hit(player) |
| 91 | self:say("Pop!") |
| 92 | sound.play("pop", { at = self }) |
| 93 | self:remove() |
| 94 | end |