Browse Source

working title: Swan

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
ed14ce3f47
16 changed files with 74 additions and 21 deletions
  1. 1
    1
      Makefile
  2. 1
    1
      Smakefile
  3. 2
    1
      idea.md
  4. 4
    0
      src/Body.cc
  5. 4
    0
      src/Body.h
  6. 4
    0
      src/Chunk.cc
  7. 4
    0
      src/Chunk.h
  8. 4
    0
      src/Game.cc
  9. 4
    0
      src/Game.h
  10. 13
    4
      src/Player.cc
  11. 9
    8
      src/Player.h
  12. 4
    0
      src/Tile.h
  13. 4
    0
      src/WorldPlane.cc
  14. 4
    0
      src/WorldPlane.h
  15. 8
    4
      src/common.h
  16. 4
    2
      src/main.cc

+ 1
- 1
Makefile View File

# 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

+ 1
- 1
Smakefile View File

PROJNAME = cpplat
PROJNAME = swan
PKGS = sfml-all PKGS = sfml-all
LDFLAGS += -lstdc++ LDFLAGS += -lstdc++

+ 2
- 1
idea.md View File

# 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

+ 4
- 0
src/Body.cc View File

#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 };
} }

}

+ 4
- 0
src/Body.h View File



#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);
}; };

}

+ 4
- 0
src/Chunk.cc View File



#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) {
} }

}

+ 4
- 0
src/Chunk.h View File

#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);
}; };

}

+ 4
- 0
src/Game.cc View File

#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();
} }

}

+ 4
- 0
src/Game.h View File

#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();
}; };

}

+ 13
- 4
src/Player.cc View File

#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);
} }

}

+ 9
- 8
src/Player.h View File

#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_;
}; };

}

+ 4
- 0
src/Tile.h View File



#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);
}; };

}

+ 4
- 0
src/WorldPlane.cc View File

#include "WorldPlane.h" #include "WorldPlane.h"


namespace Swan {

void WorldPlane::draw(Win &win) { void WorldPlane::draw(Win &win) {
} }




void WorldPlane::tick() { void WorldPlane::tick() {
} }

}

+ 4
- 0
src/WorldPlane.h View File

#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();
}; };

}

+ 8
- 4
src/common.h View File

#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_);
} }
}; };

}

+ 4
- 2
src/main.cc View File

#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();
} }

Loading…
Cancel
Save