start to map creator
This commit is contained in:
+36
-56
@@ -3,6 +3,7 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
@@ -32,13 +33,13 @@ int main() {
|
||||
sf::Vector2f velocity { 4.0f, 0 };
|
||||
} player_data;
|
||||
|
||||
// load_map(wall_list, test_level_0);
|
||||
load_map(wall_list, test_level_0);
|
||||
|
||||
// Player player {
|
||||
// player_data.size, player_data.pos, player_data.velocity,
|
||||
// player_data.border_size, GRAVITY, player_data.max_velocity_y,
|
||||
// player_data.dash_distance, sf::Color::Black, sf::Color::White
|
||||
// };
|
||||
Player player {
|
||||
player_data.size, player_data.pos, player_data.velocity,
|
||||
player_data.border_size, GRAVITY, player_data.max_velocity_y,
|
||||
player_data.dash_distance, sf::Color::Black, sf::Color::White
|
||||
};
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default);
|
||||
window.setFramerateLimit(FPS);
|
||||
@@ -53,11 +54,13 @@ int main() {
|
||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)});
|
||||
|
||||
bool running = true;
|
||||
// std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } );
|
||||
bool print = false;
|
||||
std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } );
|
||||
int mouse_mode = 0; //Single Block mode, 1 multiblock mode
|
||||
char tmp_level[MAX_ROWS][MAX_COLS] = {};
|
||||
while (window.isOpen()) {
|
||||
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()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
running = false;
|
||||
@@ -68,56 +71,33 @@ int main() {
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) {
|
||||
if(mouse_mode == 0) mouse_mode = 1;
|
||||
else if(mouse_mode == 1) mouse_mode = 0;
|
||||
}
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
|
||||
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(mouse_mode == 1) {
|
||||
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||
clear_map(wall_list);
|
||||
if(current_level == 0) {
|
||||
load_map(wall_list, test_level_1);
|
||||
current_level = 1;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
}
|
||||
else if(current_level == 1) {
|
||||
load_map(wall_list, test_level_0);
|
||||
current_level = 0;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
}
|
||||
}
|
||||
|
||||
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||
// clear_map(wall_list);
|
||||
// if(current_level == 0) {
|
||||
// load_map(wall_list, test_level_1);
|
||||
// current_level = 1;
|
||||
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
// }
|
||||
// else if(current_level == 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
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// 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
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
@@ -131,11 +111,11 @@ int main() {
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
}
|
||||
#endif
|
||||
// window.draw(player.rect);
|
||||
window.draw(player.rect);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
clear_map(wall_list);
|
||||
// player_dash_cooldown.join();
|
||||
player_dash_cooldown.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user