@@ -66,6 +66,16 @@ Player::Player()
6666 sprintingSouthEastXStart = 1440 ; sprintingSouthEastYStart = 1920 ; sprintingSouthEastXEnd = 240 ; sprintingSouthEastYEnd = 2160 ;
6767 sprintingSouthWestXStart = 480 ; sprintingSouthWestYStart = 2160 ; sprintingSouthWestXEnd = 1680 ; sprintingSouthWestYEnd = 2160 ;
6868 sprintingWestXStart = 1920 ; sprintingWestYStart = 2160 ; sprintingWestXEnd = 720 ; sprintingWestYEnd = 2400 ;
69+
70+ sprinting = false ;
71+ attackEastXStart = 1440 ; attackEastYStart = 1200 ; attackEastXEnd = 240 ; attackEastYEnd = 1440 ;
72+ attackNorthXStart = 480 ; attackNorthYStart = 1440 ; attackNorthXEnd = 1680 ; attackNorthYEnd = 1440 ;
73+ attackNorthEastXStart = 1920 ; attackNorthEastYStart = 1440 ; attackNorthEastXEnd = 720 ; attackNorthEastYEnd = 1680 ;
74+ attackNorthWestXStart = 960 ; attackNorthWestYStart = 1680 ; attackNorthWestXEnd = 2160 ; attackNorthWestYEnd = 1680 ;
75+ attackSouthXStart = 0 ; attackSouthYStart = 1920 ; attackSouthXEnd = 1200 ; attackSouthYEnd = 1920 ;
76+ attackSouthEastXStart = 1440 ; attackSouthEastYStart = 1920 ; attackSouthEastXEnd = 240 ; attackSouthEastYEnd = 2160 ;
77+ attackSouthWestXStart = 480 ; attackSouthWestYStart = 2160 ; attackSouthWestXEnd = 1680 ; attackSouthWestYEnd = 2160 ;
78+ attackWestXStart = 1920 ; attackWestYStart = 2160 ; attackWestXEnd = 720 ; attackWestYEnd = 2400 ;
6979}
7080
7181void Player::handleInput () {
@@ -183,6 +193,47 @@ void Player::handleInput() {
183193 } else {
184194 moving = false ;
185195 }
196+ // If space pressed then attack and change to attack animation
197+ if (sf::Keyboard::isKeyPressed (sf::Keyboard::Scan::Space)) {
198+ attacking = true ;
199+ timer += 0 .08f ;
200+ // Check direction user is facing
201+ if (north) {
202+ // Attack animation
203+ if (timer >= timerMax) {textureX += 240 ; animate (attackNorthXStart, attackNorthXEnd,
204+ attackNorthYStart, attackNorthYEnd); timer = 0 .0f ;}
205+ } else if (northEast) {
206+ // Attack animation
207+ if (timer >= timerMax) {textureX += 240 ; animate (attackNorthEastXStart, attackNorthEastXEnd,
208+ attackNorthEastYStart, attackNorthEastYEnd); timer = 0 .0f ;}
209+ } else if (east) {
210+ // Attack animation
211+ if (timer >= timerMax) {textureX += 240 ; animate (attackEastXStart, attackEastXEnd,
212+ attackEastYStart, attackEastYEnd); timer = 0 .0f ;}
213+ } else if (southEast) {
214+ // Attack animation
215+ if (timer >= timerMax) {textureX += 240 ; animate (attackSouthEastXStart, attackSouthEastXEnd,
216+ attackSouthEastYStart, attackSouthEastYEnd); timer = 0 .0f ;}
217+ } else if (south) {
218+ // Attack animation
219+ if (timer >= timerMax) {textureX += 240 ; animate (attackSouthXStart, attackSouthXEnd,
220+ attackSouthYStart, attackSouthYEnd); timer = 0 .0f ;}
221+ } else if (southWest) {
222+ // Attack animation
223+ if (timer >= timerMax) {textureX += 240 ; animate (attackSouthWestXStart, attackSouthWestXEnd,
224+ attackSouthWestYStart, attackSouthWestYEnd); timer = 0 .0f ;}
225+ } else if (west) {
226+ // Attack animation
227+ if (timer >= timerMax) {textureX += 240 ; animate (attackWestXStart, attackWestXEnd,
228+ attackWestYStart, attackWestYEnd); timer = 0 .0f ;}
229+ } else if (northWest) {
230+ // Attack animation
231+ if (timer >= timerMax) {textureX += 240 ; animate (attackNorthWestXStart, attackNorthWestXEnd,
232+ attackNorthWestYStart, attackNorthWestYEnd); timer = 0 .0f ;}
233+ }
234+ } else {
235+ attacking = false ;
236+ }
186237}
187238
188239// Reusable function for animating player
@@ -216,7 +267,7 @@ void Player::sprint(bool sprint) {
216267// Checking for changes to player
217268void Player::update () {
218269 // If player is not moving then change player to standing pose
219- if (moving == false ) {
270+ if (moving == false && attacking == false ) {
220271 if (east) {textureX = standingEastX; textureY = standingEastY;}
221272 if (north) {textureX = standingNorthX; textureY = standingNorthY;}
222273 if (northEast) {textureX = standingNorthEastX; textureY = standingNorthEastY;}
0 commit comments