aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog26
-rw-r--r--Goals.txt2
-rw-r--r--assets/BennyHillTheme.wavbin21318852 -> 0 bytes
-rw-r--r--assets/air-horn-club-sample_1.wavbin149804 -> 0 bytes
-rw-r--r--assets/click.wavbin0 -> 17684 bytes
-rw-r--r--assets/items/flashlight_off.pngbin0 -> 330 bytes
-rw-r--r--assets/sounds/cricket.wavbin0 -> 8695476 bytes
-rw-r--r--assets/sounds/longSwing.wavbin0 -> 85376 bytes
-rw-r--r--assets/sounds/sanic.wavbin0 -> 2299686 bytes
-rw-r--r--assets/sounds/shortSwing.wavbin0 -> 100196 bytes
-rw-r--r--config/items.h10
-rw-r--r--include/Texture.h2
-rw-r--r--include/common.h2
-rw-r--r--include/entities.h3
-rw-r--r--include/ui.h7
-rw-r--r--include/world.h8
-rw-r--r--main.cpp31
-rw-r--r--src/entities.cpp33
-rw-r--r--src/gameplay.cpp219
-rw-r--r--src/inventory.cpp8
-rw-r--r--src/ui.cpp136
-rw-r--r--src/world.cpp163
22 files changed, 383 insertions, 267 deletions
diff --git a/Changelog b/Changelog
index 61dee12..0a44904 100644
--- a/Changelog
+++ b/Changelog
@@ -387,4 +387,28 @@
- continued to document header files through doxygen
- added border to dialogBox
- fix entity movement handling; npcs stop when you talk to them
- - added sword animation? \ No newline at end of file
+<<<<<<< HEAD
+ - added sword animation?
+=======
+ - added sword animation?
+
+12/9/2015,
+12/10/2015:
+===========
+
+ - added sound effects
+ - fixed disappearing building
+ - began actually plotting areas
+ - fixed layer switching-ish
+ - added passive dialogs
+ - began working on particles stuffses
+ - improved village spawning
+
+12/11/2015:
+===========
+
+ - plotted out a tutorial-ish area in game
+ - imrpoved BGM handling
+ - continued work on particles, made a fountain
+ - added sanic
+>>>>>>> 43bbcf02fd5e4e69a9aa521fa4cd572cc8675cf3
diff --git a/Goals.txt b/Goals.txt
index 208c7e5..140cdd3 100644
--- a/Goals.txt
+++ b/Goals.txt
@@ -27,7 +27,7 @@ Summary:
idea of a parallaxed background was applied, with up to four layers of tiled background material.
Combinations of background layers were sorted and added to the World class with a World::setBackground()
function. The inventory was created, with an animated inventory view based off of the player finished
-by the end of the month.
+by the end of the month. ...
End of December:
================
diff --git a/assets/BennyHillTheme.wav b/assets/BennyHillTheme.wav
deleted file mode 100644
index a926902..0000000
--- a/assets/BennyHillTheme.wav
+++ /dev/null
Binary files differ
diff --git a/assets/air-horn-club-sample_1.wav b/assets/air-horn-club-sample_1.wav
deleted file mode 100644
index 50c5bf8..0000000
--- a/assets/air-horn-club-sample_1.wav
+++ /dev/null
Binary files differ
diff --git a/assets/click.wav b/assets/click.wav
new file mode 100644
index 0000000..976fb42
--- /dev/null
+++ b/assets/click.wav
Binary files differ
diff --git a/assets/items/flashlight_off.png b/assets/items/flashlight_off.png
new file mode 100644
index 0000000..8f6f204
--- /dev/null
+++ b/assets/items/flashlight_off.png
Binary files differ
diff --git a/assets/sounds/cricket.wav b/assets/sounds/cricket.wav
new file mode 100644
index 0000000..70be7e5
--- /dev/null
+++ b/assets/sounds/cricket.wav
Binary files differ
diff --git a/assets/sounds/longSwing.wav b/assets/sounds/longSwing.wav
new file mode 100644
index 0000000..e9b60f2
--- /dev/null
+++ b/assets/sounds/longSwing.wav
Binary files differ
diff --git a/assets/sounds/sanic.wav b/assets/sounds/sanic.wav
new file mode 100644
index 0000000..18708a9
--- /dev/null
+++ b/assets/sounds/sanic.wav
Binary files differ
diff --git a/assets/sounds/shortSwing.wav b/assets/sounds/shortSwing.wav
new file mode 100644
index 0000000..bd42737
--- /dev/null
+++ b/assets/sounds/shortSwing.wav
Binary files differ
diff --git a/config/items.h b/config/items.h
index 1bd9111..ee1024c 100644
--- a/config/items.h
+++ b/config/items.h
@@ -11,8 +11,8 @@ ID DEBUG_ITEM
ID TEST_ITEM
NAME "Dank MayMay"
TYPE TOOL
- WIDTH HLINE*1
- HEIGHT HLINE*1
+ WIDTH HLINE*10
+ HEIGHT HLINE*10
STACKSIZE 420
TEX "assets/items/ITEM_TEST.png"
ENI
@@ -29,10 +29,10 @@ ID PLAYER_BAG
ID FLASHLIGHT
NAME "Flashlight"
TYPE TOOL
- WIDTH HLINE*2
- HEIGHT HLINE*4
+ WIDTH HLINE*4
+ HEIGHT HLINE*8
STACKSIZE 1
- TEX "assets/items/ITEM_TEST.png"
+ TEX "assets/items/flashlight_off.png"
ENI
ID SWORD_WOOD
diff --git a/include/Texture.h b/include/Texture.h
index bcd95af..85225d8 100644
--- a/include/Texture.h
+++ b/include/Texture.h
@@ -52,7 +52,7 @@ public:
* Contains an array of the GLuints returned from Texture::loadTexture().
*/
- GLuint *image;
+ GLuint *image = NULL;
/**
* Populates the image array from a list of strings, with each string as a
diff --git a/include/common.h b/include/common.h
index f8bd935..095b3e3 100644
--- a/include/common.h
+++ b/include/common.h
@@ -64,7 +64,7 @@ typedef struct {
* The desired width of the game window.
*/
-#define SCREEN_WIDTH 1280
+#define SCREEN_WIDTH 1024
/**
* The desired height of the game window.
diff --git a/include/entities.h b/include/entities.h
index 77ca347..dd3adab 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -16,7 +16,7 @@
enum _TYPE { //these are the main types of entities
OBJECTT = -2,
- STRUCTURET = -1,
+ STRUCTURET,
PLAYERT,
NPCT,
MOBT
@@ -79,6 +79,7 @@ public:
Texturec *tex;
+ unsigned int randDialog;
void draw(void);
void spawn(float, float);
diff --git a/include/ui.h b/include/ui.h
index f2c0114..2fe3b0a 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -27,7 +27,7 @@ namespace ui {
extern unsigned int fontSize;
extern bool dialogBoxExists;
extern unsigned char dialogOptChosen;
- extern bool edown;
+ extern bool dialogImportant;
/*
* Initializes the FreeType system.
@@ -60,7 +60,7 @@ namespace ui {
* limited until a right click is given, closing the box.
*/
- void dialogBox(const char *name,const char *opt,const char *text,...);
+ void dialogBox(const char *name,const char *opt,bool passive,const char *text,...);
void waitForDialog(void);
/*
@@ -85,6 +85,9 @@ namespace ui {
*/
void toggleBlack(void);
+ void toggleBlackFast(void);
+ void toggleWhite(void);
+ void waitForCover(void);
}
diff --git a/include/world.h b/include/world.h
index ccf93a8..1e78cd0 100644
--- a/include/world.h
+++ b/include/world.h
@@ -17,6 +17,11 @@
#define GEN_INC 10
+
+#define GEN_MIN 80
+#define GEN_MAX 110
+
+
/**
* Defines how many game ticks it takes for a day to elapse.
*/
@@ -194,8 +199,7 @@ public:
*/
void setBGM(const char *path);
- void bgmPlay(void);
- void bgmStop(void);
+ void bgmPlay(World *prev);
/*
* Looks for the furthest back layer in this world and adds a new layer of width `width` behind it.
diff --git a/main.cpp b/main.cpp
index d1fd85e..4e45189 100644
--- a/main.cpp
+++ b/main.cpp
@@ -116,6 +116,8 @@ unsigned int deltaTime = 0;
GLuint fragShader;
GLuint shaderProgram;
+Mix_Chunk *crickets;
+
/*
* names is used to open a file containing all possible NPC names. It is externally
* referenced in src/entities.cpp for getting random names.
@@ -208,6 +210,8 @@ unsigned int millis(void){
extern WEATHER weather;
extern bool fadeEnable;
+extern bool fadeWhite;
+extern bool fadeFast;
extern unsigned int fadeIntensity;
/*******************************************************************************
@@ -252,6 +256,7 @@ int main(/*int argc, char *argv[]*/){
std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
return -1;
}
+ Mix_AllocateChannels(8);
// Run Mix_Quit when main returns
atexit(Mix_CloseAudio);
@@ -401,6 +406,9 @@ int main(/*int argc, char *argv[]*/){
*/
names = fopen("assets/names_en-us", "r+");
+
+ crickets=Mix_LoadWAV("assets/sounds/crickets.wav");
+ //Mix_Volume(2,25);
/*
* Create all the worlds, entities, mobs, and the player. This function is defined in
@@ -485,8 +493,7 @@ void mainLoop(void){
ui::handleEvents();
if(prev != currentWorld){
- prev->bgmStop();
- currentWorld->bgmPlay();
+ currentWorld->bgmPlay(prev);
}
if(prevPrevTime + MSEC_PER_TICK <= currentTime){
@@ -709,7 +716,10 @@ void render(){
*/
if(fadeIntensity){
- glColor4ub(0,0,0,fadeIntensity);
+ if(fadeWhite)
+ glColor4ub(255,255,255,fadeIntensity);
+ else
+ glColor4ub(0,0,0,fadeIntensity);
glRectf(offset.x-SCREEN_WIDTH /2,
offset.y-SCREEN_HEIGHT/2,
offset.x+SCREEN_WIDTH /2,
@@ -819,11 +829,6 @@ void logic(){
* click detection is done as well for NPC/player interaction.
*
*/
- if((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) && !ui::dialogBoxExists)player->inv->usingi = true;
- if(player->inv->usingi){
- player->inv->useItem();
- }
-
for(auto &n : currentWorld->npc){
if(n->alive){
/*
@@ -950,8 +955,10 @@ void logic(){
if(!(tickCount%DAY_CYCLE)||!tickCount){
if(weather==SUNNY){
weather=DARK;
+ Mix_PlayChannel(2,crickets,0);
}else{
weather=SUNNY;
+ Mix_Pause(2);
}
}
@@ -965,11 +972,11 @@ void logic(){
* Transition to and from black if necessary.
*/
if(fadeEnable){
- if(fadeIntensity < 160)fadeIntensity+=10;
- else if(fadeIntensity < 255)fadeIntensity+=5;
+ if(fadeIntensity < 150)fadeIntensity+=fadeFast?30:10;
+ else if(fadeIntensity < 255)fadeIntensity+=fadeFast?15:5;
}else{
- if(fadeIntensity > 150)fadeIntensity-=5;
- else if(fadeIntensity > 0) fadeIntensity-=10;
+ if(fadeIntensity > 150)fadeIntensity-=fadeFast?15:5;
+ else if(fadeIntensity > 0) fadeIntensity-=fadeFast?30:10;
}
/*
diff --git a/src/entities.cpp b/src/entities.cpp
index f2d7270..5c00cc7 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -102,6 +102,8 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
tex = new Texturec(1,"assets/NPC.png");
inv = new Inventory(NPC_INV_SIZE);
+
+ randDialog = rand() % 10 - 1;
}
NPC::~NPC(){
while(!aiFunc.empty()){
@@ -146,7 +148,7 @@ Mob::Mob(int sub){
height = HLINE * 8;
tex = new Texturec(1, "assets/robin.png");
case MS_TRIGGER:
- width = HLINE * 8;
+ width = HLINE * 20;
height = 2000;
tex = new Texturec(0);
break;
@@ -307,22 +309,43 @@ void NPC::addAIFunc(int (*func)(NPC *),bool preload){
else aiFunc.push_back(func);
}
+const char *randomDialog[] = {
+ "What a beautiful day it is.",
+ "Have you ever went fast? I have.",
+ "I heard if you complete a quest, you'll get a special reward.",
+ "How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
+ "I don\'t think anyone has ever been able to climb up that hill.",
+ "If you ever see a hole in the ground, watch out; it could mean the end for you.",
+ "Did you know this game has over 4000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
+ "HELP MY CAPS LOCK IS STUCK",
+ "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
+ "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment."
+};
+
void NPC::interact(){ //have the npc's interact back to the player
int (*func)(NPC *);
loc.y += 5;
+
+ canMove=false;
+ left = (player->loc.x < loc.x);
+ right = !left;
+
if(aiFunc.size()){
func=aiFunc.front();
- canMove=false;
+
if(!func(this)){
if(aiFunc.size())aiFunc.erase(aiFunc.begin());
}
- canMove=true;
+ }else{
+ ui::dialogBox(name,NULL,false,randomDialog[randDialog]);
}
+ ui::waitForDialog();
+ canMove=true;
}
void Object::interact(void){
if(questObject && alive){
- ui::dialogBox("You",":Yes:No",pickupDialog);
+ ui::dialogBox(player->name,":Yes:No",false,pickupDialog);
ui::waitForDialog();
if(ui::dialogOptChosen == 1){
player->inv->addItem((ITEM_ID)(identifier), (char)1);
@@ -411,8 +434,6 @@ void Mob::wander(int timeRun){
case MS_TRIGGER:
if(player->loc.x + player->width / 2 > loc.x &&
player->loc.x + player->width / 2 < loc.x + width ){
- if(player->left)player->loc.x = loc.x + width;
- else if(player->right) player->loc.x = loc.x - player->width;
hey(this);
}
break;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 856b397..a9d29c4 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -1,144 +1,132 @@
#include <common.h>
+#include <entities.h>
#include <world.h>
#include <ui.h>
-#include <entities.h>
extern World *currentWorld;
extern Player *player;
-int compTestQuest(NPC *speaker){
- ui::dialogBox(speaker->name,NULL,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
- player->qh.finish("Test",player);
- return 0;
+/*
+ * int (npc*)
+ *
+ * dialog
+ * wait...
+ *
+ * switch optchosen
+ *
+ * qh.assign
+ * addAIFunc?
+ *
+ * return 1 = repeat
+ */
+
+void story(Mob *callee){
+ player->vel.x = 0;
+ Mix_FadeOutMusic(0);
+ ui::importantText("It was a dark and stormy night...");
+ ui::waitForDialog();
+ callee->alive = false;
+}
+
+float gen_worldSpawnHill1(float x){
+ return (float)(pow(2,(-x+200)/5) + GEN_MIN);
}
-int giveTestQuest(NPC *speaker){
- ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!");
- ui::waitForDialog();
-
- if(ui::dialogOptChosen == 1){
-
- ui::dialogBox(speaker->name,"","Have a good day! :)");
- ui::waitForDialog();
-
- player->qh.assign("Test");
- currentWorld->npc[1]->addAIFunc(compTestQuest,true);
-
- }else return 1;
-
- return 0;
+float gen_worldSpawnHill3(float x){
+ float tmp = 60*atan(-(x/30-20))+GEN_MIN*2;
+ return tmp>GEN_MIN?tmp:GEN_MIN;
}
-void CUTSCENEEE(Mob *callee){
+/*
+ * Thing-thangs
+ */
+
+void worldSpawnHill1_hillBlock(Mob *callee){
player->vel.x = 0;
-
- ui::dialogBox(player->name,":K then","No way I\'m gettin\' up this hill.");
- ui::waitForDialog();
+ player->loc.x = callee->loc.x + callee->width;
+ ui::dialogBox(player->name,NULL,false,"This hill seems to steep to climb up...");
+ callee->alive = true;
+}
- player->right = true;
- player->left = false;
- player->loc.x += HLINE * 5;
-
+void worldSpawnHill2_infoSprint(Mob *callee){
+ ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
callee->alive = false;
}
-void CUTSCENEEE2(Mob *callee){
- player->vel.x = 0;
- ui::dialogBox(player->name,":Yeah.",
- "What the fuck is this dead end supposed to mean, and why this place smell like soap.");
- ui::waitForDialog();
+void worldSpawnHill3_itemGet(Mob *callee){
+ ui::dialogBox("B-) ",NULL,true,"Right click to pick up items!");
callee->alive = false;
}
-void story(Mob *callee){
- player->vel.x = 0;
- ui::importantText("It was a dark and stormy night...");
- ui::waitForDialog();
+void worldSpawnHill3_itemSee(Mob *callee){
+ ui::dialogBox("B-) ",NULL,true,"Press \'e\' to open your inventory!");
callee->alive = false;
}
-float playerSpawnHillFunc(float x){
- return (float)(pow(2,(-x+200)/5) + 80);
+void worldSpawnHill3_leave(Mob *callee){
+ ui::dialogBox("B-) ",NULL,true,"Now jump in this hole, and let your journey begin :)");
+ callee->alive = false;
}
-static World *test;
-static World *playerSpawnHill;
-static IndoorWorld *iw;
+/*
+ * new world
+ * gen
+ * setbackground
+ * setbgm
+ * add...
+ *
+ */
-void destroyEverything(void);
+/*
+ * World definitions
+ */
+
+static World *worldSpawnHill1;
+static World *worldSpawnHill2;
+static World *worldSpawnHill3;
+/*
+ * initEverything() start
+ */
+
+void destroyEverything(void);
void initEverything(void){
- //FILE *load;
-
- /*
- * World creation:
- */
-
- test=new World();
-
- test->generate(SCREEN_WIDTH*2);
- test->setBackground(BG_FOREST);
- test->setBGM("assets/music/embark.wav");
-
- test->addHole(100,150);
- test->addLayer(400);
-
- playerSpawnHill=new World();
- playerSpawnHill->setBackground(BG_FOREST);
- playerSpawnHill->setBGM("assets/music/embark.wav");
-
- /*if((load=fopen("world.dat","rb"))){
- playerSpawnHill->load(load);
- fclose(load);
- }else{*/
- playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
- //}
-
- /*
- * Setup the current world, making the player initially spawn in `test`.
- */
-
- currentWorld=playerSpawnHill;
-
- playerSpawnHill->toRight=test;
- test->toLeft=playerSpawnHill;
-
- /*
- * Create the player.
- */
+
+ worldSpawnHill1 = new World();
+ worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
+ worldSpawnHill1->setBackground(BG_FOREST);
+ worldSpawnHill1->setBGM("assets/music/embark.wav");
+ worldSpawnHill1->addMob(MS_TRIGGER,0,0,worldSpawnHill1_hillBlock);
+
+ worldSpawnHill2 = new World();
+ worldSpawnHill2->generate(700);
+ worldSpawnHill2->setBackground(BG_FOREST);
+ worldSpawnHill2->setBGM("assets/music/embark.wav");
+ worldSpawnHill2->addMob(MS_TRIGGER,-400,0,worldSpawnHill2_infoSprint);
- player=new Player();
- player->spawn(-1000,200);
+ worldSpawnHill3 = new World();
+ worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
+ worldSpawnHill3->setBackground(BG_FOREST);
+ worldSpawnHill3->setBGM("assets/music/embark.wav");
+ worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet);
+ worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee);
+ worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300);
+ worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave);
+ worldSpawnHill3->addHole(800,1000);
- /*
- * Create a structure (this will create villagers when spawned).
- */
+ worldSpawnHill1->toRight = worldSpawnHill2;
+ worldSpawnHill2->toLeft = worldSpawnHill1;
- iw=new IndoorWorld();
- iw->setBackground(BG_WOODHOUSE);
- iw->generate(200);
- iw->addMob(MS_TRIGGER,0,0,CUTSCENEEE2);
+ worldSpawnHill2->toRight = worldSpawnHill3;
+ worldSpawnHill3->toLeft = worldSpawnHill2;
- /*
- * Spawn some entities.
- */
-
- playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story);
-
- playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),100,test,iw);
- playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
+ currentWorld = worldSpawnHill1;
- playerSpawnHill->addObject(SWORD_WOOD, false, "", 480,200);
- playerSpawnHill->addObject(FLASHLIGHT, false, "", 500,200);
- playerSpawnHill->addObject(PLAYER_BAG, false, "", 520,200);
- playerSpawnHill->addObject(TEST_ITEM, false, "", 540,200);
+ player = new Player();
+ player->spawn(200,100);
- test->addMob(MS_RABBIT,200,100);
- test->addMob(MS_BIRD,-500,500);
+ currentWorld->bgmPlay(NULL);
- playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
-
- currentWorld->bgmPlay();
atexit(destroyEverything);
}
@@ -146,21 +134,8 @@ extern std::vector<int (*)(NPC *)> AIpreload;
extern std::vector<NPC *> AIpreaddr;
void destroyEverything(void){
- //FILE *save;
-
- /*save = fopen("world.dat","wb");
- playerSpawnHill->save(save);
- fclose(save);*/
-
- delete test;
- delete playerSpawnHill;
-
- while(!AIpreload.empty()){
+ while(!AIpreload.empty())
AIpreload.pop_back();
- }
- while(!AIpreaddr.empty()){
+ while(!AIpreaddr.empty())
AIpreaddr.pop_back();
- }
-
- //delete iw; // segfaults
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index c1595e8..8d8f958 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -10,6 +10,7 @@ static float hangle = 0.0f;
static bool up = true;
static float xc,yc;
static vec2 itemLoc;
+Mix_Chunk* swordSwing;
static const Item item[ITEM_COUNT]= {
#include "../config/items.h"
@@ -23,6 +24,9 @@ void initInventorySprites(void){
for(i = 0;i < ITEM_COUNT;i++){
itemtex[i] = Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
}
+
+ swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
+ Mix_Volume(2,75);
}
char *getItemTexturePath(ITEM_ID id){
@@ -311,11 +315,11 @@ int Inventory::useItem(void){
switch(type){
case SWORD:
if(!player->left){
- if(hangle==-15)up=true;
+ if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle-=15;
if(hangle<=-90)hangle=-14;
}else{
- if(hangle==15)up=true;
+ if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle+=15;
if(hangle>=90)hangle=14;
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 6fa2770..26b30c4 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -48,9 +48,10 @@ static char dialogBoxText[512];
static char *dialogOptText[4];
static float dialogOptLoc[4][3];
static unsigned char dialogOptCount = 0;
+static bool dialogPassive = false;
static bool typeOutDone = true;
-static bool dialogImportant = false;
+Mix_Chunk *dialogClick;
extern void mainLoop(void);
@@ -59,6 +60,8 @@ extern void mainLoop(void);
*/
bool fadeEnable = false;
+bool fadeWhite = false;
+bool fadeFast = false;
unsigned int fadeIntensity = 0;
bool inBattle = false;
@@ -87,7 +90,8 @@ namespace ui {
* Dialog stuff that needs to be 'public'.
*/
- bool dialogBoxExists=false;
+ bool dialogBoxExists = false;
+ bool dialogImportant = false;
unsigned char dialogOptChosen = 0;
/*
@@ -111,6 +115,8 @@ namespace ui {
#ifdef DEBUG
DEBUG_printf("Initialized FreeType2.\n",NULL);
#endif // DEBUG
+ dialogClick = Mix_LoadWAV("assets/click.wav");
+ Mix_Volume(1,50);
}
/*
@@ -341,7 +347,8 @@ namespace ui {
if(linc<size)
linc++;
- else typeOutDone = true;
+ else
+ typeOutDone = true;
}
return ret; // The buffered string.
@@ -380,11 +387,13 @@ namespace ui {
return width;
}
- void dialogBox(const char *name,const char *opt,const char *text,...){
+ void dialogBox(const char *name,const char *opt,bool passive,const char *text,...){
va_list dialogArgs;
unsigned int len;
char *sopt,*soptbuf;
+ dialogPassive = passive;
+
/*
* Set up the text buffer.
*/
@@ -417,7 +426,7 @@ namespace ui {
};
dialogOptChosen=0;
- dialogOptCount=0;
+ memset(&dialogOptLoc,0,sizeof(float)*12);
if(opt){
@@ -448,6 +457,11 @@ namespace ui {
mainLoop();
}while(ui::dialogBoxExists);
}
+ void waitForCover(void){
+ do{
+ mainLoop();
+ }while(fadeIntensity != 255);
+ }
void importantText(const char *text,...){
va_list textArgs;
@@ -516,8 +530,12 @@ namespace ui {
}
setFontColor(255,255,255);
}
- }else if(!dialogImportant){
-
+
+ if(strcmp(rtext,dialogBoxText)){
+ Mix_PlayChannel(1,dialogClick,0);
+ }
+
+ }else if(!dialogImportant && !fadeIntensity){
vec2 hub = {
(SCREEN_WIDTH/2+offset.x)-fontSize*10,
(offset.y+SCREEN_HEIGHT/2)-fontSize
@@ -551,11 +569,34 @@ namespace ui {
}
}
}
+ void dialogAdvance(void){
+ unsigned char i;
+ if(!typeOutDone){
+ typeOutDone = true;
+ return;
+ }
+
+ for(i=0;i<dialogOptCount;i++){
+ if(mouse.x > dialogOptLoc[i][0] &&
+ mouse.x < dialogOptLoc[i][2] &&
+ mouse.y > dialogOptLoc[i][1] &&
+ mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
+ dialogOptChosen = i + 1;
+ goto DONE;
+ }
+ }
+DONE:
+ if(dialogImportant){
+ dialogImportant = false;
+ setFontSize(16);
+ toggleBlack();
+ }
+ dialogBoxExists = false;
+ }
void handleEvents(void){
static bool left=true,right=false;
static vec2 premouse={0,0};
static int heyOhLetsGo = 0;
- unsigned char i;
World *tmp;
SDL_Event e;
@@ -573,28 +614,10 @@ namespace ui {
break;
case SDL_MOUSEBUTTONDOWN:
if((e.button.button&SDL_BUTTON_RIGHT)&&dialogBoxExists){
-
- if(!typeOutDone){
- typeOutDone = true;
- break;
- }
-
- for(i=0;i<dialogOptCount;i++){
- if(mouse.x > dialogOptLoc[i][0] &&
- mouse.x < dialogOptLoc[i][2] &&
- mouse.y > dialogOptLoc[i][1] &&
- mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
- dialogOptChosen = i + 1;
- goto DONE;
- }
- }
-DONE:
- if(dialogImportant){
- dialogImportant = false;
- setFontSize(16);
- toggleBlack();
- }
- dialogBoxExists = false;
+ dialogAdvance();
+ }
+ if((e.button.button&SDL_BUTTON_LEFT)&&!dialogBoxExists){
+ player->inv->usingi = true;
}
break;
/*
@@ -603,12 +626,19 @@ DONE:
case SDL_KEYDOWN:
if(SDL_KEY == SDLK_ESCAPE){
gameRunning = false;
+ return;
+ }else if(SDL_KEY == SDLK_SPACE){
+ if(dialogBoxExists)
+ dialogAdvance();
+ else if(player->ground){
+ player->vel.y=.4;
+ player->loc.y+=HLINE*2;
+ player->ground=false;
+ }
break;
- }else if(!dialogBoxExists){//&&!fadeEnable){
+ }else if(!dialogBoxExists || dialogPassive){
+ tmp = currentWorld;
switch(SDL_KEY){
- case SDLK_ESCAPE:
- gameRunning=false;
- break;
case SDLK_a:
player->vel.x=-.15;
player->left = true;
@@ -616,6 +646,8 @@ DONE:
left = true;
right = false;
currentWorld=currentWorld->goWorldLeft(player);
+ if(tmp!=currentWorld)
+ dialogBoxExists = false;
break;
case SDLK_d:
player->vel.x=.15;
@@ -624,6 +656,8 @@ DONE:
left = false;
right = true;
currentWorld=currentWorld->goWorldRight(player);
+ if(tmp!=currentWorld)
+ dialogBoxExists = false;
break;
case SDLK_s:
if(player->ground == 2){
@@ -636,15 +670,7 @@ DONE:
currentWorld=((Arena *)currentWorld)->exitArena(player);
else currentWorld=currentWorld->goInsideStructure(player);
break;
- case SDLK_SPACE:
- if(player->ground){
- player->vel.y=.4;
- player->loc.y+=HLINE*2;
- player->ground=false;
- }
- break;
case SDLK_i:
- tmp=currentWorld;
currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
if(tmp!=currentWorld){
currentWorld->detect(player);
@@ -654,17 +680,22 @@ DONE:
}
break;
case SDLK_k:
- tmp=currentWorld;
currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
if(tmp!=currentWorld){
- player->loc.y=0;
currentWorld->behind->detect(player);
player->vel.y=.2;
+ player->loc.y+=HLINE*5;
player->ground=false;
}
break;
case SDLK_LSHIFT:
- player->speed = debug ? 4.0f : 3.0f;
+ if(debug){
+ Mix_Chunk *sanic;
+ sanic = Mix_LoadWAV("assets/sounds/sanic.wav");
+ Mix_PlayChannel(1,sanic,-1);
+ player->speed = 4.0f;
+ }else
+ player->speed = 2.0f;
break;
case SDLK_LCTRL:
player->speed = .5;
@@ -702,6 +733,9 @@ DONE:
right = false;
break;
case SDLK_LSHIFT:
+ if(player->speed == 4){
+ Mix_FadeOutChannel(1,2000);
+ }
player->speed = 1;
break;
case SDLK_LCTRL:
@@ -748,5 +782,17 @@ DONE:
void toggleBlack(void){
fadeEnable ^= true;
+ fadeWhite = false;
+ fadeFast = false;
+ }
+ void toggleBlackFast(void){
+ fadeEnable ^= true;
+ fadeWhite = false;
+ fadeFast = true;
+ }
+ void toggleWhite(void){
+ fadeEnable ^= true;
+ fadeWhite = true;
+ fadeFast = false;
}
}
diff --git a/src/world.cpp b/src/world.cpp
index 2bceba5..3f35e21 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -1,9 +1,8 @@
#include <world.h>
+#include <ui.h>
#define getWidth(w) ((w->lineCount-GEN_INC)*HLINE) // Calculates the width of world 'w'
-#define GEN_MIN 80
-#define GEN_MAX 110
#define GEN_INIT 60
#define GRASS_HEIGHT 4 // Defines how long the grass layer of a line should be in multiples of HLINE.
@@ -40,7 +39,13 @@ const float bgDraw[3][3]={
};
float worldGetYBase(World *w){
- return w?GEN_MIN:0;
+ World *tmp = w;
+ float base = GEN_MIN;
+ while(tmp->infront){
+ tmp = tmp->infront;
+ base -= DRAW_Y_OFFSET;
+ }
+ return base;
}
void World::setBackground(WORLD_BG_TYPE bgt){
@@ -105,9 +110,13 @@ void World::deleteEntities(void){
}
World::~World(void){
- if(behind)
+ if(behind != NULL)
delete behind;
+ if(bgmObj)
+ Mix_FreeMusic(bgmObj);
+ if(bgm)
+ delete[] bgm;
delete bgTex;
delete[] star;
delete[] line;
@@ -271,6 +280,9 @@ void World::update(Player *p,unsigned int delta){
p->loc.y += p->vel.y * delta;
p->loc.x +=(p->vel.x * p->speed) * delta;
+ if(p->inv->usingi){
+ p->inv->useItem();
+ }
/*
* Update coordinates of all entities except for structures.
@@ -284,33 +296,33 @@ void World::update(Player *p,unsigned int delta){
else if(e->vel.x > 0)e->left = false;
}
}
+
+ if(ui::dialogImportant){
+ Mix_FadeOutMusic(2000);
+ }else if(!Mix_PlayingMusic()){
+ Mix_FadeInMusic(bgmObj,-1,2000);
+ }
}
void World::setBGM(const char *path){
if(!bgm) delete[] bgm;
- //if(!path){
+ if(path != NULL){
bgm = new char[strlen(path) + 1];
strcpy(bgm,path);
bgmObj = Mix_LoadMUS(bgm);
- //}else std::cout<<path;
-}
-
-static Mix_Music *bgmC;
-
-void World::bgmPlay(void){
- if(bgmObj && bgmC != bgmObj){
- Mix_VolumeMusic(15);
- Mix_PlayMusic(bgmObj,-1); // Loop infinitely
- bgmC = bgmObj;
+ }else{
+ bgm = new char[1];
+ bgm[0] = '\0';
}
}
-void World::bgmStop(void){
- if(bgmObj){
- if(bgmC != bgmObj){
- Mix_FreeMusic(bgmObj);
- }
- }
+void World::bgmPlay(World *prev){
+ if(!prev || strcmp(bgm,prev->bgm)){
+ Mix_VolumeMusic(50);
+ Mix_PlayMusic(bgmObj,-1); // Loop infinitely
+ }/*else{
+ Mix_FadeOutMusic(800);
+ }*/
}
int worldShade = 0;
@@ -321,38 +333,47 @@ extern unsigned int tickCount;
void World::draw(Player *p){
static float yoff=DRAW_Y_OFFSET; // Initialize stuff
static int shade,bgshade;
- static World *current;
+ static World *current=this;
unsigned int i;
int is,ie,v_offset,cx_start,width;
struct line_t *cline;
+ float base;
bgshade = worldShade << 1; // *2
- width = (-x_start) << 1;
+ base = worldGetYBase(this);
/*
* Draw the background images in the appropriate order.
*/
+LLLOOP:
+ if(current->infront){
+ current=current->infront;
+ goto LLLOOP;
+ }
+ cx_start = current->x_start;
+ width = (-x_start) << 1;
+
glEnable(GL_TEXTURE_2D);
bgTex->bind(0);
safeSetColorA(255,255,255,255 - worldShade * 4);
glBegin(GL_QUADS);
- glTexCoord2i(0,0);glVertex2i( x_start,SCREEN_HEIGHT);
- glTexCoord2i(1,0);glVertex2i(-x_start,SCREEN_HEIGHT);
- glTexCoord2i(1,1);glVertex2i(-x_start,0);
- glTexCoord2i(0,1);glVertex2i( x_start,0);
+ glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
+ glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
+ glTexCoord2i(1,1);glVertex2i(-cx_start,0);
+ glTexCoord2i(0,1);glVertex2i( cx_start,0);
glEnd();
bgTex->bindNext();
safeSetColorA(255,255,255,worldShade * 4);
glBegin(GL_QUADS);
- glTexCoord2i(0,0);glVertex2i( x_start,SCREEN_HEIGHT);
- glTexCoord2i(1,0);glVertex2i(-x_start,SCREEN_HEIGHT);
- glTexCoord2i(1,1);glVertex2i(-x_start,0);
- glTexCoord2i(0,1);glVertex2i( x_start,0);
+ glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
+ glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
+ glTexCoord2i(1,1);glVertex2i(-cx_start,0);
+ glTexCoord2i(0,1);glVertex2i( cx_start,0);
glEnd();
glDisable(GL_TEXTURE_2D);
@@ -389,10 +410,10 @@ void World::draw(Player *p){
glBegin(GL_QUADS);
for(int i = 0; i <= width/1920; i++){
- glTexCoord2i(0,1);glVertex2i(width/-2+(1920*i )+offset.x*.85,GEN_MIN);
- glTexCoord2i(1,1);glVertex2i(width/-2+(1920*(i+1))+offset.x*.85,GEN_MIN);
- glTexCoord2i(1,0);glVertex2i(width/-2+(1920*(i+1))+offset.x*.85,GEN_MIN+1080);
- glTexCoord2i(0,0);glVertex2i(width/-2+(1920*i )+offset.x*.85,GEN_MIN+1080);
+ glTexCoord2i(0,1);glVertex2i(width/-2+(1920*i )+offset.x*.85,base);
+ glTexCoord2i(1,1);glVertex2i(width/-2+(1920*(i+1))+offset.x*.85,base);
+ glTexCoord2i(1,0);glVertex2i(width/-2+(1920*(i+1))+offset.x*.85,base+1080);
+ glTexCoord2i(0,0);glVertex2i(width/-2+(1920*i )+offset.x*.85,base+1080);
}
glEnd();
@@ -405,11 +426,11 @@ void World::draw(Player *p){
safeSetColorA(bgDraw[i][0]-bgshade,bgDraw[i][0]-bgshade,bgDraw[i][0]-bgshade,bgDraw[i][1]);
glBegin(GL_QUADS);
- for(int j = x_start; j <= -x_start; j += 600){
- glTexCoord2i(0,1);glVertex2i( j +offset.x*bgDraw[i][2],GEN_MIN);
- glTexCoord2i(1,1);glVertex2i((j+600)+offset.x*bgDraw[i][2],GEN_MIN);
- glTexCoord2i(1,0);glVertex2i((j+600)+offset.x*bgDraw[i][2],GEN_MIN+400);
- glTexCoord2i(0,0);glVertex2i( j +offset.x*bgDraw[i][2],GEN_MIN+400);
+ for(int j = cx_start; j <= -cx_start; j += 600){
+ glTexCoord2i(0,1);glVertex2i( j +offset.x*bgDraw[i][2],base);
+ glTexCoord2i(1,1);glVertex2i((j+600)+offset.x*bgDraw[i][2],base);
+ glTexCoord2i(1,0);glVertex2i((j+600)+offset.x*bgDraw[i][2],base+400);
+ glTexCoord2i(0,0);glVertex2i( j +offset.x*bgDraw[i][2],base+400);
}
glEnd();
}
@@ -490,9 +511,7 @@ LOOP2:
*/
for(auto &b : current->build){
- b->loc.y+=(yoff-DRAW_Y_OFFSET);
b->draw();
- b->loc.y-=(yoff-DRAW_Y_OFFSET);
}
/*
@@ -504,7 +523,7 @@ LOOP2:
for(i=is;i<(unsigned)ie-GEN_INC;i++){
cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
if(!cline[i].y){
- cline[i].y+=50;
+ cline[i].y=base;
hey=true;
safeSetColor(cline[i].color-100+shade,cline[i].color-150+shade,cline[i].color-200+shade);
}else{
@@ -748,29 +767,33 @@ void World::singleDetect(Entity *e){
* Check that the entity isn't trying to run through a wall.
*/
- if(e->loc.y + e->height > line[i-(int)e->width/2/HLINE].y &&
- e->loc.y + e->height > line[i+(int)e->width/2/HLINE].y ){
+ //if(e->loc.y + e->height > line[i-(int)e->width/2/HLINE].y &&
+ // e->loc.y + e->height > line[i+(int)e->width/2/HLINE].y ){
e->loc.y=line[i].y - .001 * deltaTime;
e->ground=true;
e->vel.y=0;
- }else{
+ //}else{
/*
* Push the entity out of the wall if it's trying to go through it.
*/
- do{
+ /*do{
e->loc.x+=.001 * e->vel.x>0?-1:1;
l=(e->loc.x - e->width / 2 - x_start) / HLINE;
- if(l < 0){ e->alive = false; return; }
+ if(l < 0){
+ std::cout<<"push kill lol "<<e->type<<std::endl;
+ e->alive = false; return; }
i = l;
- if(i > lineCount-1){ e->alive = false; return; }
+ if(i > lineCount-1){
+ std::cout<<"push kill lol "<<e->type<<std::endl;
+ e->alive = false; return; }
}while(line[i].y>e->loc.y+ e->height);
- }
+ }*/
/*
* Handle gravity if the entity is above the line.
@@ -778,8 +801,13 @@ void World::singleDetect(Entity *e){
}else{
- if(e->vel.y > -2)e->vel.y-=.003 * deltaTime;
-
+ if(e->type == STRUCTURET && e->loc.y > 2000){
+ e->loc.y = line[i].y;
+ e->vel.y = 0;
+ e->ground = true;
+ return;
+ }else if(e->vel.y > -2)e->vel.y-=.003 * deltaTime;
+
}
/*
@@ -801,6 +829,7 @@ void World::singleDetect(Entity *e){
}
void World::detect(Player *p){
+ World *hey = this;
/*
* Handle the player.
@@ -812,8 +841,13 @@ void World::detect(Player *p){
* Handle all remaining entities in this world.
*/
- for(auto &e : entity)
- singleDetect(e);
+LOOOOP:
+ for(auto &e : hey->entity)
+ hey->singleDetect(e);
+ if(hey->infront){
+ hey = hey->infront;
+ goto LOOOOP;
+ }
}
void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){
@@ -824,18 +858,6 @@ void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){
entity.push_back(build.back());
}
-
-/*template<class T>
-void World::getEntityLocation(std::vector<T*>&vecBuf, unsigned int n){
- T bufVar = vecBuf.at(n);
- unsigned int i = 0;
- for(auto &e : entity){
- if(entity.at(i) == bufVar){
- entity.erase(entity.begin()+i);
- }
- i++;
- }
-}*/
void World::addMob(int t,float x,float y){
mob.push_back(new Mob(t));
@@ -882,6 +904,9 @@ void World::addLayer(unsigned int width){
behind=new World();
behind->generate(width);
behind->infront=this;
+ behind->star=star;
+ behind->bgmObj=bgmObj;
+ behind->bgTex=bgTex;
}
World *World::goWorldLeft(Player *p){
@@ -923,6 +948,9 @@ World *World::goInsideStructure(Player *p){
if(p->loc.x > b->loc.x &&
p->loc.x + p->width < b->loc.x + b->width ){
thing.push_back(this);
+ ui::toggleBlackFast();
+ ui::waitForCover();
+ ui::toggleBlackFast();
return (World *)b->inside;
}
}
@@ -932,6 +960,9 @@ World *World::goInsideStructure(Player *p){
World *tmp = (World *)thing.back();
p->loc.x = b->loc.x + (b->width / 2) - (p->width / 2);
thing.erase(thing.end()-1);
+ ui::toggleBlackFast();
+ ui::waitForCover();
+ ui::toggleBlackFast();
return tmp;
}
}