Mario: add basic big mario logic

This commit is contained in:
2022-09-25 19:44:28 +02:00
parent 09cb13195c
commit 4109cfe1af
12 changed files with 156 additions and 57 deletions
+61
View File
@@ -4,6 +4,11 @@
#include "../sdlpp/sdlpp_rectrenderer.hpp"
#include "sprites.hpp"
#include "blocks.hpp"
#include <_types/_uint8_t.h>
#define BIG_FLAG 0x0001
#define FIRE_FLAG 0x0002
#define STAR_FLAG 0x0004
class Mario : public MarioBlock {
public:
@@ -20,6 +25,40 @@ public:
bool isDead() {
return _death;
}
void handleDeath();
void setBig() {
if (isBig()) {
setFireFlag();
} else {
setBigFlag();
}
}
void unsetBig() {
if (hasFire()) {
unsetFireFlag();
} else {
unsetBigFlag();
}
}
void setStar() {
setStarFlag();
}
void unsetStar() {
unsetStarFlag();
}
bool isBig() const {
return special_flags & BIG_FLAG;
}
bool hasFire() const {
return special_flags & FIRE_FLAG;
}
bool hasStar() const {
return special_flags & STAR_FLAG;
}
bool isJumping() const {
return jumping;
}
private:
void setDeath(bool dead = true) {
@@ -37,13 +76,35 @@ private:
double slow_jump = 0;
bool on_ground = true;
int ticks_till_gravity = 0;
int ticks_till_vulnurable = 0;
// gravity should be added every frame in 60fps game
const int base_gravity_ticks = 1000 / 60;
const int base_vulnurable_ticks = 1000;
const double gravity_add_jumping = jump_movement / 32.0;
const double gravity_add_falling = jump_movement / (64.0 / 7.0);
std::shared_ptr<SDLPP::RectColider> top_collision = nullptr;
void setWorldTypeSrc(LandType::Value world) override;
void stopMovement();
uint8_t special_flags = 0;
void setBigFlag() {
special_flags = special_flags | BIG_FLAG;
}
void setFireFlag() {
special_flags = special_flags | FIRE_FLAG;
}
void setStarFlag() {
special_flags = special_flags | STAR_FLAG;
}
void unsetBigFlag() {
special_flags = special_flags & ~BIG_FLAG;
}
void unsetFireFlag() {
special_flags = special_flags & ~FIRE_FLAG;
}
void unsetStarFlag() {
special_flags = special_flags & ~STAR_FLAG;
}
};
#endif