Moving our character with onscreen controls
In this section, we will start by connecting George's movement to the joystick.
Currently, the George class inherits his movement from the base class, Character, which it shares with the Skeleton and Zombie classes. As George will have different movement code from the enemy sprites, let's refactor the code to allow the enemy sprites' movement code. We will move the existing movement code into an EnemyCharacter class, which will become the new base class for the enemy sprites and remove this code from the Character class.
Let's get started:
- In the
componentsfolder, create a file calledcharacter_enemy.dart. - Open the file and add the code at https://github.com/PacktPublishing/Building-Games-with-Flutter/blob/main/chapter05/lib/components/character_enemy.dart.
In this code, the EnemyCharacter class extends our Character class, and we have copied the onCollision, update, and changeDirection functions...