start to map creator
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
#define TILESIZE 32
|
#define TILESIZE 32
|
||||||
#define WIDTH 608
|
#define WIDTH 608
|
||||||
#define HEIGHT 416
|
#define HEIGHT 416
|
||||||
|
#define FPS 60
|
||||||
|
#define GRAVITY 1
|
||||||
#define MAX_COLS WIDTH / TILESIZE // 19 cols
|
#define MAX_COLS WIDTH / TILESIZE // 19 cols
|
||||||
#define MAX_ROWS HEIGHT / TILESIZE // 13 rows
|
#define MAX_ROWS HEIGHT / TILESIZE // 13 rows
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+61
-34
@@ -1,7 +1,10 @@
|
|||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
|
#include <SFML/Window/Mouse.hpp>
|
||||||
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -23,23 +26,22 @@ int main() {
|
|||||||
struct {
|
struct {
|
||||||
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
|
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
|
||||||
sf::Vector2<float> pos { TILESIZE, TILESIZE };
|
sf::Vector2<float> pos { TILESIZE, TILESIZE };
|
||||||
float acceleration { 1.0f };
|
|
||||||
float max_velocity_y { 15.0f };
|
float max_velocity_y { 15.0f };
|
||||||
float border_size { -1.0f };
|
float border_size { -1.0f };
|
||||||
float dash_distance { 20.0f };
|
float dash_distance { 20.0f };
|
||||||
sf::Vector2f velocity { 4.0f, 0 };
|
sf::Vector2f velocity { 4.0f, 0 };
|
||||||
} player_data;
|
} player_data;
|
||||||
|
|
||||||
load_map(wall_list, test_level_0);
|
// load_map(wall_list, test_level_0);
|
||||||
|
|
||||||
Player player {
|
// Player player {
|
||||||
player_data.size, player_data.pos, player_data.velocity,
|
// player_data.size, player_data.pos, player_data.velocity,
|
||||||
player_data.border_size, player_data.acceleration, player_data.max_velocity_y,
|
// player_data.border_size, GRAVITY, player_data.max_velocity_y,
|
||||||
player_data.dash_distance, sf::Color::Black, sf::Color::White
|
// player_data.dash_distance, sf::Color::Black, sf::Color::White
|
||||||
};
|
// };
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default);
|
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default);
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(FPS);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/SFML_game_engine/assets/pixel.ttf");
|
sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/SFML_game_engine/assets/pixel.ttf");
|
||||||
@@ -51,10 +53,11 @@ int main() {
|
|||||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)});
|
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)});
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } );
|
// std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } );
|
||||||
|
int mouse_mode = 0; //Single Block mode, 1 multiblock mode
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
window.clear(sf::Color::Black);
|
window.clear(sf::Color::Black);
|
||||||
text.setString(std::to_string(player.timers.dash_cooldown));
|
// text.setString(std::to_string(player.timers.dash_cooldown));
|
||||||
while (const std::optional event = window.pollEvent()) {
|
while (const std::optional event = window.pollEvent()) {
|
||||||
if (event->is<sf::Event::Closed>()) {
|
if (event->is<sf::Event::Closed>()) {
|
||||||
running = false;
|
running = false;
|
||||||
@@ -65,32 +68,56 @@ int main() {
|
|||||||
running = false;
|
running = false;
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) {
|
||||||
clear_map(wall_list);
|
if(mouse_mode == 0) mouse_mode = 1;
|
||||||
if(current_level == 0) {
|
else if(mouse_mode == 1) mouse_mode = 0;
|
||||||
load_map(wall_list, test_level_1);
|
}
|
||||||
current_level = 1;
|
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
|
||||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
sf::Vector2i mouse_position = sf::Mouse::getPosition(window);
|
||||||
|
sf::Vector2f worldPos = window.mapPixelToCoords(mouse_position);
|
||||||
|
float grid_x = std::floor(worldPos.x / 32);
|
||||||
|
float grid_y = std::floor(worldPos.y / 32);
|
||||||
|
if(mouse_mode == 0) {
|
||||||
|
wall_list[(int)grid_y][(int)grid_x] = new Entity {
|
||||||
|
{ TILESIZE, TILESIZE },
|
||||||
|
{ grid_x * TILESIZE, grid_y * TILESIZE },
|
||||||
|
{ 0, 0 },
|
||||||
|
-2.0f,
|
||||||
|
sf::Color::Black
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else if(current_level == 1) {
|
else if(mouse_mode == 1) {
|
||||||
load_map(wall_list, test_level_0);
|
|
||||||
current_level = 0;
|
|
||||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Horizontal movement and collisions
|
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||||
player.handle_movment();
|
// clear_map(wall_list);
|
||||||
player.get_horizontal_collision(wall_list);
|
// if(current_level == 0) {
|
||||||
|
// load_map(wall_list, test_level_1);
|
||||||
player.handle_gravity();
|
// current_level = 1;
|
||||||
if(player.get_velocity().y > ((float)TILESIZE / 2)) {
|
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||||
player.set_velocity_y(TILESIZE / 2);
|
// }
|
||||||
}
|
// else if(current_level == 1) {
|
||||||
if(!player.get_vertical_bottom_collision(wall_list)) {
|
// load_map(wall_list, test_level_0);
|
||||||
player.get_vertical_top_collision(wall_list);
|
// current_level = 0;
|
||||||
}
|
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Handle Horizontal movement and collisions
|
||||||
|
// player.handle_movment();
|
||||||
|
// player.get_horizontal_collision(wall_list);
|
||||||
|
//
|
||||||
|
// player.handle_gravity();
|
||||||
|
// if(player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) {
|
||||||
|
// player.set_velocity_y((TILESIZE / 2) - GRAVITY);
|
||||||
|
// }
|
||||||
|
// if(!player.get_vertical_bottom_collision(wall_list)) {
|
||||||
|
// player.get_vertical_top_collision(wall_list);
|
||||||
|
// }
|
||||||
|
//
|
||||||
// Drawing Everything to window
|
// Drawing Everything to window
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||||
@@ -104,11 +131,11 @@ int main() {
|
|||||||
window.draw(wall_list[i][j]->rect);
|
window.draw(wall_list[i][j]->rect);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
window.draw(player.rect);
|
// window.draw(player.rect);
|
||||||
window.draw(text);
|
window.draw(text);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
clear_map(wall_list);
|
clear_map(wall_list);
|
||||||
player_dash_cooldown.join();
|
// player_dash_cooldown.join();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user