Exemplo n.º 1
0
/// Reset GameModel.
void GameModel::reset() {
	score = 0;
	lives = 3;
	level = 0;
	enemiesShot = 0;
	gameOver = false;
	enemiesMoveDown = false;

	initializeShields();
	initializeEntities();
 }
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO);
    displayWindow = SDL_CreateWindow("My Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 360, SDL_WINDOW_OPENGL);
    SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
    SDL_GL_MakeCurrent(displayWindow, context);
#ifdef _WINDOWS
    glewInit();
#endif

    glViewport(0, 0, 640, 360);
    srand(time(0));
    
    ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");
    
    Matrix projectionMatrix;
    Matrix modelMatrix;
    Matrix viewMatrix;
    projectionMatrix.setOrthoProjection(-3.55f, 3.55f, -2.0f, 2.0f, -1.0f, 1.0f);
    //Setup(program, projectionMatrix);
    
    //Animation, Matrix, and Entitys variables
    
    initializeEntities();
    
    //enable blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    while (!done) {
        ticks = (float)SDL_GetTicks() / 1000.0f;
        elapsed = ticks - lastFrameTicks;
        lastFrameTicks = ticks;
        ProcessEvents();
        
        glUseProgram(program.programID);
        //p1Entity.Update(elapsed);
        setBackgroundColorAndClear();
        program.setModelMatrix(modelMatrix);
        program.setViewMatrix(viewMatrix);
        program.setProjectionMatrix(projectionMatrix);
        
        Update(lastFrameTicks, modelMatrix, program);
        
        Render(program, modelMatrix);
        
        SDL_GL_SwapWindow(displayWindow);
    }
    
    SDL_Quit();
    return 0;
}
Exemplo n.º 3
0
/// Go to the next level.
void GameModel::nextLevel() {
	if (level < 5)
		level++;
	else
		level = 5;

	lives++;
	score += 1000;
	enemiesShot = 0;

	initializeEntities();
	notifyObserversReset();
	notifyObserversAll();
}
Exemplo n.º 4
0
void Model::initialize()
{
    System* const aRootSystem( getRootSystem() );

    checkSizeVariable( aRootSystem );

    preinitializeEntities( aRootSystem );

    // initialization of Stepper needs four stages:
    // (1) update current times of all the steppers, and integrate Variables.
    // (2) call user-initialization methods of Processes.
    // (3) call user-defined initialize() methods.
    // (4) post-initialize() procedures:
    //         - construct stepper dependency graph and
    //         - fill theIntegratedVariableVector.
    initializeEntities( aRootSystem );

    std::for_each( theStepperMap.begin(), theStepperMap.end(),
        ComposeUnary( boost::bind( &Stepper::initialize, _1 ),
                      SelectSecond< StepperMap::value_type >() ) );
    theSystemStepper.initialize();

    std::for_each( theStepperMap.begin(), theStepperMap.end(),
        ComposeUnary( boost::bind( &Stepper::updateIntegratedVariableVector, _1 ),
                      SelectSecond< StepperMap::value_type >() ) );

    theScheduler.updateEventDependency();

    for( EventIndex c( 0 ); c != theScheduler.getSize(); ++c )
    {
        StepperEvent& anEvent( theScheduler.getEvent( c ) );
        DifferentialStepper* aStepper( dynamic_cast< DifferentialStepper* >( anEvent.getStepper() ) );
        if ( aStepper )
        {
            aStepper->updateInternalState( aStepper->getStepInterval() );
        }
        // anEvent.reschedule();
        theScheduler.rescheduleEvent(c);
    }

    isDirty_ = false;
}
Exemplo n.º 5
0
////////////////////////////////////////////////////////////////////////////////
// Plays a complete game, until the death of the main character
//
u16 game(u16 hiscore) {
   u8 alive = 1;        // Main character still alive?
   TCharacter* c;       // Pointer to main character

   // Initialize game
   initializeGameScreen(hiscore);   // Set up Game Screen
   initializeEntities();            // Set up initial entities
   c = getCharacter();              // Get the main character

   /////
   // Main Game Loop (while character is alive)
   /////
   while(alive) {
      updateUser(c);                // Update user status (depending on keypresses)
      scrollWorld();                // Update world scrolling
      alive = updateCharacter(c);   // Update character status     
      cpct_waitVSYNC();             // Wait for VSYNC and...
      drawAll();                    // ..draw everything
   }

   // Return final score, at the end of the game
   return getScore();
}
Exemplo n.º 6
0
/// Default constructor.
GameModel::GameModel() : enemiesMoveDown(false), gameOver(false),
							score(0), lives(3), level(0), enemiesShot(0), powerUpType(0), powerUpTime(0) {
	factory = std::shared_ptr< Entities::EntityFactory > (new Entities::EntityFactory);
	initializeShields();
	initializeEntities();
}