Reactor Defence (a game for CoronaDefold game jam)

I’ve made level progression, everything is smooth now in Chrome. But because of Variable Dt(?) Firefox version is really easy to win, but Chrome is not.

Mob’s hp increments in time, something like every 1 seconds add 100 more hps to initial hp (when factory spawns mob). But because of Variable Dt these 2 seconds are not actually 2 seconds as I may guess. The same thing happens with britzl’s timer and with other approach of making timer (like in some tutorial with spawning stars to collect).

Or there is some kinda problem with damage dealing which now works like that: if mob receives collision message from laser, than mob takes damage.

Or math.random behaves differently in Chrome and Firefox? Hm…

Any suggestions how to make Chrome and Firefox versions be the same difficulty?


Intro menu slightly redone:

Play.

1 Like

You could use os.time() or socket.gettime() to read system time and decouple it from dt. Although dt should be the correct way to solve this problem I think. Or you could use my timer module.

1 Like

I’ve checked HP incrementing and os.time(), socket.gettime(). It seems that problem is in damage dealing, not in hp incrementing.

Here is the brief example:
Chrome:

Firefox:

As you may see, in Chrome version mob has passed the whole second floor, but in Firefox not (you also may notice how much hp he has: initial hps for Chrome - 575, for Firefox - 657). It seems that Сhrome processes messages slower and this causing lower hp damage. ~0-1 ms for Firefox, ~2+ ms in Chrome.

I have the following code for damage dealing:

--laser script
function on_message(self, message_id, message, sender)
    if message_id == hash("collision_response") then
    	msg.post(message.other_id, "do_damage", {damage = self.damage * self.damage })
    end
end
--mob script
function on_message(self, message_id, message, sender)
    if message_id == hash("do_damage") then
        self.hp = self.hp - message.damage
    end
end

If I understand all this thing right, I need to add a timer here? To kinda slow down Firefox to not receive messages too fast. What’s the best way to implement this? I need to send only one message at a time not the bunch of messages.

P.S. Also, the problem is not in the Chrome itself. It’s in the performance of the device and browser. Lower performance = slower message passing = lower hp damage. I’ve added timer to sending messages but this doesn’t work well. It seems that “collision_response” behaves very differently. With timer there can be such a situation that mobs will not be damaged at all for some amount of time. Don’t know what to do with all of this - I just can’t balance the game, because browsers and performance may vary. Really annoying.

Yeah, that’s most likely low FPS issue. You need variable_dt option and rely solely on time markers: count seconds and not messages. Inflict damage each second or half a second.

On slow machines you get fewer frames, fewer messages, hence smaller damage per second.

2 Likes

I would give each laser a collision object set to “trigger”. Match the collision masks and layers so it reacts to the enemies of course, then do the following (untested code).

-- Laser script
function on_message(self, message_id, message, sender)
    if message_id == hash("trigger_response")
        if message.enter then
            msg.post(message.other_id, "start_damage", {damage = self.damage})
        else
            msg.post(message.other_id, "end_damage")
        end
    end
end

-- Enemy script
function on_message(self, message_id, message, sender)
    if message_id == hash("start_damage") then
        self.damage = message.damage
    elseif message_id == hash("end_damage") then
        self.damage = nil
    end
end

function update(self, dt)
    if self.damage then
        self.health = self.health - self.damage * dt
        if self.health <= 0 then
            -- enemy death code here
        end
    end
end

You’ll need a bit more than this to cover everything. Upgrades for example. You’ll need to keep a table of all the enemies the laser is hitting—add them to the list on trigger enter and remove them on trigger exit. When the laser is upgraded (damage increased), resend the “start_damage” message with the updated damage to every target enemy. That means you’ll need to keep that list updated when enemies are killed, but I think you’ll get the “trigger_response” exit message when the enemy is deleted, so it may just work.

1 Like

Thanks, I’ll check this approach maybe , but now I found how to build the game with release mode actually working. It was not working because of some Native Extensions. More info here.

So, now I can make build running smoothly in Chrome and Firefox.

At last I’ve fixed all the weird performance and balancing stuff. :slight_smile: Thanks to everyone who helped me on this forum. Guys, you’re awesome! Final build on itch. Enjoy!

You say final build, but maybe the buttons should say “Build / Build + ON” when there is no initial turret? Keep working on the project outside of the jam?

1 Like

Sure. I mean final version for the jam. :slight_smile: Hope to polish it a little bit in future and lunch on Google Play.

1 Like

Now it’s tougher! Good.

2 Likes

Community page has been updated.

5 Likes