added create_map and attempt to work
This commit is contained in:
+3
-36
@@ -10,51 +10,19 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#else
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
#include "globals.hpp"
|
||||
#include "elements.hpp"
|
||||
#include "maps.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
void draw_wall(sf::RenderWindow &window, sf::Vector2i &local_position, sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, bool &dragging, bool &prev_dragging, Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
if(local_position.x > 0 && local_position.x < WIDTH && local_position.y > 0 && local_position.y < HEIGHT) {
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !dragging) {
|
||||
dragging = true;
|
||||
start_mouse_pos = local_position;
|
||||
}
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging) {
|
||||
prev_dragging = true;
|
||||
end_mouse_pos = local_position;
|
||||
sf::RectangleShape rect { { (float) (end_mouse_pos.x - start_mouse_pos.x), 1.0f } };
|
||||
rect.setPosition({ (float)start_mouse_pos.x, (float)(std::floor(start_mouse_pos.y / 32) * TILESIZE + ((float)TILESIZE / 2))} );
|
||||
window.draw(rect);
|
||||
}
|
||||
if(!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging && prev_dragging) {
|
||||
sf::Vector2i start_integers = { (int)std::floor(start_mouse_pos.x / 32), (int)std::floor(start_mouse_pos.y / 32) };
|
||||
sf::Vector2i end_integers = { (int)std::floor(end_mouse_pos.x / 32), (int)std::floor(end_mouse_pos.y / 32) };
|
||||
|
||||
if(end_integers.x - start_integers.x > 0) {
|
||||
if(wall_list[start_integers.x][start_integers.y] == nullptr) {
|
||||
wall_list[start_integers.x][start_integers.y] = new Entity {
|
||||
{ float(end_integers.x - start_integers.x + 1) * TILESIZE, TILESIZE },
|
||||
{ (float)(start_integers.x * TILESIZE), (float)(start_integers.y * TILESIZE) },
|
||||
{ 0, 0 },
|
||||
-2.0f,
|
||||
sf::Color::Black
|
||||
};
|
||||
}
|
||||
}
|
||||
prev_dragging = false;
|
||||
dragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Timer time;
|
||||
Entity *wall_list[MAX_ROWS][MAX_COLS] = {};
|
||||
@@ -99,7 +67,6 @@ int main() {
|
||||
local_position = sf::Mouse::getPosition(window);
|
||||
window.clear(sf::Color::Black);
|
||||
text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " + std::to_string((int)std::floor(local_position.y / 32)));
|
||||
std::cout << dragging << "\n";
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
// running = false;
|
||||
@@ -117,7 +84,7 @@ int main() {
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
dragging = false;
|
||||
}
|
||||
draw_wall(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list);
|
||||
create_map(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list);
|
||||
|
||||
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||
// clear_map(wall_list);
|
||||
|
||||
Reference in New Issue
Block a user