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

@@ -1,6 +1,6 @@
# Makefile generated by smake.

PROJNAME = cpplat
PROJNAME = swan
PROJTYPE = exe

SRCS = src/Body.cc src/Chunk.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc

+ 1
- 1
Smakefile View File

@@ -1,3 +1,3 @@
PROJNAME = cpplat
PROJNAME = swan
PKGS = sfml-all
LDFLAGS += -lstdc++

+ 2
- 1
idea.md View File

@@ -1,5 +1,6 @@
# Game Idea
# Game Idea: Swan

* Working title: Swan (maybe the final name should be 'Project: Swan'?)
* 2D tile-based platformer-esque game
* Circuit network shit
* Move along a third axis, the Z axis

+ 4
- 0
src/Body.cc View File

@@ -1,5 +1,7 @@
#include "Body.h"

namespace Swan {

void Body::friction(float coef) {
force_ += -vel_ * coef;
}
@@ -23,3 +25,5 @@ void Body::update(float dt) {
pos_ += vel_ * dt;
force_ = { 0, 0 };
}

}

+ 4
- 0
src/Body.h View File

@@ -4,6 +4,8 @@

#include "common.h"

namespace Swan {

class Body {
public:
Vec2 force_ = { 0, 0 };
@@ -21,3 +23,5 @@ public:
void outline(Win &win);
void update(float dt);
};

}

+ 4
- 0
src/Chunk.cc View File

@@ -2,9 +2,13 @@

#include <string.h>

namespace Swan {

void Chunk::clear() {
memset(tiles_, 0, sizeof(tiles_));
}

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

}

+ 4
- 0
src/Chunk.h View File

@@ -3,6 +3,8 @@
#include "common.h"
#include "Tile.h"

namespace Swan {

class Chunk {
public:
int x_;
@@ -12,3 +14,5 @@ public:
void clear();
void draw(Win &win);
};

}

+ 4
- 0
src/Game.cc View File

@@ -1,5 +1,7 @@
#include "Game.h"

namespace Swan {

void Game::registerTile(std::string &name, Tile &tile) {
Tile::TileID id = registered_tiles_.size();
registered_tiles_.push_back(tile);
@@ -28,3 +30,5 @@ void Game::tick() {
for (WorldPlane *plane: planes_)
plane->tick();
}

}

+ 4
- 0
src/Game.h View File

@@ -9,6 +9,8 @@
#include "Player.h"
#include "Tile.h"

namespace Swan {

class Game {
public:
Player *player_;
@@ -24,3 +26,5 @@ public:
void update(float dt);
void tick();
};

}

+ 13
- 4
src/Player.cc View File

@@ -1,5 +1,12 @@
#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;

void Player::draw(Win &win) {
@@ -8,15 +15,17 @@ void Player::draw(Win &win) {

void Player::update(float dt) {
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))
body_.force_.y += force;
body_.force_ += Vec2(0, force);
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))
body_.force_.x += force;
body_.force_ += Vec2(force, 0);

body_.friction(friction);
body_.gravity();
body_.update(dt);
}

}

+ 9
- 8
src/Player.h View File

@@ -1,24 +1,25 @@
#pragma once

#include <SFML/Graphics.hpp>

#include "common.h"
#include "Body.h"

namespace Swan {

class Player {
public:
Player(Vec2 pos):
body_(pos, Vec2(width, height), mass) {}
body_(pos, size, mass) {}

void draw(Win &win);
void update(float dt);

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

}

+ 4
- 0
src/Tile.h View File

@@ -2,9 +2,13 @@

#include <stdint.h>

namespace Swan {

class Tile {
public:
using TileID = uint16_t;

Tile(std::string name);
};

}

+ 4
- 0
src/WorldPlane.cc View File

@@ -1,5 +1,7 @@
#include "WorldPlane.h"

namespace Swan {

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

@@ -8,3 +10,5 @@ void WorldPlane::update(float dt) {

void WorldPlane::tick() {
}

}

+ 4
- 0
src/WorldPlane.h View File

@@ -5,6 +5,8 @@
#include "common.h"
#include "Chunk.h"

namespace Swan {

class WorldPlane {
public:
std::vector<Chunk> chunks_;
@@ -17,3 +19,5 @@ public:
void update(float dt);
void tick();
};

}

+ 8
- 4
src/common.h View File

@@ -3,10 +3,12 @@
#include <SFML/System/Vector2.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> {
public:
@@ -65,3 +67,5 @@ public:
window_.draw(drawable, transform_);
}
};

}

+ 4
- 2
src/main.cc View File

@@ -6,14 +6,16 @@
#include "Player.h"
#include "Game.h"

double getTime() {
using namespace Swan;

static double getTime() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000.0;
}

template<typename T>
void draw_ents(std::vector<T> ents) {
static void draw_ents(std::vector<T> ents) {
for (auto &ent: ents)
ent.draw();
}

Loading…
Cancel
Save