Ver código fonte

actual game idea and stuff

opengl-renderer-broken
Martin Dørum 4 anos atrás
pai
commit
42804b32e7
13 arquivos alterados com 144 adições e 21 exclusões
  1. 2
    2
      Makefile
  2. 1
    0
      Smakefile
  3. 22
    0
      idea.md
  4. 9
    1
      src/Body.cc
  5. 6
    2
      src/Body.h
  6. 20
    0
      src/Game.cc
  7. 18
    0
      src/Game.h
  8. 13
    4
      src/Player.cc
  9. 5
    1
      src/Player.h
  10. 10
    0
      src/WorldPlane.cc
  11. 10
    0
      src/WorldPlane.h
  12. 1
    0
      src/common.h
  13. 27
    11
      src/main.cc

+ 2
- 2
Makefile Ver arquivo

PROJNAME = cpplat PROJNAME = cpplat
PROJTYPE = exe PROJTYPE = exe


SRCS = src/Body.cc src/main.cc src/Player.cc
HDRS = src/Body.h src/common.h src/Player.h
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
OBJS = $(patsubst src/%,$(BUILD)/obj/%.o,$(SRCS)) OBJS = $(patsubst src/%,$(BUILD)/obj/%.o,$(SRCS))
DEPS = $(patsubst src/%,$(BUILD)/dep/%.d,$(SRCS)) DEPS = $(patsubst src/%,$(BUILD)/dep/%.d,$(SRCS))
PUBLICHDRS = PUBLICHDRS =

+ 1
- 0
Smakefile Ver arquivo

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

+ 22
- 0
idea.md Ver arquivo

# Game Idea

* 2D tile-based platformer-esque game
* Circuit network shit
* Move along a third axis, the Z axis
* "Dimentional Shifter"
* Mobs ofc
* Some kind of crafting? IDK
* Progression?
* Minecraft-like exploration-driven progression with no clear path?
* Terraria-like linear-ish boss-driven progression?
* Power system
* Circuit network shit requires power
* Maybe emulate a simplified electrical system?
* Transistors could be the core, where power flows from A to B if C is
receiving power (B = C ? A + C : 0)
* Everything (pistons, doors, gates, sensors, whatever) uses power
* Power gen could be one of the main "goals" of the game
* Turing machines?
* Idk, had this idea for a minecraft mod once.
* A robot which runs a dialect of Brainfuck with some extra operations for
I/O to interact with the world.

+ 9
- 1
src/Body.cc Ver arquivo

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


void Body::friction(float coef) {
force_ += -vel_ * coef;
}

void Body::gravity(Vec2 g) {
force_ += g * mass_;
}

void Body::outline(Win &win) { void Body::outline(Win &win) {
win.setPos(pos_); win.setPos(pos_);


} }


void Body::update(float dt) { void Body::update(float dt) {
vel_ += force_ * dt;
vel_ += (force_ / mass_) * dt;
pos_ += vel_ * dt; pos_ += vel_ * dt;
force_ = { 0, 0 }; force_ = { 0, 0 };
} }

+ 6
- 2
src/Body.h Ver arquivo

Vec2 vel_ = { 0, 0 }; Vec2 vel_ = { 0, 0 };
Vec2 pos_; Vec2 pos_;
Vec2 size_; Vec2 size_;
float mass_;


Body(Vec2 pos, Vec2 size):
pos_(pos), size_(size) {};
Body(Vec2 pos, Vec2 size, float mass):
pos_(pos), size_(size), mass_(mass) {};

void friction(float coef);
void gravity(Vec2 g = Vec2(0, 9.81));


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

+ 20
- 0
src/Game.cc Ver arquivo

#include "Game.h"

void Game::draw(Win &win) {
for (WorldPlane *plane: planes_)
plane->draw(win);

player_->draw(win);
}

void Game::update(float dt) {
for (WorldPlane *plane: planes_)
plane->update(dt);

player_->update(dt);
}

void Game::tick() {
for (WorldPlane *plane: planes_)
plane->tick();
}

+ 18
- 0
src/Game.h Ver arquivo

#pragma once

#include <vector>

#include "common.h"
#include "WorldPlane.h"
#include "Player.h"

class Game {
public:
Player *player_;
WorldPlane *current_plane_;
std::vector<WorldPlane *> planes_;

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

+ 13
- 4
src/Player.cc Ver arquivo

#include "Player.h" #include "Player.h"


using Keyboard = sf::Keyboard;

void Player::draw(Win &win) { void Player::draw(Win &win) {
body_.outline(win); body_.outline(win);
} }


void Player::update(float dt) { void Player::update(float dt) {
body_.vel_.x = 1;
body_.update(dt);
if (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up))
body_.force_.y -= force;
if (Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down))
body_.force_.y += force;
if (Keyboard::isKeyPressed(Keyboard::A) || Keyboard::isKeyPressed(Keyboard::Left))
body_.force_.x -= force;
if (Keyboard::isKeyPressed(Keyboard::D) || Keyboard::isKeyPressed(Keyboard::Right))
body_.force_.x += force;


if (body_.pos_.x > 20)
body_.pos_.x = 0;
body_.friction(friction);
body_.gravity();
body_.update(dt);
} }

+ 5
- 1
src/Player.h Ver arquivo

class Player { class Player {
public: public:
Player(Vec2 pos): Player(Vec2 pos):
body_(pos, Vec2(1, 1)) {}
body_(pos, Vec2(1, 1), 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 = 50;

Body body_; Body body_;
}; };

+ 10
- 0
src/WorldPlane.cc Ver arquivo

#include "WorldPlane.h"

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

void WorldPlane::update(float dt) {
}

void tick() {
}

+ 10
- 0
src/WorldPlane.h Ver arquivo

#pragma once

#include "common.h"

class WorldPlane {
public:
void draw(Win &win);
void update(float dt);
void tick();
};

+ 1
- 0
src/common.h Ver arquivo

#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>


#define UNIT_SIZE 32.0 #define UNIT_SIZE 32.0
#define TICK_RATE 20


class Vec2: public sf::Vector2<float> { class Vec2: public sf::Vector2<float> {
public: public:

+ 27
- 11
src/main.cc Ver arquivo

#include <vector> #include <vector>
#include <time.h> #include <time.h>
#include <unistd.h>


#include "common.h" #include "common.h"
#include "Player.h" #include "Player.h"
#include "Game.h"


double getTime() { double getTime() {
struct timespec ts; struct timespec ts;
} }


int main() { int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
sf::RenderWindow window(sf::VideoMode(800, 600), "good gaem");
window.setVerticalSyncEnabled(true);
sf::Transform transform; sf::Transform transform;
transform.scale(UNIT_SIZE, UNIT_SIZE); transform.scale(UNIT_SIZE, UNIT_SIZE);


Win win = { window, transform }; Win win = { window, transform };


Player player(Vec2(1, 1));
Game game;
game.player_ = new Player(Vec2(1, 1));


double prevtime = getTime(); double prevtime = getTime();
double acc = 0;
double fpsAcc = 0;
double tickAcc = 0;
int fcount = 0; int fcount = 0;


while (window.isOpen()) { while (window.isOpen()) {
sf::Event event; sf::Event event;
while (window.pollEvent(event)) { while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
if (event.type == sf::Event::Closed) {
window.close(); window.close();
} else if (event.type == sf::Event::Resized) {
sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
window.setView(sf::View(visibleArea));
}
} }


// Display FPS
double now = getTime(); double now = getTime();
double dt = now - prevtime; double dt = now - prevtime;
prevtime = now; prevtime = now;
acc += dt;
fpsAcc += dt;
fcount += 1; fcount += 1;
if (acc >= 1) {
fprintf(stderr, "fps %i\n", fcount);
acc = 0;
if (fpsAcc >= 1) {
fprintf(stderr, "FPS: %i\n", fcount);
fpsAcc -= 1;
fcount = 0; fcount = 0;
} }


window.clear(sf::Color(135, 206, 250));
game.update(dt);


player.draw(win);
player.update(dt);
// Call tick TICK_RATE times per second
tickAcc += dt;
while (tickAcc >= 1.0 / TICK_RATE) {
tickAcc -= 1.0 / TICK_RATE;
game.tick();
}


window.clear(sf::Color(135, 206, 250));
game.draw(win);
window.display(); window.display();
} }



Carregando…
Cancelar
Salvar