aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-04-05 08:48:29 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-04-05 08:48:29 -0400
commit16920d744a2e638f564753f15f1269f51c131b6b (patch)
treeae3ee1ba2b2f7a92c196347853e0c82e2dd14973 /src
parent4ea7b19bf2d4c64719471a53e6223aac7c250585 (diff)
sword improvements, page threading
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp4
-rw-r--r--src/entities.cpp23
-rw-r--r--src/gameplay.cpp19
-rw-r--r--src/inventory.cpp52
-rw-r--r--src/ui.cpp57
-rw-r--r--src/world.cpp13
6 files changed, 107 insertions, 61 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 2ee13d4..b8a483d 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -60,6 +60,10 @@ namespace config {
ui::initFonts();
ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
+
+ if ( xml.FirstChildElement("debug") )
+ ui::debug = ui::posFlag = true;
+
config::update();
}
diff --git a/src/entities.cpp b/src/entities.cpp
index 4fd21fd..5470245 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -86,6 +86,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
//canMove = true;
ground = false;
hit = false;
+ forcedMove = false;
ticksToUse = 0;
@@ -389,7 +390,12 @@ NOPE:
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
- if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
+ if ( near )
+ ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
+ if ( health != maxHealth ) {
+ glColor3ub(150,0,0); glRectf( loc.x, loc.y + height, loc.x + width, loc.y + height + HLINE * 2 );
+ glColor3ub(255,0,0); glRectf( loc.x, loc.y + height, loc.x + width * ( health / maxHealth ), loc.y + height + HLINE * 2 );
+ }
}
/**
@@ -401,6 +407,9 @@ wander( int timeRun )
{
static int direction;
+ if ( forcedMove )
+ return;
+
if ( followee ) {
if ( loc.x < followee->loc.x - 40 )
direction = 1;
@@ -473,6 +482,10 @@ void NPC::interact(){ //have the npc's interact back to the player
void Merchant::wander(int timeRun){
static int direction;
+
+ if ( forcedMove )
+ return;
+
if ( ticksToUse == 0 ) {
ticksToUse = timeRun;
@@ -600,6 +613,9 @@ void Mob::wander(int timeRun){
static unsigned int heya=0,hi=0;
static bool YAYA = false;
+ if ( forcedMove )
+ return;
+
if ( followee ) {
if ( loc.x < followee->loc.x - 40 )
direction = 1;
@@ -667,11 +683,12 @@ void Mob::wander(int timeRun){
ui::mouse.y > loc.y - width / 2 &&
ui::mouse.y < loc.y + width * 1.5 &&
SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
- if(speed != 666){
+ std::thread([this]{hey(this);}).detach();
+ /*if(speed != 666){
speed = 666;
hey(this);
speed = 0;
- }
+ }*/
}
break;
default:
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 351cf0f..ce514a4 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -219,16 +219,19 @@ CONT:
}
void commonPageFunc( Mob *callee ){
- static bool lock = false;
-
- if ( !lock ) {
- lock = true;
+ //static bool lock = false;
+ /*if ( !lock ) {
+ lock = true;*/
+ if ( !ui::dialogBoxExists ) {
+ std::cout<<"begin\n";
ui::drawPage( callee->heyid );
- ui::waitForDialog();
+ while( ui::pageExists() );
+ std::cout<<"done\n";
+ //ui::waitForDialog();
- callee->alive = false;
- lock = false;
+ callee->health = 0;
+ //lock = false;
}
}
@@ -267,7 +270,7 @@ void commonTriggerFunc(Mob *callee){
ui::toggleBlackFast();
- callee->alive = false;
+ callee->health = 0;
lock = false;
}
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 14ccfd06..521b695 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -522,6 +522,8 @@ void Inventory::draw(void){
}
void itemDraw(Player *p,uint id){
+ static unsigned char inc = 0;
+
itemLoc.y = p->loc.y+(p->height/3);
itemLoc.x = p->left?p->loc.x:p->loc.x+p->width;
glPushMatrix();
@@ -540,9 +542,16 @@ void itemDraw(Player *p,uint id){
p->inv->usingi = false;
}
}
- }else hangle = 0.0f;
+ } else
+ hangle = 0;
+
if ( p->inv->usingi )
+ inc = 10;
+
+ if ( inc ) {
+ inc--;
p->inv->useItem();
+ }
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
@@ -564,25 +573,31 @@ void itemDraw(Player *p,uint id){
glUseProgram(0);
}
-int Inventory::useItem(void){
+int Inventory::useItem( void )
+{
static bool up = false;
- if(!invHover){
-
- if(itemMap[items[sel].id]->type == "Sword"){
-
- 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 ( !invHover ) {
+ if ( itemMap[items[sel].id]->type == "Sword" ) {
+ if ( swing ) {
+ int dir = player->left ? 1 : -1;
+
+ if ( hangle == 15 * dir ) {
+ up = true;
+ Mix_PlayChannel( 2, swordSwing, 0 );
}
- }else if(!swing){
- swing=true;
- Mix_PlayChannel(2,swordSwing,0);
+
+ if ( up )
+ hangle += 0.325f * dir * deltaTime;
+
+ if ( !player->left ) {
+ if ( hangle <= -90 )
+ hangle = -14;
+ } else if ( hangle >= 90 )
+ hangle = 14;
+ } else {
+ swing = true;
+ Mix_PlayChannel( 2, swordSwing, 0 );
}
}else if(itemMap[items[sel].id]->type == "Cooked Food"){
player->health += itemMap[items[sel].id]->attribValue;
@@ -601,7 +616,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
if(items.empty() || !items[sel].count)
return false;
if(itemMap[items[sel].id]->type == "Sword"){
- std::cout<<"Collision???"<<std::endl;
while(i<itemMap[items[sel].id]->height){
xc = itemLoc.x; yc = itemLoc.y;
xc += float(i) * cos((hangle+90)*PI/180);
diff --git a/src/ui.cpp b/src/ui.cpp
index 69ff7e3..c9f91ab 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -632,6 +632,11 @@ namespace ui {
void drawPage( std::string path ) {
pageTex = Texture::loadTexture( path );
+ std::cout<<"page set\n";
+ }
+
+ bool pageExists( void ) {
+ return pageTex;
}
void draw(void){
@@ -641,6 +646,8 @@ namespace ui {
if ( pageTex ) {
+ std::cout<<"page draw\n";
+
glEnable( GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, pageTex );
glBegin( GL_QUADS );
@@ -1204,6 +1211,7 @@ namespace ui {
unsigned char i;
if ( pageTex ) {
+ std::cout<<"rip page\n";
glDeleteTextures( 1, &pageTex );
pageTex = 0;
return;
@@ -1280,7 +1288,12 @@ EXIT:
break;
case SDL_MOUSEBUTTONUP:
- if(ig) {
+
+ // right click advances dialog
+ if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTex) )
+ dialogAdvance();
+
+ if ( ig ) {
ig->vel.x = (fr.x - mouse.x) / 50.0f;
ig->vel.y = (fr.y - mouse.y) / 50.0f;
ig = NULL;
@@ -1289,9 +1302,7 @@ EXIT:
// mouse clicks
case SDL_MOUSEBUTTONDOWN:
- // right click advances dialog
- if ( ( e.button.button & SDL_BUTTON_RIGHT ) && (dialogBoxExists | pageTex) )
- dialogAdvance();
+
// left click uses item
if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists )
player->inv->usingi = true;
@@ -1397,9 +1408,6 @@ EXIT:
} else if( (tmp = currentWorld->goInsideStructure( player )) != currentWorld )
currentWorld = tmp;
break;
- case SDLK_i:
- player->health -= 5;
- break;
case SDLK_LSHIFT:
if(debug){
Mix_PlayChannel(1,sanic,-1);
@@ -1410,12 +1418,6 @@ EXIT:
case SDLK_LCTRL:
player->speed = .5;
break;
- case SDLK_F3:
- debug ^= true;
- break;
- case SDLK_b:
- if(debug)posFlag ^= true;
- break;
case SDLK_e:
edown=true;
if(!heyOhLetsGo){
@@ -1447,7 +1449,10 @@ EXIT:
player->save();
return;
}
- switch(SDL_KEY){
+ switch ( SDL_KEY ) {
+ case SDLK_F3:
+ debug ^= true;
+ break;
case SDLK_z:
weather = WorldWeather::Snowy;
break;
@@ -1497,23 +1502,15 @@ EXIT:
case SDLK_f:
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
break;
- case SDLK_g:
- //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, NULL);
- break;
- case SDLK_h:
- //currentWorld->addStructure(TOWN_HALL, player->loc.x, player->loc.y, NULL);
- break;
- case SDLK_j:
- //currentWorld->addStructure(FOUNTAIN, player->loc.x, player->loc.y, NULL);
- break;
- case SDLK_v:
- //currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, NULL);
- break;
case SDLK_b:
- currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
- currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
- currentWorld->light.back().follow(currentWorld->build.back());
- currentWorld->light.back().makeFlame();
+ if ( debug )
+ posFlag ^= true;
+ else {
+ currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
+ currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
+ currentWorld->light.back().follow(currentWorld->build.back());
+ currentWorld->light.back().makeFlame();
+ }
break;
case SDLK_F12:
// Make the BYTE array, factor of 3 because it's RBG.
diff --git a/src/world.cpp b/src/world.cpp
index e009f78..f7e9096 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -718,7 +718,9 @@ singleDetect( Entity *e )
* Kill any dead entities.
*/
- if ( !e->alive || e->health <= 0 ) {
+ if ( e->alive && e->health <= 0 ) {
+ e->alive = false;
+ e->health = 0;
for ( i = 0; i < entity.size(); i++) {
if ( entity[i] == e ){
switch ( e->type ) {
@@ -776,6 +778,15 @@ singleDetect( Entity *e )
// handle only living entities
if ( e->alive ) {
+
+ // forced movement gravity
+ if ( e->forcedMove ) {
+ if ( e->vel.x > .0005 || e->vel.x < -.0005 )
+ e->vel.x *= .6;
+ else
+ e->forcedMove = false;
+ }
+
if ( e->type == MOBT && Mobp(e)->subtype == MS_TRIGGER )
return;