setting up for magic mechanics: Synergy structures, their interface, globals relating to them

This commit is contained in:
Iris Lightshard 2018-10-12 20:35:45 -07:00
parent 4a5b926621
commit b87b25b5a6
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
15 changed files with 191 additions and 17 deletions

View file

@ -107,6 +107,8 @@ void interact()
case A_BUTTON:
actionbutton = 1;
break;
case B_BUTTON:
spellbutton = 1;
case PAUSE_BUTTON:
pausemenu();
break;
@ -146,6 +148,8 @@ void interact()
case A_BUTTON:
actionbutton = 0;
break;
case B_BUTTON:
spellbutton = 0;
default: break;
}
break;

7
Kaos.c
View file

@ -281,20 +281,25 @@ void runFaceEachother(Kaos* self)
FaceEachother* kSelf = self->kType;
SDL_Rect p1Clip = {0,0,16,16};
SDL_Rect p2Clip = {0,0,16,16};
if (kSelf->p1->point.x > kSelf->p2->point.x)
p2Clip.x = 64;
if (kSelf->p1->point.x < kSelf->p2->point.x)
p1Clip.x = 64;
if (kSelf->p1->point.y > kSelf->p2->point.y)
{
p1Clip.x = 96;
p2Clip.x = 32;
}
if (kSelf->p1->point.y < kSelf->p2->point.y)
{
p1Clip.x = 32;
p2Clip.x = 96;
}
changeSprite(kSelf->p1, &p1Clip);
changeSprite(kSelf->p2, &p2Clip);
}
@ -353,7 +358,7 @@ void runErase(Kaos* self)
{
case 'w':
deleteWarp(rightHere, kSelf->index);
break;
break;
case 't':
deleteTrigger(rightHere, kSelf->index);
break;

View file

@ -7,7 +7,7 @@ all: game
scenetest: sceneTest.c Scene.o Engine.o Timer.o Player.o Room.o WorldData.o Kaos.o HyperKaos.o TextBox.o
$(CC) -o $@ $^ $(CFLAGS)
game: main.c Player.o Engine.o Timer.o Room.o WorldData.o TextBox.o Kaos.o HyperKaos.o Scene.o
game: main.c Player.o Engine.o Timer.o Room.o WorldData.o TextBox.o Kaos.o HyperKaos.o Scene.o Synergy.o
$(CC) -o $@ $^ $(CFLAGS)
cleanobj:

View file

@ -15,6 +15,7 @@ typedef struct timer Timer;
typedef struct textBox TextBox;
typedef struct kaos Kaos;
typedef struct scene Scene;
typedef struct hyperKaos HyperKaos;
#include "extern.h"
Player* newPlayer(char* filename, int a, int b)
@ -76,7 +77,7 @@ void movePlayer(Player* self, Room* hereNow)
// obstacle collision
if (checkCollision(rightHere, &(self->boundBox), rightHere->obstacle))
if (checkCollision(rightHere, self, rightHere->obstacle))
{
self->point.x -= self->bearing.x;
self->boundBox.x = self->point.x - 8;
@ -86,7 +87,7 @@ void movePlayer(Player* self, Room* hereNow)
self->boundBox.y = self->point.y - 8;
if (checkCollision(rightHere, &(self->boundBox), rightHere->obstacle))
if (checkCollision(rightHere, self, rightHere->obstacle))
{
self->point.y -= self->bearing.y;
self->boundBox.y = self->point.y - 8;
@ -246,3 +247,38 @@ void walkAnim(Player* self)
self->counter++;
if (self->counter == 8) self->counter = 0;
}
int playerFaces(Player* self, char dir)
{
switch (dir)
{
case 'n':
if (self->frontFaceBox.y < self->boundBox.y)
return 1;
break;
case 's':
if (self->frontFaceBox.y > self->boundBox.y)
return 1;
break;
case 'e':
if (self->frontFaceBox.x > self->boundBox.x)
return 1;
break;
case 'w':
if (self->frontFaceBox.x < self->boundBox.x)
return 1;
break;
}
return 0;
}
int playerIsInRect(Player* self, SDL_Rect* rect)
{
SDL_Rect* pBox = &(self->boundBox);
int playerX = pBox->x + (pBox->w)/2;
int playerY = pBox->y + (pBox->h)/2;
if ((playerX >= rect->x && playerX <= rect->x + rect->w)
&& (playerY >= rect->y && playerY <= rect->y + rect->h))
return 1;
else return 0;
}

View file

@ -24,3 +24,6 @@ void movePlayer(Player* self, Room* rightHere);
void changeSprite(Player* self, SDL_Rect* clip);
void drawPlayer(Player* self);
void walkAnim(Player* self);
int playerFaces(Player* self, char dir);
int playerIsInRect(Player* self, SDL_Rect* rect);

46
Room.c
View file

@ -10,6 +10,7 @@
#include "Player.h"
#include "Room.h"
#include "HyperKaos.h"
#include "Synergy.h"
typedef struct timer Timer;
typedef struct textBox TextBox;
@ -42,6 +43,10 @@ Room* newRoom(char* filename, int a)
self->numberOfPeople = 0;
self->maxNumberOfPeople = 4;
self->sigils = malloc(4*sizeof(Synergy*));
self->numberOfSigils = 0;
self->maxNumberOfSigils = 4;
SDL_Rect zeroRect;
zeroRect.x=0;
zeroRect.y=0;
@ -151,16 +156,15 @@ void animate(Room* self)
// collision detection
//
int checkCollision(Room* self, SDL_Rect* player, SDL_Rect* box)
int checkCollision(Room* self, Player* player, SDL_Rect* box)
{
int i;
int playerX = player->x + (player->w)/2;
int playerY = player->y + (player->h)/2;
for (i = 1; i <= self->numberOfObstacles; i++)
{
if ( (playerX >= box->x && playerX <= box->x + box->w)
&& (playerY >= box->y && playerY <= box->y + box->h) )
if (playerIsInRect(player, box))
// if ( (playerX >= box->x && playerX <= box->x + box->w)
// && (playerY >= box->y && playerY <= box->y + box->h) )
{
return 1;
}
@ -444,6 +448,38 @@ void deleteTrigger(Room* self, int i)
self->numberOfTriggers--;
}
void addSigil(Room* self, Synergy* newSigil)
{
int i;
if (self->numberOfSigils+1 > self->maxNumberOfSigils)
{
self->maxNumberOfSigils *= 2;
Synergy** temp = malloc(self->maxNumberOfSigils*sizeof(Synergy*));
for (i = 0; i < self->numberOfSigils; i++)
temp[i] = self->sigils[i];
free(self->sigils);
self->sigils = temp;
temp = NULL;
}
self->sigils[self->numberOfSigils++] = newSigil;
}
void deleteSigil(Room* self, int i)
{
int j;
Synergy** temp = malloc(self->maxNumberOfSigils*sizeof(Synergy*));
for (j = 0; j < i; j++)
temp[j] = self->sigils[j];
for (j = i + 1; j < self->numberOfSigils; j++)
temp[j-1] = self->sigils[j];
deleteSynergy(self->sigils[i]);
free(self->sigils);
self->sigils = temp;
temp = NULL;
self->numberOfSigils--;
}
void addPerson(Room* self, Player* newPlayer)
{
int i;

10
Room.h
View file

@ -1,4 +1,5 @@
typedef struct hyperKaos HyperKaos;
typedef struct synergy Synergy;
typedef struct fgImage
{
@ -43,6 +44,10 @@ typedef struct room
int numberOfTriggers;
int maxNumberOfTriggers;
Synergy** sigils;
int numberOfSigils;
int maxNumberOfSigils;
Player** people;
int numberOfPeople;
int maxNumberOfPeople;
@ -57,7 +62,7 @@ void deleteRoom(Room* target);
void changeRSprite(Room* self, SDL_Rect* clip);
void animate(Room* self);
int checkCollision(Room* self, SDL_Rect* player, SDL_Rect* box);
int checkCollision(Room* self, Player* player, SDL_Rect* box);
int checkWCollision(Room* self, SDL_Rect* player, WarpZone* warpBoxes, int* whichWarp);
int checkKCollision(Room* self, SDL_Rect* player, HyperKaos** triggers, int* whichTrigger, int* triggerType);
@ -75,6 +80,9 @@ void deleteWarp(Room* self, int i);
void addTrigger(Room* self, HyperKaos* newTrigger);
void deleteTrigger(Room* self, int i);
void addSigil(Room* self, Synergy* newSigil);
void deleteSigil(Room* self, int i);
void addPerson(Room* self, Player* newPlayer);
void deletePerson(Room* self, int i);
void drawPeople(Room* self);

View file

@ -15,6 +15,7 @@ typedef struct kaos Kaos;
typedef struct textBox TextBox;
typedef struct room Room;
typedef struct player Player;
typedef struct hyperKaos HyperKaos;
#include "extern.h"
SLayer* newSLayer(SDL_Surface* img, int x, int y, int h, int v, int alpha)

51
Synergy.c Normal file
View file

@ -0,0 +1,51 @@
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_mixer.h>
#include "enum.h"
#include "Player.h"
#include "Kaos.h"
#include "Room.h"
#include "HyperKaos.h"
#include "Synergy.h"
typedef struct player Player;
//typedef struct room Room;
//typedef struct kaos Kaos;
typedef struct scene Scene;
typedef struct timer Timer;
typedef struct textBox TextBox;
#include "extern.h"
Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t)
{
Synergy* self = malloc(sizeof(Synergy));
self->spell = s;
self->dir = d;
self->zone = z;
self->trigger = t;
return self;
}
void deleteSynergy(Synergy* target)
{
free(target);
}
void Synergize()
{
int i;
Synergy* sigil = rightHere->sigils[0];
for (i = 0; i < rightHere->numberOfSigils; i++)
{
if (sigil->spell == spellFlag
&& playerFaces(hero, sigil->dir)
&& playerIsInRect(hero, &(sigil->zone)))
run(sigil->trigger);
sigil++;
}
}

12
Synergy.h Normal file
View file

@ -0,0 +1,12 @@
typedef struct synergy
{
int spell;
char dir;
SDL_Rect zone;
HyperKaos* trigger;
} Synergy;
Synergy* newSynergy(int s, char d, SDL_Rect z, HyperKaos* t);
void deleteSynergy(Synergy* target);
void Synergize();

View file

@ -13,6 +13,7 @@
typedef struct room Room;
typedef struct kaos Kaos;
typedef struct scene Scene;
typedef struct hyperKaos HyperKaos;
#include "extern.h"

View file

@ -21,6 +21,7 @@ void bufferData(enum dataChunks chunk)
hasMusic = 0;
applySurface(0,0, loadingTxt, screen, NULL);
SDL_Flip(screen);
printf("Loading map chunk\n");
switch (chunk){
case LEVEL1:
bgmData[0] = loadBGM("assets/snd/bgm/artificial sun stage (mamon machine mix).mp3");
@ -160,7 +161,8 @@ void bufferData(enum dataChunks chunk)
case LEVEL3:
break;
}
}
printf("Loaded map chunk\n");
}
void dataPurge(int a, int b, int c, int d, int e)
@ -180,6 +182,7 @@ void dataPurge(int a, int b, int c, int d, int e)
void unloadData(enum dataChunks chunk)
{
printf("Unloading old map chunk\n");
switch(chunk)
{
case LEVEL1:
@ -191,14 +194,17 @@ void unloadData(enum dataChunks chunk)
case LEVEL3:
break;
}
printf("Unloaded old map chunk\n");
}
void pushBufferData()
{
printf("Pushing map buffer\n");
mapData = mapBuffer;
mapBuffer = (Room**)malloc(64*sizeof(Room*));
if (hasMusic)
Mix_PlayMusic(bgmData[0], -1);
printf("Mapbuffer clean\n");
}
void pager()

View file

@ -5,5 +5,8 @@
#define DPAD_LEFT SDLK_a
#define DPAD_RIGHT SDLK_d
#define A_BUTTON SDLK_j
#define B_BUTTON SDLK_k
#define L_BUTTON SDLK_o
#define R_BUTTON SDLK_p
#define FS_BUTTON SDLK_f
#define PAUSE_BUTTON SDLK_q

View file

@ -3,20 +3,24 @@ extern int fullscreen;
extern int quit;
extern int playing;
extern int actionbutton;
extern int spellbutton;
extern int captive;
extern int hasMusic;
extern SDL_Event event;
extern SDL_Surface* screen;
extern Timer fps;
extern Room* rightHere;
extern Room* menuBG;
extern int kaosFlag;
extern long long int savestate;
extern Player* hero;
extern HyperKaos** spellBook;
extern int kaosFlag;
extern int spellFlag;
extern long long int savestate;
extern int spellKnowledge;
extern Room* menuBG;
extern SDL_Surface* saveMenu;
extern SDL_Surface* textBoxBG;
extern SDL_Surface* choiceBox;

4
main.c
View file

@ -24,6 +24,7 @@ int fullscreen = 0;
int playing = 0;
int quit = 0;
int actionbutton = 0;
int spellbutton = 0;
int captive = 0;
int hasMusic = 0;
@ -32,6 +33,7 @@ SDL_Event event;
SDL_Surface* screen = NULL;
Room* rightHere = NULL;
HyperKaos** spellBook = NULL;
SDL_Surface* saveMenu = NULL;
SDL_Surface* textBoxBG = NULL;
@ -48,6 +50,7 @@ Room* menuBG = NULL;
Mix_Music* menuBGM = NULL;
long long int savestate = 2;
int spellKnowledge = 2;
Room** mapData = NULL;
Room** mapBuffer = NULL;
@ -58,6 +61,7 @@ Kaos** kaosData = NULL;
Scene** theatre = NULL;
int kaosFlag = -1;
int spellFlag = -1;
enum dataChunks thisChunk;
enum dataChunks nextChunk;