From 6c2fa9e1b372f71d311b376e689961dad6aaa036 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 18 Sep 2015 17:26:28 -0400 Subject: forgot stuff --- src/entities.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++ src/ui.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/world.cpp | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 src/entities.cpp create mode 100644 src/ui.cpp create mode 100644 src/world.cpp (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp new file mode 100644 index 0000000..6058e41 --- /dev/null +++ b/src/entities.cpp @@ -0,0 +1,87 @@ +#include + +int npcAmt=0; +Entity *entnpc[32]; +NPC npc[32]; + +void Entity::spawn(float x, float y){ + loc.x = x; + loc.y = y; + vel.x = 0; + vel.y = 0; + right = false; + left = false; + ticksToUse = 0; + canMove = false; +} + +void Entity::draw(void){ + glColor3ub(0,0,100); + glRectf(loc.x,loc.y,loc.x+width,loc.y+height); +} + +void Entity::wander(int timeRun, vec2 *v){ + static int hey; + if(ticksToUse == 0){ + ticksToUse = timeRun; + v->x = .00010; + hey = (getRand() % 3 - 1); + v->x *= hey; + } + ticksToUse--; +} + +Player::Player(){ + width = HLINE * 8; + height = HLINE * 12; + speed = 1; + type = 0; + subtype = 5; + alive = true; +} + +void Player::interact(){ + +} + +NPC::NPC(){ + width = HLINE * 8; + height = HLINE * 18; + speed = 1; + type = 0; + subtype = 0; + alive = false; + canMove = true; +} + +void NPC::interact(){ + loc.y += .01; + +} + +Structures::Structures(){ + type = -1; + speed = 0; +} + +void Structures::spawn(int t, float x, float y){ + loc.x = x; + loc.y = y; + type = t; + + /*VILLAGE*/ + if(type == -1){ + width = 4 * HLINE; + height = 4 * HLINE; + + int tempN = (getRand() % 5 + 1); + npcAmt = tempN; + + for(int i = 0;ispawn(loc.x + (float)(i - 5) / 8,0); //this will spawn the start of a village + } + } +} diff --git a/src/ui.cpp b/src/ui.cpp new file mode 100644 index 0000000..d7aabc0 --- /dev/null +++ b/src/ui.cpp @@ -0,0 +1,103 @@ +#include +#include +#include FT_FREETYPE_H + +#define SDL_KEY e.key.keysym.sym + +extern Player *player; + +static FT_Library ftl; +static FT_Face ftf; +static GLuint ftex; +static unsigned int fontSize; + +namespace ui { + void initFonts(void){ + 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; + h=ftf->glyph->bitmap.rows; + 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); + xo+=w; + 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 handleEvents(void){ + SDL_Event e; + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_QUIT: + gameRunning=false; + break; + case SDL_KEYDOWN: + if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; + if(SDL_KEY==SDLK_a)player->vel.x=-2; + else if(SDL_KEY==SDLK_d)player->vel.x=2; + break; + case SDL_KEYUP: + if(SDL_KEY==SDLK_a)player->vel.x=0; + else if(SDL_KEY==SDLK_d)player->vel.x=0; + break; + default: + break; + } + } + } +} diff --git a/src/world.cpp b/src/world.cpp new file mode 100644 index 0000000..d2a15f7 --- /dev/null +++ b/src/world.cpp @@ -0,0 +1,73 @@ +#include + +#define getWidth() (lineCount*HLINE) + +#define GEN_INC 10 +#define GRASS_HEIGHT 4 + +World::World(unsigned int width){ + unsigned int i; + float inc; + lineCount=width+GEN_INC; + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); // allocate space for the array of lines + line[0].y=80; + for(i=GEN_INC;i110)line[i].y=110; + } + for(i=0;ix-x_start)/HLINE; + i=v_offset-SCREEN_WIDTH/2; + if(i<0)i=0; + ie=v_offset+SCREEN_WIDTH/2; + if(ie>lineCount)ie=lineCount; + glBegin(GL_QUADS); + for(i=i;ix+width/2-x_start)/HLINE; + if(v->y<=line[i].y){ + vel->y=0; + v->y=line[i].y+HLINE/2; + return; + }else{ + vel->y-=.05; + return; + } +} -- cgit v1.2.3