From 3fde0e7edf310245e5658b767840e742c9341597 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 10 Sep 2015 11:30:41 -0400 Subject: yeah --- src/Quest.cpp | 124 +++++++++++++++++------------------ src/UIClass.cpp | 44 ++++++------- src/World.cpp | 88 ++++++++++++++++--------- src/main.cpp | 196 ++++++++++++++++++++++++++++---------------------------- 4 files changed, 239 insertions(+), 213 deletions(-) (limited to 'src') diff --git a/src/Quest.cpp b/src/Quest.cpp index 82c405d..a42e42c 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -1,62 +1,62 @@ -#include - -const Quest QuestList[TOTAL_QUESTS]={ - Quest("Test","A test quest",0) -}; - -Quest::Quest(const char *t,const char *d,unsigned int x){ - size_t len; - title=(char *)malloc((len=strlen(t))); - strncpy(title,t,len); - desc=(char *)malloc((len=strlen(d))); - strncpy(desc,d,len); - xp=x; -} -Quest::~Quest(){ - free(title); - free(desc); - xp=0; -} - -QuestHandler::QuestHandler(){ - ccnt=0; -} -int QuestHandler::assign(const char *t){ - unsigned int i=0; - if(ccnt==QUEST_LIMIT) - return -1; - for(;ititle,t)){ - for(i++;ititle,t)){ - j=current[i]->xp; - for(i++;i + +const Quest QuestList[TOTAL_QUESTS]={ + Quest("Test","A test quest",0) +}; + +Quest::Quest(const char *t,const char *d,unsigned int x){ + size_t len; + title=(char *)malloc((len=strlen(t))); + strncpy(title,t,len); + desc=(char *)malloc((len=strlen(d))); + strncpy(desc,d,len); + xp=x; +} +Quest::~Quest(){ + free(title); + free(desc); + xp=0; +} + +QuestHandler::QuestHandler(){ + ccnt=0; +} +int QuestHandler::assign(const char *t){ + unsigned int i=0; + if(ccnt==QUEST_LIMIT) + return -1; + for(;ititle,t)){ + for(i++;ititle,t)){ + j=current[i]->xp; + for(i++;i - -void UIClass::handleEvents(){ - SDL_Event e; - while(SDL_PollEvent(&e)){ - switch(e.type){ - case SDL_QUIT: - gameRunning=false; - break; - case SDL_KEYDOWN: - switch(e.key.keysym.sym){ - case 27: - gameRunning=false; - break; - default: - break; - } - default: - break; - } - } -} +#include + +void UIClass::handleEvents(){ + SDL_Event e; + while(SDL_PollEvent(&e)){ + switch(e.type){ + case SDL_QUIT: + gameRunning=false; + break; + case SDL_KEYDOWN: + switch(e.key.keysym.sym){ + case 27: + gameRunning=false; + break; + default: + break; + } + default: + break; + } + } +} diff --git a/src/World.cpp b/src/World.cpp index 3d8cfb7..022948f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,31 +1,57 @@ -#include - -World::World(float width){ - unsigned int i; - lineCount=width/HLINE; - if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ - std::cout<<"Failed to allocate memory!"< + +World::World(float width){ + unsigned int i; + double f; + lineCount=width/HLINE+1; + if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ + std::cout<<"Failed to allocate memory!"<-0.5f)line[0].start=-0.7f; + for(i=10;iyx>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ + v->x=(HLINE*i)-1+HLINE; + }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ + v->x=(HLINE*i)-1-width; + }else{ + v->y=line[i].start; + } + }else if(v->y>line[i].start+HLINE/2){ + v->y-=HLINE/4; + } + } +} diff --git a/src/main.cpp b/src/main.cpp index cb93ff4..b04cb59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,98 +1,98 @@ -#include -#include - -SDL_Window *window = NULL; -SDL_Surface *renderSurface = NULL; -SDL_GLContext mainGLContext = NULL; - -bool gameRunning = true; - -UIClass ui; - -int main(int argc,char **argv){ - //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))){ - std::cout<<"Could not init image libraries!\n"<draw(); - - /************************** - **** CLOSE THE LOOP **** - **************************/ - - glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer - SDL_GL_SwapWindow(window); //give the stack to SDL to render it - } - - /************************** - **** CLOSE PROGRAM **** - **************************/ - - //closes the window and frees resources - SDL_GL_DeleteContext(mainGLContext); - SDL_DestroyWindow(window); - return 0; -} +#include +#include + +SDL_Window *window = NULL; +SDL_Surface *renderSurface = NULL; +SDL_GLContext mainGLContext = NULL; + +bool gameRunning = true; + +UIClass ui; +Entities *entit1; +Player player; + +int main(int argc,char **argv){ + // Initialize SDL + if(!SDL_Init(SDL_INIT_VIDEO)){ + atexit(SDL_Quit); + }else{ + std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; + return -1; + } + // Initialize SDL_image + if((IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ + atexit(IMG_Quit); + }else{ + std::cout<<"Could not init image libraries!\n"<spawn(0,0); + + World *w=new World(2); + + while(gameRunning){ + ui.handleEvents(); // Handle events + //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" + //GL_PROJECTION has 2 matrices + //GL_MODELVIEW has 32 matrices + glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode + glOrtho(-1,1,-1,1,-1,1); //set the the size of the screen + glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode + glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on + glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack + + /************************** + **** RENDER STUFF HERE **** + **************************/ + + w->draw(); + glColor3ub(0,0,0); + glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); + + /************************** + **** CLOSE THE LOOP **** + **************************/ + + glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer + SDL_GL_SwapWindow(window); //give the stack to SDL to render it + } + + /************************** + **** CLOSE PROGRAM **** + **************************/ + + //closes the window and frees resources + SDL_GL_DeleteContext(mainGLContext); + SDL_DestroyWindow(window); + return 0; +} -- cgit v1.2.3 From a3db993224c994fdff6f50fedcc266c5e0b94aa8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 10 Sep 2015 11:31:30 -0400 Subject: added entities --- doc/World.htm | 40 ++++++++++++++++++++++++++++++++++++++++ include/entities.h | 26 ++++++++++++++++++++++++++ src/entities.cpp | 16 ++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 doc/World.htm create mode 100644 include/entities.h create mode 100644 src/entities.cpp (limited to 'src') diff --git a/doc/World.htm b/doc/World.htm new file mode 100644 index 0000000..d17c551 --- /dev/null +++ b/doc/World.htm @@ -0,0 +1,40 @@ + + + + World + + + +

World

+
+

Description

+

World.h contains functions to create and draw worlds, and provide basic object detection.

+
+

The standard form of world generation in World.h is an array of randomly sized vertical lines. +The width of each line is defined as a single HLINE, a macro defined in common.h. ...

+

class World

+
private:
+ struct line_t {
+ float start;
+ } *line;
+ unsigned int lineCount;
+public:
+ World(float width);
+ void draw(void);
+ void detect(vec2 *v,const float width);
+
+
    +
  • struct line_t: float start: Where the top of the line is located.
  • +
  • unsigned int lineCount: Contains the size of the array line.
  • +
+ + diff --git a/include/entities.h b/include/entities.h new file mode 100644 index 0000000..3ecf014 --- /dev/null +++ b/include/entities.h @@ -0,0 +1,26 @@ +#ifndef ENTITIES_H +#define ENTITIES_H + +#include + + +class Entities{ +public: + float width; + float height; + float speed; + int type; + vec2 loc; + + void spawn(float, float); + + +}; + +class Player : public Entities{ +public: + Player(); + ~Player(); +}; + +#endif //ENTITIES_H \ No newline at end of file diff --git a/src/entities.cpp b/src/entities.cpp new file mode 100644 index 0000000..5e86b72 --- /dev/null +++ b/src/entities.cpp @@ -0,0 +1,16 @@ +#include + +void Entities::spawn(float x, float y){ + loc.x = x; + loc.y = y; + +} + +Player::Player(){ + width = 24; + height = 42; + speed = 1; + type = 0; +} + +Player::~Player(){} \ No newline at end of file -- cgit v1.2.3