Example #1
1
bool NickScene::onInitialize()
{
    Vector3 nodeCenter = Vector3(0.0f, 0.0f, 0.0f);
    
	//-----------------------------------------------------------------
	// create the initial platform which has a button that user can hit
    // to turn the globe on
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter = Vector3(0.0f, 100.0f, 300.0f);
        
        //start position Waypoint this is where the player starts/resets
        m_WPstart  = new Start(this, "Objects/goal.obj", 0.125f);
        if ( !m_WPstart->initialize(new LightShader(0.2f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
        m_WPstart->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 10.0f));
        m_WPstart->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(m_WPstart);

		// create a platform
		Platform *platform = new Platform(this, Vector3(40.0f, 1.0f, 40.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize initial platform\n"); return false; }
		platform->setPosition(nodeCenter + Vector3(0.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
    }
	m_graph->popNode();
	
    
    //-----------------------------------------------------------------
	// create long platform that has cannons shooting at it
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter += Vector3(0.0f, -30.0f, -130.0f);
        
		// create a platform
		Platform *platform = new Platform(this, Vector3(10.0f, 1.0f, 220.0f));
		if ( !platform->initialize(new LightShader(0.3f, 1.0f, 8, RAND_LIGHT_COLOR))) { GLOG("WARNING: Could not initialize cannon platform\n"); }
		platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        bool rightSide = false;
        for (int i = 0; i < 10; i++) {
            float cannonZ = (platform->getSize().z * 0.5f) - 50.0f - (i * 15.0f);
            float fireTime = 0.4f + RANDF(1.0f);
            
            // add a cannon aiming at the platform
            Cannon *cannon = new Cannon(this, Vector3(3.0f, 3.0f, 6.0f), 120.0f, fireTime);
            if (!cannon->initialize(new LightShader(0.1f, 1.0f, 8, Color(0.1f, 0.8f, 0.2f)))) { GLOG("WARNING: could not initialize first cannon\n"); }
            float cannonX = rightSide ? 20.0f : -20.0f;
            cannon->setPosition(nodeCenter + Vector3(cannonX, 10.0f, cannonZ));
            float yaw = rightSide ? 90.0f : -90.0f;
            cannon->setOrientation(yaw, -20.0f, 0.0f);
            cannon->addToDynamicWorld(m_dynamicsWorld);
            m_graph->attach(cannon);
            rightSide = !rightSide;
            
            m_cannons.push_back(cannon);
        }
        
        // create a button that will stop the cannons
        NickButton *stop_cannon_button = new NickButton(this, &NickScene::stopCannonsHit, Vector3(8.0f, 0.5f, 4.0f));
        if (!stop_cannon_button->initialize(new LightShader(0.3f, 1.0f, 8, RAND_COLOR))) { GLOG("ERROR: could not create stop_cannon_button\n"); }
		stop_cannon_button->setPosition(nodeCenter + Vector3(0.0f, stop_cannon_button->getSize().y, -105.0f));
		stop_cannon_button->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(stop_cannon_button);
    }
	m_graph->popNode();
    
    
    //-----------------------------------------------------------------
	// create platform after the cannon platform, which just has cube pyramid
    // that covers a gap to the next platform
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter += Vector3(0.0f, 0.0f, -120.0f);
        
        // create a checkpoint now that user has gotten through cannons
        NickCheckPoint *cp = new NickCheckPoint(this, "Objects/goal.obj", 0.125f);
		if ( !cp->initialize(new LightShader(0.2f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
		cp->setPosition(nodeCenter + Vector3(8.0f, 0.5f, 0.0f));
		m_allCheckpoints.push_back(cp);
		cp->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(cp);
        cp->attachParticleSystem(new WaypointParticleSystem(200));
        
		// create a platform
		Platform *platform = new Platform(this, Vector3(50.0f, 1.0f, 12.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize gap platform\n"); return false; }
		platform->setPosition(nodeCenter + Vector3(25.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        // cube pyramid right before gap
        m_graph->pushNode();
		Vector3 cubeSize = Vector3(1.5f, 1.5f, 0.5f);
		Vector3 startPoint = nodeCenter + Vector3(49.0f, cubeSize.y / 2.0f, -5.0f);
		CubeGroups::createCubePyramid(this, 7, startPoint, cubeSize, 0.1f, 90.0f);
		m_graph->popNode();
        
        // create a second platform after gap
		platform = new Platform(this, Vector3(20.0f, 1.0f, 10.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize 2nd gap platform\n"); return false; }
		platform->setPosition(nodeCenter + Vector3(65.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
    }
	m_graph->popNode();
    
    
    // create a conveyor to take player up to next section
    Conveyor *conveyor1 = new Conveyor(this, Vector3(10.0f, 1.0f, 80.0f), 2.5f );
    if ( !conveyor1->initialize(new LightTexScrollShader(0.3f, 1.0f, 4, Color(1.0f, 1.0f, 1.0f), Vector3(0.0f, -1.0f, 0.0f), conveyor1->getSpeed() * 0.5f, 3.0f))) { GLOG("ERROR: Could not initialize conveyor1\n"); return false; }
    conveyor1->setPosition(nodeCenter + Vector3(85.0f, 2.0f, -35.0f));
    conveyor1->setOrientation(180.0f, 5.0f, 0.0f);
    conveyor1->loadTexture("Textures/conveyor.tga");
    conveyor1->addToDynamicWorld(m_dynamicsWorld);
    m_graph->attach(conveyor1);
    
    
    //-----------------------------------------------------------------
	// create seemingly random small platform that user has to jump between
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter += Vector3(85.0f, 5.0f, -85.0f);
        
        float lastZ = 0.0f;
        for (int i = 0; i < 20; i++) {
            Vector3 position = Vector3(-10.0f + RANDF(20.0f), -2.0f + RANDF(4.0f), lastZ - (5.0f + RANDF(5.0f)));
            
            Platform *platform = new Platform(this, Vector3(4.0f + RANDF(5.0f), 1.0f + RANDF(2.0f), 4.0f + RANDF(5.0f)));
            if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize sparse platform\n"); return false; }
            platform->setPosition(nodeCenter + position);
            platform->addToDynamicWorld(m_dynamicsWorld);
            m_graph->attach(platform);
            
            lastZ = position.z - platform->getSize().z * 0.5f;
        }
        
        nodeCenter.z += lastZ - 10.0f;
        
        // larger platform at the end of the small platforms
        Platform *platform = new Platform(this, Vector3(15.0f, 1.0f, 15.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize post-sparse platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
        
        // create a checkpoint now that user has gotten through sparse platforms
        NickCheckPoint *cp = new NickCheckPoint(this, "Objects/goal.obj", 0.125f);
		if ( !cp->initialize(new LightShader(0.2f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
		cp->setPosition(nodeCenter + Vector3(0.0f, 0.5f, 0.0f));
		m_allCheckpoints.push_back(cp);
		cp->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(cp);
        cp->attachParticleSystem(new WaypointParticleSystem(200));
    }
    m_graph->popNode();
    
    
    //-----------------------------------------------------------------
    // create a slanted platform that drops down onto a large trampoline
    //-----------------------------------------------------------------
    m_graph->pushNode();
    {
        nodeCenter += Vector3(-25.0f, -5.0f, -10);
        
        // angled platform down to trampoline
        Platform *platform = new Platform(this, Vector3(30.0f, 1.0f, 15.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize slanted1 platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
        platform->setOrientation(0.0f, 0.0f, -20.0f);
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
        
        // create large trampoline to bounce off
        Trampoline *tramp = new Trampoline(this, 80.0f, 50.0f);
        if ( !tramp->initialize(new TrampolineShader()) ) { GLOG("ERROR: Could not initialize large trampoline\n"); return false; }
        tramp->setPosition(nodeCenter + Vector3(-30.0f, -75.0f, 0.0f));
        tramp->loadTexture("Textures/trampoline.tga");
        tramp->addToDynamicWorld(m_dynamicsWorld);
        registerForSimulationTicks(tramp);
        m_graph->attach(tramp);
        
        // angled trampoline up on other side of trampoline
        platform = new Platform(this, Vector3(30.0f, 1.0f, 15.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize slanted2 platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(-70.0f, -15.0f, 0.0f));
        platform->setOrientation(0.0f, 0.0f, 20.0f);
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
    }
    m_graph->popNode();
    
    
    //-----------------------------------------------------------------
    // create a row of trampolines that takes you towards the globe
    //-----------------------------------------------------------------
    m_graph->pushNode();
    {
        nodeCenter += Vector3(-105.0f, -10.0f, -20.0f);
        
        // platform before trampolines
        Platform *platform = new Platform(this, Vector3(20.0f, 1.0f, 50.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize pre-tramp platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
        
        nodeCenter += Vector3(0.0f, 0.0f, -15.0f);
        
        // create 4 trampolines in a line at alternating angles
        float sign = -1.0f;
        for (int i = 0; i < 4; i++) {
            // first trampoline
            Trampoline *tramp = new Trampoline(this, 10.0f, 15.0f);
            if ( !tramp->initialize(new TrampolineShader()) ) { GLOG("ERROR: Could not initialize an angled tramp\n"); return false; }
            tramp->setPosition(nodeCenter + Vector3(sign * 6.0, 0.0f, -30.0f + (i * -15.0f)));
            sign *= -1.0f;
            tramp->setRoll(sign * 30.0f);
            tramp->loadTexture("Textures/trampoline.tga");
            tramp->addToDynamicWorld(m_dynamicsWorld);
            registerForSimulationTicks(tramp);
            m_graph->attach(tramp);
        }
        
        // platform after trampolines
        platform = new Platform(this, Vector3(50.0f, 1.0f, 20.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize after tramp platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(-25.0f, 0.0f, -100.0f));
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
        
        // create a checkpoint now that user has gotten through trampolines
        NickCheckPoint *cp = new NickCheckPoint(this, "Objects/goal.obj", 0.125f);
		if ( !cp->initialize(new LightShader(0.1f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
		cp->setPosition(nodeCenter + Vector3(-10.0f, 1.0f, -100.0f));
		m_allCheckpoints.push_back(cp);
		cp->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(cp);
        cp->attachParticleSystem(new WaypointParticleSystem(200));
    }
    m_graph->popNode();
    
    
    //-----------------------------------------------------------------
    // create a row of trampolines that takes you towards the globe
    //-----------------------------------------------------------------
    m_graph->pushNode();
    {
        nodeCenter += Vector3(-50.0f, 0.0f, -170.0f);
        
        // create a conveyor to take player past fire breathers
        Conveyor *conveyor1 = new Conveyor(this, Vector3(15.0f, 1.0f, 100.0f), 2.5f );
        if ( !conveyor1->initialize(new LightTexScrollShader(0.3f, 1.0f, 4, Color(1.0f, 1.0f, 1.0f), Vector3(0.0f, -1.0f, 0.0f), conveyor1->getSpeed() * 0.5f, 3.0f))) { GLOG("ERROR: Could not initialize conveyor1\n"); return false; }
        conveyor1->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
        conveyor1->setOrientation(180.0f, 0.0f, 0.0f);
        conveyor1->loadTexture("Textures/conveyor.tga");
        conveyor1->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(conveyor1);
        
        // create a fire breathing hydralisk
        FireBreather *fireBreather = new FireBreather(this, 15.0f, 5.0f, 2.0f);
        if ( !fireBreather->initialize(new LightTexShader(0.2f, 1.0, 8, Color(1.0f, 1.0f, 1.0f)))) { GLOG("ERROR: could not create fire breather\n"); return false; }
        fireBreather->setPosition(nodeCenter + Vector3(-20.0f, 5.0f, 15.0f));
        fireBreather->setOrientation(-90.0f, 0.0f, 0.0f);
        fireBreather->loadTexture("Textures/hydralisk.tga");
        fireBreather->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(fireBreather);
        fireBreather->attachParticleSystem(new FireParticleSystem(500));
        
        // create a fire breathing hydralisk
        fireBreather = new FireBreather(this, 15.0f, 5.0f, 2.0f);
        if ( !fireBreather->initialize(new LightTexShader(0.2f, 1.0, 8, Color(1.0f, 1.0f, 1.0f)))) { GLOG("ERROR: could not create fire breather\n"); return false; }
        fireBreather->setPosition(nodeCenter + Vector3(20.0f, 5.0f, -10.0f));
        fireBreather->setOrientation(90.0f, 0.0f, 0.0f);
        fireBreather->loadTexture("Textures/hydralisk.tga");
        fireBreather->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(fireBreather);
        fireBreather->attachParticleSystem(new FireParticleSystem(500));
    }
    m_graph->popNode();
    
    
    //-----------------------------------------------------------------
    // create platform that has cannon which shoots globe
    //-----------------------------------------------------------------
    m_graph->pushNode();
    {
        nodeCenter += Vector3(20.0f, 0.0f, -65.0f);
        
        // platform after fire breathers
        Platform *platform = new Platform(this, Vector3(15.0f, 1.0f, 30.0f));
        if ( !platform->initialize(new LightShader(0.3f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize fire platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
        platform->setOrientation(30.0f, 0.0f, 0.0f);
        platform->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(platform);
        
        // create a button that will shoot the cannon at globe
        NickButton *globe_shoot_button = new NickButton(this, &NickScene::shootGlobeHit, Vector3(10.0f, 0.5f, 6.0f));
        if (!globe_shoot_button->initialize(new LightShader(0.3f, 1.0f, 8, RAND_COLOR))) { GLOG("ERROR: could not create globe_button\n"); return false; }
		globe_shoot_button->setPosition(nodeCenter + Vector3(5.0f, globe_shoot_button->getSize().y + 0.25f, -8.0f));
        globe_shoot_button->setOrientation(30.0f, 0.0f, 0.0f);
		globe_shoot_button->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(globe_shoot_button);
        
        m_globeCannon = new Cannon(this, Vector3(5.0f, 5.0f, 10.0f), 80.0f);
        if (!m_globeCannon->initialize(new LightShader(0.1f, 1.0f, 8, Color(0.1f, 0.8f, 0.2f)))) { GLOG("WARNING: could not initialize first cannon\n"); }
        m_globeCannon->setPosition(nodeCenter + Vector3(-0.0f, 2.0f, -40.0f));
        m_globeCannon->setOrientation(260.0f, 0.0f, 0.0f);
        m_globeCannon->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(m_globeCannon);
    }
    m_graph->popNode();
    
    //-----------------------------------------------------------------
	// create the ending platform that has the globe and waypoint on it
	//-----------------------------------------------------------------
    m_graph->pushNode();
    {
        nodeCenter = Vector3(0.0f, 30.0f, -600.0f);
        
        //// create a platform
		Platform *platform = new Platform(this, Vector3(70.0f, 2.0f, 70.0f));
		if ( !platform->initialize(new LightShader(0.2f, 1.0f, 4, RAND_COLOR))) { GLOG("ERROR: Could not initialize ending platform\n"); return false; }
        platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        // create a fracture globe that explodes
        Sphere *globe = new Sphere(this, 20.0f);
        if ( !globe->initialize(new LightTexScrollShader(1.0f, 0.2f, 2, Color(1.0f, 1.0f, 1.0f, 1.0f), Vector3(1.0f, 0.0f, 0.0f), 0.001f))) { GLOG("ERROR: could not initialize globe.\n"); return false; }
        globe->setPosition(nodeCenter + Vector3(0.0f, 30.0f, 0.0f));
        globe->setOrientation(0.0f, -90.0f, 0.0f);
        globe->loadTexture("Textures/earth.tga");
        m_globeFracture = new FractureObject(globe, "Textures/voronoi_fracure.tga", 80.0f);
        if ( !m_globeFracture->addToScene(this) ) { GLOG("ERROR: could not add globe fracture to scene.\n"); return false; }
    }
    m_graph->popNode();
    
    
    // create a particle system
    ParticleSystem *m_particleSystem = new StarryParticleSystem(2000);
    m_particleSystem->startSystem();
    m_graph->attach(m_particleSystem);
    
    m_playerParticleSystem = new PlayerParticleSystem(300);
    m_playerParticleSystem->startSystem();
    m_graph->attach(m_playerParticleSystem);
    
    
	// create the player and return result
	return resetPlayer();
}
//--------------------------------------------------------------
void GrafPlayerApp::loadTags()
{
		
	if( threadedLoader.bResponseReady )
	{
		
		if( threadedLoader.getResponse() == 1 && threadedLoader.totalLoaded > 0 && tags.size() < threadedLoader.totalToLoad)
		{
			
			loadStatus = "Loading...";
			if( tags.size() < threadedLoader.totalLoaded ){
				grafTagMulti temptTag;
				tags.push_back( temptTag );
				int toLoad = tags.size()-1;
				tags[ toLoad ] = threadedLoader.tags[ toLoad ];
				smoother.smoothTag(4, &tags[ toLoad ]);
				tags[toLoad].average();
				tags[toLoad].average();
			}
			
		}else if( tags.size() > 0 && tags.size() >= threadedLoader.totalToLoad ){
			
			threadedLoader.stop();
			mode = PLAY_MODE_PLAY;
			resetPlayer(0);
		}
		
	}
	
	threadedLoader.update();
	
}
Example #3
0
void setupPlayer(PLAYER* plr)
{
	COORDINATE target;
	char direction;
	char ok = 'n';

	while(ok=='n')
	{

		resetPlayer(plr);
	
		interactivePlaceShip(plr, "Carrier", BOAT_CARRIER);
		interactivePlaceShip(plr, "Battleship", BOAT_BATTLESHIP);
		interactivePlaceShip(plr, "Destroyer", BOAT_DESTROYER);
		interactivePlaceShip(plr, "Submarine", BOAT_SUB);
		interactivePlaceShip(plr, "Patrol Boat", BOAT_PT);
		
		printGrid(plr->board);
	
		printf("Is this setup ok? [y/n] ");
		scanf(" %c", &ok);
	}


	printf("Done setting up.\n");
}
Example #4
0
///resets player position if player outside of screen window
void SoftFox::isFoxInWindow()
{
	if (playerX > WINDOW_WIDTH || playerX < 0 || playerY > WINDOW_HEIGHT || playerY < 0 - screenHeightSpriteAdjument)
	{
		resetPlayer();
	}
}
//--------------------------------------------------------------
void GrafPlayerApp::keyPressed (ofKeyEventArgs & event){


	if( panel.isAnyTextBoxActive() )
	{
		panel.addChar(event.key);
		return;
	}
	
    switch(event.key){

  		case 'x': bShowPanel=!bShowPanel; break;
		case 'p': 
			myTagPlayer.bPaused = !myTagPlayer.bPaused;
			panel.setValueB("ROTATE",bRotating);
			panel.setValueB("PLAY",!myTagPlayer.bPaused);
			break;
			
			
		case OF_KEY_RIGHT:  resetPlayer(1); break;
        case OF_KEY_LEFT:   resetPlayer(-1); break;
		
		case 'S': saveTagPositions(); break;
		case 's': saveAllTagPositions(); break;
			
		case 'R':
			if(tags.size()>0){
			tags[currentTagID].rotation.set(0,0,0);
			tags[currentTagID].position.set(0,0,1);
			rotationY = 0;
			tagPosVel.set(0,0,0);
			}
			break;
		case OF_KEY_RETURN:
			if( panel.getSelectedPanelName() == "Architecture Settings" )
				archPhysics.pGroup.addPoly();
			break;
		
		default:
  			break;

  }

	
	

}
Example #6
0
void SoftFox::hasFoxTouchedHunter()
{
	SDL_Rect hunterBox = { hunterX - SPRITE_SIZE / 2, hunterY - SPRITE_SIZE / 2 + spriteAdjustmentHunterSize, SPRITE_SIZE, SPRITE_SIZE }; 
	SDL_Rect playerBox = { playerX - SPRITE_SIZE / 2, playerY - SPRITE_SIZE / 2, SPRITE_SIZE - 70, SPRITE_SIZE - 70 }; ///putting a box around the fox and hunter so that player resets on contact
	if (physics -> isCollision (hunterBox, playerBox))//if collision occurs
	{
		resetPlayer();
	}
}
Example #7
0
void movePlayer() {
  moveObj( &ship );

  // take input
  
  if( key[KEY_LEFT] ) {
    ship.ang -= PLAYER_TURN_SPEED;
  }

  if( key[KEY_RIGHT] ) {
    ship.ang += PLAYER_TURN_SPEED;
  }

  if( key[KEY_UP] ) {
    float thrustPower = PLAYER_THRUST_POWER;
    
    ship.xv += cos(ship.ang) * thrustPower;
    ship.yv += sin(ship.ang) * thrustPower;
  }
  
  if( key[KEY_SPACE] ) {
    shoot();
  }
  
  // player bound checking
  if(ship.x > SCREEN_W) {
    resetPlayer();
  }
  if(ship.x < 0) {
    resetPlayer();
  }

  if(ship.y > SCREEN_H) {
    resetPlayer();
  }  
  if(ship.y < 0) {
    resetPlayer();
  }
}
//--------------------------------------------------------------
void GrafPlayerApp::update(){

	dt  = ofGetElapsedTimef()-lastTime;
	lastTime  = ofGetElapsedTimef();
	
	
	bool bTrans = false;
	
	if( mode == PLAY_MODE_LOAD )
	{
		loadTags();
		if(bUseAudio)audio.update();
	}
	else if( mode == PLAY_MODE_PLAY && tags.size() > 0 )
	{
		
		//---- set drawing data for render
		if( drawer.bSetupDrawer )
			drawer.setup( &tags[currentTagID], tags[currentTagID].distMax );

		//---- update tag playing state
		if( !myTagPlayer.bDonePlaying )					
		{
			myTagPlayer.update(&tags[currentTagID]);	// normal play, update tag
		
		}else if( !myTagPlayer.bPaused && myTagPlayer.bDonePlaying && waitTimer > 0)			   
		{
			waitTimer -= dt;	// pause time after drawn, before fades out
		}
		else if ( !myTagPlayer.bPaused && myTagPlayer.bDonePlaying && (drawer.alpha > 0 || particleDrawer.alpha > 0))			  		
		{
			updateTransition(0);
			bTrans = true;
		}
		else if (  !myTagPlayer.bPaused && myTagPlayer.bDonePlaying )							
		{
			resetPlayer(1);	// setup for next tag
		}
	
		
		//---------- AUDIO applied
		if( bUseAudio) updateAudio();
		
		
		//--------- ARCHITECTURE
		if( bUseArchitecture ) updateArchitecture();
		
		
		//--------- PARTICLES
		updateParticles();
			
		
		//--------- TAG ROTATION + POSITION
		if(bRotating && !myTagPlayer.bPaused ) rotationY += panel.getValueF("ROT_SPEED")*dt;
		
		// update pos / vel
		tags[currentTagID].position.x += tagPosVel.x;
		tags[currentTagID].position.y += tagPosVel.y;
		
		tagPosVel.x -= .1*tagPosVel.x;
		tagPosVel.y -= .1*tagPosVel.y;
		
		if(!bTrans)
		{
		tags[currentTagID].rotation_o = tags[currentTagID].rotation;
		tags[currentTagID].position_o = tags[currentTagID].position;
		}

	}
	
	
	
	// controls
	if( bShowPanel ) updateControlPanel();
	
	
}
Example #9
0
int main(int argc, char *argv[]){
	getinfo(&screen);
	clear(0);
	
	Triangle tri[] = {
	    {-1,0,1, -1,1,1, -2,0,1, 0xFFFF},{-2,1,1, -1,1,1, -2,0,1, 0xFFFF},
	    {-1,0,0, -1,1,0, -2,0,0, 0xFFFF},{-2,1,0, -1,1,0, -2,0,0, 0xFFFF},
	    
	    {-1,0,0, -1,0,1, -2,0,0, 0xFFFF},{-2,0,0, -1,0,1, -2,0,1, 0xFFFF},
	    {-1,1,0, -1,1,1, -2,1,0, 0xFFFF},{-2,1,0, -1,1,1, -2,1,1, 0xFFFF},
	    
	    {-1,0,0, -1,1,1, -1,0,1, 0xFFFF},{-1,0,0, -1,1,1, -1,1,0, 0xFFFF},
	    {-2,0,0, -2,1,1, -2,0,1, 0xFFFF},{-2,0,0, -2,1,1, -2,1,0, 0xFFFF}
	};
	
	Line complex[] = {
	    {2,2,2, 3,2,2, 0xFFFFFF},
	    {2,2,2, 2,2,3, 0xFFFFFF},
	    {3,2,2, 3,2,3, 0xFFFFFF},
	    {2,2,3, 3,2,3, 0xFFFFFF},

	    {2,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {2,2,3, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,3, 2.5,1,2.5, 0xFFFFFF}
	};
	
	Camera defaultcam = {0, 0, -2, 0, 0, 0, 0, 0, 1};
	Player p = {defaultcam, {100,2,0.5,0.25, //size
				defaultcam.cx,defaultcam.cy,defaultcam.cz, //position
				0,0,0, //velocity
				0,0,0, //force
				defaultcam.ox,defaultcam.oy,defaultcam.oz, //orientation
				0,0,0, //angular speed
				0,0,0 //torque
				}};
	int i;
	Cube c[] = {newCube(0.25, 0, 0, 0, 0xFF),
		    newCube(0.5, 1, 1, 1, 0xFF00),
		    newCube(1, -2, 2, 2, 0xFF0000)};
	char update = 1;
	while(!checkkey(KEYQ)){
		if(checkkey(KEYW)) movePlayer(&p, 0, 0, 0.2);
		if(checkkey(KEYA)) movePlayer(&p, 0.2, 0, 0);
		if(checkkey(KEYS)) movePlayer(&p, 0, 0, -0.2);
		if(checkkey(KEYD)) movePlayer(&p, -0.2, 0, 0);
		if(checkkey(KEYSPACE) & p.o.y==0){
		    p.o.vy = 0.2;
		}
		//if(checkkey(KEYLEFTCONTROL)) movePlayer(&p, 0, -0.2, 0);
		
		if(checkkey(KEYK)>0 & p.o.ox < M_PI/2) p.o.ox += 0.05;
		if(checkkey(KEYI)>0 & p.o.ox > -M_PI/2) p.o.ox -= 0.05;
		if(checkkey(KEYL)) p.o.oy += 0.05;
		if(checkkey(KEYJ)) p.o.oy -= 0.05;
		
		if(checkkey(KEYE)==1) wireframe = !wireframe;
		
		if(checkkey(KEYX)) resetPlayer(&p, defaultcam);
		
		
		    updatePlayer(&p);
		    
		    clear(0);
		
		    drawTriangles3D(tri, sizeof(tri)/sizeof(Triangle), p.c);
		    drawSphere(1,1,-1,0.2,0xFF00FF,p.c);
		    for(i = 0; i < sizeof(c)/sizeof(Cube); i++) drawCube(c[i], p.c);
		    drawLines3D(complex, sizeof(complex)/sizeof(Line), p.c);
		    
		    drawtext(0,0,"Wireframe test. Press q to exit.",0xFFFFFF);
		    drawline(screen.x/2-8,screen.y/2,screen.x/2+8,screen.y/2,0xFFFFFF);
		    drawline(screen.x/2,screen.y/2-8,screen.x/2,screen.y/2+8,0xFFFFFF);

		for(i = 0; i < 7; i++) hlt();
	}
	reset();
	return 0;
}
Example #10
0
void HelloWorld::intersectEnemy() {        //플레이어와 적이 충돌
	auto sPlayer = (Sprite*)this->getChildByTag(TAG_SPRITE_PLAYER);
	Rect rPlayer = Rect(sPlayer->getPositionX() - 10, sPlayer->getPositionY() - 20, 20, 40);    //주인공의 충돌박스 설정

	for (Sprite* enemy : vEnemy) {
		Rect renemy = enemy->getBoundingBox();        //적 충돌박스
		if (rPlayer.intersectsRect(renemy)) {
			SimpleAudioEngine::getInstance()->playEffect("explosion.wav");

			auto particle = ParticleSystemQuad::create("explosion.plist");
			particle->setPosition(enemy->getPosition());
			this->addChild(particle);

			particle->runAction(Sequence::create(
				DelayTime::create(2.0f),
				RemoveSelf::create(),
				NULL));

			vEMissile.eraseObject(enemy);            //적의 미사일을 지운다.
			this->removeChild(enemy);

			resetPlayer();                            //플레이어가 죽을때 호출
			return;
		}
	}
	for (Sprite* enemy2 : vEnemy2) {
		Rect renemy = enemy2->getBoundingBox();        //적 충돌박스
		if (rPlayer.intersectsRect(renemy)) {
			SimpleAudioEngine::getInstance()->playEffect("explosion.wav");

			auto particle = ParticleSystemQuad::create("explosion.plist");
			particle->setPosition(enemy2->getPosition());
			this->addChild(particle);

			particle->runAction(Sequence::create(
				DelayTime::create(2.0f),
				RemoveSelf::create(),
				NULL));

			vEMissile.eraseObject(enemy2);            //적의 미사일을 지운다.
			this->removeChild(enemy2);

			resetPlayer();                            //플레이어가 죽을때 호출
			return;
		}
	}

	for (Sprite* enemy3 : vMidBoss) {
		Rect renemy = enemy3->getBoundingBox();        //적 충돌박스
		if (rPlayer.intersectsRect(renemy)) {
			SimpleAudioEngine::getInstance()->playEffect("explosion.wav");

			auto particle = ParticleSystemQuad::create("explosion.plist");
			particle->setPosition(enemy3->getPosition());
			this->addChild(particle);

			particle->runAction(Sequence::create(
				DelayTime::create(2.0f),
				RemoveSelf::create(),
				NULL));

			vEMissile.eraseObject(enemy3);            //적의 미사일을 지운다.
			this->removeChild(enemy3);
			resetPlayer();                            //플레이어가 죽을때 호출
			return;
		}
	}

	for (Sprite* enemy4 : vBoss) {
		Rect renemy = enemy4->getBoundingBox();        //적 충돌박스
		if (rPlayer.intersectsRect(renemy)) {
			SimpleAudioEngine::getInstance()->playEffect("explosion.wav");

			auto particle = ParticleSystemQuad::create("explosion.plist");
			particle->setPosition(enemy4->getPosition());
			this->addChild(particle);

			particle->runAction(Sequence::create(
				DelayTime::create(2.0f),
				RemoveSelf::create(),
				NULL));

			vEMissile.eraseObject(enemy4);            //적의 미사일을 지운다.
			this->removeChild(enemy4);
			resetPlayer();                            //플레이어가 죽을때 호출
			return;
		}
	}
}
Example #11
0
void HelloWorld::intersectPlayer() {
	auto sPlayer = (Sprite*)this->getChildByTag(TAG_SPRITE_PLAYER);
	Rect rPlayer = Rect(sPlayer->getPositionX() - 10, sPlayer->getPositionY() - 20, 20, 40);    //주인공의 충돌박스 설정

	for (Sprite* emissile : vEMissile) {
		Rect rmissile = emissile->getBoundingBox();        //적 미사일 충돌박스
		if (rPlayer.intersectsRect(rmissile)) {
			vEMissile.eraseObject(emissile);
			this->removeChild(emissile);
			if (score >= 300) {
				score -= 300;
			} else {
				score = 0;
			}
			__String *tempScore = __String::createWithFormat("%i", score);
			scorelabel->setString(tempScore->getCString());
			resetPlayer();            //플레이어가 죽을때 호출
			return;
		}
	}

	for (Sprite* eitem : vItem) {
		Rect ritem = eitem->getBoundingBox();
		if (rPlayer.intersectsRect(ritem)) {
			SimpleAudioEngine::getInstance()->playEffect("ok2.wav");
			if (eitem == item1)
			{
				if (count == 0) {
					this->unschedule(schedule_selector(HelloWorld::setMissile));
					this->schedule(schedule_selector(HelloWorld::upGradeP2), 0.15f);
					damage = 2;
					count = 1;
				}
				else if (count == 1) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP2));
					this->unschedule(schedule_selector(HelloWorld::upGradeF2));
					this->unschedule(schedule_selector(HelloWorld::upGradeL2));
					this->schedule(schedule_selector(HelloWorld::upGradeP3), 0.15f);
					damage = 3;
					count = 2;
				}
				else if (count == 2) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP3));
					this->unschedule(schedule_selector(HelloWorld::upGradeF3));
					this->unschedule(schedule_selector(HelloWorld::upGradeL3));
					this->unschedule(schedule_selector(HelloWorld::upGradeF4));
					this->unschedule(schedule_selector(HelloWorld::upGradeL4));
					this->schedule(schedule_selector(HelloWorld::upGradeP4), 0.15f);
					damage = 4;
					count = 2;
					score += 100;
					__String *tempScore = __String::createWithFormat("%i", score);
					scorelabel->setString(tempScore->getCString());
				}
			}
			else if (eitem == item2)
			{
				if (count == 0) {
					this->unschedule(schedule_selector(HelloWorld::setMissile));
					this->schedule(schedule_selector(HelloWorld::upGradeF2), 0.15f);
					damage = 2;
					count = 1;
				}
				else if (count == 1) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP2));
					this->unschedule(schedule_selector(HelloWorld::upGradeF2));
					this->unschedule(schedule_selector(HelloWorld::upGradeL2));
					this->schedule(schedule_selector(HelloWorld::upGradeF3), 0.15f);
					damage = 3;
					count = 2;
				}
				else if (count == 2) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP3));
					this->unschedule(schedule_selector(HelloWorld::upGradeF3));
					this->unschedule(schedule_selector(HelloWorld::upGradeL3));
					this->unschedule(schedule_selector(HelloWorld::upGradeP4));
					this->unschedule(schedule_selector(HelloWorld::upGradeL4));
					this->schedule(schedule_selector(HelloWorld::upGradeF4), 0.15f);
					damage = 4;
					count = 2;
					score += 100;
					__String *tempScore = __String::createWithFormat("%i", score);
					scorelabel->setString(tempScore->getCString());
				}
			}
			else if (eitem == item3)
			{
				if (count == 0) {
					this->unschedule(schedule_selector(HelloWorld::setMissile));
					this->schedule(schedule_selector(HelloWorld::upGradeL2), 0.15f);
					damage = 2;
					count = 1;
				}
				else if (count == 1) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP2));
					this->unschedule(schedule_selector(HelloWorld::upGradeF2));
					this->unschedule(schedule_selector(HelloWorld::upGradeL2));
					this->schedule(schedule_selector(HelloWorld::upGradeL3), 0.15f);
					damage = 3;
					count = 2;
				}
				else if (count == 2) {
					this->unschedule(schedule_selector(HelloWorld::upGradeP3));
					this->unschedule(schedule_selector(HelloWorld::upGradeF3));
					this->unschedule(schedule_selector(HelloWorld::upGradeL3));
					this->unschedule(schedule_selector(HelloWorld::upGradeP4));
					this->unschedule(schedule_selector(HelloWorld::upGradeF4));
					this->schedule(schedule_selector(HelloWorld::upGradeL4), 0.15f);
					damage = 4;
					count = 2;
					score += 100;
					__String *tempScore = __String::createWithFormat("%i", score);
					scorelabel->setString(tempScore->getCString());
				}
			}

			vItem.eraseObject(eitem);
			this->removeChild(eitem);
			return;
		}
	}
}
Example #12
0
void gameSetup() {
  resetRocks();
  resetPlayer();
}
Example #13
0
void SoftFox::run()
{
	//Set all default boolean
	running = true;
	jump = false;
	hasJumped = false;
	playerCollision = false;

	resetPlayer(); 	//Sets the players position

	//Thomas Easterbrook Coding Task two start
	hunterX = tileSize * level->getVillianX() + tileSize/2;
	hunterY = tileSize * level->getVillianY() + tileSize/2;
	//Thomas Easterbrook Coding Task two end

	//Dean Harland Coding Task Two Start
	//Set mushroom start posistion to the tile using level
	mushroomX = tileSize * level->getMushroomX() + tileSize / 2;
	mushroomY = tileSize * level->getMushroomY() + tileSize / 2;
	//Dean Harland Coding Task Two End

	while (running)
	{
		//Set an event
		SDL_Event ev;
		if (SDL_PollEvent(&ev))
		{
			switch (ev.type)
			{
				//Create a case for quitting the window and set running to false to deconstruct the window
				//Break or system breaks
				case SDL_QUIT:
					running = false;
					break;

				default:
					break;
			}
		}

		SDL_RenderCopy(renderer, backgroundImage, nullptr, NULL); //Render the background first

		drawLevel(); //Draw the level using the method drawTile shown below
		playerKeyBoardCommands();

		//Thomas Easterbrook Coding Task two start
		hunterSprite->render(renderer, hunterX, hunterY + spriteAdjustmentHunterSize, tileSize, tileSize);
		//Thomas Easterbrook Coding Task two end

		//Drawing mushroom sprite
		mushroomSprite->render(renderer, mushroomX, mushroomY + spriteAdjustmentMushroomSize, SPRITE_SIZE, SPRITE_SIZE);

		///Drawing player sprite (texture class)
		playerSprite->render(renderer, playerX, playerY, SPRITE_SIZE, playerSpriteHeight);

		//Drawing player sprite (texture class)
		controls->render(renderer, WINDOW_WIDTH - spriteControlXAdjustment, spriteControlYAdjustment, tileSize * 1.5, tileSize);

		////Sam Wills coding task two start
		jumping();
		hasFoxTouchedPlatform();
		sideCollision();
		isFoxInWindow();
		//Sam Wills coding task two end

		//Thomas Easterbrook Coding Task two start
		hunterMovement();
		hasFoxTouchedHunter();
		//Thomas Easterbrook Coding Task two end

		//Dean Harland Coding Task Two Start
		endGameMushroom();	
		//Dean Harland Coding Task Two Start

		SDL_RenderPresent(renderer);				
	}
}
Example #14
0
bool MainMenu::onInitialize()
{
    //position camera so that any 3D elements we attach to the graph are rendered how we want
    s_Cam()->setPosition(Vector3(0.0f, 15.0f, 40.0f));
    s_Cam()->setLookAt(Vector3(0.0f, 5.0f, 0.0f));
    s_Cam()->setCameraMode(CM_STILL);
    
    m_graph->pushNode();
	{
		//// create a platform
		Platform *platform = new Platform(this, Vector3(50.0f, 1.0f, 50.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 4, RAND_COLOR))) { GLOG("ERROR: Could not initialize center platform\n"); return false; }
		platform->setPosition(Vector3(0.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        //new OBJmodel here
        OBJmodel *game_title = new OBJmodel(this, "Objects/game_title.obj", 1.0f, false, false ,true);
        if ( !game_title->initialize(new LightShader(0.1f, 0.8, 8, RAND_LIGHT_COLOR))) { GLOG("ERROR: could not create game_title\n"); return false; }
        game_title->setPosition(Vector3(0.0f, game_title->getSize().y * 0.5f, 00.0f));
        game_title->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(game_title);
    }
    m_graph->popNode();
    
    // create particle system for the background
    /*ParticleSystem *randomSystem = new RandomParticleSystem(500);
     randomSystem->emitterPositionVar = Vector3(5.0f, 4.0f, 0.0f);
    randomSystem->startColor = Color(0.0f, 0.0f, 0.0f, 1.0f);
    randomSystem->endColor = Color(0.5f, 0.5f, 0.5f, 0.0f);
    randomSystem->endColorVar = Color(0.5f, 0.5f, 0.5f, 0.0f);
    randomSystem->speed = 0.1f;
    randomSystem->startSystem();
    m_graph->attach(randomSystem);*/
    
    float scale = s_Cam()->getScreenWidth() / 1024.0f;
    
    // create an image for nicks level
    nicks_level = new GUIImage();
    if ( !nicks_level->initialize(new TextureShader(), "Textures/nicks_level.tga"))
        return false;
    nicks_level->setPosition(Vector3(s_Cam()->getScreenWidth() * 0.25f, s_Cam()->getScreenHeight() - 100 * scale, 0.0f));
    nicks_level->setScale(scale);
    
    // create an image for charlies level
    charlies_level = new GUIImage();
    if ( !charlies_level->initialize(new TextureShader(), "Textures/charlies_level.tga"))
        return false;
    charlies_level->setPosition(Vector3(s_Cam()->getScreenWidth() * 0.75f, s_Cam()->getScreenHeight() - 100 * scale, 0.0f));
    charlies_level->setScale(scale);
    
    // create an image for how to play
    how_to_play_button = new GUIImage();
    if ( !how_to_play_button->initialize(new TextureShader(), "Textures/how_to_play_button.tga"))
        return false;
    how_to_play_button->setPosition(Vector3(s_Cam()->getScreenWidth() * 0.5f, s_Cam()->getScreenHeight() - 220 * scale, 0.0f));
    how_to_play_button->setScale(scale);
    
    // create an image for how to play
    how_to_play = new GUIImage();
    if ( !how_to_play->initialize(new TextureShader(), "Textures/how_to_play.tga"))
        return false;
    how_to_play->setPosition(Vector3(s_Cam()->getScreenWidth() * 0.5f, s_Cam()->getScreenHeight() * 0.5f, 0.0f));
    how_to_play->setScale(scale);
    
    return resetPlayer();
}