refactor config variables to separate file
This commit is contained in:
14
config.h
Normal file
14
config.h
Normal 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
|
||||||
29
graphics.c
29
graphics.c
@@ -2,10 +2,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define uint unsigned int
|
#define uint unsigned int
|
||||||
#define ON 'x'
|
|
||||||
#define OFF '.'
|
|
||||||
|
|
||||||
typedef struct Canvas {
|
typedef struct Canvas {
|
||||||
int x;
|
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);
|
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
|
* Renders canvas* c on screen and adds line numbers on left and bottom
|
||||||
*/
|
*/
|
||||||
@@ -51,7 +29,9 @@ void render(Canvas* c){
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
for(int i=0; i < c->y; i++){
|
for(int i=0; i < c->y; i++){
|
||||||
|
#if LINENUMBERS
|
||||||
printf("%2i ", i); //horizontal line numbers
|
printf("%2i ", i); //horizontal line numbers
|
||||||
|
#endif
|
||||||
|
|
||||||
for(int j=0; j < c->x; j++){
|
for(int j=0; j < c->x; j++){
|
||||||
putchar(c->data[i*(c->x)+j]);
|
putchar(c->data[i*(c->x)+j]);
|
||||||
@@ -60,11 +40,12 @@ void render(Canvas* c){
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LINENUMBERS
|
||||||
// vertical line numbers
|
// vertical line numbers
|
||||||
printf(" ");
|
|
||||||
for(int i=0; i<(c->x); i+=2){
|
for(int i=0; i<(c->x); i+=2){
|
||||||
printf(" %2i", i);
|
printf(" %2i", i);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user