|
Hello world!
These last days I’ve been working on creating enemies with movement patterns into the game. So far they have sprites and movement patterns in relationship to the player each one with similar codes except from the specific numbers which will be adjusted later in the main project (the actual game project).
This is what my code looks like “in-game” with the enemies standing on different range depending on what kind they are.
What function would the enemies contribute with to the game?
The enemies are the callenge in the game, they will spawn in groups and try to kill you (so far only) at different range depending on what kind of element they are. They will also be more or less of the same enemy depending on their element. If you have defeated an enemy you will get a reward (I won’t go into specifics since it is not the point of the post).
What would the player experience?
Enemies attacking in bigger or smaller groups at longer or shorter range, possibly even either following the player while he/she moves or avoid the player.
In order to create the enemy objects (three kinds) I gave them different variables(?) which I were to work with: velocity, position, sprite, height and width. I then created Vectors from these objects in order to be able to decide how many of each I would create without having to write super duper much code for each one.
This is what the code for two of my vectors looks like that I created from my enemy objects. Here I can easily manipulate how many will show up. Later we could make it a random function within certain restraints, but I am not sure if we actually will since thats just my own thoughts.
I created a random function for where on the Y-axis the enemies in the Vectors will spawn. You can see it in the screenshot above; “int randomposwaterenemies = (rand()%(640-(290)+1))+(290);” for the water-enemy where 640 is the maximum value of the Y-position and 290 is the minimum value. The (in the water-enemy’s case) two enemy-objects will get random Y-positions within these limits.
The x-values for the spawns is just outside the field of view, so that the enemies will walk into the screen towards the player.
Since they are Vectors depeding on their cpp files I created several For-loops which directorys to the objects update function were the movement patterns and such is stored.
The last thing i did for them in the (at the moment) main.cpp was to create for-loops where im drawing the pictures.
within the objects I have put their movement patterns as if-loops within Update. there I am using velocity and position as i mentioned before. I have aslo included player.h in order to be able to create the movement depending on the player movement/position.
The first thing i did in the update was to set their movement speed (velocity) to a value at the x-axis – this makes my enemies walk into the screen, towards the player.
Then the if-loops stared. The first one tells the enemy to stop once they ahve reached a certain position compared to the player. This includes the same random function I used earlier, but this time to make them stay at slightly different x-axis values as the others of the same kind. Still I adapted the max-and minimun values of the random functions to what kind of enemy it is since as an example the water enemies is to stay at long range while the wood enemies will stay at short range.
This is what the code for my waterenemies- movement- if-codes looks like.

|