Intro ready.
This commit is contained in:
@@ -3,11 +3,28 @@
|
||||
* See the file LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include <ncursesw/ncurses.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "game_state.h"
|
||||
#include "intro.h"
|
||||
#include "main_menu.h"
|
||||
#include "in_game.h"
|
||||
|
||||
void initStateArray(gs_t ** s){
|
||||
initMMState(&((*s)[MENU]));
|
||||
initInGameState(&((*s)[IN_GAME]));
|
||||
initIntroState(&((*s)[INTRO]));
|
||||
initMMState(&((*s)[MENU]));
|
||||
initInGameState(&((*s)[IN_GAME]));
|
||||
}
|
||||
|
||||
void clear_screen(int w, int h){
|
||||
int i, j;
|
||||
move(0,0);
|
||||
attron(COLOR_PAIR(BSC_COLOR));
|
||||
for(i = 0; i < w; i++){
|
||||
for(j = 0; j < h; j++){
|
||||
move(j, i);
|
||||
printw(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ bool canMoveTo(int, int);
|
||||
void initInGameState( gs_t * gs) {
|
||||
int i, j;
|
||||
|
||||
uK = dK = lK = rK = esc = FALSE;
|
||||
uK = dK = lK = rK = esc = FALSE;
|
||||
|
||||
gs->name = IN_GAME;
|
||||
gs->input = &input;
|
||||
@@ -105,7 +105,7 @@ void input(){
|
||||
if(key == KEY_DOWN) dK = TRUE;
|
||||
if(key == KEY_LEFT) lK = TRUE;
|
||||
if(key == KEY_RIGHT) rK = TRUE;
|
||||
if(key == 27) esc = TRUE;
|
||||
if(key == 27) esc = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ gsname_t update(){
|
||||
|
||||
if(rK) nX = (iX + 1) % mW;
|
||||
|
||||
if(esc){
|
||||
/* Reset the game and go to the main menu. */
|
||||
esc = FALSE;
|
||||
initObjects();
|
||||
loadMap("maps/start.map");
|
||||
return MENU;
|
||||
}
|
||||
if(esc){
|
||||
/* Reset the game and go to the main menu. */
|
||||
esc = FALSE;
|
||||
initObjects();
|
||||
loadMap("maps/start.map");
|
||||
return MENU;
|
||||
}
|
||||
|
||||
/* Find if the player is standing on an exit, then load the next map. */
|
||||
for(i = 0; i < nO; i++){
|
||||
@@ -146,7 +146,7 @@ gsname_t update(){
|
||||
}
|
||||
}
|
||||
|
||||
/* If the player is standing on a key, pick it up. */
|
||||
/* If the player is standing on a key, pick it up. */
|
||||
for(i = 0; i < nO; i++){
|
||||
if(objs[i].type == KEY){
|
||||
if(objs[i].x == iY && objs[i].y == iX){
|
||||
@@ -183,7 +183,7 @@ gsname_t update(){
|
||||
}
|
||||
}
|
||||
|
||||
/* If the player bumps into a door, open it if the key is available. */
|
||||
/* If the player bumps into a door, open it if the key is available. */
|
||||
for(i = 0; i < nO; i++){
|
||||
if(objs[i].type == DOOR){
|
||||
if(objs[i].x == nY && objs[i].y == nX){
|
||||
@@ -212,7 +212,7 @@ gsname_t update(){
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the message buffer after a timeout. */
|
||||
/* Clear the message buffer after a timeout. */
|
||||
if(newMsg){
|
||||
msgNow = clock();
|
||||
delta = msgNow - msgThen;
|
||||
@@ -264,7 +264,7 @@ void render(int w, int h){
|
||||
w_mov = TRUE;
|
||||
}
|
||||
|
||||
pi = (((w - 1) - 1) / 2) + 1;
|
||||
pi = (((w - 2) - 1) / 2) + 1;
|
||||
pj = (h - 3) / 2 + 1;
|
||||
|
||||
ioff = (w - 28 - 27) / 2;
|
||||
|
||||
89
src/intro.c
Normal file
89
src/intro.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved.
|
||||
* See the file LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "intro.h"
|
||||
#include "intro_img.h"
|
||||
|
||||
void inInput();
|
||||
gsname_t inUpdate();
|
||||
void inRender(int, int);
|
||||
|
||||
static bool anyKey;
|
||||
static clock_t then = 0, nThen = 0;
|
||||
static int mRows = 0, mH = 0;
|
||||
|
||||
void initIntroState(gs_t * gs){
|
||||
gs->name = INTRO;
|
||||
gs->input = &inInput;
|
||||
gs->update = &inUpdate;
|
||||
gs->render = &inRender;
|
||||
}
|
||||
|
||||
void inInput(){
|
||||
int key = 0;
|
||||
|
||||
key = getch();
|
||||
|
||||
if(key != ERR && key != KEY_RESIZE){
|
||||
anyKey = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gsname_t inUpdate(){
|
||||
clock_t now, delta;
|
||||
|
||||
if(anyKey){
|
||||
anyKey = FALSE;
|
||||
mRows = 0;
|
||||
then = 0;
|
||||
nThen = 0;
|
||||
return MENU;
|
||||
}
|
||||
|
||||
now = clock();
|
||||
delta = now - then;
|
||||
if((float)delta / (float)CLOCKS_PER_SEC >= 0.15f){
|
||||
then = now;
|
||||
mRows = mRows + 1 <= mH ? mRows + 1 : mH;
|
||||
}
|
||||
|
||||
if(mRows >= mH){
|
||||
now = clock();
|
||||
delta = now - nThen;
|
||||
if((int)delta / (int)CLOCKS_PER_SEC >= 3){
|
||||
nThen = 0;
|
||||
mRows = 0;
|
||||
then = 0;
|
||||
return MENU;
|
||||
}
|
||||
}else{
|
||||
nThen = clock();
|
||||
}
|
||||
|
||||
return INTRO;
|
||||
}
|
||||
|
||||
void inRender(int w, int h){
|
||||
int i, j, jOff;
|
||||
|
||||
mH = h < 30 ? h : 30;
|
||||
jOff = mH < h ? (mH / 4) : 0;
|
||||
|
||||
clear_screen(w, h);
|
||||
|
||||
for(i = 0; i < w && i < 80; i++){
|
||||
for(j = 21; j < h + 21 && j < mRows + 21 && j < 80; j++){
|
||||
move((j - 21) + jOff, (w / 2) - 40 + i);
|
||||
attron(COLOR_PAIR(INTRO_IMG[i][j]));
|
||||
printw("\u2588");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/main.c
58
src/main.c
@@ -27,16 +27,16 @@ static bool resize = FALSE;
|
||||
|
||||
int main() {
|
||||
bool finished = FALSE;
|
||||
char * home_dir = getenv("HOME");
|
||||
FILE * f; /* To avoid a warning. */
|
||||
clock_t then, now, delta;
|
||||
unsigned int fps = 0, pfps = 0;
|
||||
char * data_dir;
|
||||
char * log_file;
|
||||
time_t raw_date;
|
||||
struct tm * current_date;
|
||||
gs_t * states;
|
||||
int c_state;
|
||||
char * home_dir = getenv("HOME");
|
||||
FILE * f; /* To avoid a warning. */
|
||||
clock_t then, now, delta;
|
||||
unsigned int fps = 0, pfps = 0;
|
||||
char * data_dir;
|
||||
char * log_file;
|
||||
time_t raw_date;
|
||||
struct tm * current_date;
|
||||
gs_t * states;
|
||||
int c_state;
|
||||
|
||||
atexit(leave);
|
||||
signal(SIGINT, manage_signal);
|
||||
@@ -84,7 +84,7 @@ int main() {
|
||||
set_colors();
|
||||
|
||||
/* Create the state data structures. */
|
||||
c_state = MENU;
|
||||
c_state = INTRO;
|
||||
states = (gs_t *)malloc(sizeof(gs_t) * NUM_STATES);
|
||||
initStateArray(&states);
|
||||
|
||||
@@ -109,23 +109,25 @@ int main() {
|
||||
|
||||
if(c_state == -1) finished = TRUE;
|
||||
|
||||
if(c_state >= INTRO && c_state <= GAME_OVER){
|
||||
states[c_state].render(w, h);
|
||||
}
|
||||
|
||||
fps++;
|
||||
|
||||
now = clock();
|
||||
delta = now - then;
|
||||
if((int)delta / (int)CLOCKS_PER_SEC == 1){
|
||||
then = now;
|
||||
pfps = fps;
|
||||
fps = 0;
|
||||
if(c_state >= INTRO && c_state <= GAME_OVER){
|
||||
states[c_state].render(w, h);
|
||||
}
|
||||
|
||||
move(1, 1);
|
||||
attron(COLOR_PAIR(BSC_COLOR));
|
||||
printw("FPS: %u", pfps);
|
||||
if(DEBUG){
|
||||
fps++;
|
||||
|
||||
now = clock();
|
||||
delta = now - then;
|
||||
if((int)delta / (int)CLOCKS_PER_SEC == 1){
|
||||
then = now;
|
||||
pfps = fps;
|
||||
fps = 0;
|
||||
}
|
||||
|
||||
move(1, 1);
|
||||
attron(COLOR_PAIR(BSC_COLOR));
|
||||
printw("FPS: %u", pfps);
|
||||
}
|
||||
|
||||
refresh();
|
||||
}while(!finished);
|
||||
@@ -219,7 +221,6 @@ void set_colors(void){
|
||||
ret_code = start_color();
|
||||
if(ret_code == OK){
|
||||
if(has_colors() == TRUE){
|
||||
init_color(COLOR_MAGENTA, 0, 0, 500);
|
||||
|
||||
init_pair(BAR_COLOR, COLOR_WHITE, COLOR_RED); /* The color for the top and bottom bars. */
|
||||
init_pair(BSC_COLOR, COLOR_WHITE, COLOR_BLACK); /* Basic text color. */
|
||||
@@ -237,6 +238,9 @@ void set_colors(void){
|
||||
init_pair(FR_COLOR, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(HL_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||
init_pair(MN_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||
|
||||
init_pair(VOID_COLOR, COLOR_BLACK, COLOR_BLACK); /* Pure black. */
|
||||
init_pair(IND_COLOR, COLOR_MAGENTA, COLOR_BLACK); /* Intro shadow. */
|
||||
}
|
||||
}else{
|
||||
fprintf(stderr, "\t%s: Colors not supported.\n", __FILE__);
|
||||
|
||||
181
src/main_menu.c
181
src/main_menu.c
@@ -10,150 +10,137 @@
|
||||
#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 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 int selOpt = 0;
|
||||
static bool uK, dK, esc, enter;
|
||||
static int selOpt = 0;
|
||||
static bool uK, dK, esc, enter;
|
||||
|
||||
void mmInput();
|
||||
gsname_t mmUpdate();
|
||||
void mmRender(int, int);
|
||||
void clear_screen(int, int);
|
||||
|
||||
void initMMState(gs_t * gs){
|
||||
gs->name = MENU;
|
||||
gs->name = MENU;
|
||||
gs->input = &mmInput;
|
||||
gs->update = &mmUpdate;
|
||||
gs->render = &mmRender;
|
||||
}
|
||||
|
||||
void mmInput(){
|
||||
int key = 0;
|
||||
int key = 0;
|
||||
|
||||
key = getch();
|
||||
|
||||
if(key != ERR){
|
||||
if(key == KEY_UP) uK = TRUE;
|
||||
if(key == KEY_DOWN) dK = TRUE;
|
||||
if(key == 27) esc = TRUE;
|
||||
if(key == KEY_ENTER || key == '\n') enter = TRUE;
|
||||
if(key == 27) esc = TRUE;
|
||||
if(key == KEY_ENTER || key == '\n') enter = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gsname_t mmUpdate(){
|
||||
if(uK){
|
||||
selOpt = selOpt - 1 < 0 ? 2 : selOpt - 1;
|
||||
uK = FALSE;
|
||||
}
|
||||
if(uK){
|
||||
selOpt = selOpt - 1 < 0 ? 2 : selOpt - 1;
|
||||
uK = FALSE;
|
||||
}
|
||||
|
||||
if(dK){
|
||||
selOpt = (selOpt + 1) % 3;
|
||||
dK = FALSE;
|
||||
}
|
||||
if(dK){
|
||||
selOpt = (selOpt + 1) % 3;
|
||||
dK = FALSE;
|
||||
}
|
||||
|
||||
if(esc) return -1;
|
||||
if(esc) return -1;
|
||||
|
||||
if(enter){
|
||||
enter = FALSE;
|
||||
if(selOpt == 0) return IN_GAME;
|
||||
else if(selOpt == 1) return MENU;
|
||||
else return -1;
|
||||
}
|
||||
if(enter){
|
||||
enter = FALSE;
|
||||
if(selOpt == 0) return IN_GAME;
|
||||
else if(selOpt == 1) return INTRO;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
return MENU;
|
||||
return MENU;
|
||||
}
|
||||
|
||||
void mmRender(int w, int h){
|
||||
int sW;
|
||||
int sW;
|
||||
|
||||
clear_screen(w, h);
|
||||
clear_screen(w, h);
|
||||
|
||||
/* Print the title. */
|
||||
sW = strlen(title);
|
||||
sW /= 2;
|
||||
/* Print the title. */
|
||||
sW = strlen(title);
|
||||
sW /= 2;
|
||||
|
||||
attron(A_BOLD);
|
||||
attron(A_BOLD);
|
||||
|
||||
move(1, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SN_COLOR));
|
||||
printw(title);
|
||||
move(1, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SN_COLOR));
|
||||
printw(title);
|
||||
|
||||
/* Print the subtitle. */
|
||||
sW = strlen(subtitle);
|
||||
sW /= 2;
|
||||
/* Print the subtitle. */
|
||||
sW = strlen(subtitle);
|
||||
sW /= 2;
|
||||
|
||||
move(2, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SW_COLOR));
|
||||
printw(subtitle);
|
||||
move(2, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SW_COLOR));
|
||||
printw(subtitle);
|
||||
|
||||
attroff(A_BOLD);
|
||||
attroff(A_BOLD);
|
||||
|
||||
/* Print the menu options. */
|
||||
sW = strlen(opt1);
|
||||
sW /= 2;
|
||||
/* Print the menu options. */
|
||||
sW = strlen(opt1);
|
||||
sW /= 2;
|
||||
|
||||
move((h / 2) - 2, (w / 2) - sW);
|
||||
if(selOpt == 0) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt1);
|
||||
move((h / 2) - 2, (w / 2) - sW);
|
||||
if(selOpt == 0) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt1);
|
||||
|
||||
sW = strlen(opt2);
|
||||
sW /= 2;
|
||||
sW = strlen(opt2);
|
||||
sW /= 2;
|
||||
|
||||
move((h / 2) - 1, (w / 2) - sW);
|
||||
if(selOpt == 1) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt2);
|
||||
move((h / 2) - 1, (w / 2) - sW);
|
||||
if(selOpt == 1) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt2);
|
||||
|
||||
sW = strlen(opt3);
|
||||
sW /= 2;
|
||||
sW = strlen(opt3);
|
||||
sW /= 2;
|
||||
|
||||
move((h / 2), (w / 2) - sW);
|
||||
if(selOpt == 2) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt3);
|
||||
move((h / 2), (w / 2) - sW);
|
||||
if(selOpt == 2) attron(COLOR_PAIR(GR_COLOR));
|
||||
else attron(COLOR_PAIR(DW_COLOR));
|
||||
printw(opt3);
|
||||
|
||||
/* Print help. */
|
||||
sW = strlen(info);
|
||||
sW /= 2;
|
||||
/* Print help. */
|
||||
sW = strlen(info);
|
||||
sW /= 2;
|
||||
|
||||
move(h - 5, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(MN_COLOR));
|
||||
printw(info);
|
||||
move(h - 5, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(MN_COLOR));
|
||||
printw(info);
|
||||
|
||||
sW = strlen(info2);
|
||||
sW /= 2;
|
||||
sW = strlen(info2);
|
||||
sW /= 2;
|
||||
|
||||
move(h - 4, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(MN_COLOR));
|
||||
printw(info2);
|
||||
move(h - 4, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(MN_COLOR));
|
||||
printw(info2);
|
||||
|
||||
/* Print credits. */
|
||||
sW = strlen(creds);
|
||||
sW /= 2;
|
||||
/* Print credits. */
|
||||
sW = strlen(creds);
|
||||
sW /= 2;
|
||||
|
||||
attron(A_BOLD);
|
||||
move(h - 2, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SW_COLOR));
|
||||
printw(creds);
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
|
||||
void clear_screen(int w, int h){
|
||||
int i, j;
|
||||
move(0,0);
|
||||
attron(COLOR_PAIR(BSC_COLOR));
|
||||
for(i = 0; i < w; i++){
|
||||
for(j = 0; j < h; j++){
|
||||
move(j, i);
|
||||
printw(" ");
|
||||
}
|
||||
}
|
||||
attron(A_BOLD);
|
||||
move(h - 2, (w / 2) - sW);
|
||||
attron(COLOR_PAIR(SW_COLOR));
|
||||
printw(creds);
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user