Animation and fps
This commit is contained in:
parent
0432d6932c
commit
366bdf7d20
4 changed files with 22 additions and 3 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 760 B |
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Rectangle Pacman::getTextureRect() const{
|
Rectangle Pacman::getTextureRect() const{
|
||||||
Rectangle result;
|
Rectangle result;
|
||||||
result.x = 0;
|
result.x = 16*frame;
|
||||||
result.y = facing*16;
|
result.y = facing*16;
|
||||||
result.height = 16;
|
result.height = 16;
|
||||||
result.width = 16;
|
result.width = 16;
|
||||||
|
|
@ -17,6 +17,7 @@ Pacman::Pacman() {
|
||||||
this->texture = LoadTexture("assets/sprites/pacman.png");
|
this->texture = LoadTexture("assets/sprites/pacman.png");
|
||||||
this->facing = 0;
|
this->facing = 0;
|
||||||
this->position = {0.,0.};
|
this->position = {0.,0.};
|
||||||
|
this->frame = 0;
|
||||||
}
|
}
|
||||||
Pacman::Pacman(Vector2 position) {
|
Pacman::Pacman(Vector2 position) {
|
||||||
this->texture = LoadTexture("assets/sprites/pacman.png");
|
this->texture = LoadTexture("assets/sprites/pacman.png");
|
||||||
|
|
@ -53,6 +54,18 @@ void Pacman::tick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pacman::process() {
|
||||||
|
this->time += GetFrameTime();
|
||||||
|
if (this->time >= 1.0/this->fps){
|
||||||
|
this->time = 0.;
|
||||||
|
this->animation_tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pacman::animation_tick() {
|
||||||
|
this->frame = (this->frame+1)%frame_count;
|
||||||
|
}
|
||||||
|
|
||||||
void Pacman::draw() const {
|
void Pacman::draw() const {
|
||||||
// Drawing
|
// Drawing
|
||||||
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,22 @@ class Entity{
|
||||||
|
|
||||||
class Pacman : public Entity{
|
class Pacman : public Entity{
|
||||||
const int speed = 16;
|
const int speed = 16;
|
||||||
|
const int frame_count = 7;
|
||||||
|
const int fps = 24;
|
||||||
private:
|
private:
|
||||||
Texture2D texture;
|
Texture2D texture;
|
||||||
int facing;
|
int facing;
|
||||||
|
|
||||||
Rectangle getTextureRect() const;
|
Rectangle getTextureRect() const;
|
||||||
public:
|
public:
|
||||||
|
unsigned char frame;
|
||||||
|
float time;
|
||||||
|
|
||||||
Pacman();
|
Pacman();
|
||||||
Pacman(Vector2 position);
|
Pacman(Vector2 position);
|
||||||
~Pacman();
|
~Pacman();
|
||||||
void tick() override;
|
void tick() override;
|
||||||
|
void process() override;
|
||||||
|
void animation_tick();
|
||||||
void draw() const override;
|
void draw() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ int main() {
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
world = create_world_with(.25);
|
world = create_world_with(1./10.);
|
||||||
|
|
||||||
world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}));
|
world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue