2018-09-20 01:27:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-11-13 21:30:59 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
#include "SDL/SDL.h"
|
|
|
|
#include "SDL/SDL_image.h"
|
|
|
|
#include "SDL/SDL_ttf.h"
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
#include "SDL/SDL_mixer.h"
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
#include "enum.h"
|
2018-09-25 17:59:52 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
#include "Engine.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "Room.h"
|
|
|
|
#include "WorldData.h"
|
|
|
|
#include "TextBox.h"
|
|
|
|
#include "Kaos.h"
|
|
|
|
#include "HyperKaos.h"
|
2018-09-24 18:41:09 +00:00
|
|
|
#include "Scene.h"
|
2018-11-13 21:08:21 +00:00
|
|
|
#include "Synergy.h"
|
2018-09-25 17:59:52 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// graphics primitives
|
|
|
|
//
|
|
|
|
|
|
|
|
SDL_Surface* loadImage(char* filename)
|
|
|
|
{
|
|
|
|
SDL_Surface* loadedImage = NULL;
|
|
|
|
SDL_Surface* optimizedImage = NULL;
|
|
|
|
loadedImage = IMG_Load(filename);
|
|
|
|
if (loadedImage != NULL)
|
|
|
|
{
|
|
|
|
optimizedImage = SDL_DisplayFormat(loadedImage);
|
|
|
|
SDL_FreeSurface(loadedImage);
|
|
|
|
}
|
|
|
|
return optimizedImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip)
|
|
|
|
{
|
|
|
|
SDL_Rect offset;
|
|
|
|
offset.x = x;
|
|
|
|
offset.y = y;
|
|
|
|
SDL_BlitSurface(source, clip, destination, &offset);
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:26:38 +00:00
|
|
|
Uint32 getPixel(SDL_Surface* surface, int x, int y)
|
|
|
|
{
|
|
|
|
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
return *(Uint32 *)p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void scaleScreen()
|
|
|
|
{
|
|
|
|
Sint32 x, y;
|
|
|
|
static SDL_Rect superPixel = {0,0, SCALE_FACTOR,SCALE_FACTOR};
|
|
|
|
|
|
|
|
switch (SCALE_FACTOR)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
applySurface(0,0,screen,window,NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
superPixel.y = 0;
|
|
|
|
for (y = 0; y < SCREEN_HEIGHT; y++)
|
|
|
|
{
|
|
|
|
superPixel.x = 0;
|
|
|
|
for (x = 0; x < SCREEN_WIDTH; x++)
|
|
|
|
{
|
|
|
|
SDL_FillRect(window, &superPixel, getPixel(screen, x, y));
|
|
|
|
superPixel.x += SCALE_FACTOR;
|
|
|
|
}
|
|
|
|
superPixel.y += SCALE_FACTOR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
//
|
|
|
|
// sound
|
|
|
|
//
|
|
|
|
|
2018-11-13 21:30:59 +00:00
|
|
|
#ifdef SOUND_ON
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
Mix_Music* loadBGM(char* filename)
|
|
|
|
{
|
|
|
|
Mix_Music* bgmTrack = Mix_LoadMUS(filename);
|
|
|
|
hasMusic = 1;
|
|
|
|
return bgmTrack;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mix_Chunk* loadSFX(char* filename)
|
|
|
|
{
|
|
|
|
Mix_Chunk* sfxClip = Mix_LoadWAV(filename);
|
|
|
|
return sfxClip;
|
|
|
|
}
|
|
|
|
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
//
|
|
|
|
// world
|
|
|
|
//
|
|
|
|
|
|
|
|
void renderBackground()
|
|
|
|
{
|
2019-01-13 20:19:57 +00:00
|
|
|
applySurface(0, 0, rightHere->spriteSheet, screen, &(rightHere->clip));
|
2018-09-20 01:27:47 +00:00
|
|
|
animate(rightHere);
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderForeground()
|
|
|
|
{
|
|
|
|
drawFgObjects1(rightHere);
|
|
|
|
drawPeople(rightHere);
|
|
|
|
drawPlayer(hero);
|
|
|
|
drawFgObjects2(rightHere);
|
|
|
|
}
|
|
|
|
|
2018-12-19 18:17:49 +00:00
|
|
|
void renderHUD()
|
|
|
|
{
|
|
|
|
SDL_Rect clip;
|
|
|
|
clip.x = bookMark*16;;
|
|
|
|
clip.y = 0;
|
|
|
|
clip.w = 16;
|
|
|
|
clip.h = 16;
|
|
|
|
applySurface(300,160, spellGlyphs, screen, &clip);
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
void interact()
|
|
|
|
{
|
|
|
|
while(SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
{
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_UP:
|
2018-09-20 01:27:47 +00:00
|
|
|
hero->bearing.y = -2;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_LEFT:
|
2018-09-20 01:27:47 +00:00
|
|
|
hero->bearing.x = -2;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_DOWN:
|
2018-09-20 01:27:47 +00:00
|
|
|
hero->bearing.y = 2;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_RIGHT:
|
2018-09-20 01:27:47 +00:00
|
|
|
hero->bearing.x = 2;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case A_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
actionbutton = 1;
|
|
|
|
break;
|
2018-10-13 03:35:45 +00:00
|
|
|
case B_BUTTON:
|
|
|
|
spellbutton = 1;
|
2018-11-13 21:08:21 +00:00
|
|
|
break;
|
2018-12-14 22:52:24 +00:00
|
|
|
case L_BUTTON:
|
|
|
|
bookMark--;
|
|
|
|
if (bookMark == -1)
|
2018-12-16 12:18:26 +00:00
|
|
|
bookMark = 9;
|
|
|
|
while (!spellKnowledge[bookMark])
|
|
|
|
{
|
|
|
|
bookMark--;
|
|
|
|
}
|
2018-12-14 22:52:24 +00:00
|
|
|
break;
|
|
|
|
case R_BUTTON:
|
|
|
|
bookMark++;
|
2018-12-16 12:18:26 +00:00
|
|
|
if (bookMark == 10)
|
2018-12-14 22:52:24 +00:00
|
|
|
bookMark = 0;
|
2018-12-16 12:18:26 +00:00
|
|
|
while (!spellKnowledge[bookMark])
|
|
|
|
{
|
|
|
|
bookMark++;
|
|
|
|
if (bookMark == 10)
|
|
|
|
bookMark = 0;
|
|
|
|
}
|
2018-12-14 22:52:24 +00:00
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case PAUSE_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
pausemenu();
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case FS_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
toggleFullscreen();
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
|
|
|
switch( event.key.keysym.sym )
|
|
|
|
{
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_UP:
|
2018-09-20 01:27:47 +00:00
|
|
|
if (hero->bearing.y < 0)
|
|
|
|
{
|
|
|
|
hero->bearing.y = 0;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_LEFT:
|
2018-09-20 01:27:47 +00:00
|
|
|
if (hero->bearing.x < 0)
|
|
|
|
{
|
|
|
|
hero->bearing.x = 0 ;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_DOWN:
|
2018-09-20 01:27:47 +00:00
|
|
|
if (hero->bearing.y > 0)
|
|
|
|
{
|
|
|
|
hero->bearing.y = 0;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_RIGHT:
|
2018-09-20 01:27:47 +00:00
|
|
|
if (hero->bearing.x > 0)
|
|
|
|
{
|
|
|
|
hero->bearing.x = 0;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case A_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
actionbutton = 0;
|
|
|
|
break;
|
2018-10-13 03:35:45 +00:00
|
|
|
case B_BUTTON:
|
|
|
|
spellbutton = 0;
|
2018-09-20 01:27:47 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT: quit = 1; playing = 0; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:36:35 +00:00
|
|
|
void kListen()
|
2018-09-20 01:27:47 +00:00
|
|
|
{
|
2018-11-13 21:08:21 +00:00
|
|
|
if (spellbutton)
|
|
|
|
{
|
2018-12-14 22:52:24 +00:00
|
|
|
spellFlag = bookMark;
|
|
|
|
run(spellBook[spellFlag]);
|
2018-11-13 21:08:21 +00:00
|
|
|
synergize();
|
|
|
|
spellFlag = -1;
|
|
|
|
}
|
2018-12-17 04:36:35 +00:00
|
|
|
if (kaosFlag >= 0)
|
2018-09-20 01:27:47 +00:00
|
|
|
{
|
2018-12-17 04:36:35 +00:00
|
|
|
run(rightHere->eventTriggers[kaosFlag]);
|
|
|
|
kaosFlag = -1;
|
2018-09-20 01:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// system
|
|
|
|
//
|
|
|
|
|
|
|
|
int init(int argc, char* args[])
|
|
|
|
{
|
|
|
|
printf("Initializing SDL\n");
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) == -1) return 0;
|
|
|
|
printf("Initialized\nOpening soundsystem\n");
|
|
|
|
if (Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT, 2, 4096) == -1) return 0;
|
|
|
|
printf("Soundsystem open\nCreating window\n");
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) == -1) return 0;
|
|
|
|
printf("Initialized\nCreating window\n");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
if (argc >= 2)
|
|
|
|
{
|
|
|
|
if (strcmp(args[1], "-w"))
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
window = SDL_SetVideoMode( SCREEN_WIDTH*SCALE_FACTOR, SCREEN_HEIGHT*SCALE_FACTOR, 32, SDL_FULLSCREEN|SDL_HWSURFACE);
|
2018-09-20 01:27:47 +00:00
|
|
|
fullscreen = 1;
|
|
|
|
}
|
2019-01-09 22:26:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
window = SDL_SetVideoMode( SCREEN_WIDTH*SCALE_FACTOR, SCREEN_HEIGHT*SCALE_FACTOR, 32, SDL_HWSURFACE|SDL_RESIZABLE);
|
|
|
|
}
|
2018-09-20 01:27:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
window = SDL_SetVideoMode( SCREEN_WIDTH*SCALE_FACTOR, SCREEN_HEIGHT*SCALE_FACTOR, 32, SDL_FULLSCREEN|SDL_HWSURFACE);
|
2018-09-20 01:27:47 +00:00
|
|
|
fullscreen = 1;
|
|
|
|
}
|
2019-01-09 22:26:38 +00:00
|
|
|
screen = loadImage("assets/img/rawscreen.png");
|
|
|
|
if (window == NULL || screen == NULL) return 0;
|
|
|
|
SDL_ShowCursor(0);
|
2018-09-20 01:27:47 +00:00
|
|
|
SDL_WM_SetCaption("Kaos Mage's Infinite Sidequest", NULL);
|
|
|
|
printf("Window created\nInitializing fonts\n");
|
|
|
|
if (TTF_Init() == -1) return 0;
|
|
|
|
printf("Fonts initialized\nInitializing data\n");
|
|
|
|
|
|
|
|
menuBG = newRoom("assets/img/backgrounds/mainmenu.png", 1);
|
|
|
|
|
2019-03-17 07:32:12 +00:00
|
|
|
//font = TTF_OpenFont("assets/ocr-b.pxl8.ttf", 9);
|
|
|
|
font = TTF_OpenFont("assets/mecha.ttf", 13);
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
saveMenu = loadImage("assets/img/windows/saveMenu.gif");
|
|
|
|
textBoxBG = loadImage("assets/img/windows/textBox.gif");
|
|
|
|
choiceBox = loadImage("assets/img/windows/choiceBox.gif");
|
|
|
|
nextArrow = loadImage("assets/img/windows/nextButton.gif");
|
|
|
|
selectArrow = loadImage("assets/img/windows/selectArrow.gif");
|
|
|
|
loadingTxt = TTF_RenderText_Solid(font, "loading map data...", textColor);
|
2018-12-19 18:17:49 +00:00
|
|
|
spellGlyphs = loadImage("assets/img/hud/spellbook.png");
|
|
|
|
SDL_SetAlpha(spellGlyphs, SDL_SRCALPHA|SDL_RLEACCEL, 156);
|
2018-09-20 01:27:47 +00:00
|
|
|
hero = newPlayer("assets/img/characters/kmage.png", 160, 90);
|
|
|
|
|
|
|
|
|
2018-09-24 18:41:09 +00:00
|
|
|
mapData = malloc(64*sizeof(Room*));
|
|
|
|
mapBuffer= malloc(64*sizeof(Room*));
|
|
|
|
dialogueData = malloc(124*sizeof(Room*));
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-24 18:41:09 +00:00
|
|
|
bgmData = malloc(8*sizeof(Mix_Music*));
|
|
|
|
sfxData = malloc(24*sizeof(Mix_Chunk*));
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-24 18:41:09 +00:00
|
|
|
kaosData = malloc(124*sizeof(Kaos*));
|
|
|
|
theatre = malloc(8*sizeof(Scene*));
|
2018-11-13 21:08:21 +00:00
|
|
|
|
|
|
|
writeSpellBook();
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
printf("Init complete\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-13 21:08:21 +00:00
|
|
|
void writeSpellBook()
|
|
|
|
{
|
|
|
|
HyperKaos* testSpell = newHyperKaos(1,0,0,0,0,0);
|
2019-03-06 01:26:01 +00:00
|
|
|
Kaos* stopPlayer = newManip("hero, xSpd 0, ySpd 0");
|
2018-11-13 21:08:21 +00:00
|
|
|
Kaos* beam = newSpell_Beam();
|
|
|
|
addKaos(testSpell, stopPlayer);
|
|
|
|
addKaos(testSpell, beam);
|
|
|
|
|
|
|
|
spellBook = malloc(4*sizeof(HyperKaos**));
|
|
|
|
spellBook[0] = testSpell;
|
2018-12-14 22:52:24 +00:00
|
|
|
|
|
|
|
testSpell = newHyperKaos(1,0,0,0,0,0);
|
2019-03-06 01:26:01 +00:00
|
|
|
Kaos* stopPlayer2 = newManip("hero, xSpd 0, ySpd 0");
|
2018-12-14 22:52:24 +00:00
|
|
|
Kaos* flash = newSpell_Flash();
|
|
|
|
addKaos(testSpell, stopPlayer2);
|
|
|
|
addKaos(testSpell, flash);
|
|
|
|
|
|
|
|
spellBook[1] = testSpell;
|
|
|
|
|
2018-11-13 21:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void burnSpellBook()
|
|
|
|
{
|
|
|
|
cleanHyperKaos(spellBook[0]);
|
|
|
|
deleteHyperKaos(spellBook[0]);
|
2018-12-14 22:52:24 +00:00
|
|
|
cleanHyperKaos(spellBook[1]);
|
|
|
|
deleteHyperKaos(spellBook[1]);
|
2018-11-13 21:08:21 +00:00
|
|
|
free(spellBook);
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
void toggleFullscreen()
|
|
|
|
{
|
|
|
|
if (!fullscreen)
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
SDL_SetVideoMode(SCREEN_WIDTH*SCALE_FACTOR, SCREEN_HEIGHT*SCALE_FACTOR, 32, SDL_FULLSCREEN|SDL_HWSURFACE);
|
2018-09-20 01:27:47 +00:00
|
|
|
fullscreen = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
SDL_SetVideoMode(SCREEN_WIDTH*SCALE_FACTOR, SCREEN_HEIGHT*SCALE_FACTOR, 32, SDL_HWSURFACE|SDL_RESIZABLE);
|
2018-09-20 01:27:47 +00:00
|
|
|
fullscreen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void timeDilation()
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
int i = getTicks(&fps);
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
if (i < 1000 / 30)
|
|
|
|
SDL_Delay(1000/30 - i);
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:26:38 +00:00
|
|
|
void frameAdvance()
|
|
|
|
{
|
|
|
|
scaleScreen();
|
|
|
|
SDL_Flip(window);
|
|
|
|
timeDilation();
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
void cleanup()
|
|
|
|
{
|
|
|
|
if(fullscreen)
|
2018-12-27 00:55:15 +00:00
|
|
|
toggleFullscreen();
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
unloadData(thisChunk);
|
|
|
|
|
|
|
|
printf("Freeing global data\n");
|
|
|
|
|
|
|
|
killPlayer(hero);
|
|
|
|
deleteRoom(menuBG);
|
|
|
|
|
|
|
|
free(mapData);
|
|
|
|
free(kaosData);
|
|
|
|
free(dialogueData);
|
|
|
|
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
free(bgmData);
|
|
|
|
free(sfxData);
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
2018-09-20 01:27:47 +00:00
|
|
|
|
2018-09-24 18:41:09 +00:00
|
|
|
free(theatre);
|
|
|
|
|
2018-11-13 21:08:21 +00:00
|
|
|
burnSpellBook();
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
SDL_FreeSurface(textBoxBG);
|
|
|
|
SDL_FreeSurface(nextArrow);
|
|
|
|
SDL_FreeSurface(saveMenu);
|
|
|
|
SDL_FreeSurface(selectArrow);
|
|
|
|
SDL_FreeSurface(loadingTxt);
|
|
|
|
SDL_FreeSurface(screen);
|
2019-01-09 22:26:38 +00:00
|
|
|
SDL_FreeSurface(window);
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
printf("Closing SDL\n");
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
Mix_CloseAudio();
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
TTF_CloseFont(font);
|
|
|
|
TTF_Quit();
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
printf("Cleanup complete\n");
|
|
|
|
}
|
|
|
|
|
2018-10-08 21:57:15 +00:00
|
|
|
void intro()
|
|
|
|
{
|
|
|
|
SDL_Color black = {0,0,0};
|
|
|
|
|
|
|
|
SLayer* nebula = newSLayer(loadImage("assets/img/backgrounds/presents.png"), 0,0,0,0,255);
|
|
|
|
SLayer* fogF = newSLayer(loadImage("assets/img/fx/fog.png"), 0,0,-1,0,128);
|
|
|
|
SLayer* fogB = newSLayer(loadImage("assets/img/fx/plasma.png"), -320,0,1,0,56);
|
|
|
|
SLayer* presents = newSLayer(TTF_RenderText_Solid(font, "nilFM presents", textColor), 120,84,0,0,128);
|
|
|
|
|
|
|
|
SLayer* menuTransition = newSLayer(loadImage("assets/img/backgrounds/mainmenu.png"),0,0,0,0,255);
|
|
|
|
|
|
|
|
Scene* intro = newScene(30,30, 200, black, black);
|
|
|
|
Scene* transition = newScene(30,0,30, black, black);
|
|
|
|
|
|
|
|
buildScene(intro, nebula);
|
|
|
|
buildScene(intro, fogB);
|
|
|
|
buildScene(intro, fogF);
|
|
|
|
buildScene(intro, presents);
|
|
|
|
|
|
|
|
buildScene(transition, menuTransition);
|
|
|
|
|
|
|
|
playScene(intro);
|
|
|
|
playScene(transition);
|
|
|
|
|
|
|
|
deleteScene(intro);
|
|
|
|
deleteScene(transition);
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
void mainmenu()
|
|
|
|
{
|
|
|
|
int menucounter = 0;
|
|
|
|
int select = 0;
|
|
|
|
FILE* saveData = fopen("sram", "r");
|
|
|
|
|
|
|
|
int level = 1;
|
|
|
|
int roomNo = 0;
|
|
|
|
int xPos = 180;
|
|
|
|
int yPos = 90;
|
|
|
|
long long int eventState = 2;
|
|
|
|
warpto(menuBG);
|
|
|
|
|
2018-11-13 21:30:59 +00:00
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
if (menuBGM == NULL)
|
|
|
|
Mix_HaltMusic();
|
|
|
|
else
|
|
|
|
Mix_PlayMusic(menuBGM, -1);
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
while (!select)
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
timeStart(&fps);
|
2019-01-13 20:19:57 +00:00
|
|
|
renderBackground();
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
while(SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
{
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_UP:
|
2018-09-20 01:27:47 +00:00
|
|
|
menucounter--;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_DOWN:
|
2018-09-20 01:27:47 +00:00
|
|
|
menucounter++;
|
|
|
|
break;
|
|
|
|
|
2018-09-25 17:59:52 +00:00
|
|
|
case A_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
select = 1;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case FS_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
toggleFullscreen();
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT: quit = 1; playing = 0; select = 1; break;
|
|
|
|
}
|
|
|
|
if (menucounter == 3) menucounter = 0;
|
|
|
|
if (menucounter == -1) menucounter = 2;
|
|
|
|
}
|
|
|
|
switch (menucounter)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
applySurface(230, 61, selectArrow, screen, NULL);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
applySurface(230, 83, selectArrow, screen, NULL);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
applySurface(230, 105, selectArrow, screen, NULL);
|
|
|
|
}
|
2019-01-09 22:26:38 +00:00
|
|
|
frameAdvance();
|
2018-09-20 01:27:47 +00:00
|
|
|
}
|
2019-01-09 22:26:38 +00:00
|
|
|
if (quit) return;
|
2018-09-20 01:27:47 +00:00
|
|
|
switch (menucounter)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-03-06 00:52:45 +00:00
|
|
|
playing = 1;
|
2018-09-20 01:27:47 +00:00
|
|
|
thisChunk = LEVEL1;
|
|
|
|
nextChunk = LEVEL1;
|
|
|
|
|
|
|
|
savestate = eventState;
|
|
|
|
bufferData(LEVEL1);
|
|
|
|
pushBufferData();
|
|
|
|
|
|
|
|
warpto(mapData[0]);
|
|
|
|
hero->point.x = 160;
|
|
|
|
hero->point.y = 90;
|
|
|
|
|
|
|
|
fclose(saveData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (saveData)
|
|
|
|
{
|
|
|
|
fscanf(saveData, "%d %d %d %d %lld", &level, &roomNo, &xPos, &yPos, &eventState);
|
|
|
|
}
|
2019-03-06 00:52:45 +00:00
|
|
|
playing = 1;
|
2018-09-20 01:27:47 +00:00
|
|
|
thisChunk = (enum dataChunks)(level);
|
|
|
|
nextChunk = (enum dataChunks)(level);
|
|
|
|
|
|
|
|
savestate = eventState;
|
|
|
|
bufferData((enum dataChunks)(level));
|
|
|
|
pushBufferData();
|
|
|
|
|
|
|
|
hero->point.x = xPos;
|
|
|
|
hero->point.y = yPos;
|
|
|
|
warpto(mapData[roomNo]);
|
|
|
|
|
|
|
|
fclose(saveData);
|
|
|
|
printf("Loaded save: level %d, room %d (%d,%d) state: %lld\n", level, roomNo, xPos, yPos, eventState);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
quit = 1;
|
|
|
|
playing = 0;
|
|
|
|
fclose(saveData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pausemenu()
|
|
|
|
{
|
|
|
|
int paused = 1;
|
|
|
|
int menucounter = 0;
|
|
|
|
int select = 0;
|
|
|
|
int roomNo;
|
|
|
|
int i;
|
|
|
|
FILE* saveData;
|
|
|
|
hero->bearing.x = 0;
|
|
|
|
hero->bearing.y = 0;
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
Mix_VolumeMusic(MIX_MAX_VOLUME/3);
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
if (rightHere == mapData[i])
|
|
|
|
{
|
|
|
|
roomNo = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (paused)
|
|
|
|
{
|
2019-01-09 22:26:38 +00:00
|
|
|
timeStart(&fps);
|
2018-09-20 01:27:47 +00:00
|
|
|
applySurface(60, 45, saveMenu ,screen, NULL);
|
|
|
|
while(SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
{
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_UP:
|
2018-09-20 01:27:47 +00:00
|
|
|
menucounter--;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_DOWN:
|
2018-09-20 01:27:47 +00:00
|
|
|
menucounter++;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case A_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
select = 1;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case PAUSE_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
paused = 0;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case FS_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
toggleFullscreen();
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT: quit = 1; paused = 0; playing = 0; break;
|
|
|
|
}
|
|
|
|
if (menucounter == 3) menucounter = 0;
|
|
|
|
if (menucounter == -1) menucounter = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (menucounter)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
applySurface(93, 60, selectArrow, screen, NULL);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
applySurface(93, 82, selectArrow, screen, NULL);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
applySurface(93, 104, selectArrow, screen, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (select)
|
|
|
|
{
|
|
|
|
switch (menucounter)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
printf("Saving data: level %d, room %d (%d,%d) state: %lld\n", thisChunk, roomNo, hero->point.x, hero->point.y, savestate);
|
|
|
|
saveData = fopen("sram", "w");
|
|
|
|
fprintf(saveData, "%d %d %d %d %lld", (int)(thisChunk), roomNo, hero->point.x, hero->point.y, savestate);
|
|
|
|
paused = 0;
|
|
|
|
fclose(saveData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
printf("Saving data: level %d, room %d (%d,%d) state: %lld\n", thisChunk, roomNo, hero->point.x, hero->point.y, savestate);
|
|
|
|
saveData = fopen("sram", "w");
|
|
|
|
fprintf(saveData, "%d %d %d %d %lld", (int)(thisChunk), roomNo, hero->point.x, hero->point.y, savestate);
|
|
|
|
paused = 0;
|
|
|
|
playing = 0;
|
|
|
|
fclose(saveData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
paused = 0;
|
|
|
|
playing = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-01-09 22:26:38 +00:00
|
|
|
frameAdvance();
|
2018-09-20 01:27:47 +00:00
|
|
|
}
|
2018-11-13 21:30:59 +00:00
|
|
|
|
|
|
|
#ifdef SOUND_ON
|
2018-09-20 01:27:47 +00:00
|
|
|
Mix_VolumeMusic(MIX_MAX_VOLUME);
|
2018-11-13 21:30:59 +00:00
|
|
|
#endif
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
}
|