@@ -48,9 +48,17 @@ void worldSpawnHill1_hillBlock(Mob *callee){
callee->alive = true;
}

static Arena *a;
void worldSpawnHill2_infoSprint(Mob *callee){
ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
callee->alive = false;
a = new Arena(currentWorld,player);
a->setBackground(BG_FOREST);
a->setBGM("assets/music/embark.wav");
ui::toggleWhiteFast();
ui::waitForCover();
currentWorld = a;
ui::toggleWhiteFast();
//ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
}

void worldSpawnHill3_itemGet(Mob *callee){
@@ -103,7 +111,7 @@ void initEverything(void){
worldSpawnHill2->setBackground(BG_FOREST);
worldSpawnHill2->setBGM("assets/music/embark.wav");
worldSpawnHill2->addMob(MS_TRIGGER,-400,0,worldSpawnHill2_infoSprint);

worldSpawnHill3 = new World();
worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
worldSpawnHill3->setBackground(BG_FOREST);
@@ -116,10 +124,23 @@ void initEverything(void){

worldSpawnHill1->toRight = worldSpawnHill2;
worldSpawnHill2->toLeft = worldSpawnHill1;

worldSpawnHill2->toRight = worldSpawnHill3;
worldSpawnHill3->toLeft = worldSpawnHill2;


/*
* Spawn some entities.
*/

//playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story);

//worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
//playerSpawnHill->addStructure(STRUCTURET,FOUNTAIN,(rand()%120*HLINE)+100*HLINE,100,test,iw);
//playerSpawnHill->addStructure(STRUCTURET,HOUSE2,(rand()%120*HLINE)+300*HLINE,100,test,iw);

//playerSpawnHill->addVillage(5,1,4,STRUCTURET,rand()%500+120,(float)200,playerSpawnHill,iw);
//playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/


currentWorld = worldSpawnHill1;

player = new Player();
@@ -7,7 +7,7 @@
extern Player *player;
extern GLuint invUI;
static float hangle = 0.0f;
static bool up = true;
static bool swing = false;
static float xc,yc;
static vec2 itemLoc;
Mix_Chunk* swordSwing;
@@ -26,7 +26,7 @@ void initInventorySprites(void){
}

swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
Mix_Volume(2,75);
Mix_Volume(2,100);
}

char *getItemTexturePath(ITEM_ID id){
@@ -278,13 +278,13 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
if(hangle < 15){
hangle=15.0f;
p->inv->usingi = false;
up = false;
//swing=false;
}
}else{
if(hangle > -15){
hangle=-15.0f;
p->inv->usingi = false;
up = false;
//swing=false;
}
}
break;
@@ -310,19 +310,35 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
}

int Inventory::useItem(void){
static bool up = false;
ITEM_TYPE type = item[inv[sel].id].type;
if(!invHover){
switch(type){
case SWORD:
if(!player->left){
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;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle+=15;
if(hangle>=90)hangle=14;
}
if(swing){
if(!player->left){
if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle-=.75*deltaTime;
if(hangle<=-90)hangle=-14;
}else{
if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);}
if(up)hangle+=.75*deltaTime;
if(hangle>=90)hangle=14;
/*
if(hangle<90&&!up)hangle+=.75*deltaTime;
if(hangle>=90&&!up)up=true;
if(up)hangle-=.75*deltaTime;
if(up&&hangle<=15){
up=false;
swing=false;
hangle=15;
return 0;
}*/
}
}else if(!swing){
swing=true;
Mix_PlayChannel(2,swordSwing,0);
}
break;
default:
break;
@@ -65,6 +65,7 @@ bool fadeFast = false;
unsigned int fadeIntensity = 0;

bool inBattle = false;
Mix_Chunk *battleStart;

namespace ui {

@@ -460,7 +461,8 @@ namespace ui {
void waitForCover(void){
do{
mainLoop();
}while(fadeIntensity != 255);
}while(fadeIntensity < 255);
fadeIntensity = 255;
}
void importantText(const char *text,...){
va_list textArgs;
@@ -598,6 +600,7 @@ namespace ui {
static vec2 premouse={0,0};
static int heyOhLetsGo = 0;
World *tmp;
vec2 oldpos,tmppos;
SDL_Event e;

mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
@@ -628,9 +631,9 @@ namespace ui {
gameRunning = false;
return;
}else if(SDL_KEY == SDLK_SPACE){
if(dialogBoxExists)
/*if(dialogBoxExists)
dialogAdvance();
else if(player->ground){
else */if(player->ground){
player->vel.y=.4;
player->loc.y+=HLINE*2;
player->ground=false;
@@ -640,35 +643,65 @@ namespace ui {
tmp = currentWorld;
switch(SDL_KEY){
case SDLK_a:
if(fadeEnable)break;
player->vel.x=-.15;
player->left = true;
player->right = false;
left = true;
right = false;
currentWorld=currentWorld->goWorldLeft(player);
if(tmp!=currentWorld)
dialogBoxExists = false;
if(currentWorld->isWorldLeft()){
memcpy(&oldpos,&player->loc,sizeof(vec2));
tmp = currentWorld->goWorldLeft(player);
if(currentWorld != tmp){
memcpy(&tmppos,&player->loc,sizeof(vec2));
memcpy(&player->loc,&oldpos,sizeof(vec2));
toggleBlackFast();
waitForCover();
memcpy(&player->loc,&tmppos,sizeof(vec2));
currentWorld = tmp;
toggleBlackFast();
dialogBoxExists = false;
}
}
break;
case SDLK_d:
if(fadeEnable)break;
player->vel.x=.15;
player->right = true;
player->left = false;
left = false;
right = true;
currentWorld=currentWorld->goWorldRight(player);
if(tmp!=currentWorld)
dialogBoxExists = false;
if(currentWorld->isWorldRight()){
memcpy(&oldpos,&player->loc,sizeof(vec2));
tmp = currentWorld->goWorldRight(player);
if(currentWorld != tmp){
memcpy(&tmppos,&player->loc,sizeof(vec2));
memcpy(&player->loc,&oldpos,sizeof(vec2));
toggleBlackFast();
waitForCover();
memcpy(&player->loc,&tmppos,sizeof(vec2));
currentWorld = tmp;
toggleBlackFast();
dialogBoxExists = false;
}
}
break;
case SDLK_s:
if(player->ground == 2){
/*if(player->ground == 2){
player->ground=false;
player->loc.y-=HLINE*1.5;
}
}*/
break;
case SDLK_w:
if(inBattle)
currentWorld=((Arena *)currentWorld)->exitArena(player);
else currentWorld=currentWorld->goInsideStructure(player);
if(inBattle){
tmp = currentWorld;
currentWorld = ((Arena *)currentWorld)->exitArena(player);
if(tmp != currentWorld){
//delete &tmp;
toggleBlackFast();
}
}else
currentWorld=currentWorld->goInsideStructure(player);
break;
case SDLK_i:
currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
@@ -718,6 +751,13 @@ namespace ui {
default:
break;
}
if(tmp != currentWorld){
std::swap(tmp,currentWorld);
toggleBlackFast();
waitForCover();
std::swap(tmp,currentWorld);
toggleBlackFast();
}
}
break;
/*
@@ -795,4 +835,11 @@ namespace ui {
fadeWhite = true;
fadeFast = false;
}
void toggleWhiteFast(void){
fadeEnable ^= true;
fadeWhite = true;
fadeFast = true;
battleStart = Mix_LoadWAV("assets/sounds/frig.wav");
Mix_PlayChannel(1,battleStart,0);
}
}
@@ -106,7 +106,13 @@ void World::deleteEntities(void){
delete object.back();
object.pop_back();
}
while(!entity.empty()) entity.pop_back();
while(!entity.empty()){
entity.pop_back();
}
while(!particles.empty()){
delete particles.back();
particles.pop_back();
}
}

World::~World(void){
@@ -296,6 +302,28 @@ void World::update(Player *p,unsigned int delta){
else if(e->vel.x > 0)e->left = false;
}
}
uint oh = 0;
for(auto &pa : particles){
if(pa->kill(deltaTime)){
delete pa;
particles.erase(particles.begin()+oh);
}else if(pa->canMove){
pa->loc.y += pa->vely * deltaTime;
pa->loc.x += pa->velx * deltaTime;

for(auto &b : build){
if(b->bsubtype==FOUNTAIN){
if(pa->loc.x >= b->loc.x && pa->loc.x <= b->loc.x+b->width){
if(pa->loc.y <= b->loc.y + b->height*.25){
delete pa;
particles.erase(particles.begin()+oh);
}
}
}
}
}
oh++;
}oh=0;

if(ui::dialogImportant){
Mix_FadeOutMusic(2000);
@@ -351,7 +379,7 @@ void World::draw(Player *p){
current=current->infront;
goto LLLOOP;
}
cx_start = current->x_start;
cx_start = current->x_start * 1.5;
width = (-x_start) << 1;

glEnable(GL_TEXTURE_2D);
@@ -437,6 +465,9 @@ void World::draw(Player *p){

glDisable(GL_TEXTURE_2D);

glColor3ub(0,0,0);
glRectf(cx_start,GEN_MIN,-cx_start,0);

/*
* World drawing is done recursively, meaning that this function jumps
* back as many 'layers' as it can and then draws, eventually coming
@@ -592,7 +623,7 @@ void World::draw(Player *p){
/*
* Draw non-structure entities.
*/
for(auto &part : particles){part->draw();}
for(auto &n : current->npc){
n->loc.y+=(yoff-DRAW_Y_OFFSET);
n->draw();
@@ -610,6 +641,7 @@ void World::draw(Player *p){
o->loc.y-=(yoff-DRAW_Y_OFFSET);
}
}


/*
* If we're drawing the closest/last world, handle and draw the player.
@@ -842,23 +874,52 @@ void World::detect(Player *p){
*/

LOOOOP:
static int what = 0;
for(auto &e : hey->entity)
hey->singleDetect(e);
for(auto &part : particles){
int l;
unsigned int i;
l=(part->loc.x + part->width / 2 - x_start) / HLINE;
if(l < 0) l=0;
i = l;
if(i > lineCount-1) i=lineCount-1;
if(part->loc.y < line[i].y){
part->loc.y = line[i].y;
part->vely = 0;
part->velx = 0;
part->canMove = false;
}else{
if(part->vely > -2)part->vely-=.003 * deltaTime;
}
what++;
}what=0;
if(hey->infront){
hey = hey->infront;
goto LOOOOP;
}
}

void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){
void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *outside,World *inside){
build.push_back(new Structures());
build.back()->spawn(t,x,y);
build.back()->spawn(t,sub,x,y);
build.back()->inWorld=outside;
build.back()->inside=(void *)inside;

entity.push_back(build.back());
}

void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside){
std::cout << npcMin << ", " << npcMax << std::endl;
int xwasd;
for(int i = 0; i < bCount; i++){
xwasd = (rand()%(int)x+1000*HLINE);
HERE:
for(auto &bu : build){
if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE;
}
addStructure(t,HOUSE,xwasd,y,outside,inside);
}
}
void World::addMob(int t,float x,float y){
mob.push_back(new Mob(t));
mob.back()->spawn(x,y);
@@ -888,6 +949,11 @@ void World::addObject(ITEM_ID i, bool q, const char *p, float x, float y){
entity.push_back(object.back());
}

void World::addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d){
particles.push_back(new Particles(x,y,w,h,vx,vy,color,d));
particles.back()->canMove = true;
}

/*void World::removeObject(Object i){
object.delete[](i);
}*/
@@ -941,6 +1007,14 @@ World *World::goWorldFront(Player *p){
return this;
}

bool World::isWorldLeft(void){
return toLeft ? true : false;
}

bool World::isWorldRight(void){
return toRight ? true : false;
}

std::vector<void *>thing;
World *World::goInsideStructure(Player *p){
if(!thing.size()){
@@ -1078,18 +1152,13 @@ extern bool inBattle;

Arena::Arena(World *leave,Player *p){
generate(300);
//door.y = line[299].y;
//door.x = 100;
exit = leave;

/*npc.push_back(new NPC());
entity.push_back(npc.back());
entity.back()->spawn(door.x,door.y);
entity.back()->width = HLINE * 12;
entity.back()->height = HLINE * 16;*/

addMob(MS_DOOR,100,100);
inBattle = true;
exit = leave;
pxy = p->loc;

star = new vec2[100];
memset(star,0,100 * sizeof(vec2));
}

Arena::~Arena(void){
@@ -1101,11 +1170,11 @@ Arena::~Arena(void){
}

World *Arena::exitArena(Player *p){
npc[0]->loc.x = door.x;
npc[0]->loc.y = door.y;
if(p->loc.x + p->width / 2 > door.x &&
p->loc.x + p->width / 2 < door.x + HLINE * 12 ){
if(p->loc.x + p->width / 2 > mob[0]->loc.x &&
p->loc.x + p->width / 2 < mob[0]->loc.x + HLINE * 12 ){
inBattle = false;
ui::toggleBlackFast();
ui::waitForCover();
p->loc = pxy;
return exit;
}else{
BIN +3.04 KB xcf/maybeplayer.xcf
Binary file not shown.