Maploading
This commit is contained in:
parent
73bf0d83e1
commit
a2dffd7cb9
8 changed files with 82 additions and 36 deletions
8
makefile
8
makefile
|
|
@ -2,9 +2,11 @@ CP=clang
|
|||
CFLAGS=$(shell cat compiler_flags.txt | tr '\n' ' ')
|
||||
FILES=$(wildcard src/*.cpp)
|
||||
|
||||
build/raylib-test-linux.x86_64 : $(FILES)
|
||||
mkdir -p build
|
||||
$(CP) $(FILES) $(CFLAGS) -o build/raylib-test-linux.x86_64
|
||||
.PHONY : clean cross-windows
|
||||
|
||||
build/linux/raylib-test-linux.x86_64 : $(FILES)
|
||||
mkdir -p build/linux
|
||||
$(CP) $(FILES) $(CFLAGS) -o build/linux/raylib-test-linux.x86_64
|
||||
|
||||
|
||||
clean :
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include "components.h"
|
||||
#include "world.h"
|
||||
#include "maploader.h"
|
||||
|
||||
|
|
@ -8,20 +7,20 @@ const int SCREEN_HEIGHT = 320;
|
|||
const int SCREEN_WIDTH = 320;
|
||||
|
||||
int main() {
|
||||
loadmap();
|
||||
return 0;
|
||||
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test game");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
world = create_world_with(1./10.);
|
||||
|
||||
world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}));
|
||||
loadmap(world);
|
||||
|
||||
world.setup();
|
||||
|
||||
while (WindowShouldClose() == false) {
|
||||
|
||||
if(IsKeyPressed(KEY_F1))
|
||||
world.debug = !world.debug;
|
||||
|
||||
world.process();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,47 @@
|
|||
#include "maploader.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "components.h"
|
||||
#include "world.h"
|
||||
|
||||
void loadmap() {
|
||||
std::ifstream input_stream;
|
||||
input_stream.open("assets/map");
|
||||
void loadmap(World& world) {
|
||||
std::ifstream in;
|
||||
in.open("assets/map");
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if(input_stream.is_open() == false)
|
||||
return;
|
||||
|
||||
std::cout << input_stream.getline()
|
||||
|
||||
input_stream.close();
|
||||
while(in.eof() == false)
|
||||
{
|
||||
char c;
|
||||
in.get(c);
|
||||
|
||||
switch (c) {
|
||||
case '#':
|
||||
{
|
||||
Wall* wall = new Wall;
|
||||
wall->position = {(float)x*16,(float)y*16};
|
||||
world.entities.push_back(wall);
|
||||
x++;
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
{
|
||||
Pacman* pacman = new Pacman;
|
||||
pacman->position = {(float)x*16,(float)y*16};
|
||||
world.entities.push_back(pacman);
|
||||
x++;
|
||||
}
|
||||
|
||||
break;
|
||||
case '\n':
|
||||
x = 0;
|
||||
y++;
|
||||
break;
|
||||
default:
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef MAPLOADER_H
|
||||
#define MAPLOADER_H
|
||||
|
||||
void loadmap();
|
||||
#include "world.h"
|
||||
|
||||
void loadmap(World& world);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -71,22 +71,5 @@ void Pacman::draw() const {
|
|||
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
||||
}
|
||||
|
||||
// Wall definitions
|
||||
|
||||
Wall::Wall() {
|
||||
this->texture = LoadTexture("assets/sprites/walls.png");
|
||||
}
|
||||
|
||||
Wall::~Wall() {
|
||||
UnloadTexture(this->texture);
|
||||
}
|
||||
|
||||
void Wall::ready() {
|
||||
// Set neigbors depending on state
|
||||
}
|
||||
|
||||
void Wall::draw() const {
|
||||
// Draw based on neighbors
|
||||
}
|
||||
|
||||
|
||||
19
src/wall.cpp
Normal file
19
src/wall.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "components.h"
|
||||
#include <raylib.h>
|
||||
|
||||
Wall::Wall() {
|
||||
this->texture = LoadTexture("assets/sprites/wall.png");
|
||||
}
|
||||
|
||||
Wall::~Wall() {
|
||||
UnloadTexture(this->texture);
|
||||
}
|
||||
|
||||
void Wall::ready() {
|
||||
// Set neigbors depending on state
|
||||
}
|
||||
|
||||
void Wall::draw() const {
|
||||
// Draw based on neighbors
|
||||
DrawTexture(this->texture, this->position.x, this->position.y, WHITE);
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ World::World(){
|
|||
this->entities = {};
|
||||
this->seconds_per_tick = 0;
|
||||
this->clock = 0;
|
||||
this->debug = false;
|
||||
}
|
||||
|
||||
World::~World(){
|
||||
|
|
@ -21,6 +22,11 @@ void World::setup(){
|
|||
void World::process(){
|
||||
this->clock += GetFrameTime();
|
||||
|
||||
if(IsKeyPressed(KEY_F2))
|
||||
this->seconds_per_tick-=0.025;
|
||||
if(IsKeyPressed(KEY_F3))
|
||||
this->seconds_per_tick+=0.025;
|
||||
|
||||
this->update_grid();
|
||||
|
||||
for(int i = 0; i < this->entities.size(); i++) {
|
||||
|
|
@ -39,6 +45,11 @@ void World::draw() const {
|
|||
for(int i = 0; i < this->entities.size(); i++) {
|
||||
this->entities[i]->draw();
|
||||
}
|
||||
if (this->debug == false)
|
||||
return;
|
||||
|
||||
DrawText(TextFormat("entities: %i",this->entities.size()), 0, 0, 14, WHITE);
|
||||
DrawText(TextFormat("seconds_per_tick: %f",this->seconds_per_tick), 0, 16, 14, WHITE);
|
||||
}
|
||||
|
||||
int indexify_position(Vector2 vector){
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class World {
|
|||
public:
|
||||
World();
|
||||
~World();
|
||||
|
||||
bool debug;
|
||||
std::vector<Entity*> entities; /// Main subjects of game world.
|
||||
Entity* grid[GRID_CAPACITY]; /// Grid representation
|
||||
float seconds_per_tick; /// Internal clock speed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue