derp, forgot to add all the actual lighning beam stuff

This commit is contained in:
Iris Lightshard 2018-11-13 13:08:21 -08:00
parent b8bca9f1f2
commit 3fdb066689
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
12 changed files with 203 additions and 26 deletions

View file

@ -18,6 +18,7 @@
#include "Kaos.h"
#include "HyperKaos.h"
#include "Scene.h"
#include "Synergy.h"
#include "extern.h"
@ -109,6 +110,7 @@ void interact()
break;
case B_BUTTON:
spellbutton = 1;
break;
case PAUSE_BUTTON:
pausemenu();
break;
@ -156,11 +158,17 @@ void interact()
case SDL_QUIT: quit = 1; playing = 0; break;
}
}
walkAnim(hero);
}
void kListen(int* whichKaos)
{
if (spellbutton)
{
spellFlag = 0;
run(spellBook[0]);
synergize();
spellFlag = -1;
}
if (*whichKaos >= 0)
{
run(rightHere->eventTriggers[*whichKaos]);
@ -222,10 +230,32 @@ int init(int argc, char* args[])
sfxData = malloc(24*sizeof(Mix_Chunk*));
kaosData = malloc(124*sizeof(Kaos*));
theatre = malloc(8*sizeof(Scene*));
writeSpellBook();
printf("Init complete\n");
return 1;
}
void writeSpellBook()
{
HyperKaos* testSpell = newHyperKaos(1,0,0,0,0,0);
Kaos* stopPlayer = newManip(hero, 0,0);
Kaos* beam = newSpell_Beam();
addKaos(testSpell, stopPlayer);
addKaos(testSpell, beam);
spellBook = malloc(4*sizeof(HyperKaos**));
spellBook[0] = testSpell;
}
void burnSpellBook()
{
cleanHyperKaos(spellBook[0]);
deleteHyperKaos(spellBook[0]);
free(spellBook);
}
void toggleFullscreen()
{
if (!fullscreen)
@ -254,7 +284,6 @@ void cleanup()
{
if(fullscreen)
SDL_ShowCursor(1);
printf("Freeing map data\n");
unloadData(thisChunk);
@ -272,6 +301,8 @@ void cleanup()
free(theatre);
burnSpellBook();
SDL_FreeSurface(textBoxBG);
SDL_FreeSurface(nextArrow);
SDL_FreeSurface(saveMenu);

View file

@ -24,6 +24,8 @@ void kListen(int* whichKaos);
int init(int argc, char* args[]);
void writeSpellBook();
void toggleFullscreen();
void timeDilation();

View file

@ -35,9 +35,25 @@ void deleteHyperKaos(HyperKaos* self)
free(self);
}
//
// chains of events
//
void cleanHyperKaos(HyperKaos* self)
{
Kaos* here = self->head;
Kaos* next;
savestate *= self->kaosID;
if (self->head == NULL) return;
else
{
next = here->next;
while (here != NULL)
{
here->destroy(here);
here = next;
if (here != NULL)
next = here->next;
}
}
}
void addKaos(HyperKaos* self, Kaos* target)
{

View file

@ -10,6 +10,7 @@ typedef struct hyperKaos
HyperKaos* newHyperKaos(int id, int type, int x, int y, int w, int h);
void deleteHyperKaos(HyperKaos* target);
void cleanHyperKaos(HyperKaos* self);
void run(HyperKaos* self);
void addKaos(HyperKaos* self, Kaos* target);

103
Kaos.c
View file

@ -358,7 +358,7 @@ void runErase(Kaos* self)
{
case 'w':
deleteWarp(rightHere, kSelf->index);
break;
break;
case 't':
deleteTrigger(rightHere, kSelf->index);
break;
@ -368,6 +368,9 @@ void runErase(Kaos* self)
case 'f':
deleteFgObj(rightHere, kSelf->index);
break;
case 's':
deleteSigil(rightHere, kSelf->index);
break;
default:break;
}
}
@ -417,4 +420,102 @@ void deleteWait(Kaos* target)
{
free(target->kType);
free(target);
}
Kaos* newSpell_Beam()
{
Kaos* core = rawKaos();
Spell_Beam* self = malloc(sizeof(Spell_Beam));
self->core = core;
core->kType = self;
self->aura = loadImage("assets/img/fx/spellBeam.png");
SDL_SetAlpha(self->aura, SDL_SRCALPHA|SDL_RLEACCEL, 124);
core->run = &runSpell_Beam;
core->destroy = &deleteSpell_Beam;
return core;
}
void runSpell_Beam(Kaos* self)
{
int i;
char facing;
SDL_Rect offset, clip;
Spell_Beam* kSelf = self->kType;
if (playerFaces(hero, 's'))
{
facing = 's';
offset.x = hero->boundBox.x - hero->boundBox.w/2;
offset.y = hero->boundBox.y + hero->boundBox.h;
clip.x = 0;
clip.y = 128;
clip.w = 32;
clip.h = 180;
}
else if (playerFaces(hero, 'w'))
{
facing = 'w';
offset.x = hero->boundBox.x - SCREEN_WIDTH;
offset.y = hero->boundBox.y - hero->boundBox.h/2;
clip.x = 15;
clip.y = 0;
clip.w = 320;
clip.h = 32;
}
else if (playerFaces(hero, 'e'))
{
facing = 'e';
offset.x = hero->boundBox.x + hero->boundBox.w;
offset.y = hero->boundBox.y - hero->boundBox.h/2;
clip.x = 0;
clip.y = 0;
clip.w = 320;
clip.h = 32;
}
else
{
facing = 'n';
offset.x = hero->boundBox.x - hero->boundBox.w/2;
offset.y = hero->boundBox.y - SCREEN_HEIGHT;
clip.x = 128;
clip.y = 128;
clip.w = 32;
clip.h = 180;
}
for (i = 0; i < 16; i++)
{
timeStart(fps);
renderBackground();
renderForeground();
switch (facing)
{
case 'n':
clip.x = 128 + (i%4)*32;
applySurface(offset.x, offset.y, kSelf->aura, screen, &clip);
break;
case 's':
clip.x = (i%4)*32;
applySurface(offset.x, offset.y, kSelf->aura, screen, &clip);
break;
case 'w':
case 'e':
clip.y = (i%4)*32;
applySurface(offset.x, offset.y, kSelf->aura, screen, &clip);
break;
}
SDL_Flip(screen);
timeDilation();
}
}
void deleteSpell_Beam(Kaos* target)
{
Spell_Beam* kSelf = target->kType;
SDL_FreeSurface(kSelf->aura);
free(kSelf);
free(target);
}

10
Kaos.h
View file

@ -75,6 +75,12 @@ typedef struct kaos_Wait
int frames;
} Wait;
typedef struct kaos_Spell_Beam
{
Kaos* core;
SDL_Surface* aura;
} Spell_Beam;
Kaos* rawKaos();
Kaos* newConversation(int i);
@ -112,3 +118,7 @@ void deleteErase(Kaos* target);
Kaos* newWait(char t, int i);
void runWait(Kaos* self);
void deleteWait(Kaos* target);
Kaos* newSpell_Beam();
void runSpell_Beam(Kaos* self);
void deleteSpell_Beam(Kaos* target);

View file

@ -174,6 +174,7 @@ void movePlayer(Player* self, Room* hereNow)
void drawPlayer(Player* self)
{
applySurface(self->point.x - 8, self->point.y - 8, self->sprite, screen, NULL);
walkAnim(self);
}

2
Room.c
View file

@ -304,7 +304,7 @@ void deleteFgObj(Room* self, int i)
temp[j] = self->fgObject[j];
for (j = i + 1; j < self->numberOfObj; j++)
temp[j-1] = self->fgObject[j];
free(self->fgObject[i].spriteSheet);
SDL_FreeSurface(self->fgObject[i].spriteSheet);
free(self->fgObject);
self->fgObject = temp;
temp = NULL;

View file

@ -19,13 +19,13 @@ typedef struct timer Timer;
typedef struct textBox TextBox;
#include "extern.h"
Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t)
Synergy* newSynergy(int s, char d, int x, int y, int w, int h, HyperKaos* t)
{
Synergy* self = malloc(sizeof(Synergy));
self->spell = s;
self->dir = d;
self->zone = z;
self->zone = (SDL_Rect){x, y, w, h};
self->trigger = t;
return self;
@ -36,16 +36,16 @@ void deleteSynergy(Synergy* target)
free(target);
}
void Synergize()
void synergize()
{
int i;
Synergy* sigil = rightHere->sigils[0];
Synergy* sigil;
for (i = 0; i < rightHere->numberOfSigils; i++)
{
sigil = rightHere->sigils[i];
if (sigil->spell == spellFlag
&& playerFaces(hero, sigil->dir)
&& playerIsInRect(hero, &(sigil->zone)))
run(sigil->trigger);
sigil++;
}
}

View file

@ -6,7 +6,7 @@ typedef struct synergy
HyperKaos* trigger;
} Synergy;
Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t);
Synergy* newSynergy(int s, char d, int x, int y, int w, int h, HyperKaos* t);
void deleteSynergy(Synergy* target);
void Synergize();
void synergize();

View file

@ -4,7 +4,9 @@
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h"
#include "config.h"
#include "enum.h"
#include "Engine.h"
#include "Player.h"
#include "Room.h"
@ -12,6 +14,7 @@
#include "HyperKaos.h"
#include "TextBox.h"
#include "Scene.h"
#include "Synergy.h"
typedef struct timer Timer;
#include "extern.h"
@ -78,6 +81,9 @@ void bufferData(enum dataChunks chunk)
kaosData[5] = newConversation(2);
kaosData[6] = newConversation(3);
kaosData[7] = newConversation(4);
kaosData[12] = newErase('f', 1);
kaosData[13] = newErase('o', 1);
kaosData[14] = newErase('s', 0);
HyperKaos* choiceBranchA = newHyperKaos(1,0, 0, 0, 0, 0);
addKaos(choiceBranchA, kaosData[7]);
@ -91,14 +97,26 @@ void bufferData(enum dataChunks chunk)
addTrigger(mapBuffer[3], choiceBranchB);
choiceBranchB = NULL;
HyperKaos* destroyChp2 = newHyperKaos(1,0,0,0,0,0);
addKaos(destroyChp2, kaosData[12]);
addKaos(destroyChp2, kaosData[13]);
addKaos(destroyChp2, kaosData[14]);
Synergy* testSigil = newSynergy(0,'e', 0, 74, 256, 48, destroyChp2);
addSigil(mapBuffer[0], testSigil);
destroyChp2 = NULL;
testSigil = NULL;
kaosData[8] = newChoice("Let her know?", "Sure thing", "Nope", mapBuffer[3]->eventTriggers[0], mapBuffer[3]->eventTriggers[1]);
if(notCompleted(3))
{
HyperKaos* testTextBox = newHyperKaos(3, 0, 0, 0, 320, 180);
addKaos(testTextBox, kaosData[4]);
addKaos(testTextBox, kaosData[0]);
addKaos(testTextBox, kaosData[1]);
addKaos(testTextBox, kaosData[4]);
addKaos(testTextBox, kaosData[8]);
addTrigger(mapBuffer[3], testTextBox);
@ -135,15 +153,7 @@ void bufferData(enum dataChunks chunk)
addTrigger(mapBuffer[1], randomDudeConvo);
randomDudeConvo = NULL;
HyperKaos* chipDesc1 = newHyperKaos(1,1, 64, 64, 22, 55);
addKaos(chipDesc1, kaosData[5]);
addKaos(chipDesc1, kaosData[2]);
addTrigger(mapBuffer[0], chipDesc1);
chipDesc1 = NULL;
HyperKaos* chipDesc2 = newHyperKaos(1,1, 320 - 64 - 22, 64, 22, 55);
addKaos(chipDesc2, kaosData[5]);
addTrigger(mapBuffer[0], chipDesc2);
chipDesc2 = NULL;
break;
case LEVEL2:
@ -186,7 +196,7 @@ void unloadData(enum dataChunks chunk)
switch(chunk)
{
case LEVEL1:
dataPurge(4,5,12,1,0);
dataPurge(4,5,15,1,0);
break;
case LEVEL2:
dataPurge(2,0,0,0,0);
@ -204,7 +214,7 @@ void pushBufferData()
mapBuffer = (Room**)malloc(64*sizeof(Room*));
if (hasMusic)
Mix_PlayMusic(bgmData[0], -1);
printf("Mapbuffer clean\n");
printf("Map buffer clean\n");
}
void pager()

View file

@ -10,3 +10,8 @@
#define R_BUTTON SDLK_p
#define FS_BUTTON SDLK_f
#define PAUSE_BUTTON SDLK_q
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 180
#define SOUND_ON