diff --git a/Makefile b/Makefile index 8a8d31b..f5ef482 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = gcc -OBJECTS = obj/main.o obj/game_state.o obj/in_game.o obj/main_menu.o obj/map.o obj/intro.o +OBJECTS = obj/main.o obj/game_state.o obj/in_game.o obj/main_menu.o obj/map.o obj/intro.o obj/game_over.o TARGET = bin/cyjam CFLAGS = -Wall -I./include -std=c99 LDFLAGS = -L./lib @@ -29,6 +29,9 @@ obj/main_menu.o: src/main_menu.c include/main_menu.h include/game_state.h obj/intro.o: src/intro.c include/intro.h include/intro_img.h include/game_state.h $(CC) -c -o $@ $< $(CFLAGS) +obj/game_over.o: src/game_over.c include/game_over.h include/game_state.h + $(CC) -c -o $@ $< $(CFLAGS) + obj/map.o: src/map.c include/map.h $(CC) -c -o $@ $< $(CFLAGS) diff --git a/include/constants.h b/include/constants.h index 101dbd3..9d469ea 100644 --- a/include/constants.h +++ b/include/constants.h @@ -6,7 +6,7 @@ #ifndef STATE_CONSTS_H #define STATE_CONSTS_H -static const int DEBUG = 1; +static const int DEBUG = 0; #define F_SEP "/" enum COLORS { diff --git a/include/game_over.h b/include/game_over.h new file mode 100644 index 0000000..7da303e --- /dev/null +++ b/include/game_over.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved. + * See the file LICENSE for more details. + */ + +#ifndef GAME_OVER_H +#define GAME_OVER_H + +#include "game_state.h" + +void initGOState(gs_t *); + +#endif diff --git a/maps/start.map b/maps/start.map index c47a355..56ee246 100644 --- a/maps/start.map +++ b/maps/start.map @@ -39,7 +39,7 @@ player = 27 15 %exit = X Y MAP_NAME MAP_X MAP_Y exit = 8 25 maps/start.map 0 0 exit = 9 25 maps/start.map 0 0 -exit = 10 24 maps/start.map 0 0 +exit = 10 24 END 0 0 exit = 10 25 maps/start.map 0 0 [DOORS] %door = X Y ID UNLOCKED diff --git a/src/game_over.c b/src/game_over.c new file mode 100644 index 0000000..cecd1b2 --- /dev/null +++ b/src/game_over.c @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved. + * See the file LICENSE for more details. + */ + +#include +#include +#include + +#include "constants.h" +#include "game_over.h" + +static const char * title = "TITLE PENDING"; +static const char * subtitle = "A game for the Cyberpunk Jam 2014"; +static const char * aWinnerIsYou = "You have completed the scenario!"; +static const char * thanks = "Thank you for playing."; +static const char * goInfo = "Press enter to return to the main menu."; + +static bool enter; + +void goInput(); +gsname_t goUpdate(); +void goRender(int, int); + +void initGOState(gs_t * gs){ + gs->name = GAME_OVER; + gs->input = &goInput; + gs->update = &goUpdate; + gs->render = &goRender; +} + +void goInput(){ + int key = 0; + + key = getch(); + + if(key != ERR){ + if(key == KEY_ENTER || key == '\n') enter = TRUE; + } +} + +gsname_t goUpdate(){ + if(enter){ + enter = FALSE; + return MENU; + } + + return GAME_OVER; +} + +void goRender(int w, int h){ + int sW; + + clear_screen(w, h); + + /* Print the title. */ + sW = strlen(title); + sW /= 2; + + attron(A_BOLD); + + move(1, (w / 2) - sW); + attron(COLOR_PAIR(SN_COLOR)); + printw(title); + + /* Print the subtitle. */ + sW = strlen(subtitle); + sW /= 2; + + move(2, (w / 2) - sW); + attron(COLOR_PAIR(SW_COLOR)); + printw(subtitle); + + attroff(A_BOLD); + + /* Print the game over message. */ + sW = strlen(aWinnerIsYou); + sW /= 2; + + move((h / 2) - 2, (w / 2) - sW); + attron(COLOR_PAIR(GR_COLOR)); + printw(aWinnerIsYou); + + sW = strlen(thanks); + sW /= 2; + + move((h / 2) - 1, (w / 2) - sW); + attron(COLOR_PAIR(GR_COLOR)); + printw(thanks); + + /* Print help. */ + sW = strlen(goInfo); + sW /= 2; + + move(h - 5, (w / 2) - sW); + attron(COLOR_PAIR(MN_COLOR)); + printw(goInfo); +} + diff --git a/src/game_state.c b/src/game_state.c index e952eae..9ddb253 100644 --- a/src/game_state.c +++ b/src/game_state.c @@ -10,11 +10,13 @@ #include "intro.h" #include "main_menu.h" #include "in_game.h" +#include "game_over.h" void initStateArray(gs_t ** s){ initIntroState(&((*s)[INTRO])); initMMState(&((*s)[MENU])); initInGameState(&((*s)[IN_GAME])); + initGOState(&((*s)[GAME_OVER])); } void clear_screen(int w, int h){ diff --git a/src/in_game.c b/src/in_game.c index 420bae4..59d1bc0 100644 --- a/src/in_game.c +++ b/src/in_game.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -140,8 +141,14 @@ gsname_t update(){ if(objs[i].x == iY && objs[i].y == iX){ player.x = objs[i].eX; player.y = objs[i].eY; - loadMap(objs[i].target); - return IN_GAME; + if(strcmp(objs[i].target, "END") != 0){ + loadMap(objs[i].target); + return IN_GAME; + }else{ + initObjects(); + loadMap("maps/start.map"); + return GAME_OVER; + } } } } @@ -519,7 +526,7 @@ void setPlayerStart(){ } void initObjects(){ - int i; + int i, j; for(i = 0; i < MAX_OBJECTS; ++i){ objs[i].type = NONE; @@ -531,9 +538,11 @@ void initObjects(){ objs[i].sY = 0; objs[i].id = 0; objs[i].dId = 0; - objs[i].name[0] = '\0'; - objs[i].target[0] = '\0'; - objs[i].dialog[0] = '\0'; + for(j = 0; j < MAX_STR; j++){ + objs[i].name[j] = '\0'; + objs[i].target[j] = '\0'; + objs[i].dialog[j] = '\0'; + } objs[i].unlocked = 0; } } diff --git a/src/main_menu.c b/src/main_menu.c index 224ada5..2434dee 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -10,14 +10,14 @@ #include "constants.h" #include "main_menu.h" -static char * title = "TITLE PENDING"; -static char * subtitle = "A game for the Cyberpunk Jam 2014"; -static char * opt1 = "New game"; -static char * opt2 = "Replay intro"; -static char * opt3 = "Quit"; -static char * creds = "Designed and programmed by Miky"; -static char * info = "Press enter to select an option. Scroll with the arrow keys."; -static char * info2 = "Press escape while in game to return to the main menu."; +static const char * title = "TITLE PENDING"; +static const char * subtitle = "A game for the Cyberpunk Jam 2014"; +static const char * opt1 = "New game"; +static const char * opt2 = "Replay intro"; +static const char * opt3 = "Quit"; +static const char * creds = "Designed and programmed by Miky"; +static const char * info = "Press enter to select an option. Scroll with the arrow keys."; +static const char * info2 = "Press escape while in game to return to the main menu."; static int selOpt = 0; static bool uK, dK, esc, enter; diff --git a/src/map.c b/src/map.c index 494b0f4..904242d 100644 --- a/src/map.c +++ b/src/map.c @@ -26,8 +26,6 @@ errcode_t readMapData(const char * file, map_cell_t *** map, int * w, int * h){ int rc, i, j; char *end; - fprintf(stderr, "\t%s.readMapData() : found a map.\n", __FILE__); - rc = getline(&buffer, &n, f); if(rc == -1){ free(buffer);