It is a top down game where you have a shield that makes projectiles bounce and a sword which you can throw at enemies (I just couldn’t design a proper slash movement!). I have 2 levels, but I want to do another 2 levels.
So here comes the questions:
Every single enemy is done manually and every interaction is coded one by one, but I have a feeling that I’m doing everything wrong. There should be a way to refactor my code and make it smaller.
Every time I make a new enemy I code the collision between it and the sword and I have a feeling I shouldn’t do that. I should use “for each” or something like that, I just don’t know exactly how.
Just as an example, there is an scorpion enemy who creates little enemy spiders every 9 seconds or so. Each spider is supposed to have its health following it, but only one spider get the health display.
I am sorry if my questions are too convoluted, I just have a feeling I have been doing everything wrong in the sense that I have been repeating too much code.
It sounds like you could do the collision actions common to all the enemies with an object group. If there are actions specific to an enemy type, you can code for those too buy getting the object’s name.
At a guess, you should be linking the spider and it’s health bar, and possibly using the sticker extenstion.
Hi. Thinking like a developer comes with experience. I’m still fairly new to this and know where you’re coming from. I still code a lot my stuff in - what I assume is - a long-winded way because I don’t yet have a firm grasp on things like ‘repeat for each’ and other more dynamic and efficient ways of doing things. My code works the way I want it to, but I have the feeling that there is a better way of doing it, with fewer events needed.
I don’t think there’s an easy answer for that or a quick way to get to that stage. It just takes practice, research, asking questions when stuck, watching tutorials from more experienced users etc. My code is better than it was 10 months ago, and will hopefully be better still, and more dynamic and efficient, in 10 months from now. Good luck with your learning and projects.