aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-14 16:50:45 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-14 16:50:45 -0400
commit78bd3d738a4b1cec8bd4504a36120f5795029e8b (patch)
tree458b761360164f74a826570fa80cb07860c20ae9 /src
parent329c8cb80d29aff078284db227af6c2cb114fc2f (diff)
fixes
Diffstat (limited to 'src')
-rw-r--r--src/UIClass.cpp19
-rw-r--r--src/World.cpp9
-rw-r--r--src/main.cpp49
3 files changed, 31 insertions, 46 deletions
diff --git a/src/UIClass.cpp b/src/UIClass.cpp
index b0e0206..68654c7 100644
--- a/src/UIClass.cpp
+++ b/src/UIClass.cpp
@@ -22,9 +22,10 @@ void UIClass::init(const char *ttf){
}
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;
@@ -57,10 +58,20 @@ void UIClass::putText(float x,float y,const char *s){
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;
@@ -91,6 +102,7 @@ void UIClass::handleEvents(){
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;
}
}
@@ -98,6 +110,7 @@ void UIClass::handleEvents(){
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;
}
}
diff --git a/src/World.cpp b/src/World.cpp
index 45df63c..41649d9 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -110,13 +110,14 @@ void World::detect(vec2 *v,vec2 *vel,const float width){
if(v->y<line[i].start){ // If we're inside the line
if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ // And we're inside it ;)
vel->y=0;v->y=line[i].start+HLINE/8; // Correct
-// return; // :/
+ return; // :/
}else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ // Same as above, but coming from right side instead of left
vel->y=0;v->y=line[i].start+HLINE/8;
-// return; // ;)
+ return; // ;)
}
- }else if(v->y>line[i].start+HLINE){ // Trashy gravity handling
- vel->y-=.0000002;
+ }
+ if(v->y>line[i].start+HLINE){ // Trashy gravity handling
+ vel->y-=.0000001;
}
}
}
diff --git a/src/main.cpp b/src/main.cpp
index a92ff16..4d48d81 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,5 @@
#include <common.h>
#include <cstdio>
-#include <ctime>
#include <chrono>
#define TICKS_PER_SEC 20
@@ -29,17 +28,13 @@ World *currentWorld;//u-huh
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))){
@@ -80,7 +75,6 @@ int main(int argc,char **argv){
**************************/
ui.init("ttf/VCR_OSD_MONO_1.001.ttf");
- ui.setFontSize(100);
irand(time(NULL));
entPlay = &player;
@@ -104,8 +98,7 @@ int main(int argc,char **argv){
currentWorld->addEntity((void *)entnpc[jklasdf]);
}
- initTime=clock();
- currentTime=initTime;
+ currentTime=millis();
while(gameRunning){
prevTime = currentTime;
@@ -118,6 +111,7 @@ int main(int argc,char **argv){
}
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){
@@ -125,26 +119,7 @@ int main(int argc,char **argv){
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();
}
@@ -192,7 +167,8 @@ void 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 ****
@@ -203,17 +179,12 @@ void render(){
}
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();