window scaling
This commit is contained in:
parent
73eedda429
commit
ad944ba385
4 changed files with 51 additions and 22 deletions
15
src/main.cpp
15
src/main.cpp
|
|
@ -2,20 +2,19 @@
|
|||
#include <raymath.h>
|
||||
#include "world.h"
|
||||
|
||||
const int SCREEN_HEIGHT = 320;
|
||||
const int SCREEN_WIDTH = 320;
|
||||
|
||||
int main() {
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test game");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
int main() {
|
||||
create_world_with(1./10.);
|
||||
|
||||
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");
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
world.setup();
|
||||
|
||||
while (WindowShouldClose() == false) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "components.h"
|
||||
#include "world.h"
|
||||
|
||||
|
|
@ -10,19 +9,10 @@ void load_world(World& world,const char* 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;
|
||||
in.get(c);
|
||||
|
||||
switch (c) {
|
||||
|
||||
|
|
@ -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){
|
||||
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 CELL_SIZE = 16;
|
||||
|
||||
struct Vector2i{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
/// Class that holds information about game world
|
||||
class World {
|
||||
public:
|
||||
|
|
@ -32,6 +37,7 @@ class World {
|
|||
|
||||
void draw() const; /// Should be called at the end of frame.
|
||||
/// Calls draw() on every entity
|
||||
void set_size(Vector2i);
|
||||
private:
|
||||
float clock;
|
||||
void update_grid();
|
||||
|
|
@ -40,6 +46,7 @@ class World {
|
|||
void create_world_with(float seconds_per_tick);
|
||||
World& get_world(); // Thanks, 2ndbeam, helps a lot
|
||||
int indexify_position(Vector2 vector);
|
||||
Vector2i get_map_size(const char* path);
|
||||
void load_world(World& world, const char* path);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue