window scaling
This commit is contained in:
parent
73eedda429
commit
ad944ba385
4 changed files with 51 additions and 22 deletions
13
src/main.cpp
13
src/main.cpp
|
|
@ -2,20 +2,19 @@
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
const int SCREEN_HEIGHT = 320;
|
|
||||||
const int SCREEN_WIDTH = 320;
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test game");
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
create_world_with(1./10.);
|
create_world_with(1./10.);
|
||||||
|
|
||||||
World& world = get_world();
|
World& world = get_world();
|
||||||
|
Vector2i window_size = get_map_size("assets/map");
|
||||||
|
|
||||||
|
InitWindow(window_size.x, window_size.y, "Zoomba");
|
||||||
|
|
||||||
|
world.set_size(window_size);
|
||||||
load_world(world,"assets/map");
|
load_world(world,"assets/map");
|
||||||
|
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
world.setup();
|
world.setup();
|
||||||
|
|
||||||
while (WindowShouldClose() == false) {
|
while (WindowShouldClose() == false) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
|
|
@ -10,20 +9,11 @@ void load_world(World& world,const char* path) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
int max_x = 0;
|
|
||||||
int max_y = 0;
|
|
||||||
|
|
||||||
while(in.eof() == false)
|
while(in.eof() == false)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
in.get(c);
|
in.get(c);
|
||||||
|
|
||||||
|
|
||||||
if (max_x < x)
|
|
||||||
max_x = x;
|
|
||||||
if (max_y < y)
|
|
||||||
max_y = y;
|
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
|
|
@ -57,7 +47,37 @@ void load_world(World& world,const char* path) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
world.height = CELL_SIZE * (max_y-1);
|
|
||||||
world.width = CELL_SIZE * (max_x-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2i get_map_size(const char* path){
|
||||||
|
std::ifstream in;
|
||||||
|
in.open(path);
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
int max_x = 0;
|
||||||
|
int max_y = 0;
|
||||||
|
|
||||||
|
while(in.eof() == false)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
in.get(c);
|
||||||
|
|
||||||
|
|
||||||
|
if (max_x < x)
|
||||||
|
max_x = x;
|
||||||
|
if (max_y < y)
|
||||||
|
max_y = y;
|
||||||
|
|
||||||
|
if(c == '\n'){
|
||||||
|
x = 0;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {max_x * CELL_SIZE,max_y * CELL_SIZE};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,10 @@ void World::update_grid() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::set_size(Vector2i size){
|
||||||
|
this->width = size.x;
|
||||||
|
this->height = size.y;
|
||||||
|
}
|
||||||
|
|
||||||
void create_world_with(float seconds_per_tick){
|
void create_world_with(float seconds_per_tick){
|
||||||
get_world().seconds_per_tick = seconds_per_tick;
|
get_world().seconds_per_tick = seconds_per_tick;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ const int GRID_COLUMNS = 20;
|
||||||
const int GRID_CAPACITY = GRID_COLUMNS*GRID_ROWS;
|
const int GRID_CAPACITY = GRID_COLUMNS*GRID_ROWS;
|
||||||
const int CELL_SIZE = 16;
|
const int CELL_SIZE = 16;
|
||||||
|
|
||||||
|
struct Vector2i{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
/// Class that holds information about game world
|
/// Class that holds information about game world
|
||||||
class World {
|
class World {
|
||||||
public:
|
public:
|
||||||
|
|
@ -32,6 +37,7 @@ class World {
|
||||||
|
|
||||||
void draw() const; /// 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
|
||||||
|
void set_size(Vector2i);
|
||||||
private:
|
private:
|
||||||
float clock;
|
float clock;
|
||||||
void update_grid();
|
void update_grid();
|
||||||
|
|
@ -40,6 +46,7 @@ class World {
|
||||||
void create_world_with(float seconds_per_tick);
|
void create_world_with(float seconds_per_tick);
|
||||||
World& get_world(); // Thanks, 2ndbeam, helps a lot
|
World& get_world(); // Thanks, 2ndbeam, helps a lot
|
||||||
int indexify_position(Vector2 vector);
|
int indexify_position(Vector2 vector);
|
||||||
|
Vector2i get_map_size(const char* path);
|
||||||
void load_world(World& world, const char* path);
|
void load_world(World& world, const char* path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue