Compare commits
2 commits
76284d80b9
...
366bdf7d20
| Author | SHA1 | Date | |
|---|---|---|---|
| 366bdf7d20 | |||
| 0432d6932c |
12 changed files with 103 additions and 17 deletions
20
assets/map
Normal file
20
assets/map
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
######### #########
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# P #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
|
||||||
|
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
######### #########
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 760 B |
BIN
assets/sprites/wall.png
Normal file
BIN
assets/sprites/wall.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 134 B |
|
|
@ -2,4 +2,3 @@
|
||||||
-lraylib
|
-lraylib
|
||||||
-lstdc++
|
-lstdc++
|
||||||
-lm
|
-lm
|
||||||
-v
|
|
||||||
|
|
|
||||||
5
makefile
5
makefile
|
|
@ -1,9 +1,10 @@
|
||||||
CFLAGS=$(shell cat compiler_flags.txt)
|
CP=clang
|
||||||
|
CFLAGS=$(shell cat compiler_flags.txt | tr '\n' ' ')
|
||||||
FILES=$(wildcard src/*.cpp)
|
FILES=$(wildcard src/*.cpp)
|
||||||
|
|
||||||
build/raylib-test-linux.x86_64 : $(FILES)
|
build/raylib-test-linux.x86_64 : $(FILES)
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
clang $(FILES) $(CFLAGS) -o build/raylib-test-linux.x86_64
|
$(CP) $(FILES) $(CFLAGS) -o build/raylib-test-linux.x86_64
|
||||||
|
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
// Pacman definitions
|
// Pacman definitions
|
||||||
|
|
||||||
|
|
||||||
Rectangle Pacman::getTextureRect(){
|
Rectangle Pacman::getTextureRect() const{
|
||||||
Rectangle result;
|
Rectangle result;
|
||||||
result.x = 0;
|
result.x = 16*frame;
|
||||||
result.y = facing*16;
|
result.y = facing*16;
|
||||||
result.height = 16;
|
result.height = 16;
|
||||||
result.width = 16;
|
result.width = 16;
|
||||||
|
|
@ -17,6 +17,7 @@ Pacman::Pacman() {
|
||||||
this->texture = LoadTexture("assets/sprites/pacman.png");
|
this->texture = LoadTexture("assets/sprites/pacman.png");
|
||||||
this->facing = 0;
|
this->facing = 0;
|
||||||
this->position = {0.,0.};
|
this->position = {0.,0.};
|
||||||
|
this->frame = 0;
|
||||||
}
|
}
|
||||||
Pacman::Pacman(Vector2 position) {
|
Pacman::Pacman(Vector2 position) {
|
||||||
this->texture = LoadTexture("assets/sprites/pacman.png");
|
this->texture = LoadTexture("assets/sprites/pacman.png");
|
||||||
|
|
@ -53,7 +54,19 @@ void Pacman::tick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pacman::draw() {
|
void Pacman::process() {
|
||||||
|
this->time += GetFrameTime();
|
||||||
|
if (this->time >= 1.0/this->fps){
|
||||||
|
this->time = 0.;
|
||||||
|
this->animation_tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pacman::animation_tick() {
|
||||||
|
this->frame = (this->frame+1)%frame_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pacman::draw() const {
|
||||||
// Drawing
|
// Drawing
|
||||||
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +85,7 @@ void Wall::ready() {
|
||||||
// Set neigbors depending on state
|
// Set neigbors depending on state
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wall::draw() {
|
void Wall::draw() const {
|
||||||
// Draw based on neighbors
|
// Draw based on neighbors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,34 @@ class Entity{
|
||||||
public:
|
public:
|
||||||
virtual ~Entity(){}
|
virtual ~Entity(){}
|
||||||
|
|
||||||
|
Vector2 position;
|
||||||
|
|
||||||
virtual void ready() {}
|
virtual void ready() {}
|
||||||
virtual void process() {}
|
virtual void process() {}
|
||||||
virtual void draw() {}
|
virtual void draw() const {}
|
||||||
virtual void tick() {}
|
virtual void tick() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Pacman : public Entity{
|
class Pacman : public Entity{
|
||||||
const int speed = 16;
|
const int speed = 16;
|
||||||
|
const int frame_count = 7;
|
||||||
|
const int fps = 24;
|
||||||
private:
|
private:
|
||||||
Texture2D texture;
|
Texture2D texture;
|
||||||
Vector2 position;
|
|
||||||
int facing;
|
int facing;
|
||||||
|
Rectangle getTextureRect() const;
|
||||||
Rectangle getTextureRect();
|
|
||||||
public:
|
public:
|
||||||
|
unsigned char frame;
|
||||||
|
float time;
|
||||||
|
|
||||||
Pacman();
|
Pacman();
|
||||||
Pacman(Vector2 position);
|
Pacman(Vector2 position);
|
||||||
~Pacman();
|
~Pacman();
|
||||||
void tick() override;
|
void tick() override;
|
||||||
void draw() override;
|
void process() override;
|
||||||
|
void animation_tick();
|
||||||
|
void draw() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Wall : public Entity {
|
class Wall : public Entity {
|
||||||
|
|
@ -38,7 +45,7 @@ class Wall : public Entity {
|
||||||
Wall();
|
Wall();
|
||||||
~Wall();
|
~Wall();
|
||||||
void ready() override;
|
void ready() override;
|
||||||
void draw() override;
|
void draw() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ int main() {
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
world = create_world_with(.25);
|
world = create_world_with(1./10.);
|
||||||
|
|
||||||
world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}));
|
world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}));
|
||||||
|
|
||||||
|
|
@ -35,3 +35,7 @@ int main() {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_map(const char * path){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
8
src/maploader.cpp
Normal file
8
src/maploader.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "maploader.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
void loadmap() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
6
src/maploader.h
Normal file
6
src/maploader.h
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef MAPLOADER_H
|
||||||
|
#define MAPLOADER_H
|
||||||
|
|
||||||
|
void loadmap();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -21,6 +21,8 @@ void World::setup(){
|
||||||
void World::process(){
|
void World::process(){
|
||||||
this->clock += GetFrameTime();
|
this->clock += GetFrameTime();
|
||||||
|
|
||||||
|
this->update_grid();
|
||||||
|
|
||||||
for(int i = 0; i < this->entities.size(); i++) {
|
for(int i = 0; i < this->entities.size(); i++) {
|
||||||
this->entities[i]->process();
|
this->entities[i]->process();
|
||||||
if (this->clock>=this->seconds_per_tick) {
|
if (this->clock>=this->seconds_per_tick) {
|
||||||
|
|
@ -33,12 +35,31 @@ void World::process(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::draw() {
|
void World::draw() const {
|
||||||
for(int i = 0; i < this->entities.size(); i++) {
|
for(int i = 0; i < this->entities.size(); i++) {
|
||||||
this->entities[i]->draw();
|
this->entities[i]->draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int indexify_position(Vector2 vector){
|
||||||
|
return (int)(vector.x / 16.0) + GRID_COLUMNS * (int)(vector.y / 16.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::update_grid() {
|
||||||
|
for(int i = 0; i < GRID_CAPACITY; i++)
|
||||||
|
this->grid[i] = nullptr;
|
||||||
|
|
||||||
|
for(int i = 0; i < this->entities.size(); i++)
|
||||||
|
{
|
||||||
|
int indexified_position = indexify_position(this->entities[i]->position);
|
||||||
|
if (indexified_position < 0 || indexified_position >= GRID_CAPACITY)
|
||||||
|
continue;
|
||||||
|
grid[indexified_position] = this->entities[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
World create_world_with(float seconds_per_tick){
|
World create_world_with(float seconds_per_tick){
|
||||||
World result = World();
|
World result = World();
|
||||||
|
|
||||||
|
|
|
||||||
11
src/world.h
11
src/world.h
|
|
@ -4,6 +4,10 @@
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
const int GRID_ROWS = 20;
|
||||||
|
const int GRID_COLUMNS = 20;
|
||||||
|
const int GRID_CAPACITY = GRID_COLUMNS*GRID_ROWS;
|
||||||
|
|
||||||
/// Class that holds information about game world
|
/// Class that holds information about game world
|
||||||
class World {
|
class World {
|
||||||
public:
|
public:
|
||||||
|
|
@ -11,7 +15,8 @@ class World {
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
std::vector<Entity*> entities; /// Main subjects of game world.
|
std::vector<Entity*> entities; /// Main subjects of game world.
|
||||||
float seconds_per_tick; /// Internal clock speed
|
Entity* grid[GRID_CAPACITY]; /// Grid representation
|
||||||
|
float seconds_per_tick; /// Internal clock speed
|
||||||
|
|
||||||
void setup(); /// Sets up game world.
|
void setup(); /// Sets up game world.
|
||||||
/// Should be called once when entites are set.
|
/// Should be called once when entites are set.
|
||||||
|
|
@ -19,14 +24,16 @@ class World {
|
||||||
void process(); /// Should be called every frame. Calls
|
void process(); /// Should be called every frame. Calls
|
||||||
/// process() on every entity
|
/// process() on every entity
|
||||||
|
|
||||||
void draw(); /// Should be called at the end of frame.
|
void draw() const; /// Should be called at the end of frame.
|
||||||
/// Calls draw() on every entity
|
/// Calls draw() on every entity
|
||||||
private:
|
private:
|
||||||
float clock;
|
float clock;
|
||||||
|
void update_grid();
|
||||||
};
|
};
|
||||||
|
|
||||||
static World world; /// World singleton
|
static World world; /// World singleton
|
||||||
|
|
||||||
World create_world_with(float seconds_per_tick);
|
World create_world_with(float seconds_per_tick);
|
||||||
|
int indexify_position(Vector2 vector);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue