Taking a slight break from my village building game to work on something simpler. At least that’s the idea. I had this idea of making a game like https://suikagame.com/, but the game is based on a circle instead of a box. Since I imagined I’d work with a lot of concepts I normally don’t use in my games, such as circles and physics, I sought out the help of ChatGPT.
I created a custom GPT that uses live web browsing and Defold’s most-recent API. Results have been better than expected so far.
In one instance, I wasn’t sure how to generate one message per collision (i.e., a merge). Here’s what it recommended.
local function check_collission_shape(self, message)
local other_url = msg.url(nil, message.other_id, "script")
local other_shape = go.get(other_url, "shape")
if self.shape == other_shape then
-- Create a deterministic order based on instance IDs
local id1 = tostring(go.get_id())
local id2 = tostring(message.other_id)
if id1 < id2 then
-- Only send the try_merge message if this object has the "lesser" id
msg.post(message.other_id, "try_merge", { other_shape = self.shape })
end
end
end
Since instances are numerical, comparing two instances (i.e., two collisions) and sending a message from the instance with the lowest value is a simple and effective way to send one message per collision.
The next thing I needed help with was confining my cursor to a circle.
function confine_cursor_to_rim(cursor_x, cursor_y, center_x, center_y, radius)
local dx = cursor_x - center_x
local dy = cursor_y - center_y
local angle = math.atan2(dy, dx)
local confined_x = center_x + radius * math.cos(angle)
local confined_y = center_y + radius * math.sin(angle)
-- Set the cursor position to the confined coordinates
-- Depending on how you handle cursor position in Defold, this might vary.
-- This is a generic way to update cursor position.
cursor.set_position(vmath.vector3(confined_x, confined_y, 0))
end
I can’t say that using GPT is a gamechanger, but it is a convenient tool. You still need knowledge of Defold. GPT makes mistakes and there’s also the matter of knowing how to communicate your goals. One thing it does a better job than me at is referencing information. It’s basically a faster search tool.
Here’s some basic gameplay so far.