Pickup & Weapon Systems; Random Map Generation

Hey, so I’m having a murder of a time trying to work out how to do a pickup and weapon system.

I want the player to be able to find weapons laying on the floor, and collect them. I’m not sure though, how to tell the player what weapon they’ve collected short of just having a massive table of weapons and all the weapon logic in the player.

In OOP I’d either do it all with inheritance, of have some kind of weapon struct that defined the weapons stats, and a weapon functionality class that took a stat block and used it to create a bullet (which might be another stat block).

What’s the “Defold” way to solve this?

Additionally, I’ve also been having a bit of a mare doing random world generation. I was thinking I could just build a tilemap by setting different images, but I think I can only do that within the size of an existing tilemap.

So next I was thinking I could randomly generate the world as a data representation, and then just draw the visible tiles each frame, but if I have walls or what have you in that representation, then how do I ensure that things don’t walk through them, etc. Is there a better way to do this? Is there a way to generate a tilemap programatically?

There was a discussion about weapon systems a while back: Creating a weapon system

Slightly related: Calling a function with a string

Yes, you need to define the bounds of your tilemap even when you’re generating the actual contents at runtime. It’s enough to set one tile in each corner of the tilemap and the use tilemap.get_bounds() and tilemap.set_tile()

Thanks. I’d read that thread, and a lot of it seemed to jam the implementation of weapon into the player script, which I’m trying to avoid.

I dig the other thread though. I guess my only question is (and really this is the bit I’m not grokking I think), how do I tell the player “you’ve now got weapon-n”. Could you pass the weapon name as a string, and look the string up in a table? That table would contain the details for the weapons (like in the “Calling a function with a string” thread)?

Yes, I’d suggest storing the available weapons in a Lua table keyed on weapon id/name and then use the name/id to look-up the wielded weapon from the player script. Either use a string or a hash as key. I can post an example later on if you’d like.