From 75b782c83954e77554d2ad30f9e45e723e91765e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 26 Sep 2015 16:07:07 -0400 Subject: created base for indoor areas --- src/main.cpp | 16 ++++++++-------- src/world.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 6049d2c..1747915 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,11 +86,18 @@ int main(int argc, char *argv[]){ //************************************************************************// // Make a world - World *test =new World(SCREEN_WIDTH/2); + World *test=new World(); + test->generate(SCREEN_WIDTH/2); test->addLayer(400); test->addLayer(100); currentWorld=test; + IndoorWorld *iw=new IndoorWorld(); + iw->generate(200); + + test->toRight=iw; + iw->toLeft=test; + // Make the player player=new Player(); player->spawn(0,100); @@ -105,13 +112,6 @@ int main(int argc, char *argv[]){ for(i=0;iinWorld=test; } - for(i=0;ientity; void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to directly using glColor3ub() to set @@ -24,7 +26,10 @@ void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to dir glColor3ub(r,g,b); } -World::World(unsigned int width){ // Generates the world and sets all variables contained in the World class. +World::World(void){ +} + +void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class. unsigned int i; // Used for 'for' loops float inc; // See line 40 lineCount=width+GEN_INC; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. @@ -149,7 +154,8 @@ void World::addLayer(unsigned int width){ behind->addLayer(width); return; } - behind=new World(width); + behind=new World(); + behind->generate(width); behind->infront=this; } @@ -184,3 +190,50 @@ World *World::goWorldFront(Player *p){ } return this; } + + + + +IndoorWorld::IndoorWorld(void){ +} + +IndoorWorld::~IndoorWorld(void){ + free(line); +} + +void IndoorWorld::generate(unsigned int width){ // Generates a flat area of width 'width' + unsigned int i; // Used for 'for' loops + lineCount=width+GEN_INC; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. + + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); // Allocate memory for the array 'line' + + for(i=0;ix-x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' + i=v_offset-SCREEN_WIDTH/2; // um + if(i<0)i=0; // If the player is past the start of that world 'i' should start at the beginning + // of the world + ie=v_offset+SCREEN_WIDTH/2; // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie') + if(ie>lineCount)ie=lineCount; // If the player is past the end of that world 'ie' should contain the end of that world + glBegin(GL_QUADS); + for(i=i;iinWorld==this) + entity[i]->draw(); + } +} -- cgit v1.2.3