fixes and optimizations
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
#ifndef DATA_HPP
|
||||
#define DATA_HPP
|
||||
|
||||
#include "globals.hpp"
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
struct Map {
|
||||
const char map[MAX_ROWS][MAX_COLS];
|
||||
};
|
||||
|
||||
struct Player {
|
||||
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
|
||||
sf::Vector2<float> pos { TILESIZE, TILESIZE };
|
||||
float max_velocity_y { 15.0f };
|
||||
float border_size { -1.0f };
|
||||
|
||||
float dash_distance { 20.0f };
|
||||
sf::Vector2f velocity { 3.0f, 0 };
|
||||
};
|
||||
|
||||
#endif
|
||||
+21
-15
@@ -1,24 +1,27 @@
|
||||
#ifndef PLAYER_HPP
|
||||
#define PLAYER_HPP
|
||||
|
||||
#include "globals.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include "scheduler.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
enum class CollisionDir { None, Left, Right, Top, Bottom };
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White);
|
||||
CollisionDir find_intersection(Entity &entity);
|
||||
public:
|
||||
Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
|
||||
sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White);
|
||||
CollisionDir find_intersection(Entity& entity);
|
||||
void set_velocity(sf::Vector2f velocity);
|
||||
void set_velocity_x(int velocity);
|
||||
void set_velocity_y(int velocity);
|
||||
sf::Vector2<float> get_velocity();
|
||||
sf::RectangleShape rect;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
sf::Vector2f _velocity;
|
||||
sf::Color _inside_color;
|
||||
sf::Color _border_color;
|
||||
@@ -26,8 +29,10 @@ protected:
|
||||
};
|
||||
|
||||
class Player : public Entity {
|
||||
public:
|
||||
Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, sf::Color border_color);
|
||||
public:
|
||||
Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
|
||||
float gravity, float max_acceleration, float dash_distance, sf::Color inside_color,
|
||||
sf::Color border_color);
|
||||
float m_acceleration;
|
||||
float m_jump_strength;
|
||||
float m_dash_distance;
|
||||
@@ -37,13 +42,14 @@ public:
|
||||
void handle_movment();
|
||||
void handle_gravity();
|
||||
bool get_jumping();
|
||||
void horizontal_no_out_of_bounds(Entity &base);
|
||||
void vertical_no_out_of_bounds(Entity &base);
|
||||
bool get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
bool get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
private:
|
||||
bool get_vertical_bottom_collision_by_offset(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
void horizontal_no_out_of_bounds(Entity& base);
|
||||
void vertical_no_out_of_bounds(Entity& base);
|
||||
bool get_horizontal_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||
bool get_vertical_top_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||
bool get_vertical_bottom_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||
|
||||
private:
|
||||
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||
sf::Vector2f _min_velocity;
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
#ifndef GLOBALS_HPP
|
||||
#define GLOBALS_HPP
|
||||
#define TILESIZE 32
|
||||
#define WIDTH 608
|
||||
#define HEIGHT 416
|
||||
#define MAX_COLS 8 // 19 cols
|
||||
#define MAX_ROWS 8 // 13 rows
|
||||
#define WIDTH TILESIZE * MAX_COLS
|
||||
#define HEIGHT TILESIZE * MAX_ROWS
|
||||
#define FPS 60
|
||||
#define GRAVITY 1
|
||||
#define MAX_COLS WIDTH / TILESIZE // 19 cols
|
||||
#define MAX_ROWS HEIGHT / TILESIZE // 13 rows
|
||||
#endif
|
||||
|
||||
+6
-12
@@ -1,10 +1,11 @@
|
||||
#ifndef MAPS_HPP
|
||||
#define MAPS_HPP
|
||||
|
||||
#include "elements.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <array>
|
||||
#include "globals.hpp"
|
||||
#include "elements.hpp"
|
||||
|
||||
struct Level {
|
||||
char data[MAX_ROWS][MAX_COLS];
|
||||
@@ -12,15 +13,8 @@ struct Level {
|
||||
};
|
||||
|
||||
extern Level levels[];
|
||||
extern const char map[MAX_ROWS][MAX_COLS];
|
||||
|
||||
void clear_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list);
|
||||
void load_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list, const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data);
|
||||
std::array<std::array<char, MAX_COLS>, MAX_ROWS> create_map(sf::RenderWindow &window,
|
||||
sf::Vector2i &local_position,
|
||||
sf::Vector2i &start_mouse_pos,
|
||||
sf::Vector2i &end_mouse_pos,
|
||||
bool &dragging,
|
||||
bool &prev_dragging,
|
||||
std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list);
|
||||
|
||||
void clear_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>& wall_list);
|
||||
void load_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>& wall_list, const char map_data[MAX_ROWS][MAX_COLS]);
|
||||
#endif
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
struct Times {
|
||||
float dash_cooldown { 0 };
|
||||
float dash_cooldown_max { 5 };
|
||||
float dash_cooldown_max { .5 };
|
||||
float level_switch_cooldown { 0 };
|
||||
float level_switch_cooldown_max { 1 };
|
||||
};
|
||||
|
||||
struct Timer {
|
||||
void update_timers(bool &running, Times ×);
|
||||
void update_timers(bool& running, Times& times);
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user