#pragma once
#include "GameObject.H"
struct Rika : GameObject {
int width = 600;
int height = 600;
int myFrames[2][12]{
0, 0,
1, 0,
2, 0,
3, 0,
4, 0,
3, 0,
2, 0,
1, 0,
0, 0,
0, 0,
0, 0,
0, 0
};
Rika(float x, float y, string image) : GameObject(x, y, image) {}
void update(float time) override {
x += velX * time;
y += velY * time;
switch (animState) {
case ANIMSTATE::IDLE:
setFrames(ANIMSTATE::IDLE);
frame += time * 2;
if (frame >= 4) frame = 0;
sprite.setTextureRect( IntRect( myFrames[(int)frame][0]* width, myFrames[(int)frame][1] * height, width, height ));
break;
case ANIMSTATE::PUNCH:
setFrames(ANIMSTATE::PUNCH);
frame += time * 5;
if (frame >= 7) frame = 0;
sprite.setTextureRect(IntRect( myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
if ((int)frame == 3 && snd_fight_punch_hit.getStatus() != sf::Sound::Status::Playing)
snd_fight_punch_hit.play();
break;
case ANIMSTATE::KICK:
setFrames(ANIMSTATE::KICK);
frame += time * 5;
if (frame >= 8) frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::HEAD:
setFrames(ANIMSTATE::HEAD);
frame += time * 5;
if (frame >= 7) frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::BLOCK:
setFrames(ANIMSTATE::BLOCK);
frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::WALKING:
setFrames(ANIMSTATE::WALKING);
frame += time * 5;
if (frame >= 4) frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::TALKING:
setFrames(ANIMSTATE::TALKING);
frame += time * 5;
if (frame >= 2) frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::DAMAGE:
setFrames(ANIMSTATE::DAMAGE);
frame += time * 5;
if (frame >= 4) animState = ANIMSTATE::IDLE;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::DEATH:
setFrames(ANIMSTATE::DEATH);
frame += time * 5;
if (frame >= 6) animState = ANIMSTATE::DEATH_LOOP;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
case ANIMSTATE::DEATH_LOOP:
setFrames(ANIMSTATE::DEATH_LOOP);
frame += time * 5;
if (frame >= 2) frame = 0;
sprite.setTextureRect(IntRect(myFrames[(int)frame][0] * width, myFrames[(int)frame][1] * height, width, height));
break;
}
}
void setFrames(ANIMSTATE anim_state) {
switch (anim_state) {
case ANIMSTATE::IDLE:
myFrames[0][0] = 0;
myFrames[1][0] = 1;
myFrames[2][0] = 2;
myFrames[3][0] = 1;
for (int i = 0; i < 10; i++)
myFrames[i][1] = 0;
break;
case ANIMSTATE::PUNCH:
myFrames[0][0] = 4;
myFrames[1][0] = 5;
myFrames[2][0] = 6;
myFrames[3][0] = 7;
myFrames[4][0] = 8;
myFrames[5][0] = 9;
myFrames[6][0] = 3;
for (int i = 0; i < 10; i++)
myFrames[i][1] = 0;
break;
case ANIMSTATE::KICK:
myFrames[0][0] = 11;
myFrames[1][0] = 12;
myFrames[2][0] = 13;
myFrames[3][0] = 14;
myFrames[4][0] = 15;
myFrames[5][0] = 16;
myFrames[6][0] = 17;
myFrames[7][0] = 10;
for (int i = 0; i < 10; i++)
myFrames[i][1] = 0;
break;
case ANIMSTATE::HEAD:
myFrames[0][0] = 19;
myFrames[0][1] = 0;
myFrames[1][0] = 0;
myFrames[2][0] = 1;
myFrames[3][0] = 2;
myFrames[4][0] = 3;
myFrames[5][0] = 4;
myFrames[1][1] = 1;
myFrames[2][1] = 1;
myFrames[3][1] = 1;
myFrames[4][1] = 1;
myFrames[5][1] = 1;
myFrames[6][0] = 18;
myFrames[6][1] = 0;
break;
case ANIMSTATE::BLOCK:
myFrames[0][0] = 5;
myFrames[0][1] = 1;
break;
case ANIMSTATE::WALKING:
myFrames[0][0] = 6;
myFrames[1][0] = 8;
myFrames[2][0] = 7;
myFrames[3][0] = 8;
for (int i = 0; i < 10; i++) {
myFrames[i][1] = 1;
}
break;
case ANIMSTATE::TALKING:
myFrames[0][0] = 9;
myFrames[1][0] = 10;
for (int i = 0; i < 4; i++)
myFrames[i][1] = 1;
break;
case ANIMSTATE::DAMAGE:
myFrames[0][0] = 12;
myFrames[1][0] = 13;
myFrames[2][0] = 14;
myFrames[3][0] = 11;
for (int i = 0; i < 4; i++)
myFrames[i][1] = 1;
break;
case ANIMSTATE::DEATH:
myFrames[0][0] = 15;
myFrames[1][0] = 16;
myFrames[2][0] = 17;
myFrames[3][0] = 18;
myFrames[4][0] = 19;
myFrames[0][1] = 1;
myFrames[1][1] = 1;
myFrames[2][1] = 1;
myFrames[3][1] = 1;
myFrames[4][1] = 1;
myFrames[5][0] = 0;
myFrames[5][1] = 2;
break;
case ANIMSTATE::DEATH_LOOP:
myFrames[0][0] = 1;
myFrames[1][0] = 2;
myFrames[0][1] = 2;
myFrames[1][1] = 2;
break;
}
}
void paint(sf::RenderWindow& window) override {
sprite.setPosition(x, y);
window.draw(sprite);
}
};