#define UICLASS_H\r
\r
#include <common.h>\r
+#include <cstdarg>\r
+#include <cstdio>\r
\r
class UIClass {\r
- public:\r
- void init(const char *ttf);\r
- void setFontSize(unsigned int fs);\r
- void putText(float x,float y,const char *s);\r
- void handleEvents();\r
+private:\r
+ unsigned int fontSize;\r
+public:\r
+ void init(const char *ttf);\r
+ void setFontSize(unsigned int fs);\r
+ void putText(const float x,const float y,const char *s,...);\r
+ void putString(const float x,const float y,const char *s);\r
+ void handleEvents();\r
};\r
\r
#endif // UICLASS_H\r
}
void UIClass::setFontSize(unsigned int fs){
- FT_Set_Pixel_Sizes(ftf,0,fs);
+ fontSize=fs;
+ FT_Set_Pixel_Sizes(ftf,0,fontSize);
}
-void UIClass::putText(float x,float y,const char *s){
+void UIClass::putString(const float x,const float y,const char *s){
unsigned int i=0,j;
float xo=x,yo=y,w,h;
char *buf;
glTexCoord2f(0,0);glVertex2f(xo,yo+h);
glEnd();
glDisable(GL_TEXTURE_2D);
- xo+=w+.01;
+ xo+=w+(fontSize*.0001);
free(buf);
}while(s[i++]);
}
+void UIClass::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 UIClass::handleEvents(){
static bool space=false;
if(player.loc.x>thing-1&&
player.loc.x<thing-1+currentWorld->behind->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;
}
}
#include <common.h>
#include <cstdio>
-#include <ctime>
#include <chrono>
#define TICKS_PER_SEC 20
void logic();
void render();
-static unsigned int initTime;
unsigned int millis(void){
- //return (float)(clock()-initTime)/(CLOCKS_PER_SEC/1000.0f);
std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
- std::chrono::nanoseconds m=now.time_since_epoch();
- return std::chrono::duration_cast<std::chrono::milliseconds>(m).count();
+ return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
}
int main(int argc,char **argv){
- float gw;
- //runs start-up procedures
+ //runs start-up procedures
if(!SDL_Init(SDL_INIT_VIDEO)){
atexit(SDL_Quit);
if(!(IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){
**************************/
ui.init("ttf/VCR_OSD_MONO_1.001.ttf");
- ui.setFontSize(100);
irand(time(NULL));
entPlay = &player;
currentWorld->addEntity((void *)entnpc[jklasdf]);
}
- initTime=clock();
- currentTime=initTime;
+ currentTime=millis();
while(gameRunning){
prevTime = currentTime;
}
player.loc.x += (player.vel.x * player.speed) * deltaTime; //update the player's x based on
+// printf("%lf * %u\n",player.vel.y,deltaTime);
player.loc.y += player.vel.y * deltaTime;
for(int i = 0; i < eAmt(entnpc); i++){
if(npc[i].alive == true){
npc[i].loc.x += npc[i].vel.x * deltaTime;
}
}
-
-
- gw=currentWorld->getWidth();
- if(player.loc.x+player.width>-1+gw){
- if(currentWorld->toRight){
- goWorldRight(currentWorld)
- player.loc.x=-1+HLINE;
- }else{
- player.loc.x=gw-1-player.width-HLINE;
- }
- }
- if(player.loc.x<-1){
- if(currentWorld->toLeft){
- goWorldLeft(currentWorld);
- player.loc.x=currentWorld->getWidth()-1-player.width-HLINE;
- }else{
- player.loc.x=-1+HLINE;
- }
- }
-
+
render();
}
glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height);
///BWAHHHHHHHHHHHH
- ui.putText(0,0,"Hello");
+ ui.setFontSize(16);
+ ui.putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y);
/**************************
**** CLOSE THE LOOP ****
}
void logic(){
- static unsigned int lastTime=0;
float gw;
ui.handleEvents(); // Handle events
- if(player.right == true) {player.vel.x = .00075;}
- if(player.left == true) {player.vel.x = -.00075;}
- if(player.right == false && player.left == false) {player.vel.x = 0;}
-
- //std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")";
- std::cout<<millis()-lastTime<<std::endl;
- lastTime=millis();
+ if(player.right)player.vel.x=.00075;
+ else if(player.left)player.vel.x=-.00075;
+ else player.vel.x = 0;
currentWorld->detect(&player.loc,&player.vel,player.width);
gw=currentWorld->getWidth();