// stub boost::shared_ptr<Solid> Repository::newSolid(SolidEnum type) { switch(type) { case ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(1000,2000,20,Vector2d(120,120),Vector2d(0,.1),0.,.1); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case BIG_ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(5000,10000,35,Vector2d(720,320),Vector2d(0,-.1),0.,.03); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case ALIEN: { boost::shared_ptr<Image> pa1( new BitmapImage("images/alien1-1.bmp") ); boost::shared_ptr<Image> pa2( new BitmapImage("images/alien1-2.bmp") ); boost::shared_ptr<Image> pa3( new BitmapImage("images/alien1-3.bmp") ); AnimatedImage * pa( new AnimatedImage(pa1,5) ); pa->add(pa2); pa->add(pa3); NewtonianMass * pm = new NewtonianMass(100,2000,12,Vector2d(500,300), Vector2d(-.1,0),0,0) ; boost::shared_ptr<Mass> pBaseAlienMass( pm ); Mass * alienMass = new DamageMass(pBaseAlienMass, 1000); boost::shared_ptr<Solid> alien(new SimpleSolid( alienMass, pa) ); return alien; } default: throw(0); } }
void ShipBuildingArea::deinitialise() { // Stop all sounds ambientSound_->stop(); robot()->stopAllSounds(); alien()->stopAllSounds(); // Delete sound delete ambientSound_; ambientSound_ = 0; escapePodBuildingPuzzle_.deinitialise(); sky_.deinitialise(); distantBackground_.deinitialise(); closeBackground_.deinitialise(); midground_.deinitialise(); playerStage_.deinitialise(); foreground_.deinitialise(); delete ending_; }
void ShipBuildingArea::initialise() { ambientSound_ = new SoundEffect; ambientSound_->initialise("audio/Background Ambience/Ambience1.wav"); ambientSound_->play(0); escapePodBuildingPuzzle_.initialise(); sky_.initialise("scripts/ShipBuildingAreaSky.txt"); distantBackground_.initialise("scripts/ShipBuildingAreaDistantBackground.txt"); closeBackground_.initialise("scripts/ShipBuildingAreaCloseBackground.txt"); midground_.initialise("scripts/ShipBuildingAreaMidground.txt"); playerStage_.initialise("scripts/ShipBuildingAreaPlayerStage.txt"); foreground_.initialise("scripts/ShipBuildingAreaForeground.txt"); // Set alien x alien()->setX(200); robot()->setCenterX(150); ending_ = new Video; ending_->initialise("cutscenes/5Ending.mp4"); }
void ShipBuildingArea::render() { sky_.render(); distantBackground_.render(); closeBackground_.render(); midground_.render(); playerStage_.render(); if(secondPass_) { escapePodBuildingPuzzle_.render(); } if(!secondPass_) { // Render the robot robot()->render(); } // Render alien alien()->render(); foreground_.render(); }
void show_screensaver(){ //erase_screen(); reset_current_video(); alien(); }
void ShipBuildingArea::independentUpdate(float deltaTime) { setScreenWidth( IwGxGetScreenWidth() ); setScreenHeight( IwGxGetScreenHeight() ); int direction = 0; // Make the robot follow the alien if(!secondPass_) { robot()->followAlien(alien()->getX(), alien()->getY()); } // Update pointer system input()->update(); // Check for screen touches if (input()->getTouchCount() != 0) { // Create a touch pointer and let it point to the the current touch command Touch* touch = input()->getTouch(0); // If a touch was set correctly if (touch != NULL) { escapePodBuildingPuzzle_.touchUpdate(touch->x_, touch->y_); if( !escapePodBuildingPuzzle_.movingABuildPiece() && !secondPass_) { // If player is trying to move right while the alien is at the edge of its moving area if( alien()->getX() >= ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_))) && touch->x_ > ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_)) ) ) { if (playerStage_.isScrollingRight()) { alien()->setWalkingState(true); robot()->setWalking(); direction = -1; } } // If player is trying to move left while the alien is at the edge of its moving area else if( alien()->getX() <= ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) && touch->x_ < ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) ) { if (playerStage_.isScrollingLeft()) { alien()->setWalkingState(true); robot()->setWalking(); direction = 1; } } else { // If the touch is to the right of the alien if (touch->x_ > alien()->getX() ) { // Move the alien right alien()->moveRight(); alien()->setWalkingState(true); } // If the touch is the left of the alien if (touch->x_ < alien()->getX()) { // Move the alien left alien()->moveLeft(); alien()->setWalkingState(true); } } } } // end if (touch != NULL) // if multi-touch is available then ... if (input()->isMultiTouch()) { if (input()->getTouchCount() > 1) { touch = input()->getTouch(1); if (touch != NULL) { // Add update input effects here } } } } if (input()->getTouchCount() == 0 ) { escapePodBuildingPuzzle_.noTouchEventsActive(); // Set the alien walking to false as there are no touch events alien()->setWalkingState(false); } sky_.update(direction*deltaTime*SCROLL_SPEED*0.2); distantBackground_.update(direction*deltaTime*SCROLL_SPEED*0.4); closeBackground_.update(direction*deltaTime*SCROLL_SPEED*0.6); midground_.update(direction*deltaTime*SCROLL_SPEED*0.8); playerStage_.update(direction*deltaTime*SCROLL_SPEED); foreground_.update(direction*deltaTime*SCROLL_SPEED*1.8); escapePodBuildingPuzzle_.movePuzzle(direction*deltaTime*SCROLL_SPEED); // If the alien is beyond a set distance from the escape pod if( alien()->getX() >= ( escapePodBuildingPuzzle_.getCenterX() + offsetFromEscapePod) ) { // Move to the next level ambientSound_->stop(); robot()->stopAllSounds(); alien()->stopAllSounds(); Level::playerExitingLevel(); } if(escapePodBuildingPuzzle_.isComplete() && !endingPlayed_) { ambientSound_->stop(); ending_->play(); endingPlayed_ = true; } if(secondPass_) { alien()->setHoldingHose(true); } }
int main(int argc, char *argv[]) { Matrix projectionMatrix; Matrix modelMatrix; Matrix viewMatrix; init(); ShaderProgram program(RESOURCE_FOLDER "vertex_textured.glsl", RESOURCE_FOLDER "fragment_textured.glsl"); glUseProgram(program.programID); float lastFrameTicks = 0.0f; // float vertices[] = {-0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5}; // float texCoords[] = {0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0}; // float vertices[] = {-0.09, -0.09, 0.09, -0.09, 0.09, 0.09, -0.09, -0.09, 0.09, 0.09, -0.09, 0.09}; Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 4096 ); SDL_Event event; bool done = false; /* Sprites courtesy of http://gooperblooper22.deviantart.com/art/Space-Invaders-Sprite-Sheet-135338373 */ GLuint spriteSheetTexture = LoadTexture("space_invaders_sprite_sheet_by_gooperblooper22.png"); GLuint white = LoadTexture("white.png"); GLuint textTexture = LoadTexture("font1.png"); Mix_Music *bgm = Mix_LoadMUS("bgm.mp3"); Mix_Chunk *missile = Mix_LoadWAV("157439__nengisuls__misslie-1.wav"); bool pressed = false; int score = 0; int currentIndex = 0; int state; const int numFrames = 2; float animation[] = {(74.0f/617.0f),(107.0f/617.0f)}; float animationElapsed = 0.0f; float framesPerSecond = 0.0004f; std::vector<SheetSprite> aliens; while (!done) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) { done = true; } } program.setProjectionMatrix(projectionMatrix); program.setModelMatrix(modelMatrix); program.setViewMatrix(viewMatrix); float ticks = (float)SDL_GetTicks()/1000; float elapsed = ticks - lastFrameTicks; lastFrameTicks = ticks; animationElapsed += 1/elapsed; if(animationElapsed > 1.0/framesPerSecond) { currentIndex++; animationElapsed = 0.0; if(currentIndex > numFrames-1) { currentIndex = 0; } } glClear(GL_COLOR_BUFFER_BIT); score = ticks; SheetSprite menu(spriteSheetTexture, 160.0f/617.0f, 1.0f/2035.0f, 250.0f/617.0f, 171.0f/2035.0f, 0.5); Entity text; Player cannon(spriteSheetTexture, 277.0f/617.0f, 227.0f/2035.0f, 26.0f/617.0f, 17.0f/2035.0f, 0.05); SheetSprite alien(spriteSheetTexture, animation[currentIndex], (225.0f/2035.0f), 22.0f/617.0f, 16.0f/2035.0f, 0.05); const Uint8 *keys = SDL_GetKeyboardState(NULL); switch (state) { case STATE_MAIN_MENU: menu.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, true); menu.draw(program); if (!Mix_PlayingMusic()) { Mix_PlayMusic(bgm, -1); } if (keys[SDL_SCANCODE_RETURN]) { state++; } break; case STATE_GAME_LEVEL: text.DrawText(program, textTexture, "Score:" + std::to_string(score), 0.075, 0, -0.23, 0.9); cannon.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, white, alien); cannon.draw(program); alien.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, false); alien.draw(program); if (keys[SDL_SCANCODE_SPACE]) { Mix_PlayChannel( -1, missile, 0); Mix_VolumeChunk(missile, 15); } if (keys[SDL_SCANCODE_ESCAPE] && (state == 1)) { pressed = true; state++; } break; case STATE_PAUSE: if (Mix_PlayingMusic()) { Mix_PausedMusic(); } text.DrawText(program, textTexture, "Paused", 0.1, 0, -0.23, 0); if (keys[SDL_SCANCODE_ESCAPE] && pressed) { pressed = false; state--; } break; } SDL_GL_SwapWindow(displayWindow); } Mix_FreeMusic(bgm); Mix_FreeChunk(missile); Mix_Quit(); cleanup(); return 0; }