game/mario/mario.hpp

127 lines
3.5 KiB
C++
Raw Normal View History

2021-05-22 21:13:26 +00:00
#ifndef MARIO_H
#define MARIO_H
#include "../sdlpp/sdlpp_rectrenderer.hpp"
2021-05-23 21:32:15 +00:00
#include "sprites.hpp"
#include "blocks.hpp"
2022-11-19 22:02:13 +00:00
#include <functional>
2022-09-25 17:44:28 +00:00
#define BIG_FLAG 0x0001
#define FIRE_FLAG 0x0002
#define STAR_FLAG 0x0004
2021-05-22 21:13:26 +00:00
class Mario : public MarioBlock {
2021-05-22 21:13:26 +00:00
public:
2022-11-19 22:10:33 +00:00
Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer,
std::function<void(std::shared_ptr<MarioBlock> &, bool)> addObject);
Mario(const std::shared_ptr<SDLPP::Renderer> &renderer,
std::function<void(std::shared_ptr<MarioBlock> &, bool)> addObject);
2021-05-22 21:13:26 +00:00
void walkLeft();
void walkRight();
void setStanding();
2021-10-18 07:08:35 +00:00
void handleVisitor(SDLPP::Visitor &visitor) override;
2021-05-22 21:54:01 +00:00
void jump();
2022-11-13 18:52:39 +00:00
void crouch();
void uncrouch();
2022-11-12 20:32:18 +00:00
#ifndef EDITOR
void fire();
2022-11-19 22:10:33 +00:00
void setAddObjFunc(
std::function<void(std::shared_ptr<MarioBlock> &, bool)> func);
std::function<void(std::shared_ptr<MarioBlock> &, bool)> getAddObjFunc();
2022-11-12 20:32:18 +00:00
#endif
2021-05-22 21:54:01 +00:00
void stopJump();
2021-10-18 07:08:35 +00:00
void custom_move(int ticks) override;
void visit(SDLPP::Visitor &visitor) override;
2022-09-23 14:46:50 +00:00
bool isDead() {
return _death;
}
2022-09-25 17:44:28 +00:00
void handleDeath();
void setBig();
void unsetBig();
2022-09-25 17:44:28 +00:00
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;
}
2022-11-13 18:52:39 +00:00
bool isCrouching() const {
return _crouching;
}
bool walkingLeft() const {
return getMovement().getX() < 0;
}
bool walkingRight() const {
return getMovement().getX() > 0;
}
2021-05-22 21:13:26 +00:00
private:
2022-11-19 22:10:33 +00:00
std::function<void(std::shared_ptr<MarioBlock> &, bool)> _addObject;
2022-09-23 14:46:50 +00:00
void setDeath(bool dead = true) {
_death = dead;
}
bool _death = false;
bool controllable = true;
2021-05-22 21:13:26 +00:00
bool faces_right = true;
2021-10-17 13:56:10 +00:00
double side_movement = 0.3;
2021-05-23 21:32:15 +00:00
double jump_movement = 1.0;
2021-05-22 21:54:01 +00:00
bool jumping = false;
bool stop_jump = false;
2022-11-13 18:52:39 +00:00
bool _crouching = false;
2021-05-22 21:54:01 +00:00
double max_jump = 0;
double min_jump = 0;
double slow_jump = 0;
bool on_ground = true;
2021-05-23 21:32:15 +00:00
int ticks_till_gravity = 0;
2022-09-25 17:44:28 +00:00
int ticks_till_vulnurable = 0;
2021-05-23 21:32:15 +00:00
// gravity should be added every frame in 60fps game
const int base_gravity_ticks = 1000 / 60;
2022-09-25 17:44:28 +00:00
const int base_vulnurable_ticks = 1000;
const double gravity_add_jumping = jump_movement / 32.0;
2021-10-18 07:08:35 +00:00
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;
2022-09-23 14:46:50 +00:00
void stopMovement();
2022-09-25 17:44:28 +00:00
uint8_t special_flags = 0;
// SRCs
const SDL_Rect *standing_src = &MARIO_STANDING_SRC;
const SDL_Rect *death_src = &MARIO_DEATH_SRC;
const SDL_Rect *change_dir_src = &MARIO_CHANGE_DIR_SRC;
const SDL_Rect *jump_src = &MARIO_JUMP_SRC;
const std::vector<SDL_Rect> *walk_anim = &MARIO_WALK_ANIM;
2022-09-25 17:44:28 +00:00
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;
}
2021-05-22 21:13:26 +00:00
};
#endif