summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2018-03-23 21:01:28 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2018-03-23 21:01:28 -0400
commitacb5114c79a9bc157602d75c6ee76a898980117e (patch)
tree912d33855c69d09d379e692bd6313c7692b33e11 /src
parentf4456093b25812e3e890d29c0734f87bfd0d4df2 (diff)
Added properties.
Diffstat (limited to 'src')
-rw-r--r--src/Qualum.cpp4
-rw-r--r--src/Qualum.h2
-rw-r--r--src/Rendering.cpp21
-rw-r--r--src/Rendering.h8
-rw-r--r--src/main.cpp39
5 files changed, 65 insertions, 9 deletions
diff --git a/src/Qualum.cpp b/src/Qualum.cpp
index 02327e8..3fbe47a 100644
--- a/src/Qualum.cpp
+++ b/src/Qualum.cpp
@@ -5,14 +5,16 @@
#include <vector>
#include <iostream>
-int Qualum::locations[Rendering::GRID_HEIGHT][Rendering::GRID_WIDTH];
+int** Qualum::locations;
std::vector<Qualum*> Qualum::qualums;
int Qualum::iterations = 0;
void Qualum::initialize()
{
+ locations = (int**) malloc(Rendering::GRID_HEIGHT*sizeof(int*));
for (int i = 0; i < Rendering::GRID_HEIGHT; i++)
{
+ locations[i] = (int*) malloc(Rendering::GRID_WIDTH*sizeof(int));
for (int j = 0; j < Rendering::GRID_WIDTH; j++)
{
locations[i][j] = -1;
diff --git a/src/Qualum.h b/src/Qualum.h
index 49a92b2..d88a287 100644
--- a/src/Qualum.h
+++ b/src/Qualum.h
@@ -19,7 +19,7 @@ public:
static void initialize();
static int iterations;
private:
- static int locations[Rendering::GRID_HEIGHT][Rendering::GRID_WIDTH];
+ static int** locations;
static void two_perpendiculars(int speedx, int speedy, int* speedx1, int* speedy1, int* speedx2, int* speedy2);
static void combine_speeds(int speedx1, int speedy1, int speedx2, int speedy2, int* speedx, int* speedy);
void collide_with(Qualum* q);
diff --git a/src/Rendering.cpp b/src/Rendering.cpp
index 542c679..e5209cc 100644
--- a/src/Rendering.cpp
+++ b/src/Rendering.cpp
@@ -1,5 +1,26 @@
#include "Rendering.h"
int Rendering::RENDER_SCALE = 3;
+int Rendering::GRID_WIDTH = 400;
+int Rendering::GRID_HEIGHT = 300;
int Rendering::WIDTH = GRID_WIDTH * RENDER_SCALE;
int Rendering::HEIGHT = GRID_HEIGHT * RENDER_SCALE;
+
+void Rendering::set_grid_width(int new_value)
+{
+ GRID_WIDTH = new_value;
+ WIDTH = GRID_WIDTH * RENDER_SCALE;
+}
+
+void Rendering::set_grid_height(int new_value)
+{
+ GRID_HEIGHT = new_value;
+ HEIGHT = GRID_HEIGHT * RENDER_SCALE;
+}
+
+void Rendering::set_render_scale(int new_value)
+{
+ RENDER_SCALE = new_value;
+ WIDTH = GRID_WIDTH * RENDER_SCALE;
+ HEIGHT = GRID_HEIGHT * RENDER_SCALE;
+} \ No newline at end of file
diff --git a/src/Rendering.h b/src/Rendering.h
index fcc147b..2b07fc9 100644
--- a/src/Rendering.h
+++ b/src/Rendering.h
@@ -4,12 +4,14 @@
class Rendering {
public:
static int RENDER_SCALE;
- static const int GRID_WIDTH = 400;
- static const int GRID_HEIGHT = 300;
+ static int GRID_WIDTH;
+ static int GRID_HEIGHT;
static int WIDTH;
static int HEIGHT;
+ static void set_grid_width(int new_value);
+ static void set_grid_height(int new_value);
+ static void set_render_scale(int new_value);
private:
-
};
#endif /* RENDERING_H */
diff --git a/src/main.cpp b/src/main.cpp
index 6b217f1..c95cf87 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,7 +14,7 @@ const char SLASH = '/';
SDL_Window* window;
-float TIME_SCALE = 4.0f;
+double TIME_SCALE = 4.0;
void quit()
{
@@ -53,6 +53,30 @@ char* getfilename(char* path)
return filename;
}
+void str_tolower(char* str)
+{
+ int i;
+ for (i = 0; str[i]; i++)
+ str[i] = tolower(str[i]);
+
+}
+
+void set_property(const char* property, const char* value)
+{
+ int int_value;
+ double double_value;
+ if (!strcmp(property, "width") && (int_value = atoi(value)))
+ Rendering::set_grid_width(int_value);
+ else if (!strcmp(property, "height") && (int_value = atoi(value)))
+ Rendering::set_grid_height(int_value);
+ else if (!strcmp(property, "scale") && (int_value = atoi(value)))
+ Rendering::set_render_scale(int_value);
+ else if (!strcmp(property, "speed"))
+ {
+ TIME_SCALE = double_value;
+ }
+}
+
void read_file(char* directory, char* filename, int x, int y, int speedx, int speedy)
{
// Create the qualums from the given file
@@ -71,13 +95,18 @@ void read_file(char* directory, char* filename, int x, int y, int speedx, int sp
int xrel, yrel, speedxrel, speedyrel; // Read input file
char* color_str = (char*) malloc(4096);
+ char* property = (char*) malloc(4096);
+ char* value = (char*) malloc(4096);
while (fgets(buffer, 4096, input_file))
{
buffer += strspn(buffer, " \t"); // Remove whitespace at start
if (buffer[0] == '%') // Other data (width, height, etc.)
{
-
+ buffer++;
+ sscanf(buffer, "%s %s", property, value);
+ str_tolower(property);
+ set_property(property, value);
continue;
}
@@ -109,7 +138,9 @@ int main(int argc, char** argv)
return 1;
}
+ read_file(getdirname(argv[1]), getfilename(argv[1]), 0, 0, 0, 0);
Qualum::initialize();
+
window = SDL_CreateWindow("Qualums", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, Rendering::WIDTH, Rendering::HEIGHT,
SDL_WINDOW_SHOWN);
@@ -118,7 +149,7 @@ int main(int argc, char** argv)
SDL_Event event;
bool will_quit = false;
- read_file(getdirname(argv[1]), getfilename(argv[1]), 0, 0, 0, 0);
+
int i = 0, last_printed = -1;
while (!will_quit)
@@ -144,7 +175,7 @@ int main(int argc, char** argv)
case SDL_KEYDOWN:
if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9)
{
- TIME_SCALE = (float)(event.key.keysym.sym - SDLK_0);
+ TIME_SCALE = (double)(event.key.keysym.sym - SDLK_0);
break;
}
switch (event.key.keysym.sym)