From: Andy Belle-Isle Date: Wed, 16 Sep 2015 15:55:17 +0000 (-0400) Subject: hi X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=76ae330e93cfdc09826beee41970772cbd0486ea;p=clyne%2Fgamedev.git hi --- 76ae330e93cfdc09826beee41970772cbd0486ea diff --cc include/UIClass.h index 9bf301c,745dec3..867044e --- a/include/UIClass.h +++ b/include/UIClass.h @@@ -15,8 -13,6 +13,6 @@@ namespace ui void putString(const float x,const float y,const char *s); void msgBox(const char *str,...); void handleEvents(); - int mousex, mousey; - bool debug = false; -} +}; #endif // UICLASS_H diff --cc src/UIClass.cpp index 0ee56ca,86a7be6..94aa09c --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@@ -9,154 -9,159 +9,166 @@@ extern World *currentWorld static FT_Library ftl; static FT_Face ftf; static GLuint ftex; + static unsigned int fontSize; - void UIClass::init(const char *ttf){ - if(FT_Init_FreeType(&ftl)){ - std::cout<<"Error! Couldn't initialize freetype."<glyph->bitmap.width*ftf->glyph->bitmap.rows*4); - for(j=0;jglyph->bitmap.width*ftf->glyph->bitmap.rows;j++){ - buf[j*4]=255; - buf[j*4+1]=255; - buf[j*4+2]=255; - buf[j*4+3]=ftf->glyph->bitmap.buffer[j]?255:0; - } - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); - w=ftf->glyph->bitmap.width*(2.0/SCREEN_WIDTH); - h=ftf->glyph->bitmap.rows *(2.0/SCREEN_HEIGHT); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D,ftex); - if(s[i]=='\''|| - s[i]=='\"'|| - s[i]=='-'|| - s[i]=='*'){ - yo+=fontSize*.001; - } - glBegin(GL_QUADS); - glColor3ub(255,255,255); - glTexCoord2f(0,1);glVertex2f(xo,yo); - glTexCoord2f(1,1);glVertex2f(xo+w,yo); - glTexCoord2f(1,0);glVertex2f(xo+w,yo+h); - glTexCoord2f(0,0);glVertex2f(xo,yo+h); - glEnd(); - if(s[i]=='\''|| - s[i]=='\"'|| - s[i]=='-'|| - s[i]=='*'){ - yo-=fontSize*.001; - } - glDisable(GL_TEXTURE_2D); - xo+=w+(fontSize*.0002); - free(buf); + void init(const char *ttf){ + if(FT_Init_FreeType(&ftl)){ + std::cout<<"Error! Couldn't initialize freetype."<glyph->bitmap.width*ftf->glyph->bitmap.rows*4); + for(j=0;jglyph->bitmap.width*ftf->glyph->bitmap.rows;j++){ + buf[j*4]=255; + buf[j*4+1]=255; + buf[j*4+2]=255; + buf[j*4+3]=ftf->glyph->bitmap.buffer[j]?255:0; + } + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); + w=ftf->glyph->bitmap.width*(2.0/SCREEN_WIDTH); + h=ftf->glyph->bitmap.rows *(2.0/SCREEN_HEIGHT); + if(s[i]=='\''|| + s[i]=='\"'|| + s[i]=='-'|| + s[i]=='*'){ + yo+=fontSize*.001; + } + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D,ftex); + glBegin(GL_QUADS); + glColor3ub(255,255,255); + glTexCoord2f(0,1);glVertex2f(xo,yo); + glTexCoord2f(1,1);glVertex2f(xo+w,yo); + glTexCoord2f(1,0);glVertex2f(xo+w,yo+h); + glTexCoord2f(0,0);glVertex2f(xo,yo+h); + glEnd(); + glDisable(GL_TEXTURE_2D); + if(s[i]=='\''|| + s[i]=='\"'|| + s[i]=='-'|| + s[i]=='*'){ + yo-=fontSize*.001; + } + xo+=w+(fontSize*.0002); + free(buf); + } + }while(s[i++]); + } + void putText(const float x,const float y,const char *str,...){ + va_list args; + char *buf; + buf=(char *)calloc(128,sizeof(char)); + va_start(args,str); + vsnprintf(buf,128,str,args); + va_end(args); + putString(x,y,buf); + free(buf); + } + void msgBox(const char *str,...){ + va_list args; + va_start(args,str); + glColor3ub(0,0,0); + glRectf(-1,.6,1,1); + setFontSize(24); + putText(-1,1-24*.0022,str,args); + va_end(args); + } - void UIClass::handleEvents(){ - static bool space=false; - float thing; - SDL_Event e; - while(SDL_PollEvent(&e)){ - switch(e.type){ - case SDL_MOUSEMOTION: - mousex=e.motion.x; - mousey=e.motion.y; - break; - case SDL_WINDOWEVENT: - switch(e.window.event){ - case SDL_WINDOWEVENT_CLOSE: - gameRunning = false; + void handleEvents(){ + static bool space=false; + float thing; + SDL_Event e; + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_MOUSEMOTION: + mousex=e.motion.x; + mousey=e.motion.y; break; - } - case SDL_KEYDOWN: - if(e.key.keysym.sym == SDLK_d) player.right = true; - if(e.key.keysym.sym == SDLK_a) player.left = true; - if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 3; - if(e.key.keysym.sym == SDLK_SPACE){ - if(!space&&player.vel.y<=0){ - space=true; - player.loc.y += HLINE*1.2; - player.vel.y += .003; + case SDL_WINDOWEVENT: + switch(e.window.event){ + case SDL_WINDOWEVENT_CLOSE: + gameRunning = false; + break; } - } - if(e.key.keysym.sym == SDLK_i){ - if(currentWorld->behind){ - thing=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; - if(player.loc.x>thing-1&& - player.loc.xbehind->getWidth()){ - player.loc.x-=thing; + case SDL_KEYDOWN: + if(e.key.keysym.sym == SDLK_d) player.right = true; + if(e.key.keysym.sym == SDLK_a) player.left = true; + if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 3; + if(e.key.keysym.sym == SDLK_SPACE){ + if(!space&&player.vel.y<=0){ + space=true; + player.loc.y += HLINE*1.2; + player.vel.y += .003; + } + } ++ if(e.key.keysym.sym == SDLK_k){ ++ if(currentWorld->infront){ ++ player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; + memset(&player.vel,0,sizeof(vec2)); - currentWorld=currentWorld->behind; ++ currentWorld=currentWorld->infront; + } + } - } - if(e.key.keysym.sym == SDLK_k){ - if(currentWorld->infront){ - player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; - memset(&player.vel,0,sizeof(vec2)); - currentWorld=currentWorld->infront; ++ break; + if(e.key.keysym.sym == SDLK_i){ + if(currentWorld->behind){ + thing=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; + if(player.loc.x>thing-1&& + player.loc.xbehind->getWidth()){ + player.loc.x-=thing; + memset(&player.vel,0,sizeof(vec2)); + currentWorld=currentWorld->behind; + } + } } - if(e.key.keysym.sym == SDLK_k){ - if(currentWorld->infront){ - player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; - memset(&player.vel,0,sizeof(vec2)); - currentWorld=currentWorld->infront; - } - } - break; + } + if(e.key.keysym.sym == SDLK_F3){ + debug = !debug; + } + break; - case SDL_KEYUP: - if(e.key.keysym.sym == SDLK_d) player.right = false; - if(e.key.keysym.sym == SDLK_a) player.left = false; - if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 1.0; - if(e.key.keysym.sym == SDLK_SPACE) - if(player.vel.y<=.001)space=false; - - if(e.key.keysym.sym == SDLK_ESCAPE) gameRunning = false; - break; - } + case SDL_KEYUP: + if(e.key.keysym.sym == SDLK_d) player.right = false; + if(e.key.keysym.sym == SDLK_a) player.left = false; + if(e.key.keysym.sym == SDLK_LSHIFT) player.speed = 1.0; + if(e.key.keysym.sym == SDLK_SPACE) + if(player.vel.y<=.001)space=false; + + if(e.key.keysym.sym == SDLK_ESCAPE) gameRunning = false; + break; + } + } ++ } } diff --cc src/main.cpp index cad8fc9,e48a66a..3b525d5 --- a/src/main.cpp +++ b/src/main.cpp @@@ -185,8 -180,9 +185,8 @@@ void render() d=deltaTime; fps=(1000/d); } - ui::putText(-.98 + player.loc.x, .94, "FPS: %1.0f\nDT: %1.0f",fps,d); //ui.putText(-.98 + player.loc.x, .88, "DT: %1.0f",d); - ui.putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y); + ui::putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y); /************************** **** CLOSE THE LOOP **** @@@ -247,19 -234,17 +248,28 @@@ void logic() player.loc.x=-1+HLINE; } } - + currentWorld->detect(&build.loc,&build.vel,build.width); + for(int i = 0; i < eAmt(entnpc); i++){ + if(npc[i].alive == true){ + currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width); + entnpc[i]->wander((grand()%181 + 1), &npc[i].vel); + if((mx > entnpc[i]->loc.x && mx < entnpc[i]->loc.x + entnpc[i]->width) && (my > entnpc[i]->loc.y && my < entnpc[i]->loc.y + entnpc[i]->height)&&(SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))){ + if(pow((entnpc[i]->loc.x - player.loc.x),2) + pow((entnpc[i]->loc.y - player.loc.y),2) < pow(.2,2)){ + entnpc[i]->interact(); + ui.putText(entnpc[i]->loc.x, entnpc[i]->loc.y - HLINE * 3, "HEY", NULL); + } + } ++ + /*for(int i = 0; i < 32; i++){ + if(entnpc[i]->alive){ + currentWorld->detect(&entnpc[i]->loc,&entnpc[i]->vel,entnpc[i]->width); + std::cout<<(void *)entnpc[i]<<" "<wander(30, &entnpc[i]->vel); ++ } - }*/ - ////////////////////// - std::cout<<"shit"; + } ++ */ + tickCount++; }