@@ -3,8 +3,8 @@ | |||
PROJNAME = cpplat | |||
PROJTYPE = exe | |||
SRCS = src/Body.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc | |||
HDRS = src/Body.h src/common.h src/Game.h src/Player.h src/WorldPlane.h | |||
SRCS = src/Body.cc src/Chunk.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc | |||
HDRS = src/Body.h src/Chunk.h src/common.h src/Game.h src/Player.h src/Tile.h src/WorldPlane.h | |||
OBJS = $(patsubst src/%,$(BUILD)/obj/%.o,$(SRCS)) | |||
DEPS = $(patsubst src/%,$(BUILD)/dep/%.d,$(SRCS)) | |||
PUBLICHDRS = |
@@ -0,0 +1,10 @@ | |||
#include "Chunk.h" | |||
#include <string.h> | |||
void Chunk::clear() { | |||
memset(tiles_, 0, sizeof(tiles_)); | |||
} | |||
void Chunk::draw(Win &win) { | |||
} |
@@ -0,0 +1,14 @@ | |||
#pragma once | |||
#include "common.h" | |||
#include "Tile.h" | |||
class Chunk { | |||
public: | |||
int x_; | |||
int y_; | |||
Tile::TileID tiles_[CHUNK_HEIGHT][CHUNK_WIDTH]; | |||
void clear(); | |||
void draw(Win &win); | |||
}; |
@@ -1,5 +1,15 @@ | |||
#include "Game.h" | |||
void Game::registerTile(std::string &name, Tile &tile) { | |||
Tile::TileID id = registered_tiles_.size(); | |||
registered_tiles_.push_back(tile); | |||
tile_id_map_[name] = id; | |||
} | |||
Tile::TileID Game::getTileID(std::string &name) { | |||
return tile_id_map_[name]; | |||
} | |||
void Game::draw(Win &win) { | |||
for (WorldPlane *plane: planes_) | |||
plane->draw(win); |
@@ -1,16 +1,24 @@ | |||
#pragma once | |||
#include <vector> | |||
#include <map> | |||
#include <string> | |||
#include "common.h" | |||
#include "WorldPlane.h" | |||
#include "Player.h" | |||
#include "Tile.h" | |||
class Game { | |||
public: | |||
Player *player_; | |||
WorldPlane *current_plane_; | |||
std::vector<WorldPlane *> planes_; | |||
std::vector<Tile> registered_tiles_; | |||
std::map<std::string, Tile::TileID> tile_id_map_; | |||
void registerTile(std::string &name, Tile &tile); | |||
Tile::TileID getTileID(std::string &name); | |||
void draw(Win &win); | |||
void update(float dt); |
@@ -8,7 +8,7 @@ | |||
class Player { | |||
public: | |||
Player(Vec2 pos): | |||
body_(pos, Vec2(1, 1), mass) {} | |||
body_(pos, Vec2(width, height), mass) {} | |||
void draw(Win &win); | |||
void update(float dt); | |||
@@ -16,7 +16,9 @@ public: | |||
private: | |||
static constexpr float force = 600; | |||
static constexpr float friction = 100; | |||
static constexpr float mass = 50; | |||
static constexpr float mass = 80; | |||
static constexpr float width = 1; | |||
static constexpr float height = 2; | |||
Body body_; | |||
}; |
@@ -0,0 +1,10 @@ | |||
#pragma once | |||
#include <stdint.h> | |||
class Tile { | |||
public: | |||
using TileID = uint16_t; | |||
Tile(std::string name); | |||
}; |
@@ -6,5 +6,5 @@ void WorldPlane::draw(Win &win) { | |||
void WorldPlane::update(float dt) { | |||
} | |||
void tick() { | |||
void WorldPlane::tick() { | |||
} |
@@ -1,9 +1,18 @@ | |||
#pragma once | |||
#include <vector> | |||
#include "common.h" | |||
#include "Chunk.h" | |||
class WorldPlane { | |||
public: | |||
std::vector<Chunk> chunks_; | |||
int max_chunk_x_ = 0; | |||
int min_chunk_x_ = 0; | |||
int max_chunk_y_ = 0; | |||
int min_chunk_y_ = 0; | |||
void draw(Win &win); | |||
void update(float dt); | |||
void tick(); |
@@ -3,8 +3,10 @@ | |||
#include <SFML/System/Vector2.hpp> | |||
#include <SFML/Graphics.hpp> | |||
#define UNIT_SIZE 32.0 | |||
#define UNIT_SIZE 12.0 | |||
#define TICK_RATE 20 | |||
#define CHUNK_HEIGHT 32 | |||
#define CHUNK_WIDTH 32 | |||
class Vec2: public sf::Vector2<float> { | |||
public: |
@@ -28,6 +28,8 @@ int main() { | |||
Game game; | |||
game.player_ = new Player(Vec2(1, 1)); | |||
game.current_plane_ = new WorldPlane(); | |||
game.planes_.push_back(game.current_plane_); | |||
double prevtime = getTime(); | |||
double fpsAcc = 0; |