[Project Week 5.2] Character script

Character script

For this day I also created the character script, which there are going to be different types of characters in my game for example the player, enemies and NPC vendors. All these types of characters share things in common, so instead of rewriting all the functionalities over and over again I made a character script that contains all the general functionality of the characters so that the enemies and vendors can inherit these functions. For example, both the player and the enemy both need to move around within the world, so instead of creating separate scripts to execute this we can make it so both the player and character inherit from one script. The only difference between both the movements of the player and enemy is that the enemy requires a path-finding algorithm to move towards the player, whereas the player just needs keyboard inputs.

Here is the character script, as you can see it's pretty much copy and paste from the player script apart from the input function. The reason for this is because the enemy will not require input from the player and you wouldn't want to control the enemy, the enemy should control itself (A.I).



Conclusion

The player in my game works as it did when I created the player script, except now it takes functionality from the character script (as the enemy will later on).

Comments