refactor config variables to separate file

This commit is contained in:
Ole Morud
2022-06-08 17:16:38 +02:00
parent b8907c3961
commit c425e2b5b7
2 changed files with 20 additions and 25 deletions

14
config.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#define ON 'x'
#define OFF '.'
#define HEIGHT 40
#define WIDTH 40
#define FRAMERATE 60
#define GRAVITY 0.001f
#define LINENUMBERS 0
#endif

View File

@@ -2,10 +2,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "config.h"
#define uint unsigned int
#define ON 'x'
#define OFF '.'
typedef struct Canvas {
int x;
@@ -22,27 +21,6 @@ void line(Canvas* c, uint start_x, uint start_y, uint end_x, uint end_y);
void dot(Canvas* c, const uint x, const uint y);
/*
* main
*/
//int main(){
// char *data = malloc(40*40);
// Canvas c = {40, 40, data};
// memset(c.data, OFF, c.x * c.y);
//
// //line(&c, 1, 1, 8, 8);
// //line(&c, 8, 8, 1, 1);
// //line(&c, 0, 5, 8, 8);
// line(&c, 8, 8, 35, 39);
//
//
// render(&c);
//
// return 0;
//}
/*
* Renders canvas* c on screen and adds line numbers on left and bottom
*/
@@ -51,7 +29,9 @@ void render(Canvas* c){
putchar('\n');
for(int i=0; i < c->y; i++){
#if LINENUMBERS
printf("%2i ", i); //horizontal line numbers
#endif
for(int j=0; j < c->x; j++){
putchar(c->data[i*(c->x)+j]);
@@ -60,11 +40,12 @@ void render(Canvas* c){
putchar('\n');
}
#if LINENUMBERS
// vertical line numbers
printf(" ");
for(int i=0; i<(c->x); i+=2){
printf("%2i ", i);
printf(" %2i", i);
}
#endif
}