Preparing the player (and other sprites)
Let's add the code for the player's sprite as well as a few more sprites and textures at the same time. The following, quite large, block of code also adds a gravestone sprite for when the player gets squashed, an axe sprite to chop with, and a log sprite that can whiz away each time the player chops.
Notice that, after the spritePlayer
object, we declare a side
variable, playerSide
, to keep track of where the player is currently standing. Furthermore, we add some extra variables for the spriteLog
object, including logSpeedX
, logSpeedY
, and logActive
, to store how fast the log will move and whether it is currently moving. The spriteAxe
also has two related float
constant variables to remember where the ideal pixel position is on both the left and the right.
Add the following block of code just before the while(window.isOpen())
code, like we have done so often before. Note that all of the code in the following block is new, not...