Skip to content

Commit

Permalink
Merge pull request #5 from Rafael-Dev-21/dev2
Browse files Browse the repository at this point in the history
Dev2
  • Loading branch information
Rafael-Dev-21 authored Feb 29, 2024
2 parents 61b1711 + 3b3adb4 commit 87e8bca
Show file tree
Hide file tree
Showing 37 changed files with 703 additions and 347 deletions.
18 changes: 0 additions & 18 deletions include/controller/curses.hpp

This file was deleted.

8 changes: 8 additions & 0 deletions include/draw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DRAW_H
#define DRAW_H

// draw
void draw_map(Map * const, Point);
void draw_player(Point pos, Point cursor);

#endif
Empty file added include/draw.hpp
Empty file.
9 changes: 9 additions & 0 deletions include/engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef ENGINE_H
#define ENGINE_H

#define ESC 27

// engine
void init_curses(void);

#endif
2 changes: 1 addition & 1 deletion include/model/engine.hpp → include/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "entity.hpp"
#include "level.hpp"

#include "util/events.hpp"
#include "events.hpp"

class Engine: public EventListener {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/model/entity.hpp → include/entity.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "util/geom.hpp"
#include "geom.hpp"

class Entity {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/util/events.hpp → include/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ class EventSystem {

private:
std::list<EventListener *> listeners;
};
};
File renamed without changes.
61 changes: 44 additions & 17 deletions include/model/level.hpp → include/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,61 @@

#include <map>
#include <utility>
#include <vector>
#include <string>

#include <chrono>

#include "util/geom.hpp"
#include "util/noise.hpp"
#include "objects.hpp"
#include "geom.hpp"
#include "noise.hpp"

enum class TileType { GRASS, WATER, SAND, STONE };

enum class Biome { DESERT, PLAINS, FOREST, TUNDRA };

struct Tile {
Tile(TileType type = TileType::GRASS, Biome biome = Biome::PLAINS);
class Tile {
public:
Tile();
~Tile();

TileType type;
Biome biome;
int sprite;
int colors;
TileType getType();
Biome getBiome();
bool isVisible();

FixedObject *fixedObject = nullptr;
LooseObject *looseObject = nullptr;
void setType(TileType type);
void setBiome(Biome biome);
void setVisible(bool visible);

private:
TileType type;
Biome biome;
bool visible;
};

class Chunk {
public:
Chunk();
~Chunk();

void update(float dt);
void generate(Noise const& noise);

Tile& getTile(int x, int y) const;
bool isLoaded();
bool isVisible();

static const int CHUNK_SIZE = 16;
private:
int x;
int y;
bool loaded{false};
bool visible{false};
Tile * * tiles;
};

struct WorldParams {
int width = 44000;
int height = 44000;
int chunkSize = 32;
int chunkRadius = 2;
unsigned seed = static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count());
int maxAltitude = 32;
Expand All @@ -43,7 +71,8 @@ class World {
public:
World(WorldParams params = {});

Tile tileAt(int x, int y);
Tile const& tileAt(int x, int y);
Chunk const& chunkAt(int x, int y);

IPoint getSpawn();

Expand All @@ -59,12 +88,10 @@ class World {

private:
void genInitial();
void genChunk(int chunkX, int chunkY);
TileType getTile(float e, Biome b);
Biome getBiome(float m, float t);

std::map<std::pair<int, int>, Tile> tiles;
std::map<std::pair<int, int>, bool> chunkVisited;
std::unordered_map<std::pair<int, int>, Chunk> chunks;

WorldParams worldParams;

Expand Down Expand Up @@ -95,4 +122,4 @@ class WorldBuilder {

private:
WorldParams params;
};
};
File renamed without changes.
12 changes: 12 additions & 0 deletions include/move.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef MOVE_H
#define MOVE_H

#include "position.h"
#include "world.h"

// move
void move_from(Point *, Direction);
void move_and_collide(Map * const, Point *, Direction);
Direction dir_from_ch(int, Direction);

#endif
20 changes: 20 additions & 0 deletions include/mymath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MYMATH_H
#define MYMATH_H

#include <stdint.h>

typedef struct {
float x;
float y;
} Vec2;

// math
float lerp(float a, float b, float t);
float smooth(float t);
float smoother(float t);
float normalize(float value, float min, float max);
float hash_posf(int x, int y);
size_t hash_pos(int x, int y);
float dot(Vec2 a, Vec2 b);

#endif
21 changes: 21 additions & 0 deletions include/noise.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef NOISE_H
#define NOISE_H

typedef struct {
float frequency;
float amplitude;
float lacunarity;
float persistence;
int octaves;
float (*noisefn)(float, float);
} FBMParams;

// noise
float value2d(float x, float y);
float perlin2d(float x, float y);
float simplex2d(float x, float y);
float fbm2d(float x, float y, FBMParams params);

extern FBMParams default_fbm;

#endif
2 changes: 1 addition & 1 deletion include/util/noise.hpp → include/noise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class Simplex : public Noise {
unsigned seed;

static int grads[12][3];
};
};
2 changes: 1 addition & 1 deletion include/model/objects.hpp → include/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ struct FixedObject {
struct LooseObject {
std::string name;
int quantity;
};
};
16 changes: 16 additions & 0 deletions include/position.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef POSITION_H
#define POSITION_H

typedef enum {
UP,
DOWN,
LEFT,
RIGHT
} Direction;

typedef struct {
int x;
int y;
} Point;

#endif
38 changes: 0 additions & 38 deletions include/view/curses.hpp

This file was deleted.

54 changes: 54 additions & 0 deletions include/world.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef WORLD_H
#define WORLD_H

#include <stdbool.h>

enum {
TILE_NONE,
TILE_GRASS,
TILE_SAND,
TILE_WATER,
TILE_STONE,
TILE_COUNT
};

enum {
OBJ_NONE,
OBJ_WALL,
OBJ_COUNT
};

typedef struct {
int glyph;
int color;
} TileType;

typedef struct {
int glyph;
int color;
bool solid;
} ObjectType;

typedef struct {
int type;
int object;
} Tile;

typedef struct {
int width;
int height;
Tile * * tiles;
} Map;

// map
Map * create_map(int, int);
void free_map(Map *);
void init_map(Map *);
void place_wall(Map *, Point);
void break_wall(Map *, Point);
bool is_solid(Map * const, Point);

extern TileType tile_types[TILE_COUNT];
extern ObjectType obj_types[OBJ_COUNT];

#endif
Loading

0 comments on commit 87e8bca

Please sign in to comment.