2018-09-20 01:27:47 +00:00
|
|
|
#include "SDL/SDL.h"
|
|
|
|
#include "SDL/SDL_image.h"
|
|
|
|
#include "SDL/SDL_ttf.h"
|
|
|
|
#include "SDL/SDL_mixer.h"
|
|
|
|
|
2018-09-25 17:59:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
#include "enum.h"
|
|
|
|
#include "Engine.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
#include "Kaos.h"
|
|
|
|
#include "TextBox.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "Room.h"
|
|
|
|
#include "HyperKaos.h"
|
2018-09-24 18:41:09 +00:00
|
|
|
#include "Scene.h"
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
Kaos* rawKaos()
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Kaos* self = malloc(sizeof(Kaos));
|
2018-09-20 01:27:47 +00:00
|
|
|
self->next = NULL;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newConversation(int i)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Conversation* self = malloc(sizeof(Conversation));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->index = i;
|
|
|
|
|
|
|
|
core->kType = self;
|
|
|
|
self->core = core;
|
|
|
|
core->run = &runConversation;
|
|
|
|
core->destroy = &deleteConversation;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runConversation(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Conversation* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
displayTextBox(dialogueData[kSelf->index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteConversation(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newChoice(char* q, char* a1, char* a2, HyperKaos* p1, HyperKaos* p2)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Choice* self = malloc(sizeof(Choice));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->question = TTF_RenderText_Solid(font, q, textColor);
|
|
|
|
self->answ1 = TTF_RenderText_Solid(font, a1, textColor);
|
|
|
|
self->answ2 = TTF_RenderText_Solid(font, a2, textColor);
|
|
|
|
self->path1 = p1;
|
|
|
|
self->path2 = p2;
|
|
|
|
|
|
|
|
core->kType = self;
|
|
|
|
self->core = core;
|
|
|
|
core->run = &runChoice;
|
|
|
|
core->destroy = &deleteChoice;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runChoice(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Choice* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
int choice = 0;
|
|
|
|
int textIsRelevent = 1;
|
|
|
|
actionbutton = 0;
|
|
|
|
while (textIsRelevent)
|
|
|
|
{
|
|
|
|
timeStart(fps);
|
|
|
|
renderBackground();
|
|
|
|
renderForeground();
|
|
|
|
|
|
|
|
applySurface(22,73, choiceBox, screen, NULL);
|
|
|
|
applySurface(74,76, kSelf->question, screen, NULL);
|
|
|
|
|
|
|
|
applySurface(74,90, kSelf->answ1, screen, NULL);
|
|
|
|
applySurface(180,90, kSelf->answ2, screen, NULL);
|
|
|
|
|
|
|
|
switch(choice)
|
|
|
|
{
|
|
|
|
case 0: applySurface(59,86, selectArrow, screen, NULL); break;
|
|
|
|
case 1: applySurface(165,86, selectArrow, screen, NULL); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT: quit = 1; playing = 0; textIsRelevent = 0; break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch(event.key.keysym.sym)
|
|
|
|
{
|
2018-09-25 17:59:52 +00:00
|
|
|
case DPAD_LEFT:
|
|
|
|
case DPAD_RIGHT:
|
2018-09-20 01:27:47 +00:00
|
|
|
if (choice == 0) choice = 1;
|
|
|
|
else choice = 0;
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case A_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
textIsRelevent = 0;
|
|
|
|
if (choice == 0) run(kSelf->path1);
|
|
|
|
else run(kSelf->path2);
|
|
|
|
break;
|
2018-09-25 17:59:52 +00:00
|
|
|
case FS_BUTTON:
|
2018-09-20 01:27:47 +00:00
|
|
|
toggleFullscreen();
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_Flip(screen);
|
|
|
|
timeDilation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteChoice(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Choice* kSelf = self->kType;
|
|
|
|
SDL_FreeSurface(kSelf->question);
|
|
|
|
SDL_FreeSurface(kSelf->answ1);
|
|
|
|
SDL_FreeSurface(kSelf->answ2);
|
2018-09-20 01:27:47 +00:00
|
|
|
free(self->kType);
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newManip(Player* t, int x, int y)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Manip* self = malloc(sizeof(Manip));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->target= t;
|
|
|
|
self->xSpd = x;
|
|
|
|
self->ySpd = y;
|
|
|
|
|
|
|
|
core->kType = self;
|
|
|
|
self->core = core;
|
|
|
|
core->run = &runManip;
|
|
|
|
core->destroy = &deleteManip;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runManip(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Manip* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
kSelf->target->bearing.x = kSelf->xSpd;
|
|
|
|
kSelf->target->bearing.y = kSelf->ySpd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteManip(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newLook(Player* t, char d)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Look* self = malloc(sizeof(Look));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->target = t;
|
|
|
|
self->dir = d;
|
|
|
|
|
|
|
|
self->core = core;
|
|
|
|
core->kType = self;
|
|
|
|
core->run = &runLook;
|
|
|
|
core->destroy = &deleteLook;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runLook(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Look* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
SDL_Rect playerClip = { 0,0,16,16};
|
|
|
|
switch(kSelf->dir)
|
|
|
|
{
|
|
|
|
case 'n':
|
|
|
|
playerClip.x = 96;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
playerClip.x = 32;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
playerClip.x = 64;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
changeSprite(kSelf->target, &playerClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteLook(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newTeleport(Player* p, int x, int y, int o)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Teleport* self = malloc(sizeof(Teleport));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->target = p;
|
|
|
|
self->x = x;
|
|
|
|
self->y = y;
|
|
|
|
self->out = o;
|
|
|
|
self->aura = loadImage("assets/img/fx/blkthunder.png");
|
|
|
|
|
|
|
|
self->core = core;
|
|
|
|
core->kType = self;
|
|
|
|
core->run = &runTeleport;
|
|
|
|
core->destroy = &deleteTeleport;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runTeleport(Kaos* self)
|
|
|
|
{
|
|
|
|
Teleport* kSelf = self->kType;
|
|
|
|
int i;
|
|
|
|
SDL_Rect clip = {0,0,32,32};
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
if (i == 11)
|
|
|
|
{
|
|
|
|
if (kSelf->out)
|
|
|
|
{
|
|
|
|
kSelf->target->point.x = -16;
|
|
|
|
kSelf->target->point.y = -16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kSelf->target->point.x = kSelf->x;
|
|
|
|
kSelf->target->point.y = kSelf->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clip.x = (i%4)*32;
|
|
|
|
timeStart(fps);
|
|
|
|
renderBackground();
|
|
|
|
renderForeground();
|
|
|
|
applySurface(kSelf->x-16, kSelf->y-16, kSelf->aura, screen, &clip);
|
|
|
|
SDL_Flip(screen);
|
|
|
|
timeDilation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteTeleport(Kaos* target)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Teleport* kSelf = target->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
SDL_FreeSurface(kSelf->aura);
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newFaceEachother(Player* p1, Player* p2)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
FaceEachother* self = malloc(sizeof(FaceEachother));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->p1 = p1;
|
|
|
|
self->p2 = p2;
|
|
|
|
|
|
|
|
core->kType = self;
|
|
|
|
self->core = core;
|
|
|
|
core->run = &runFaceEachother;
|
|
|
|
core->destroy = &deleteFaceEachother;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runFaceEachother(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
FaceEachother* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
SDL_Rect p1Clip = {0,0,16,16};
|
|
|
|
SDL_Rect p2Clip = {0,0,16,16};
|
2018-10-13 03:35:45 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
if (kSelf->p1->point.x > kSelf->p2->point.x)
|
|
|
|
p2Clip.x = 64;
|
2018-10-13 03:35:45 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
if (kSelf->p1->point.x < kSelf->p2->point.x)
|
|
|
|
p1Clip.x = 64;
|
2018-10-13 03:35:45 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
if (kSelf->p1->point.y > kSelf->p2->point.y)
|
|
|
|
{
|
|
|
|
p1Clip.x = 96;
|
|
|
|
p2Clip.x = 32;
|
|
|
|
}
|
2018-10-13 03:35:45 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
if (kSelf->p1->point.y < kSelf->p2->point.y)
|
|
|
|
{
|
|
|
|
p1Clip.x = 32;
|
|
|
|
p2Clip.x = 96;
|
|
|
|
}
|
2018-10-13 03:35:45 +00:00
|
|
|
|
2018-09-20 01:27:47 +00:00
|
|
|
changeSprite(kSelf->p1, &p1Clip);
|
|
|
|
changeSprite(kSelf->p2, &p2Clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteFaceEachother(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newPlaySound(int i)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
PlaySound* self = malloc(sizeof(PlaySound));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->i = i;
|
|
|
|
|
|
|
|
core->kType = self;
|
|
|
|
self->core = core;
|
|
|
|
core->run = &runPlaySound;
|
|
|
|
core->destroy = &deletePlaySound;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runPlaySound(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
PlaySound* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
Mix_PlayChannel(-1, sfxData[kSelf->i], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deletePlaySound(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newErase(char t, int i)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Erase* self = malloc(sizeof(Erase));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->type = t;
|
|
|
|
self->index = i;
|
|
|
|
|
|
|
|
self->core = core;
|
|
|
|
core->kType = self;
|
|
|
|
core->run = &runErase;
|
|
|
|
core->destroy = &deleteErase;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runErase(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Erase* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
switch (kSelf->type)
|
|
|
|
{
|
|
|
|
case 'w':
|
|
|
|
deleteWarp(rightHere, kSelf->index);
|
2018-10-13 03:35:45 +00:00
|
|
|
break;
|
2018-09-20 01:27:47 +00:00
|
|
|
case 't':
|
|
|
|
deleteTrigger(rightHere, kSelf->index);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
deleteObstacle(rightHere, kSelf->index);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
deleteFgObj(rightHere, kSelf->index);
|
|
|
|
break;
|
|
|
|
default:break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteErase(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
Kaos* newWait(char t, int i)
|
|
|
|
{
|
|
|
|
Kaos* core = rawKaos();
|
2018-09-21 19:57:07 +00:00
|
|
|
Wait* self = malloc(sizeof(Wait));
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
self->type = t;
|
|
|
|
self->frames = i;
|
|
|
|
|
|
|
|
self->core = core;
|
|
|
|
core->kType = self;
|
|
|
|
core->run = &runWait;
|
|
|
|
core->destroy = &deleteWait;
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runWait(Kaos* self)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
Wait* kSelf = self->kType;
|
2018-09-20 01:27:47 +00:00
|
|
|
int i;
|
|
|
|
if (kSelf->type == 'f')
|
|
|
|
captive = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < kSelf->frames; i++)
|
|
|
|
{
|
|
|
|
timeStart(fps);
|
|
|
|
if (captive)
|
|
|
|
interact();
|
|
|
|
renderBackground();
|
|
|
|
renderForeground();
|
|
|
|
SDL_Flip(screen);
|
|
|
|
timeDilation();
|
|
|
|
}
|
|
|
|
captive = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWait(Kaos* target)
|
|
|
|
{
|
|
|
|
free(target->kType);
|
|
|
|
free(target);
|
|
|
|
}
|