Game Development Reference
In-Depth Information
Figure 17-30 . Create a conditional if using attackCounter inside the .update() method that calls initiateAttack() meth-
od
Most of this “auto-attack” code we will be writing during this admittedly advanced
chapter will leverage this .update() method, which will be called from the .handle()
method that runs our game from the GamePlayLoop class. The reason I installed this
.update() method that you need to override in every Actor subclass, is in case you
wanted to animate things in the game. If an Actor is static, the .update() method simply
exists as an empty or unused method.
AttackingonBothSidesoftheScreen:.initiateAttack()
Method
The way to make your attack come from both sides of the screen is to have a boolean
variable that can be set to right (true) or left (false), which we will call takeSides . De-
clare this variable at the top of the Enemy class, and then create an empty private
void initiateAttack(){} method structure underneath your .update() method.
Inside of this .initiateAttack() method, create an empty if-else structure
if(takeSides){}else{} to hold your attack programming logic, so private
void initiateAttack(){if(takeSides){}else{}} if you are into writ-
ing super compact Java code (this is valid Java code, but does absolutely nothing thus
 
Search WWH ::




Custom Search