Compare commits

..

No commits in common. "b3f1071a1d553af3ce65d831f0d6df5460fedb65" and "25e266d430546a0ff1b16b906dd28aefc115c768" have entirely different histories.

4 changed files with 14 additions and 33 deletions

View file

@ -1,10 +1,7 @@
#include "app.h" #include "app.h"
#include "map/map.h" #include "map/map.h"
#include "interfaces/itemsink.h"
#include "items/wrench.h"
#include "tiles/rainbow.h" #include "tiles/rainbow.h"
#include "tiles/conveyor.h"
#include "tiles/dirt.h" #include "tiles/dirt.h"
#include "tiles/grass.h" #include "tiles/grass.h"
#include "util/vector2.h" #include "util/vector2.h"
@ -26,16 +23,14 @@ bool App::OnUserCreate()
bool App::OnUserUpdate(float delta) bool App::OnUserUpdate(float delta)
{ {
auto &map = Map::instance();
Vector2<int> screen = {ScreenWidth(), ScreenHeight()}; Vector2<int> screen = {ScreenWidth(), ScreenHeight()};
Vector2<int> mouse = {GetMouseX(), GetMouseY()}; Vector2<int> mouse = {GetMouseX(), GetMouseY()};
// Save and load keys // Save and load keys
if(GetKey(olc::Key::S).bReleased) if(GetKey(olc::Key::S).bReleased)
map.save(); m_map.save();
if(GetKey(olc::Key::L).bReleased) if(GetKey(olc::Key::L).bReleased)
map.load(); m_map.load();
// Basic block placing // Basic block placing
if(GetMouse(0).bPressed) { if(GetMouse(0).bPressed) {
@ -43,21 +38,14 @@ bool App::OnUserUpdate(float delta)
auto tile_pos = screen_pos / (TILE_SIZE + 1); auto tile_pos = screen_pos / (TILE_SIZE + 1);
if(screen_pos.x() < 0) tile_pos -= {1, 0}; if(screen_pos.x() < 0) tile_pos -= {1, 0};
if(screen_pos.y() < 0) tile_pos -= {0, 1}; if(screen_pos.y() < 0) tile_pos -= {0, 1};
map.set_tile(tile_pos, new Conveyor()); m_map.set_tile(tile_pos, new Rainbow());
} }
if(GetMouse(1).bPressed) { if(GetMouse(1).bPressed) {
auto screen_pos = mouse - m_camera_pos; auto screen_pos = mouse - m_camera_pos;
auto tile_pos = screen_pos / (TILE_SIZE + 1); auto tile_pos = screen_pos / (TILE_SIZE + 1);
if(screen_pos.x() < 0) tile_pos -= {1, 0}; if(screen_pos.x() < 0) tile_pos -= {1, 0};
if(screen_pos.y() < 0) tile_pos -= {0, 1}; if(screen_pos.y() < 0) tile_pos -= {0, 1};
// map.set_tile(tile_pos, new Dirt()); m_map.set_tile(tile_pos, new Dirt());
auto sink = dynamic_cast<ItemSink *>(&map.at(tile_pos).entity());
std::cout << "Insert " << sink << std::endl;
if(sink) {
std::cout << sink->can_accept(*(new Wrench())) << std::endl;
sink->insert(*(new Wrench()));
std::cout << sink->can_accept(*(new Wrench())) << std::endl;
}
} }
// Pan camera with middle mouse // Pan camera with middle mouse
@ -80,7 +68,7 @@ bool App::OnUserUpdate(float delta)
for(int y = min.y() - 1; y < max.y() + 1; y++) { for(int y = min.y() - 1; y < max.y() + 1; y++) {
for(int x = min.x() - 1; x < max.x() + 1; x++) { for(int x = min.x() - 1; x < max.x() + 1; x++) {
auto &node = map.at(Vector2<int>(x, y)); auto &node = m_map.at(Vector2<int>(x, y));
node.update(delta); node.update(delta);
node.render(m_render); node.render(m_render);
} }

View file

@ -17,6 +17,7 @@ public:
private: private:
Render m_render; Render m_render;
Map m_map;
Vector2<int> m_drag_start; Vector2<int> m_drag_start;
Vector2<int> m_camera_pos; Vector2<int> m_camera_pos;

View file

@ -10,14 +10,6 @@ class Map {
public: public:
Map() = default; Map() = default;
Map(Map const &) = delete;
void operator=(const Map &) = delete;
static Map &instance() {
static Map s_instance;
return s_instance;
}
Node &at(Vector2<int> pos); Node &at(Vector2<int> pos);
void set_tile(Vector2<int> pos, Tile *tile); void set_tile(Vector2<int> pos, Tile *tile);

View file

@ -50,10 +50,10 @@ void Render::fill_rectangle_sz(Vector2<int> size, Color color) {
} }
void Render::draw_lines(std::vector<Vector2<float>> points, Color color) { void Render::draw_lines(std::vector<Vector2<float>> points, Color color) {
auto prev_cache = m_view_matrix * m_matrix * Vector3<float>(points[0], 1); auto prev_cache = m_matrix * m_view_matrix * Vector3<float>(points[0], 1);
for(size_t i = 1; i < points.size(); i++) { for(size_t i = 1; i < points.size(); i++) {
auto start = prev_cache; auto start = prev_cache;
auto end = m_view_matrix * m_matrix * Vector3<float>(points[i], 1); auto end = m_matrix * m_view_matrix * Vector3<float>(points[i], 1);
m_pge->DrawLine( m_pge->DrawLine(
start.x(), start.x(),
@ -118,10 +118,10 @@ void Render::pop_matrix() {
void Render::translate(Vector2<float> trans) { void Render::translate(Vector2<float> trans) {
switch(m_matrix_mode) { switch(m_matrix_mode) {
case MODEL: case MODEL:
m_matrix *= translation_matrix(trans); m_matrix = translation_matrix(trans) * m_matrix;
break; break;
case PROJECTION: case PROJECTION:
m_view_matrix *= translation_matrix(trans); m_view_matrix = translation_matrix(trans) * m_view_matrix;
break; break;
} }
} }
@ -129,10 +129,10 @@ void Render::translate(Vector2<float> trans) {
void Render::rotate(float theta) { void Render::rotate(float theta) {
switch(m_matrix_mode) { switch(m_matrix_mode) {
case MODEL: case MODEL:
m_matrix *= rotation_matrix(theta); m_matrix = rotation_matrix(theta) * m_matrix;
break; break;
case PROJECTION: case PROJECTION:
m_view_matrix *= rotation_matrix(theta); m_view_matrix = rotation_matrix(theta) * m_view_matrix;
break; break;
} }
} }
@ -140,10 +140,10 @@ void Render::rotate(float theta) {
void Render::scale(Vector2<float> scale) { void Render::scale(Vector2<float> scale) {
switch(m_matrix_mode) { switch(m_matrix_mode) {
case MODEL: case MODEL:
m_matrix *= scale_matrix(scale); m_matrix = scale_matrix(scale) * m_matrix;
break; break;
case PROJECTION: case PROJECTION:
m_view_matrix *= scale_matrix(scale); m_view_matrix = scale_matrix(scale) * m_view_matrix;
} }
} }