# Makefile generated by smake. | # Makefile generated by smake. | ||||
PROJNAME = cpplat | |||||
PROJNAME = swan | |||||
PROJTYPE = exe | PROJTYPE = exe | ||||
SRCS = src/Body.cc src/Chunk.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc | SRCS = src/Body.cc src/Chunk.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc |
PROJNAME = cpplat | |||||
PROJNAME = swan | |||||
PKGS = sfml-all | PKGS = sfml-all | ||||
LDFLAGS += -lstdc++ | LDFLAGS += -lstdc++ |
# Game Idea | |||||
# Game Idea: Swan | |||||
* Working title: Swan (maybe the final name should be 'Project: Swan'?) | |||||
* 2D tile-based platformer-esque game | * 2D tile-based platformer-esque game | ||||
* Circuit network shit | * Circuit network shit | ||||
* Move along a third axis, the Z axis | * Move along a third axis, the Z axis |
#include "Body.h" | #include "Body.h" | ||||
namespace Swan { | |||||
void Body::friction(float coef) { | void Body::friction(float coef) { | ||||
force_ += -vel_ * coef; | force_ += -vel_ * coef; | ||||
} | } | ||||
pos_ += vel_ * dt; | pos_ += vel_ * dt; | ||||
force_ = { 0, 0 }; | force_ = { 0, 0 }; | ||||
} | } | ||||
} |
#include "common.h" | #include "common.h" | ||||
namespace Swan { | |||||
class Body { | class Body { | ||||
public: | public: | ||||
Vec2 force_ = { 0, 0 }; | Vec2 force_ = { 0, 0 }; | ||||
void outline(Win &win); | void outline(Win &win); | ||||
void update(float dt); | void update(float dt); | ||||
}; | }; | ||||
} |
#include <string.h> | #include <string.h> | ||||
namespace Swan { | |||||
void Chunk::clear() { | void Chunk::clear() { | ||||
memset(tiles_, 0, sizeof(tiles_)); | memset(tiles_, 0, sizeof(tiles_)); | ||||
} | } | ||||
void Chunk::draw(Win &win) { | void Chunk::draw(Win &win) { | ||||
} | } | ||||
} |
#include "common.h" | #include "common.h" | ||||
#include "Tile.h" | #include "Tile.h" | ||||
namespace Swan { | |||||
class Chunk { | class Chunk { | ||||
public: | public: | ||||
int x_; | int x_; | ||||
void clear(); | void clear(); | ||||
void draw(Win &win); | void draw(Win &win); | ||||
}; | }; | ||||
} |
#include "Game.h" | #include "Game.h" | ||||
namespace Swan { | |||||
void Game::registerTile(std::string &name, Tile &tile) { | void Game::registerTile(std::string &name, Tile &tile) { | ||||
Tile::TileID id = registered_tiles_.size(); | Tile::TileID id = registered_tiles_.size(); | ||||
registered_tiles_.push_back(tile); | registered_tiles_.push_back(tile); | ||||
for (WorldPlane *plane: planes_) | for (WorldPlane *plane: planes_) | ||||
plane->tick(); | plane->tick(); | ||||
} | } | ||||
} |
#include "Player.h" | #include "Player.h" | ||||
#include "Tile.h" | #include "Tile.h" | ||||
namespace Swan { | |||||
class Game { | class Game { | ||||
public: | public: | ||||
Player *player_; | Player *player_; | ||||
void update(float dt); | void update(float dt); | ||||
void tick(); | void tick(); | ||||
}; | }; | ||||
} |
#include "Player.h" | #include "Player.h" | ||||
namespace Swan { | |||||
const float Player::force = 600; | |||||
const float Player::friction = 100; | |||||
const float Player::mass = 80; | |||||
const Vec2 Player::size = Vec2(1, 2); | |||||
using Keyboard = sf::Keyboard; | using Keyboard = sf::Keyboard; | ||||
void Player::draw(Win &win) { | void Player::draw(Win &win) { | ||||
void Player::update(float dt) { | void Player::update(float dt) { | ||||
if (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) | if (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) | ||||
body_.force_.y -= force; | |||||
body_.force_ += Vec2(0, -force); | |||||
if (Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) | if (Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) | ||||
body_.force_.y += force; | |||||
body_.force_ += Vec2(0, force); | |||||
if (Keyboard::isKeyPressed(Keyboard::A) || Keyboard::isKeyPressed(Keyboard::Left)) | if (Keyboard::isKeyPressed(Keyboard::A) || Keyboard::isKeyPressed(Keyboard::Left)) | ||||
body_.force_.x -= force; | |||||
body_.force_ += Vec2(-force, 0); | |||||
if (Keyboard::isKeyPressed(Keyboard::D) || Keyboard::isKeyPressed(Keyboard::Right)) | if (Keyboard::isKeyPressed(Keyboard::D) || Keyboard::isKeyPressed(Keyboard::Right)) | ||||
body_.force_.x += force; | |||||
body_.force_ += Vec2(force, 0); | |||||
body_.friction(friction); | body_.friction(friction); | ||||
body_.gravity(); | body_.gravity(); | ||||
body_.update(dt); | body_.update(dt); | ||||
} | } | ||||
} |
#pragma once | #pragma once | ||||
#include <SFML/Graphics.hpp> | |||||
#include "common.h" | #include "common.h" | ||||
#include "Body.h" | #include "Body.h" | ||||
namespace Swan { | |||||
class Player { | class Player { | ||||
public: | public: | ||||
Player(Vec2 pos): | Player(Vec2 pos): | ||||
body_(pos, Vec2(width, height), mass) {} | |||||
body_(pos, size, mass) {} | |||||
void draw(Win &win); | void draw(Win &win); | ||||
void update(float dt); | void update(float dt); | ||||
private: | private: | ||||
static constexpr float force = 600; | |||||
static constexpr float friction = 100; | |||||
static constexpr float mass = 80; | |||||
static constexpr float width = 1; | |||||
static constexpr float height = 2; | |||||
static const float force; | |||||
static const float friction; | |||||
static const float mass; | |||||
static const Vec2 size; | |||||
Body body_; | Body body_; | ||||
}; | }; | ||||
} |
#include <stdint.h> | #include <stdint.h> | ||||
namespace Swan { | |||||
class Tile { | class Tile { | ||||
public: | public: | ||||
using TileID = uint16_t; | using TileID = uint16_t; | ||||
Tile(std::string name); | Tile(std::string name); | ||||
}; | }; | ||||
} |
#include "WorldPlane.h" | #include "WorldPlane.h" | ||||
namespace Swan { | |||||
void WorldPlane::draw(Win &win) { | void WorldPlane::draw(Win &win) { | ||||
} | } | ||||
void WorldPlane::tick() { | void WorldPlane::tick() { | ||||
} | } | ||||
} |
#include "common.h" | #include "common.h" | ||||
#include "Chunk.h" | #include "Chunk.h" | ||||
namespace Swan { | |||||
class WorldPlane { | class WorldPlane { | ||||
public: | public: | ||||
std::vector<Chunk> chunks_; | std::vector<Chunk> chunks_; | ||||
void update(float dt); | void update(float dt); | ||||
void tick(); | void tick(); | ||||
}; | }; | ||||
} |
#include <SFML/System/Vector2.hpp> | #include <SFML/System/Vector2.hpp> | ||||
#include <SFML/Graphics.hpp> | #include <SFML/Graphics.hpp> | ||||
#define UNIT_SIZE 12.0 | |||||
#define TICK_RATE 20 | |||||
#define CHUNK_HEIGHT 32 | |||||
#define CHUNK_WIDTH 32 | |||||
namespace Swan { | |||||
static constexpr float UNIT_SIZE = 12; | |||||
static constexpr int TICK_RATE = 20; | |||||
static constexpr int CHUNK_HEIGHT = 32; | |||||
static constexpr int CHUNK_WIDTH = 32; | |||||
class Vec2: public sf::Vector2<float> { | class Vec2: public sf::Vector2<float> { | ||||
public: | public: | ||||
window_.draw(drawable, transform_); | window_.draw(drawable, transform_); | ||||
} | } | ||||
}; | }; | ||||
} |
#include "Player.h" | #include "Player.h" | ||||
#include "Game.h" | #include "Game.h" | ||||
double getTime() { | |||||
using namespace Swan; | |||||
static double getTime() { | |||||
struct timespec ts; | struct timespec ts; | ||||
clock_gettime(CLOCK_MONOTONIC, &ts); | clock_gettime(CLOCK_MONOTONIC, &ts); | ||||
return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000.0; | return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000.0; | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
void draw_ents(std::vector<T> ents) { | |||||
static void draw_ents(std::vector<T> ents) { | |||||
for (auto &ent: ents) | for (auto &ent: ents) | ||||
ent.draw(); | ent.draw(); | ||||
} | } |