diff --git a/Heart.sdf b/Heart.sdf index 66cafcf..8fc6809 100644 Binary files a/Heart.sdf and b/Heart.sdf differ diff --git a/Heart.suo b/Heart.suo index 8fe0ff8..d90b380 100644 Binary files a/Heart.suo and b/Heart.suo differ diff --git a/README.txt b/README.txt index 44f236a..4be46fe 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ -Z - Jump/Select +Z - Jump/Back X - Shoot/Select C - Change Weapons Enter - Select -Space - Pause/Select +Space - Pause/Unpause Arrow keys - Move Escape - Quit diff --git a/anims/bg/bbg_04.png b/anims/bg/bbg_04.png new file mode 100644 index 0000000..6153960 Binary files /dev/null and b/anims/bg/bbg_04.png differ diff --git a/anims/bg/bg_10.png b/anims/bg/bg_10.png new file mode 100644 index 0000000..6ec13d7 Binary files /dev/null and b/anims/bg/bg_10.png differ diff --git a/anims/hp/hp_3_0.png b/anims/hp/hp_3_0.png new file mode 100644 index 0000000..ed26ab9 Binary files /dev/null and b/anims/hp/hp_3_0.png differ diff --git a/anims/hp/hp_3_1.png b/anims/hp/hp_3_1.png new file mode 100644 index 0000000..be0a724 Binary files /dev/null and b/anims/hp/hp_3_1.png differ diff --git a/anims/hp/hp_3_2.png b/anims/hp/hp_3_2.png new file mode 100644 index 0000000..cca41b7 Binary files /dev/null and b/anims/hp/hp_3_2.png differ diff --git a/anims/hp/hp_3_3.png b/anims/hp/hp_3_3.png new file mode 100644 index 0000000..5fae18b Binary files /dev/null and b/anims/hp/hp_3_3.png differ diff --git a/anims/items/blaster.png b/anims/items/blaster.png new file mode 100644 index 0000000..f5e5910 Binary files /dev/null and b/anims/items/blaster.png differ diff --git a/anims/items/blaster_card.png b/anims/items/blaster_card.png new file mode 100644 index 0000000..6e45c6c Binary files /dev/null and b/anims/items/blaster_card.png differ diff --git a/anims/items/card.png b/anims/items/card.png new file mode 100644 index 0000000..fad3935 Binary files /dev/null and b/anims/items/card.png differ diff --git a/anims/items/sword.png b/anims/items/sword.png new file mode 100644 index 0000000..8881577 Binary files /dev/null and b/anims/items/sword.png differ diff --git a/anims/items/sword_card.png b/anims/items/sword_card.png new file mode 100644 index 0000000..7e38043 Binary files /dev/null and b/anims/items/sword_card.png differ diff --git a/anims/menu/equip.png b/anims/menu/equip.png new file mode 100644 index 0000000..0566f33 Binary files /dev/null and b/anims/menu/equip.png differ diff --git a/anims/menu/here.png b/anims/menu/here.png new file mode 100644 index 0000000..84ee9a3 Binary files /dev/null and b/anims/menu/here.png differ diff --git a/anims/menu/long_select.png b/anims/menu/long_select.png new file mode 100644 index 0000000..b350134 Binary files /dev/null and b/anims/menu/long_select.png differ diff --git a/anims/menu/map_0.png b/anims/menu/map_0.png index acddf4a..1b49b8d 100644 Binary files a/anims/menu/map_0.png and b/anims/menu/map_0.png differ diff --git a/anims/menu/map_1.png b/anims/menu/map_1.png index 467b1f9..7098ae2 100644 Binary files a/anims/menu/map_1.png and b/anims/menu/map_1.png differ diff --git a/anims/menu/map_full.png b/anims/menu/map_full.png index 2ac152c..c868090 100644 Binary files a/anims/menu/map_full.png and b/anims/menu/map_full.png differ diff --git a/anims/menu/unseen.png b/anims/menu/unseen.png new file mode 100644 index 0000000..6d5be73 Binary files /dev/null and b/anims/menu/unseen.png differ diff --git a/heart/Alonebot.cpp b/heart/Alonebot.cpp index 769f96d..898c698 100644 --- a/heart/Alonebot.cpp +++ b/heart/Alonebot.cpp @@ -23,12 +23,14 @@ Alonebot::Alonebot( float x, float y, int d, Alonebot* p ) { armOffset = Vector2D( 0.f, 0.f ); if( p == 0 || p->currentHP < 1 ) { - maxHP = 3; // TODO: Load shit from savefile - currentHP = 3; + maxHP = 12; // TODO: Load shit from savefile + currentHP = 12; setWeap( 0 ); + offHandWeap = 0; chargeCur = 0.f; chargeInc = 0.f; chargeMax = 0; + std::fill( visited, visited + MAX_ROOMS, false ); } else { w = p->w; @@ -36,8 +38,13 @@ Alonebot::Alonebot( float x, float y, int d, Alonebot* p ) { maxHP = p->maxHP; currentHP = p->currentHP; setWeap( p->weapon ); + offHandWeap = p->offHandWeap; for( std::set::iterator i = p->items.begin(); i != p->items.end(); ++i ) items.emplace( *i ); + for( std::set::iterator i = p->equips.begin(); i != p->equips.end(); ++i ) + equips.emplace( *i ); + for( int i=0; ivisited[i]; chargeCur = p->chargeCur; chargeInc = p->chargeInc; chargeMax = p->chargeMax; @@ -88,7 +95,7 @@ void Alonebot::init( FMOD::System* fmodSys ) { texture = LoadTexture( std::string( "..\\anims\\chars\\alonebot.png" ) ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); - loadVA( (float)w, (float)h ); + loadVA( w, h ); defaultHeight = h; defaultWidth = w; arm[0] = LoadTexture( std::string( "..\\anims\\weapons\\arm.png" ) ); @@ -114,11 +121,16 @@ void Alonebot::init( FMOD::System* fmodSys ) { swrdFrames[i] = LoadTexture( std::string( "..\\anims\\weapons\\sword\\sword_" + s.str() ) + ".png" ); } crouchFrame = LoadTexture( std::string( "..\\anims\\crouch\\alonebot_crouch.png" ) ); - for( int i=0; i<4; i++ ) { + for( int i=0; i<3; i++ ) { std::stringstream s; s << i; HP[i] = LoadTexture( std::string( "..\\anims\\hp\\hp_" + s.str() + ".png" ) ); } + for( int i=0; i<4; i++ ) { + std::stringstream s; + s << i; + HP[i+3] = LoadTexture( std::string( "..\\anims\\hp\\hp_3_" + s.str() + ".png" ) ); + } for( int i=0; i<3; i++ ) { std::stringstream s; s << i; @@ -147,6 +159,19 @@ void Alonebot::init( FMOD::System* fmodSys ) { heartBeat.start( ); } +void Alonebot::add( Item* i ) { + // Add equipment to equipment inventory + if( i->equip ) + equips.emplace( i->id ); + // Or an item to item inventory + else { + items.emplace( i->id ); + // If it's a heart container, increase maxHP and restore to full + if( i->id >= 100 ) + currentHP = maxHP = maxHP + 4; + } +} + GLuint Alonebot::getTex( ) { int ticks = heartBeat.get_ticks( ); int temp = 0; @@ -270,7 +295,7 @@ GLuint Alonebot::getArm( ) { return shotFrames[temp]; } -int Alonebot::getDeath( ) { +int Alonebot::getDeathTime( ) { if( !movable ) return heartBeat.get_ticks( ) - deathStart; return 0; @@ -285,18 +310,18 @@ void Alonebot::drawHP( ) { glPushMatrix( ); glTranslatef( 8.f, 40.f, 0.f ); // Offset glBindTexture( GL_TEXTURE_2D, charge[0] ); - float w, h; - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); + int w, h; + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); - glVertex3f( 0.f, 0.f, 0.f ); + glVertex2i( 0, 0 ); glTexCoord2i( 1, 0 ); - glVertex3f( w, 0.f, 0.f ); + glVertex2i( w, 0 ); glTexCoord2i( 1, 1 ); - glVertex3f( w, h, 0.f ); + glVertex2i( w, h ); glTexCoord2i( 0, 1 ); - glVertex3f( 0.f, h, 0.f ); + glVertex2i( 0, h ); glEnd( ); glTranslatef( 2.f, 2.f, 0.f ); glBindTexture( GL_TEXTURE_2D, charge[1] ); @@ -308,48 +333,48 @@ void Alonebot::drawHP( ) { else if( chargeTime.get_ticks( ) >= 100 ) chargeTime.stop( ); } - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); if( chargeCur == 0 && chargeTime.is_started( ) ) { // Cooldown for shooting - w *= ( (float)chargeMax - chargeTime.get_ticks( ) ) / chargeMax; + w = (int)( w * ( (float)chargeMax - chargeTime.get_ticks( ) ) / chargeMax ); if( weapon == 1 ) // Hidden for blaster w = 0; } else // And for charging - w *= chargeCur / 100.f; + w = (int)( w * chargeCur / 100.f ); if( w < 0 ) w = 0; glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); - glVertex3f( 0.f, 0.f, 0.f ); + glVertex2i( 0, 0 ); glTexCoord2i( 1, 0 ); - glVertex3f( w, 0.f, 0.f ); + glVertex2i( w, 0 ); glTexCoord2i( 1, 1 ); - glVertex3f( w, h, 0.f ); + glVertex2i( w, h ); glTexCoord2i( 0, 1 ); - glVertex3f( 0.f, h, 0.f ); + glVertex2i( 0, h ); glEnd( ); glPopMatrix( ); } for( int i=0; i<3; i++ ) { // Draw HP bar if( i == 1 ) { // Middle portions - for( int j=0; j 0 ) - glTranslatef( 26.f + 20.f*(maxHP-2), 0.f, 0.f ); // Alter transformations for last piece + glTranslatef( 26.f + 20.f*(maxHP/4-2), 0.f, 0.f ); // Alter transformations for last piece glBindTexture( GL_TEXTURE_2D, HP[i] ); - float w, h; - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); + int w, h; + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); - glVertex3f( 0.f, 0.f, 0.f ); + glVertex2i( 0, 0 ); glTexCoord2i( 1, 0 ); - glVertex3f( w, 0.f, 0.f ); + glVertex2i( w, 0 ); glTexCoord2i( 1, 1 ); - glVertex3f( w, h, 0.f ); + glVertex2i( w, h ); glTexCoord2i( 0, 1 ); - glVertex3f( 0.f, h, 0.f ); + glVertex2i( 0, h ); glEnd( ); glPopMatrix( ); } @@ -379,20 +404,20 @@ void Alonebot::drawHP( ) { for( int i=0; i items; + std::set equips; + int maxHP, currentHP; + int weapon, offHandWeap, chargeMax; + float jumpSpeed, chargeCur, chargeInc; Timer jumpTime, courage, idle, chargeTime; int jumpStart, shotStart, crouchStart, deathStart; bool walking, jumping, crouching, canJump, canDrop, drop, canDmg; - float jumpSpeed, chargeCur, chargeInc; - Vector2D armOffset; - int maxHP, currentHP; - int weapon, chargeMax; - std::set items; FMOD::Sound *jumpSFX, *landSFX, *hurtSFX, *doorSFX, *itemSFX, *blstSFX, *swrdSFX; Alonebot( float x = 0.f, float y = 0.f, int d = 1, Alonebot* p = 0 ); ~Alonebot( ); void init( FMOD::System* fmodSys ); + void add( Item* i ); void jump( ); void stand( ); void shoot( ); void crouch( ); void drawHP( ); - int getDeath( ); + int getDeathTime( ); GLuint getTex( ); GLuint getArm( ); int getCourage( ); diff --git a/heart/Game.cpp b/heart/Game.cpp index 1c0063c..14b3aff 100644 --- a/heart/Game.cpp +++ b/heart/Game.cpp @@ -1,7 +1,7 @@ #include "Game.h" -static Level* start; // First level that loads +static Level* start; // First level that loads // Drawing code !! void Game::draw_box( Box* b ) { @@ -11,7 +11,7 @@ void Game::draw_box( Box* b ) { glBindTexture( GL_TEXTURE_2D, b->getTex( ) ); //Enable vertex arrays //Set vertex data - glVertexPointer( 2, GL_FLOAT, 0, b->vertices ); + glVertexPointer( 2, GL_INT, 0, b->vertices ); glEnableClientState( GL_VERTEX_ARRAY ); glTexCoordPointer(2, GL_FLOAT, 0, b->tvertices ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); @@ -38,9 +38,9 @@ void Game::draw_organ( Organ* o ) { glBindTexture( GL_TEXTURE_2D, o->getTex( ) ); //Enable vertex arrays //Set vertex data - glVertexPointer( 2, GL_FLOAT, 0, o->vertices ); + glVertexPointer( 2, GL_INT, 0, o->vertices ); glEnableClientState( GL_VERTEX_ARRAY ); - glTexCoordPointer(2, GL_FLOAT, 0, o->tvertices ); + glTexCoordPointer(2, GL_INT, 0, o->tvertices ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); //Draw quad using vertex data glDrawArrays( GL_QUADS, 0, 4 ); @@ -52,18 +52,18 @@ void Game::draw_organ( Organ* o ) { void Game::draw_arm( Alonebot* p ) { glPushMatrix( ); - float w, h; + int w, h; glTranslatef( p->pos.x, p->pos.y, 0.f ); // Bind texture glBindTexture( GL_TEXTURE_2D, p->getArm() ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); p->loadVA( w, h ); //Enable vertex arrays //Set vertex data - glVertexPointer( 2, GL_FLOAT, 0, p->vertices ); + glVertexPointer( 2, GL_INT, 0, p->vertices ); glEnableClientState( GL_VERTEX_ARRAY ); - glTexCoordPointer(2, GL_FLOAT, 0, p->tvertices ); + glTexCoordPointer(2, GL_INT, 0, p->tvertices ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); //Draw quad using vertex data glDrawArrays( GL_QUADS, 0, 4 ); @@ -74,7 +74,7 @@ void Game::draw_arm( Alonebot* p ) { }; void Game::draw_body( Alonebot* p, GLuint tex ) { - float w, h; + int w, h; glPushMatrix( ); glTranslatef( p->pos.x, p->pos.y, 0.f ); @@ -93,14 +93,14 @@ void Game::draw_body( Alonebot* p, GLuint tex ) { } // Bind texture glBindTexture( GL_TEXTURE_2D, tex ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); - glGetTexLevelParameterfv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); p->loadVA( w, h ); //Enable vertex arrays //Set vertex data - glVertexPointer( 2, GL_FLOAT, 0, p->vertices ); + glVertexPointer( 2, GL_INT, 0, p->vertices ); glEnableClientState( GL_VERTEX_ARRAY ); - glTexCoordPointer(2, GL_FLOAT, 0, p->tvertices ); + glTexCoordPointer(2, GL_INT, 0, p->tvertices ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); //Draw quad using vertex data glDrawArrays( GL_QUADS, 0, 4 ); @@ -128,43 +128,44 @@ void Game::draw_player( Alonebot* p ) { p->armOffset = Vector2D( 0, 0 ); - p->loadVA( (float)p->defaultWidth, (float)p->defaultHeight ); + p->loadVA( p->defaultWidth, p->defaultHeight ); }; void Game::draw_bg( GLuint bg, float p, bool stretch ) { - float w = (float)start->levelWidth; // Current level width - float h = (float)start->levelHeight; // Current level height + int w = start->levelWidth; // Current level width + int h = start->levelHeight; // Current level height if( !stretch ) - h = 480.f; + h = 480; glPushMatrix( ); - if( w != 640.f && p != 0.f ) - glTranslatef( ( w - w / p ) * ( start->cameraX / ( w - 640.f ) ), start->cameraY, 0.f ); + if( w != 640 && p != 0.f ) + glTranslatef( ( w - w / p ) * ( start->cameraX / ( w - 640 ) ), start->cameraY, 0.f ); glBindTexture( GL_TEXTURE_2D, bg ); - Vector2D vertices[4], tvertices[4]; - vertices[0].x = 0.f; // Top left - vertices[0].y = 0.f; - vertices[1].x = w / p; // Top rite - vertices[1].y = 0.f; - vertices[2].x = w / p; // Bot rite + Vector2Di vertices[4], tvertices[4]; + vertices[0].x = 0; // Top left + vertices[0].y = 0; + vertices[1].x = (int)(w / p); // Top rite + vertices[1].y = 0; + vertices[2].x = (int)(w / p); // Bot rite vertices[2].y = h; - vertices[3].x = 0.f; // Bot left + vertices[3].x = 0; // Bot left vertices[3].y = h; - tvertices[0].x = 0.f; // Top left - tvertices[0].y = 0.f; - tvertices[1].x = 1.f; // Top rite - tvertices[1].y = 0.f; - tvertices[2].x = 1.f; // Bot rite - tvertices[2].y = 1.f; - tvertices[3].x = 0.f; // Bot left - tvertices[3].y = 1.f; + tvertices[0].x = 0; // Top left + tvertices[0].y = 0; + tvertices[1].x = 1; // Top rite + tvertices[1].y = 0; + tvertices[2].x = 1; // Bot rite + tvertices[2].y = 1; + tvertices[3].x = 0; // Bot left + tvertices[3].y = 1; + //Enable vertex arrays //Set vertex data - glVertexPointer( 2, GL_FLOAT, 0, vertices ); + glVertexPointer( 2, GL_INT, 0, vertices ); glEnableClientState( GL_VERTEX_ARRAY ); - glTexCoordPointer(2, GL_FLOAT, 0, tvertices ); + glTexCoordPointer(2, GL_INT, 0, tvertices ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); //Draw quad using vertex data glDrawArrays( GL_QUADS, 0, 4 ); @@ -175,17 +176,136 @@ void Game::draw_bg( GLuint bg, float p, bool stretch ) { } void Game::draw_bg( ) { - draw_bg( start->backbackground, 1.25f ); // Background texture, parallax factor - if( start->levelWidth == 640 ) + + if( start->levelWidth == 640 ) { + draw_bg( start->backbackground, 1.f ); // Background texture, parallax factor draw_bg( start->background, 1.f ); - else + } + else { + draw_bg( start->backbackground, 1.25f ); draw_bg( start->background, 1.125f ); + } +}; + +void Game::draw_map( ) { + // Draw the area text + glPushMatrix( ); + glTranslatef( start->cameraX + 200.f, start->cameraY + 14.f, 0.f ); + draw_organ( pauseMenu->getText( start->area ) ); + glPopMatrix( ); + + // Then the full map, and the coloured area on top + glPushMatrix( ); + glTranslatef( start->cameraX + 198.f, start->cameraY + 88.f, 0.f ); + draw_organ( pauseMenu->getFullMap( ) ); + draw_organ( pauseMenu->getMap( start->area ) ); + + // Draw over the spots you have not been + Alonebot* player = start->getPlayer(); + Vector2Di tempPos = Vector2Di( ); + for( int i=0; iMAX_ROOMS; i++ ) { + if( !player->visited[i] ) { + switch( i ) { + case 0: tempPos = Vector2Di( 10, 183 ); break; + case 1: tempPos = Vector2Di( 25, 183 ); break; + case 2: tempPos = Vector2Di( 40, 183 ); break; + case 3: tempPos = Vector2Di( 55, 183 ); break; + case 4: tempPos = Vector2Di( 70, 183 ); break; + case 6: tempPos = Vector2Di( 85, 183 ); break; + case 7: tempPos = Vector2Di( 100, 183 ); break; + case 8: tempPos = Vector2Di( 100, 168 ); break; + case 9: tempPos = Vector2Di( 115, 183 ); break; + case 10: tempPos = Vector2Di( 85, 168 ); break; + case 11: tempPos = Vector2Di( 70, 168 ); break; + case 12: tempPos = Vector2Di( 115, 198 ); break; + case 13: tempPos = Vector2Di( 115, 168 ); break; + case 14: tempPos = Vector2Di( 130, 168 ); break; + case 16: tempPos = Vector2Di( 115, 213 ); break; + } + draw_organ( pauseMenu->setUnseen( tempPos ) ); + } + } + + // Draw the player position + switch( curLevel ) { + case 0: tempPos = Vector2Di( 10, 183 ); break; + case 1: tempPos = Vector2Di( 25, 183 ); break; + case 2: tempPos = Vector2Di( 40, 183 ); break; + case 3: tempPos = Vector2Di( 55, 183 ); break; + case 4: case 5: tempPos = Vector2Di( 70, 183 ); break; + case 6: tempPos = Vector2Di( 85, 183 ); break; + case 7: tempPos = Vector2Di( 100, 183 ); break; + case 8: tempPos = Vector2Di( 100, 168 ); break; + case 9: tempPos = Vector2Di( 115, 183 ); break; + case 10: tempPos = Vector2Di( 85, 168 ); break; + case 11: tempPos = Vector2Di( 70, 168 ); break; + case 12: tempPos = Vector2Di( 115, 198 ); break; + case 13: tempPos = Vector2Di( 115, 168 ); break; + case 14: case 15: tempPos = Vector2Di( 130, 168 ); break; + case 16: tempPos = Vector2Di( 115, 213 ); break; + } + draw_organ( pauseMenu->setHere( tempPos ) ); + + glPopMatrix( ); +}; + +void Game::draw_menu( ) { + Alonebot* p = start->getPlayer( ); + draw_bg( pauseMenu->getMenu( start->menuState ), start->levelWidth / 640.f, false ); + + switch( start->menuState ) { + case 0: { // Draw the pause menu and map + glPushMatrix( ); + glTranslatef( start->cameraX + 16.f, start->cameraY + 264.f + start->selection * 47.f, 0.f ); + draw_organ( pauseMenu->getSelect( ) ); + glPopMatrix( ); + + draw_map( ); + break; + } + case 1: { // Draw the equipment menu + if( p->equips.size( ) == 0 ) + break; + // Draw the currently selected card + glPushMatrix( ); + glTranslatef( start->cameraX + 445.f, start->cameraY + 65.f, 0.f ); + draw_organ( pauseMenu->getCard( start->selection ) ); + glPopMatrix( ); + + // Draw the equipment in player inventory + glPushMatrix( ); + glTranslatef( start->cameraX + 16.f, start->cameraY + 66.f, 0.f ); + draw_organ( pauseMenu->getSlot( p->weapon - 1 ) ); + glTranslatef( 0.f, 60.f, 0.f ); + for( int i=0; iequips.size( ); i++ ) { + draw_organ( pauseMenu->getSlot( i ) ); + glTranslatef( 0.f, 47.f, 0.f ); + } + glPopMatrix( ); + + // Draw the selection bar + glPushMatrix( ); + glTranslatef( start->cameraX + 16.f, start->cameraY + 126.f + start->selection * 47.f, 0.f ); + draw_organ( pauseMenu->getLongSelect( ) ); + glPopMatrix( ); + break; + } + case 2: { // Draw the items menu + break; + } + case 3: { // Draw the upgrades menu + break; + } + case 4: { // Draw the options menu + break; + } + } }; void Game::draw_title( ) { // Draw the title screen - draw_bg( start->backbackground, 1.125f ); - draw_bg( start->background, 1.125f ); + draw_bg( start->backbackground, 1.f ); + draw_bg( start->background, 1.f ); }; void Game::draw_screen( ) { @@ -202,20 +322,11 @@ void Game::draw_screen( ) { // Get a pointer to the player Alonebot* player = start->getPlayer(); - // Draw either the pause screen or the game + // Draw the pause menu if( start->paused ) { - draw_bg( pauseMenu, w / 640.f, false ); - - glPushMatrix( ); - glTranslatef( start->cameraX + 16.f, start->cameraY + 264.f + start->selection * 47.f, 0.f ); - draw_organ( pauseSelect ); - glPopMatrix( ); - - glPushMatrix( ); - glTranslatef( start->cameraX + 200.f, start->cameraY + 14.f, 0.f ); - draw_organ( areaTexts[start->area] ); - glPopMatrix( ); + draw_menu( ); } + // Draw the game else { // Draw the background draw_bg( ); @@ -224,7 +335,7 @@ void Game::draw_screen( ) { std::vector objects = start->getScene( ); // Draw each static object for( unsigned short i=0; i doors = start->getDoors( ); @@ -260,14 +371,13 @@ void Game::draw_screen( ) { draw_organ( doors[i] ); // Draw the death screen when appropriate - if( player->getDeath( ) >= 650 ) { - fadeAlpha = 1.f - ( 1650 - player->getDeath( ) ) / 1000.f; + if( player->getDeathTime( ) >= 650 ) { + fadeAlpha = 1.f - ( 1650 - player->getDeathTime( ) ) / 1000.f; glColor4f( 1.f, 1.f, 1.f, fadeAlpha ); draw_bg( deathShade, w / 640.f, false ); glColor4f( 1.f, 1.f, 1.f, 1.f ); } } - // Draw the health and charge bars always glPushMatrix( ); @@ -389,21 +499,32 @@ void Game::load_screen( bool post ) { if( post ) { post_screen( ); } + + // Load screen assets + fadeShade = LoadTexture( std::string( "..\\anims\\bg\\fade.png" ) ); + deathShade = LoadTexture( std::string( "..\\anims\\bg\\death.png" ) ); + + pauseMenu = new Menu; }; void Game::load_level( int lev, int entrance ) { Level* s; + curLevel = lev; int curArea = 0; Alonebot* p = 0; Alonebot* temp = 0; - if( start != 0 ) { + if( start != 0 ) { // Create the first player object temp = start->getPlayer( ); p = new Alonebot( temp->pos.x, temp->pos.y, temp->dir, temp ); curArea = start->area; delete start; } + // If you haven't been here before, add it to your map + if( lev != INT_MAX && !p->visited[lev] ) + p->visited[lev] = true; + switch( lev ) { case 0: s = new Tutorial0_0( ratio, entrance, p, fmodSystem, sfxChannel ); title = false; break; @@ -439,6 +560,8 @@ void Game::load_level( int lev, int entrance ) { s = new Level1_11_1( ratio, entrance, p, fmodSystem, sfxChannel ); title = false; break; case 16: s = new Level1_12( ratio, entrance, p, fmodSystem, sfxChannel ); title = false; break; + case 17: + s = new Level2_01( ratio, entrance, p, fmodSystem, sfxChannel ); title = false; break; case INT_MAX: { load_screen( true ); s = new Title( ratio, entrance, p, fmodSystem, sfxChannel ); title = true; break; } @@ -490,17 +613,6 @@ Game::Game( ) { pre_screen( ); load_level( ); - fadeShade = LoadTexture( std::string( "..\\anims\\bg\\fade.png" ) ); - deathShade = LoadTexture( std::string( "..\\anims\\bg\\death.png" ) ); - pauseMenu = LoadTexture( std::string( "..\\anims\\menu\\menu.png" ) ); - pauseSelect = new Organ( "..\\anims\\menu\\select.png" ); - - for( int i=0; i + + @@ -139,6 +141,7 @@ + diff --git a/heart/Heart.vcxproj.filters b/heart/Heart.vcxproj.filters index f490ed7..a98724c 100644 --- a/heart/Heart.vcxproj.filters +++ b/heart/Heart.vcxproj.filters @@ -13,9 +13,6 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - {eb2f6ee3-7c59-415e-b011-c8684c3d7a91} - {9e025228-248b-4e99-bb54-1cbc20fde07f} @@ -28,6 +25,9 @@ {7f4d0c22-2338-481f-b66d-a3c2577a64ff} + + {eb2f6ee3-7c59-415e-b011-c8684c3d7a91} + @@ -37,13 +37,13 @@ Source Files - Source Files\Tutorial 0 + Source Files\Level 0 - Source Files\Tutorial 0 + Source Files\Level 0 - Source Files\Tutorial 0 + Source Files\Level 0 Source Files\Level @@ -57,9 +57,6 @@ Source Files\Level - - Source Files\Assets - Source Files\Assets @@ -111,6 +108,15 @@ Source Files\Level 1 + + Source Files + + + Source Files\Level 2 + + + Source Files\Assets + @@ -122,15 +128,18 @@ Header Files - - Header Files - Header Files Header Files + + Header Files + + + Header Files + diff --git a/heart/Level.cpp b/heart/Level.cpp index 0df4e67..3f7f4a5 100644 --- a/heart/Level.cpp +++ b/heart/Level.cpp @@ -21,16 +21,16 @@ Box::~Box( ) { } void Box::loadVA( ) { - Organ::loadVA( (float)w, (float)h ); + Organ::loadVA( w, h ); tvertices[0].x = 0.f; // Top left tvertices[0].y = 0.f; - tvertices[1].x = (1.f * w)/defaultWidth; // Top rite + tvertices[1].x = (1.f * w) / defaultWidth; // Top rite tvertices[1].y = 0.f; - tvertices[2].x = (1.f * w)/defaultWidth; // Bot rite - tvertices[2].y = (1.f * h)/defaultHeight; + tvertices[2].x = (1.f * w) / defaultWidth; // Bot rite + tvertices[2].y = (1.f * h) / defaultHeight; tvertices[3].x = 0.f; // Bot left - tvertices[3].y = (1.f * h)/defaultHeight; + tvertices[3].y = (1.f * h) / defaultHeight; } @@ -110,7 +110,7 @@ Door::Door( float a, float b, int d, bool topper, int t, int e, int width, int h texture = LoadTexture( std::string( "..\\anims\\level\\door.png" ) ); defaultWidth = w; defaultHeight = h; - loadVA( (float)w, (float)h ); + loadVA( w, h ); } Door::~Door( ) { @@ -118,159 +118,6 @@ Door::~Door( ) { } -void Level::handle_key( int key, int action ) { - if( player->getDeath( ) != 0 ) { // You dead - if( action == GLFW_PRESS ) { - if( key == 'X' ) { - levelSwitch = true; - levelSwitchTo = 0; - levelSwentrance = 0; - } - else if( key == GLFW_KEY_ESC ) - quit( 0 ); - } - } - else if( paused ) { // Paused - if( action == GLFW_PRESS ) { - switch( key ) { - case 'X': { - break; - } - case GLFW_KEY_UP: { - selection--; - if( selection < 0 ) - selection = 3; - break; - } - case GLFW_KEY_DOWN: { - selection++; - if( selection > 3 ) - selection = 0; - break; - } - case GLFW_KEY_SPACE: { - paused = !paused; - heartBeat.unpause( ); - break; - } - case GLFW_KEY_ESC: { - quit( 0 ); - } - } - } - } - else { - if( action == GLFW_PRESS ) { // Pressing keys - switch( key ) { - case 'Z': { // Jump! - if( player->crouching && player->canDrop ) { - player->stand( ); - player->pos.y += 18.f; // Crouch coefficient - player->canDrop = false; - } - else if( player->canJump ) { - player->jump( ); - FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->jumpSFX, false, &sfxChannel ) ); - sfxChannel->setVolume( 0.2f ); - } - break; - } - case 'X': { // Shoot! - if( !player->chargeTime.is_started( ) ) { - switch( player->weapon ) { // Different shot depending on the weapon you use - case 1: { // Blaster - Vector2D start = Vector2D( player->dir*15.f, 21.f - (player->crouching?1.f:0.f) ); - if( player->dir == 1 ) - start.x += player->w - 11; - bullets.push_back( new BlasterShot( true, player->pos + start, Vector2D( player->dir*650.f ) ) ); - player->shoot( ); - FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->blstSFX, false, &sfxChannel ) ); - sfxChannel->setVolume( 0.2f ); - break; - } - case 2: { // Sword - Vector2D start = Vector2D( player->dir*65.f, 20.f - (player->crouching?1.f:0.f) ); - if( player->dir == 1 ) - start.x += player->w - 52; - bullets.push_back( new SwordSlash( true, player->dir, player->pos + start ) ); - player->shoot( ); - FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->swrdSFX, false, &sfxChannel ) ); - sfxChannel->setVolume( 0.2f ); - break; - } - } - } - break; - } - case 'C': { // Switch weapons - if( !player->chargeTime.is_started( ) ) { - if( player->weapon == 1 && player->items.find( 2 ) != player->items.end( ) ) { - player->setWeap( 2 ); - } - else if( player->weapon == 2 && player->items.find( 1 ) != player->items.end( ) ) { - player->setWeap( 1 ); - } - } - break; - } - case GLFW_KEY_DOWN: { // Crouch! - player->crouch( ); - break; - } - case GLFW_KEY_SPACE: { // Pause - paused = !paused; - heartBeat.pause( ); - break; - } - case GLFW_KEY_ESC: { - quit( 0 ); - } - } - } - else { // Releasing keys - switch( key ) { - case 'X': { // Charge shot! - if( player->chargeCur != 0.f ) { - float charge = player->chargeCur / 100.f; - player->chargeCur = 0.f; - switch( player->weapon ) { // Different shot depending on the weapon you use - case 1: { // Blaster - if( charge == 1.f ) { - Vector2D start = Vector2D( player->dir*15.f, 21.f - (player->crouching?1.f:0.f) ); - if( player->dir == 1 ) - start.x += player->w - 11; - bullets.push_back( new BlasterShot( true, player->pos + start, Vector2D( player->dir*650.f ) ) ); - player->shoot( ); - FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->blstSFX, false, &sfxChannel ) ); - sfxChannel->setVolume( 0.2f ); - } - break; - } - case 2: { // Sword - if( charge == 1.f ) { - Vector2D start = Vector2D( player->dir*65.f, 20.f - (player->crouching?1.f:0.f) ); - if( player->dir == 1 ) - start.x += player->w - 52; - bullets.push_back( new SwordSlash( true, player->dir, player->pos + start ) ); - player->shoot( ); - FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->swrdSFX, false, &sfxChannel ) ); - sfxChannel->setVolume( 0.2f ); - } - break; - } - } - } - break; - } - case GLFW_KEY_DOWN: { - player->stand( ); - break; - } - } - } - } -} - void Level::quit( int code ) { glfwCloseWindow( ); } @@ -281,6 +128,7 @@ Level::Level( float r, int entrance, Alonebot* p, FMOD::System* fsys, FMOD::Chan cameraV = Vector2D( ); ratio = r; selection = 0; + menuState = 0; paused = false; levelSwitch = 0; levelSwitchTo = 0; @@ -527,16 +375,15 @@ void Level::collision( ) { for( sho i=0; icollides( items[i] ); if( abs( displacement.y ) > 0.f || abs(displacement.x ) > 0.f ) { - switch( items[i]->id ) { - case 1: - case 2: - player->setWeap( items[i]->id ); break; + // Equip it if you can and add to inventory + if( items[i]->equip ) { + if( player->weapon != 0 ) + player->offHandWeap = player->weapon; + player->setWeap( items[i]->id ); } - if( items[i]->id >= 100 ) - player->currentHP = player->maxHP = player->maxHP + 1; + player->add( items[i] ); FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->itemSFX, false, &sfxChannel ) ); sfxChannel->setVolume( 0.2f ); - player->items.emplace( items[i]->id ); delete items[i]; items.erase( items.begin() + i ); break; @@ -654,6 +501,10 @@ void Level::maintenence( float dt ) { void Level::pause( ) { typedef unsigned short sho; + menuState = 0; + selection = 0; + + player->chargeTime.pause( ); heartBeat.pause( ); for( sho i=0; ipause( ); @@ -670,6 +521,9 @@ void Level::pause( ) { void Level::unpause( ) { typedef unsigned short sho; + menuState = 0; + + player->chargeTime.unpause( ); heartBeat.unpause( ); for( sho i=0; iunpause( ); @@ -686,6 +540,215 @@ void Level::unpause( ) { void Level::process_events( float dt ) { } +void Level::handle_key( int key, int action ) { + // Death controls + if( player->getDeathTime( ) != 0 ) { // You dead + if( action == GLFW_PRESS && player->getDeathTime( ) >= 1650 ) { + if( key == 'X' ) { + levelSwitchTo = 0; + levelSwitch = true; + levelSwentrance = 0; + } + else if( key == GLFW_KEY_ESC ) + quit( 0 ); + } + } + + // Pause menu controls + else if( paused ) { // Paused + if( action == GLFW_PRESS ) { + switch( key ) { + case 'Z': { // Back button on pause menu + switch( menuState ) { + case 0: paused = !paused; unpause( ); break; + case 1: menuState = 0; break; + default: break; + } + break; + } + case 'X': { // Selection button on pause menu + switch( menuState ) { + case 0: menuState = selection + 1; break; + case 1: { + if( !player->chargeTime.is_started( ) && player->weapon != selection + 1 ) { + int temp = player->weapon; + player->setWeap( selection + 1 ); + player->offHandWeap = temp; + } + break; + } + default: break; + } + break; + } + case GLFW_KEY_UP: { + selection--; + switch( menuState ) { + case 0: { + if( selection < 0 ) + selection = 3; + break; + } + case 1: { + if( selection < 0 ) + selection = player->equips.size( ) - 1; + break; + } + case 2: { + if( selection < 0 ) + selection = player->items.size( ) - 1; + break; + } + default: break; + } + break; + } + case GLFW_KEY_DOWN: { + selection++; + switch( menuState ) { + case 0: { + if( selection > 3 ) + selection = 0; + break; + } + case 1: { + if( selection > player->equips.size( ) - 1 ) + selection = 0; + break; + } + case 2: { + if( selection > player->items.size( ) - 1 ) + selection = 0; + break; + } + default: break; + } + break; + } + case GLFW_KEY_SPACE: { + paused = !paused; + unpause( ); + break; + } + case GLFW_KEY_ESC: { + quit( 0 ); + } + } + } + } + + // Gameplay controls + else { + if( action == GLFW_PRESS ) { // Pressing keys + switch( key ) { + case 'Z': { // Jump! + if( player->crouching && player->canDrop ) { + player->stand( ); + player->pos.y += 18.f; // Crouch coefficient + player->canDrop = false; + } + else if( player->canJump ) { + player->jump( ); + FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->jumpSFX, false, &sfxChannel ) ); + sfxChannel->setVolume( 0.2f ); + } + break; + } + case 'X': { // Shoot! + if( !player->chargeTime.is_started( ) ) { + switch( player->weapon ) { // Different shot depending on the weapon you use + case 1: { // Blaster + Vector2D start = Vector2D( player->dir*15.f, 21.f - (player->crouching?1.f:0.f) ); + if( player->dir == 1 ) + start.x += player->w - 11; + bullets.push_back( new BlasterShot( true, player->pos + start, Vector2D( player->dir*650.f ) ) ); + player->shoot( ); + FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->blstSFX, false, &sfxChannel ) ); + sfxChannel->setVolume( 0.2f ); + break; + } + case 2: { // Sword + Vector2D start = Vector2D( player->dir*65.f, 20.f - (player->crouching?1.f:0.f) ); + if( player->dir == 1 ) + start.x += player->w - 52; + bullets.push_back( new SwordSlash( true, player->dir, player->pos + start ) ); + player->shoot( ); + FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->swrdSFX, false, &sfxChannel ) ); + sfxChannel->setVolume( 0.2f ); + break; + } + } + } + break; + } + case 'C': { // Switch weapons + if( !player->chargeTime.is_started( ) ) { + if( player->offHandWeap != 0 ) { + int temp = player->weapon; + player->setWeap( player->offHandWeap ); + player->offHandWeap = temp; + } + } + break; + } + case GLFW_KEY_DOWN: { // Crouch! + player->crouch( ); + break; + } + case GLFW_KEY_SPACE: { // Pause + paused = !paused; + pause( ); + break; + } + case GLFW_KEY_ESC: { + quit( 0 ); + } + } + } + else { // Releasing keys + switch( key ) { + case 'X': { // Charge shot! + if( player->chargeCur != 0.f ) { + float charge = player->chargeCur / 100.f; + player->chargeCur = 0.f; + switch( player->weapon ) { // Different shot depending on the weapon you use + case 1: { // Blaster + if( charge == 1.f ) { + Vector2D start = Vector2D( player->dir*15.f, 21.f - (player->crouching?1.f:0.f) ); + if( player->dir == 1 ) + start.x += player->w - 11; + bullets.push_back( new BlasterShot( true, player->pos + start, Vector2D( player->dir*650.f ) ) ); + player->shoot( ); + FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->blstSFX, false, &sfxChannel ) ); + sfxChannel->setVolume( 0.2f ); + } + break; + } + case 2: { // Sword + if( charge == 1.f ) { + Vector2D start = Vector2D( player->dir*65.f, 20.f - (player->crouching?1.f:0.f) ); + if( player->dir == 1 ) + start.x += player->w - 52; + bullets.push_back( new SwordSlash( true, player->dir, player->pos + start ) ); + player->shoot( ); + FmodErrorCheck( fmodSystem->playSound( FMOD_CHANNEL_FREE, player->swrdSFX, false, &sfxChannel ) ); + sfxChannel->setVolume( 0.2f ); + } + break; + } + } + } + break; + } + case GLFW_KEY_DOWN: { + player->stand( ); + break; + } + } + } + } +} + Alonebot* Level::getPlayer( ) { return player; } diff --git a/heart/Level.h b/heart/Level.h index 9e20ff4..e2f96fc 100644 --- a/heart/Level.h +++ b/heart/Level.h @@ -3,6 +3,7 @@ class Box : public Organ { public: + Vector2D tvertices[4]; Box( float a = 0.f, float b = 0.f, int width = 32, int height = 16 ); ~Box( ); @@ -12,7 +13,6 @@ class Box : public Organ { class Dropbox : public Box { public: - Vector2D vertices[4], tvertices[4]; Dropbox( float a = 0.f, float b = 0.f, int width = 32, int height = 4 ); ~Dropbox( ); }; @@ -62,7 +62,7 @@ class Level { // Generic level template public: int area; bool paused; - int selection; + int selection, menuState; int optionValues[6]; GLuint background, backbackground; float cameraX, cameraY; // Camera position, might change to Vector2D ? @@ -255,4 +255,11 @@ class Level1_12 : public Level { Level1_12( float r = 1.f, int entrance = 0, Alonebot* p = 0, FMOD::System* fsys = 0, FMOD::Channel* sfx = 0 ); ~Level1_12( ); void process_events( float dt ); +}; + +class Level2_01 : public Level { + public: + Level2_01( float r = 1.f, int entrance = 0, Alonebot* p = 0, FMOD::System* fsys = 0, FMOD::Channel* sfx = 0 ); + ~Level2_01( ); + void process_events( float dt ); }; \ No newline at end of file diff --git a/heart/Level1_02.cpp b/heart/Level1_02.cpp index 9eac47b..cc14a3b 100644 --- a/heart/Level1_02.cpp +++ b/heart/Level1_02.cpp @@ -28,7 +28,7 @@ Level( r, entrance, p, fsys, sfx ) { objects.push_back( new Box( 0.f, 0.f, 486 ) ); // Ceiling objects.push_back( new Box( 666.f, 0.f, levelWidth - 666 ) ); for( int i=0; i<3; i++ ) { // Floating platforms - objects.push_back( new Box( 254 + 256.f * i, 332.f, 128, 16 ) ); + objects.push_back( new Box( 240 + 256.f * i, 332.f, 156, 16 ) ); } objects.push_back( new Dropbox( 526.f, 165.f, 100 ) ); for( int i=6; i<10; i++ ) { // Left staircase diff --git a/heart/Level1_02_1.cpp b/heart/Level1_02_1.cpp index 51d4700..d9e0842 100644 --- a/heart/Level1_02_1.cpp +++ b/heart/Level1_02_1.cpp @@ -26,7 +26,7 @@ Level( r, entrance, p, fsys, sfx ) { objects.push_back( new Box( levelWidth - 16.f, 0.f, 16, 112 ) ); // Add item(s) - if( player->items.find( 2 ) == player->items.end( ) ) + if( player->equips.find( 2 ) == player->equips.end( ) ) items.push_back( new Sword( Vector2D( levelWidth - 164.f, 132.f ) ) ); // Add doors diff --git a/heart/Level1_09.cpp b/heart/Level1_09.cpp index ef542f8..82e661f 100644 --- a/heart/Level1_09.cpp +++ b/heart/Level1_09.cpp @@ -11,7 +11,7 @@ Level( r, entrance, p, fsys, sfx ) { // Initialize backgrounds and music bgMusic = "..\\music\\beat171-restless.mp3"; background = LoadTexture( std::string( "..\\anims\\bg\\bg_07.png" ) ); - backbackground = LoadTexture( std::string( "..\\anims\\bg\\bbg_03.png" ) ); + backbackground = LoadTexture( std::string( "..\\anims\\bg\\bbg_04.png" ) ); // Create player, placement depending upon the entrance taken switch( entrance ) { diff --git a/heart/Level1_12.cpp b/heart/Level1_12.cpp index d5e9a27..796c7e2 100644 --- a/heart/Level1_12.cpp +++ b/heart/Level1_12.cpp @@ -36,7 +36,7 @@ Level( r, entrance, p, fsys, sfx ) { objects.push_back( new Box( levelWidth - 16.f, 0.f, 16, 312 ) ); // Add doors - doors.push_back( new Door( 0.f, 312.f, 1, false, 0, 0 ) ); // Left door + doors.push_back( new Door( 0.f, 312.f, 1, false, 17, 0 ) ); // Left door doorToppers.push_back( new Door( 0.f, 312.f, 1, true ) ); objects.push_back( new Box( 0.f, 312.f, 16, 4 ) ); diff --git a/heart/Level2_01.cpp b/heart/Level2_01.cpp new file mode 100644 index 0000000..2ce708a --- /dev/null +++ b/heart/Level2_01.cpp @@ -0,0 +1,77 @@ +#include "Level.h" + + +Level2_01::Level2_01( float r, int entrance, Alonebot* p, FMOD::System* fsys, FMOD::Channel* sfx ) : +Level( r, entrance, p, fsys, sfx ) { + // Inititalize area and size of level + area = 2; + levelWidth = 640; + levelHeight = 480; + + // Initialize backgrounds and music + bgMusic = "..\\music\\beat311-creep.mp3"; + background = LoadTexture( std::string( "..\\anims\\bg\\bg_10.png" ) ); + backbackground = LoadTexture( std::string( "..\\anims\\bg\\bbg_04.png" ) ); + + // Create player, placement depending upon the entrance taken + switch( entrance ) { + case 0: + player = new Alonebot( levelWidth - 38.f, 316.f, p->dir, p ); break; + case 1: + player = new Alonebot( 20.f, 316.f, p->dir, p ); break; + } + + // Add static level objects to array + objects.push_back( new Box( 0.f, 376.f, levelWidth ) ); // Ground floor + objects.push_back( new Box( 0.f, 0.f, levelWidth ) ); // Ceiling + objects.push_back( new Box( 0.f, 0.f, 16, 316 ) ); // Walls + objects.push_back( new Box( levelWidth - 16.f, 0.f, 16, 316 ) ); + + // Add doors + doors.push_back( new Door( 0.f, 312.f, 1, false, 0, 0 ) ); // Left door + doorToppers.push_back( new Door( 0.f, 312.f, 1, true ) ); + objects.push_back( new Box( 0.f, 312.f, 16, 4 ) ); + + doors.push_back( new Door( levelWidth - 32.f, 312.f, -1, false, 16, 1 ) );// Right door + doorToppers.push_back( new Door( levelWidth - 32.f, 312.f, -1, true ) ); + objects.push_back( new Box( levelWidth - 16.f, 312.f, 16, 4 ) ); + + // Start the heart + player->init( fmodSystem ); + heartBeat.start( ); + + // Try to center the camera + cameraX = player->pos.x - 320; + cameraY = player->pos.y - 240; +} + +Level2_01::~Level2_01( ) { + typedef unsigned short sho; + + sfxChannel->stop( ); + delete player; + for( sho i=0; ipos.x = (float)newPos.x; + unseen->pos.y = (float)newPos.y; + return unseen; +} + +Organ* Menu::setHere( Vector2Di newPos ) { + here->pos.x = (float)newPos.x; + here->pos.y = (float)newPos.y; + return here; +} + +GLuint Menu::getMenu( int menuState ) { + return pauseMenus[menuState]; +} + +Organ* Menu::getLongSelect( ) { + return longSelect; +} + +Organ* Menu::getSelect( ) { + return pauseSelect; +} + +Organ* Menu::getCard( int item ) { + return itemCards[item]; +} + +Organ* Menu::getSlot( int item ) { + return itemSlots[item]; +} \ No newline at end of file diff --git a/heart/Menu.h b/heart/Menu.h new file mode 100644 index 0000000..bbfdaa7 --- /dev/null +++ b/heart/Menu.h @@ -0,0 +1,33 @@ +#include "Level.h" + + +class Menu { + public: + static const int MAX_AREAS = 2; // Areas are composed of levels + + GLuint pauseMenus[4]; // Textures for pause menu + Organ *fullMap, *unseen, *here; // Main menu and map textures + Organ *pauseSelect, *longSelect; + Organ* areaTexts[MAX_AREAS]; // For describing current area + Organ* areaMaps[MAX_AREAS]; // Full area maps + + Organ* itemCards[2]; // Holds item details + Organ* itemSlots[2]; + + Menu( ); + ~Menu( ); + + Organ* getText( int area ); + Organ* getMap( int area ); + Organ* getFullMap( ); + + Organ* setUnseen( Vector2Di newPos ); + Organ* setHere( Vector2Di newPos ); + + GLuint getMenu( int menuState ); + Organ* getLongSelect( ); + Organ* getSelect( ); + + Organ* getCard( int item ); + Organ* getSlot( int item ); +}; \ No newline at end of file diff --git a/heart/Organ.cpp b/heart/Organ.cpp index efcc6ad..1dcf983 100644 --- a/heart/Organ.cpp +++ b/heart/Organ.cpp @@ -21,37 +21,37 @@ void Organ::init( const char* path ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); } GLuint Organ::getTex( ) { return texture; } -void Organ::loadVA( float w, float h ) { - vertices[0].x = 0.f; // Top left - vertices[0].y = 0.f; +void Organ::loadVA( int w, int h ) { + vertices[0].x = 0; // Top left + vertices[0].y = 0; vertices[1].x = w; // Top rite - vertices[1].y = 0.f; + vertices[1].y = 0; vertices[2].x = w; // Bot rite vertices[2].y = h; - vertices[3].x = 0.f; // Bot left + vertices[3].x = 0; // Bot left vertices[3].y = h; - tvertices[0].x = 0.f; // Top left - tvertices[0].y = 0.f; - tvertices[1].x = 1.f; // Top rite - tvertices[1].y = 0.f; - tvertices[2].x = 1.f; // Bot rite - tvertices[2].y = 1.f; - tvertices[3].x = 0.f; // Bot left - tvertices[3].y = 1.f; + tvertices[0].x = 0; // Top left + tvertices[0].y = 0; + tvertices[1].x = 1; // Top rite + tvertices[1].y = 0; + tvertices[2].x = 1; // Bot rite + tvertices[2].y = 1; + tvertices[3].x = 0; // Bot left + tvertices[3].y = 1; if( vertical == true ) { collisionBox[0] = vertices[0]; - collisionBox[1] = Vector2D( h, 0.f ); - collisionBox[2] = Vector2D( h, w ); - collisionBox[3] = Vector2D( 0.f, w ); + collisionBox[1] = Vector2Di( h, 0 ); + collisionBox[2] = Vector2Di( h, w ); + collisionBox[3] = Vector2Di( 0, w ); } else { collisionBox[0] = vertices[0]; @@ -76,20 +76,20 @@ float Organ::dist( Organ* target, bool useX, bool useY ) { } void Organ::adjustCollideBox( float mult ) { - float fw, fh; - fw = w * mult; - fh = h * mult; + int fw, fh; + fw = (int)(w * mult); + fh = (int)(h * mult); if( vertical == true ) { - collisionBox[0] += Vector2D( -fh, -fw ); - collisionBox[1] += Vector2D( fh, -fw ); - collisionBox[2] += Vector2D( fh, fw ); - collisionBox[3] += Vector2D( -fh, fw ); + collisionBox[0] += Vector2Di( -fh, -fw ); + collisionBox[1] += Vector2Di( fh, -fw ); + collisionBox[2] += Vector2Di( fh, fw ); + collisionBox[3] += Vector2Di( -fh, fw ); } else { - collisionBox[0] += Vector2D( -fw, -fh ); - collisionBox[1] += Vector2D( fw, -fh ); - collisionBox[2] += Vector2D( fw, fh ); - collisionBox[3] += Vector2D( -fw, fh ); + collisionBox[0] += Vector2Di( -fw, -fh ); + collisionBox[1] += Vector2Di( fw, -fh ); + collisionBox[2] += Vector2Di( fw, fh ); + collisionBox[3] += Vector2Di( -fw, fh ); } } @@ -103,12 +103,18 @@ Vector2D Organ::collides( Organ* target ) { // Create an array of four corners of rectangle Vector2D self[4]; - for( int i=0; i<4; i++ ) - self[i] += collisionBox[i] + pos; + for( int i=0; i<4; i++ ) { + self[i].x += collisionBox[i].x; + self[i].y += collisionBox[i].y; + self[i] += pos; + } // Same with collision target Vector2D targ[4]; - for( int i=0; i<4; i++ ) - targ[i] = target->collisionBox[i] + target->pos; + for( int i=0; i<4; i++ ) { + targ[i].x += target->collisionBox[i].x; + targ[i].y += target->collisionBox[i].y; + targ[i] += target->pos; + } // Find min and max on x axis float selfMin = min( min( min( self[0].x, self[1].x ), self[2].x ), self[3].x ); @@ -192,7 +198,7 @@ NPC::NPC( Vector2D p ) { vertical = false; movable = false; solid = true; - loadVA( 0.f, 0.f ); + loadVA( 0, 0 ); heartBeat.start( ); } @@ -223,7 +229,7 @@ Phatbot::Phatbot( Vector2D p ) { movable = false; solid = false; dir = 1; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( 0.2f ); heartBeat.start( ); } @@ -256,7 +262,7 @@ Projectile::Projectile( bool play, Vector2D p, Vector2D v ) { movable = true; solid = true; hitTime = 0; - loadVA( 0.f, 0.f ); + loadVA( 0, 0 ); heartBeat.start( ); } @@ -306,7 +312,7 @@ BlasterShot::BlasterShot( bool play, Vector2D p, Vector2D v ) { } else dir = (xspeed >= 0)?1:-1; - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( !playerShot ) adjustCollideBox( -0.2f ); heartBeat.start( ); @@ -349,7 +355,7 @@ void BlasterShot::hit( ) { glBindTexture( GL_TEXTURE_2D, texture ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( vertical ) pos.y += dir * h / 2; else @@ -380,7 +386,7 @@ SwordSlash::SwordSlash( bool play, int d, Vector2D p, Vector2D v ) { s << i; hitFrames[i] = LoadTexture( std::string( "..\\anims\\projectiles\\sword\\sword_hit_" + s.str() ) + ".png" ); } - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( !playerShot ) adjustCollideBox( -0.2f ); heartBeat.start( ); @@ -394,7 +400,8 @@ SwordSlash::~SwordSlash( ) { void SwordSlash::walk( float dt, Organ* pl ) { if( pl != 0 ) { dir = pl->dir; - pos = pl->pos + Vector2D( pl->dir*65.f, 20.f ); + pos = pl->pos; + pos += Vector2D( pl->dir*65.f, 20.f ); if( pl->dir == 1 ) pos.x += pl->w - 52; } @@ -427,7 +434,7 @@ void SwordSlash::hit( ) { glBindTexture( GL_TEXTURE_2D, texture ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); - loadVA( (float)w, (float)h ); + loadVA( w, h ); } @@ -458,7 +465,7 @@ CannonShot::CannonShot( bool play, Vector2D p, Vector2D v ) { } else dir = (xspeed >= 0)?1:-1; - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( !playerShot ) adjustCollideBox( -0.2f ); heartBeat.start( ); @@ -501,7 +508,7 @@ void CannonShot::hit( ) { glBindTexture( GL_TEXTURE_2D, texture ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( vertical == true ) pos.y += dir * h / 2; else @@ -531,7 +538,7 @@ Bone::Bone( bool play, Vector2D p, Vector2D d ) { hitFrames[i] = LoadTexture( std::string( "..\\anims\\projectiles\\bone\\bone_hit_" + s.str() ) + ".png" ); } dir = 0; - loadVA( (float)w, (float)h ); + loadVA( w, h ); if( !playerShot ) adjustCollideBox( -0.2f ); dest = d; @@ -589,7 +596,7 @@ void Bone::hit( ) { glBindTexture( GL_TEXTURE_2D, texture ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); - loadVA( (float)w, (float)h ); + loadVA( w, h ); } @@ -605,7 +612,7 @@ Enemy::Enemy( ) { maxHP = 0; currentHP = 0; flags = 0; - loadVA( 0.f, 0.f ); + loadVA( 0, 0 ); heartBeat.start( ); } @@ -657,7 +664,7 @@ Medusa::Medusa( Vector2D p, int d ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.2f ); heartBeat.start( ); } @@ -725,7 +732,7 @@ Runner::Runner( Vector2D p, int d ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.2f ); } @@ -871,7 +878,7 @@ Shooter::Shooter( Vector2D p, int d, int del, bool vert ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.2f ); heartBeat.start( ); } @@ -944,7 +951,7 @@ Sawblade::Sawblade( int dist, Vector2D p, int d, bool vert ) { start -= ( distance + w ); } } - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.2f ); heartBeat.start( ); } @@ -1024,7 +1031,7 @@ Skeleton::Skeleton( Vector2D p, int d ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.1f ); } @@ -1169,7 +1176,7 @@ Zombie::Zombie( int dist, Vector2D p, int d ) { distance = dist - w * 2; if( distance < 0 ) distance = 0; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( -0.2f ); heartBeat.start( ); } @@ -1221,11 +1228,13 @@ void Zombie::walk( float dt ) { Item::Item( Vector2D p ) { w = 0; h = 0; + id = 0; pos = p; vertical = false; movable = false; + equip = false; solid = true; - loadVA( 0.f, 0.f ); + loadVA( 0, 0 ); } Item::~Item( ) { @@ -1237,6 +1246,7 @@ Blaster::Blaster( Vector2D p ) { vertical = false; movable = false; solid = true; + equip = true; id = 1; dir = 1; @@ -1245,7 +1255,7 @@ Blaster::Blaster( Vector2D p ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( 0.2f ); } @@ -1259,6 +1269,7 @@ Sword::Sword( Vector2D p ) { vertical = false; movable = false; solid = true; + equip = true; id = 2; dir = 1; @@ -1267,7 +1278,7 @@ Sword::Sword( Vector2D p ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( 0.2f ); } @@ -1281,6 +1292,7 @@ HeartUp::HeartUp( Vector2D p, int i ) { vertical = false; movable = false; solid = true; + equip = false; id = i; dir = 1; @@ -1289,7 +1301,7 @@ HeartUp::HeartUp( Vector2D p, int i ) { glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h ); defaultHeight = h; defaultWidth = w; - loadVA( (float)w, (float)h ); + loadVA( w, h ); adjustCollideBox( 0.2f ); } diff --git a/heart/Organ.h b/heart/Organ.h index 255759e..dc5fc9c 100644 --- a/heart/Organ.h +++ b/heart/Organ.h @@ -12,8 +12,9 @@ class Organ { float xspeed, yspeed; bool movable, solid, vertical; int defaultWidth, defaultHeight; - Vector2D pos, vertices[4], tvertices[4]; - Vector2D collisionBox[4]; + Vector2D pos; + // Pointer and texture vertices + Vector2Di vertices[4], tvertices[4], collisionBox[4]; Organ( ); Organ( const char* path ); @@ -23,7 +24,7 @@ class Organ { void init( const char* path ); virtual GLuint getTex( ); - void loadVA( float w, float h ); + void loadVA( int w, int h ); float dist( Organ* target, bool useX = true, bool useY = true ); void adjustCollideBox( float mult = 0.f ); Vector2D collides( Organ* target ); @@ -248,6 +249,7 @@ class Zombie : public Enemy { class Item : public Organ { public: int id; + bool equip; Item( Vector2D p = Vector2D( ) ); virtual ~Item( ); diff --git a/heart/Title.cpp b/heart/Title.cpp index 49c257d..b4e35cd 100644 --- a/heart/Title.cpp +++ b/heart/Title.cpp @@ -4,7 +4,7 @@ Title::Title( float r, int entrance, Alonebot* p, FMOD::System* fsys, FMOD::Channel* sfx ) { area = INT_MAX; // Inititalize width of level, camera variable, level change - levelWidth = 720; // Width of level in pixels; 1.125 times the background width + levelWidth = 640; // Width of level in pixels levelHeight = 480; cameraX = 0.f; cameraY = 0.f; @@ -120,17 +120,17 @@ void Title::handle_key( int key, int action ) { case 0: { levelSwitch = true; break; - } + } case 1: { selection = 0; optionMenu = true; background = options[1][selection][optionValues[selection]]; backbackground = options[0][optionValues[0]][optionValues[1]]; break; - } + } case 2: { quit( 0 ); - } + } } } break; diff --git a/heart/Tutorial0_0.cpp b/heart/Tutorial0_0.cpp index 8c3db61..d88ed13 100644 --- a/heart/Tutorial0_0.cpp +++ b/heart/Tutorial0_0.cpp @@ -31,7 +31,7 @@ Level( r, entrance, p, fsys, sfx ) { objects.push_back( new Box( levelWidth - 158.f, 128.f, 16, 64 ) ); // Edge platform rail // Add item(s) - if( player->items.find( 1 ) == player->items.end( ) ) + if( player->equips.find( 1 ) == player->equips.end( ) ) items.push_back( new Blaster( Vector2D( levelWidth - 124.f, 152.f ) ) ); // Add NPC(s) diff --git a/heart/Tutorial0_1.cpp b/heart/Tutorial0_1.cpp index 50b5aa5..17e209e 100644 --- a/heart/Tutorial0_1.cpp +++ b/heart/Tutorial0_1.cpp @@ -16,32 +16,32 @@ Level( r, entrance, p, fsys, sfx ) { // Create player, placement depending upon the entrance taken switch( entrance ) { case 0: - player = new Alonebot( 20.f, 316.f, 1, p ); break; + player = new Alonebot( 20.f, 316.f, p->dir, p ); break; case 1: - player = new Alonebot( 20.f, 116.f, 1, p ); break; + player = new Alonebot( 20.f, 116.f, p->dir, p ); break; case 2: - player = new Alonebot( levelWidth - 38.f, 316.f, -1, p ); break; + player = new Alonebot( levelWidth - 38.f, 316.f, p->dir, p ); break; case 3: - player = new Alonebot( levelWidth - 38.f, 116.f, -1, p ); break; + player = new Alonebot( levelWidth - 38.f, 116.f, p->dir, p ); break; } // Add static level objects to array objects.push_back( new Box( 0.f, 376.f, levelWidth ) ); // Ground floor objects.push_back( new Box( 0.f, 176.f, 92 ) ); // Left door platform - objects.push_back( new Dropbox( 110.f, 234.f, 48 ) ); - objects.push_back( new Dropbox( 188.f, 292.f, 48 ) ); // Staircase platforms - objects.push_back( new Box( 270.f, 344.f, 48 ) ); - objects.push_back( new Box( 218.f, 180.f, 52 ) ); // Floating platform at start - objects.push_back( new Box( 378.f, 156.f, 52 ) ); // Floating platforms leading to edge - objects.push_back( new Box( 538.f, 132.f, 52 ) ); - objects.push_back( new Box( 698.f, 108.f, 52 ) ); // Highest platform, slightly longer + objects.push_back( new Dropbox( 100.f, 234.f, 64 ) ); // Staircase platforms + objects.push_back( new Dropbox( 180.f, 292.f, 64 ) ); + objects.push_back( new Box( 270.f, 344.f, 57 ) ); // Last staircase platform before sawblade + objects.push_back( new Box( 218.f, 180.f, 64 ) ); // Floating platform at start + objects.push_back( new Box( 378.f, 156.f, 64 ) ); // Floating platforms leading to edge + objects.push_back( new Box( 538.f, 132.f, 64 ) ); + objects.push_back( new Box( 698.f, 108.f, 72 ) ); // Highest platform, slightly longer objects.push_back( new Box( 874.f, 156.f, 128 ) ); // Two long platforms objects.push_back( new Box( 1126.f, 166.f, 128 ) ); // before the edge objects.push_back( new Box( 1368.f, 176.f, 72 ) ); // Edge platform with door - objects.push_back( new Box( 452.f, 360.f, 50 ) ); - objects.push_back( new Box( 652.f, 360.f, 50 ) ); - objects.push_back( new Box( 852.f, 360.f, 50 ) ); - objects.push_back( new Box( 1052.f, 360.f, 50 ) ); + objects.push_back( new Box( 452.f, 360.f, 75 ) ); // Three bottom platforms between sawblades + objects.push_back( new Box( 652.f, 360.f, 75 ) ); + objects.push_back( new Box( 852.f, 360.f, 75 ) ); + objects.push_back( new Box( 1052.f, 360.f, 75 ) ); // Add doors doors.push_back( new Door( 0.f, 112.f, 1, false, 0, 2 ) ); // Top left door @@ -61,10 +61,10 @@ Level( r, entrance, p, fsys, sfx ) { objects.push_back( new Box( levelWidth - 16.f, 312.f, 16, 4 ) ); // Add enemies - enemies.push_back( new Sawblade( 150, Vector2D( 302.f, 360.f ) ) ); - enemies.push_back( new Sawblade( 150, Vector2D( 502.f, 360.f ) ) ); - enemies.push_back( new Sawblade( 150, Vector2D( 702.f, 360.f ) ) ); - enemies.push_back( new Sawblade( 150, Vector2D( 902.f, 360.f ) ) ); + enemies.push_back( new Sawblade( 125, Vector2D( 327.f, 360.f ) ) ); + enemies.push_back( new Sawblade( 125, Vector2D( 527.f, 360.f ) ) ); + enemies.push_back( new Sawblade( 125, Vector2D( 727.f, 360.f ) ) ); + enemies.push_back( new Sawblade( 125, Vector2D( 927.f, 360.f ) ) ); // Start the heart player->init( fmodSystem ); diff --git a/heart/Tutorial0_2.cpp b/heart/Tutorial0_2.cpp index db411f4..4aabc6d 100644 --- a/heart/Tutorial0_2.cpp +++ b/heart/Tutorial0_2.cpp @@ -16,11 +16,11 @@ Level( r, entrance, p, fsys, sfx ) { // Create player, placement depending upon the entrance taken switch( entrance ) { case 0: - player = new Alonebot( 20.f, 316.f, 1, p ); break; + player = new Alonebot( 20.f, 316.f, p->dir, p ); break; case 1: - player = new Alonebot( 20.f, 116.f, 1, p ); break; + player = new Alonebot( 20.f, 116.f, p->dir, p ); break; case 2: - player = new Alonebot( levelWidth - 38.f, 260.f, 1, p ); break; + player = new Alonebot( levelWidth - 38.f, 260.f, p->dir, p ); break; } // Add static level objects to array diff --git a/heart/Vector2D.cpp b/heart/Vector2D.cpp index 1959b3b..b744e60 100644 --- a/heart/Vector2D.cpp +++ b/heart/Vector2D.cpp @@ -9,6 +9,13 @@ Vector2D::Vector2D( float x, float y ) { this->y = y; } +const float Vector2D::_x( ) { + return x; +} + +const float Vector2D::_y( ) { + return y; +} //----------------------------------------------------------------------------- // Purpose: Rotate a vector @@ -20,7 +27,6 @@ void Vector2D::Rotate( const float angle ) { y = yt; } - //----------------------------------------------------------------------------- // Purpose: Get vector magnitude //----------------------------------------------------------------------------- @@ -28,7 +34,6 @@ float Vector2D::Magnitude() const { return sqrtf(x * x + y * y); } - //----------------------------------------------------------------------------- // Purpose: Convert vector to a unit vector and return previous magnitude //----------------------------------------------------------------------------- @@ -43,23 +48,20 @@ float Vector2D::Normalize( ) { return mag; } - //----------------------------------------------------------------------------- // Purpose: Dot Product //----------------------------------------------------------------------------- -float Vector2D::DotProduct( const Vector2D &v2 ) const { +float Vector2D::DotProduct( const Vector2D& v2 ) const { return (x * v2.x) + (y * v2.y); } - //----------------------------------------------------------------------------- // Purpose: Cross Product //----------------------------------------------------------------------------- -float Vector2D::CrossProduct( const Vector2D &v2 ) const { +float Vector2D::CrossProduct( const Vector2D& v2 ) const { return (x * v2.y) - (y * v2.x); } - //----------------------------------------------------------------------------- // Purpose: Return an empty vector //----------------------------------------------------------------------------- @@ -67,7 +69,6 @@ Vector2D Vector2D::Zero( ) { return Vector2D(0, 0); } - //----------------------------------------------------------------------------- // Purpose: Get distance between two vectors //----------------------------------------------------------------------------- @@ -75,7 +76,6 @@ float Vector2D::Distance( const Vector2D& v1, const Vector2D& v2 ) { return sqrtf( pow((v2.x - v1.x), 2 ) + pow((v2.y - v1.y), 2) ); } - Vector2D& Vector2D::operator= ( const Vector2D& v2 ) { if (this == &v2) return *this; @@ -86,7 +86,6 @@ Vector2D& Vector2D::operator= ( const Vector2D& v2 ) { return *this; } - Vector2D& Vector2D::operator+= ( const Vector2D& v2 ) { x += v2.x; y += v2.y; @@ -94,7 +93,6 @@ Vector2D& Vector2D::operator+= ( const Vector2D& v2 ) { return *this; } - Vector2D& Vector2D::operator-= ( const Vector2D& v2 ) { x -= v2.x; y -= v2.y; @@ -102,7 +100,6 @@ Vector2D& Vector2D::operator-= ( const Vector2D& v2 ) { return *this; } - Vector2D& Vector2D::operator*= ( const float scalar ) { x *= scalar; y *= scalar; @@ -110,7 +107,6 @@ Vector2D& Vector2D::operator*= ( const float scalar ) { return *this; } - Vector2D& Vector2D::operator/= ( const float scalar ) { x /= scalar; y /= scalar; @@ -118,32 +114,165 @@ Vector2D& Vector2D::operator/= ( const float scalar ) { return *this; } - -const Vector2D Vector2D::operator+ ( const Vector2D &v2 ) const { +const Vector2D Vector2D::operator+ ( const Vector2D& v2 ) const { return Vector2D(*this) += v2; } - -const Vector2D Vector2D::operator- ( const Vector2D &v2 ) const { +const Vector2D Vector2D::operator- ( const Vector2D& v2 ) const { return Vector2D(*this) -= v2; } - const Vector2D Vector2D::operator* ( const float scalar ) const { return Vector2D(*this) *= scalar; } - const Vector2D Vector2D::operator/ ( const float scalar ) const { return Vector2D(*this) /= scalar; } - bool Vector2D::operator== ( const Vector2D& v2 ) const { return ((x == v2.x) && (y == v2.y)); } - bool Vector2D::operator!= ( const Vector2D& v2 ) const { return !((x == v2.x) && (y == v2.y)); +} + + +// Vector2Di +//----------------------------------------------------------------------------- +// Purpose: Constructor +//----------------------------------------------------------------------------- +Vector2Di::Vector2Di( int x, int y ) { + this->x = x; + this->y = y; +} + +const int Vector2Di::_x( ) { + return x; +} + +const int Vector2Di::_y( ) { + return y; +} + +//----------------------------------------------------------------------------- +// Purpose: Rotate a vector +//----------------------------------------------------------------------------- +void Vector2Di::Rotate( const float angle ) { + float xt = (x * cosf(angle)) - (y * sinf(angle)); + float yt = (y * cosf(angle)) + (x * sinf(angle)); + x = (int)xt; + y = (int)yt; +} + +//----------------------------------------------------------------------------- +// Purpose: Get vector magnitude +//----------------------------------------------------------------------------- +int Vector2Di::Magnitude() const { + return (int)sqrtf((float)x * x + (float)y * y); +} + +//----------------------------------------------------------------------------- +// Purpose: Convert vector to a unit vector and return previous magnitude +//----------------------------------------------------------------------------- +int Vector2Di::Normalize( ) { + int mag = Magnitude( ); + + if( mag != 0 ) { + x /= mag; + y /= mag; + } + + return mag; +} + +//----------------------------------------------------------------------------- +// Purpose: Dot Product +//----------------------------------------------------------------------------- +int Vector2Di::DotProduct( const Vector2Di& v2 ) const { + return (x * v2.x) + (y * v2.y); +} + +//----------------------------------------------------------------------------- +// Purpose: Cross Product +//----------------------------------------------------------------------------- +int Vector2Di::CrossProduct( const Vector2Di& v2 ) const { + return (x * v2.y) - (y * v2.x); +} + +//----------------------------------------------------------------------------- +// Purpose: Return an empty vector +//----------------------------------------------------------------------------- +Vector2Di Vector2Di::Zero( ) { + return Vector2Di(0, 0); +} + +//----------------------------------------------------------------------------- +// Purpose: Get distance between two vectors +//----------------------------------------------------------------------------- +int Vector2Di::Distance( const Vector2Di& v1, const Vector2Di& v2 ) { + return (int)sqrtf( pow(((float)v2.x - (float)v1.x), 2.f ) + pow(((float)v2.y - (float)v1.y), 2.f) ); +} + +Vector2Di& Vector2Di::operator= ( const Vector2Di& v2 ) { + if (this == &v2) + return *this; + + x = v2.x; + y = v2.y; + + return *this; +} + +Vector2Di& Vector2Di::operator+= ( const Vector2Di& v2 ) { + x += v2.x; + y += v2.y; + + return *this; +} + +Vector2Di& Vector2Di::operator-= ( const Vector2Di& v2 ) { + x -= v2.x; + y -= v2.y; + + return *this; +} + +Vector2Di& Vector2Di::operator*= ( const int scalar ) { + x *= scalar; + y *= scalar; + + return *this; +} + +Vector2Di& Vector2Di::operator/= ( const int scalar ) { + x /= scalar; + y /= scalar; + + return *this; +} + +const Vector2Di Vector2Di::operator+ ( const Vector2Di& v2 ) const { + return Vector2Di(*this) += v2; +} + +const Vector2Di Vector2Di::operator- ( const Vector2Di& v2 ) const { + return Vector2Di(*this) -= v2; +} + +const Vector2Di Vector2Di::operator* ( const int scalar ) const { + return Vector2Di(*this) *= scalar; +} + +const Vector2Di Vector2Di::operator/ ( const int scalar ) const { + return Vector2Di(*this) /= scalar; +} + +bool Vector2Di::operator== ( const Vector2Di& v2 ) const { + return ((x == v2.x) && (y == v2.y)); +} + +bool Vector2Di::operator!= ( const Vector2Di& v2 ) const { + return !((x == v2.x) && (y == v2.y)); } \ No newline at end of file diff --git a/heart/Vector2D.h b/heart/Vector2D.h index 9c17716..1428e34 100644 --- a/heart/Vector2D.h +++ b/heart/Vector2D.h @@ -4,12 +4,15 @@ class Vector2D { public: float x, y; - Vector2D(float x = 0, float y = 0); - ~Vector2D() {}; + Vector2D( float x = 0.f, float y = 0.f ); + ~Vector2D( ) {}; + + const float _x( ); + const float _y( ); void Rotate( const float angle ); - float Magnitude() const; - float Normalize(); + float Magnitude( ) const; + float Normalize( ); Vector2D& operator= ( const Vector2D& v2 ); @@ -18,16 +21,51 @@ class Vector2D { Vector2D& operator*= ( const float scalar ); Vector2D& operator/= ( const float scalar ); - const Vector2D operator+( const Vector2D &v2 ) const; + const Vector2D operator+( const Vector2D& v2 ) const; float DotProduct( const Vector2D& v2 ) const; float CrossProduct( const Vector2D& v2 ) const; static Vector2D Zero(); static float Distance( const Vector2D& v1, const Vector2D& v2 ); - const Vector2D operator-( const Vector2D &v2 ) const; + const Vector2D operator-( const Vector2D& v2 ) const; const Vector2D operator*( const float scalar ) const; const Vector2D operator/( const float scalar ) const; bool operator== ( const Vector2D& v2 ) const; bool operator!= ( const Vector2D& v2 ) const; +}; + + +class Vector2Di { + public: + int x, y; + Vector2Di( int x = 0, int y = 0 ); + ~Vector2Di() {}; + + const int _x( ); + const int _y( ); + + void Rotate( const float angle ); + int Magnitude() const; + int Normalize(); + + Vector2Di& operator= ( const Vector2Di& v2 ); + + Vector2Di& operator+= ( const Vector2Di& v2 ); + Vector2Di& operator-= ( const Vector2Di& v2 ); + Vector2Di& operator*= ( const int scalar ); + Vector2Di& operator/= ( const int scalar ); + + const Vector2Di operator+( const Vector2Di& v2 ) const; + int DotProduct( const Vector2Di& v2 ) const; + int CrossProduct( const Vector2Di& v2 ) const; + + static Vector2Di Zero(); + static int Distance( const Vector2Di& v1, const Vector2Di& v2 ); + const Vector2Di operator-( const Vector2Di& v2 ) const; + const Vector2Di operator*( const int scalar ) const; + const Vector2Di operator/( const int scalar ) const; + + bool operator== ( const Vector2Di& v2 ) const; + bool operator!= ( const Vector2Di& v2 ) const; }; \ No newline at end of file diff --git a/music/beat299-stars.mp3 b/music/beat299-stars.mp3 new file mode 100644 index 0000000..2b91d5f Binary files /dev/null and b/music/beat299-stars.mp3 differ diff --git a/music/beat432-source.mp3 b/music/beat432-source.mp3 new file mode 100644 index 0000000..73d881a Binary files /dev/null and b/music/beat432-source.mp3 differ