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. This next, quite large, block of code also adds a gravestone sprite for when the player gets squished, an ax sprite to chop with, and a log sprite that can whiz away each time the player chops.
Notice that after the spritePlayer
object we also 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 this next block of code just before the while(window.isOpen())
code as we have done so often before. Note that all the code in this next listing is new, not just the highlighted code. I haven...