Sign in
creature

Jelly

by Potluck · version 1 · Checked for all ages

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
5local world = require("@potluck/world")
6local tweak = require("@potluck/tweak")
7local sound = require("@potluck/sound@0.1")
8
9local 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
15local 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
30local 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
44local MOST_LETS = 12
45
46local 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
52end
53
54function Jelly:spawned()
55 self.bounce_in = world.random(0, 1)
56end
57
58function Jelly:tick(dt: number)
59 self:wander()
60 bounce(self, knobs.bounce, dt)
61end
62
63function 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()
74end
75
76function Jellylet:spawned()
77 self.bounce_in = 0
78 self.left = knobs.last
79end
80
81function 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
88end
89
90function Jellylet:hit(player)
91 self:say("Pop!")
92 sound.play("pop", { at = self })
93 self:remove()
94end