~ecs/tbrace

fa002647850475189531c4851325836689eee074 — Eyal Sawady 1 year, 11 days ago 130cf43
Style
4 files changed, 36 insertions(+), 13 deletions(-)

M helpers.c
M main.c
M state.c
M update.c
M helpers.c => helpers.c +3 -1
@@ 1,6 1,8 @@
#include <stdio.h>

int fgetint(char *prompt, FILE* file) {
int
fgetint(char *prompt, FILE* file)
{
	int n;
	printf("%s", prompt);
	fflush(stdout);

M main.c => main.c +4 -1
@@ 1,8 1,11 @@
#include <stdio.h>

#include "state.h"
#include "update.h"

int main(int argc, char **argv) {
int
main(int argc, char **argv)
{
	const char *filename = "./tracks/test";
	FILE *track;
	struct state *state;

M state.c => state.c +11 -4
@@ 1,10 1,13 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "state.h"

#include "helpers.h"
#include "state.h"

struct state* load_state(FILE *file) {
struct state *
load_state(FILE *file)
{
	int num_cars = fgetint("", file);
	int track_x = fgetint("", file);
	int track_y = fgetint("", file);


@@ 59,7 62,9 @@ struct state* load_state(FILE *file) {
	return state;
}

void destroy_state(struct state* state) {
void
destroy_state(struct state* state)
{
	int i;
	free(state->cars);
	for (i = 0; i < state->track_y; i++) {


@@ 69,7 74,9 @@ void destroy_state(struct state* state) {
	free(state);
}

void print_track(struct state state) {
void
print_track(struct state state)
{
	int i;
	for (i = 0; i < state.track_y; i++) {
		int j;

M update.c => update.c +18 -7
@@ 1,14 1,19 @@
#include <stdio.h>
#include <stdbool.h>
#include "state.h"
#include <stdio.h>

#include "config.h"
#include "state.h"

static void ai_update(struct state state, struct car *car) {
static void
ai_update(struct state state, struct car *car)
{
	/* TODO: implement this */
	(void)state, (void)car; /* unused */
}

static bool player_update(struct state state) {
static bool
player_update(struct state state)
{
	while (1) {
		struct car *player = &state.cars[0];
		char action;


@@ 56,7 61,9 @@ static bool player_update(struct state state) {
	}
}

static bool should_stop(struct state state, struct car *car) {
static bool
should_stop(struct state state, struct car *car)
{
	int tile = state.track[car->y][car->x];
	int delta_sign = 0;



@@ 93,7 100,9 @@ static bool should_stop(struct state state, struct car *car) {
	return false;
}

static void physics_update(struct state state) {
static void
physics_update(struct state state)
{
	unsigned i;
	for (i = 0; i < state.num_cars; i++) {
		struct car *current = &state.cars[i];


@@ 124,7 133,9 @@ static void physics_update(struct state state) {
	}
}

bool tick(struct state state) {
bool
tick(struct state state)
{
	unsigned i;
	for (i = 1; i < state.num_cars; i++) {
		ai_update(state, &state.cars[i]);