Engine ready.

This commit is contained in:
2014-03-08 21:51:12 -04:30
parent fa9e0e6760
commit 8f09cabf66
9 changed files with 143 additions and 19 deletions

View File

@@ -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)

View File

@@ -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 {

13
include/game_over.h Normal file
View File

@@ -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

View File

@@ -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

99
src/game_over.c Normal file
View File

@@ -0,0 +1,99 @@
/**
* Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved.
* See the file LICENSE for more details.
*/
#include <stdio.h>
#include <string.h>
#include <ncursesw/ncurses.h>
#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);
}

View File

@@ -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){

View File

@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ncursesw/ncurses.h>
#include <fov.h>
@@ -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;
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;
}
}

View File

@@ -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;

View File

@@ -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);