Пример #1
0
static void move() {
  switch ( status ) {
  case TITLE:
    moveTitleMenu();
    moveBoss();
    moveFoes();
    moveBackground();
    break;
  case IN_GAME:
  case STAGE_CLEAR:
    moveShip();
    moveBoss();
    moveLasers();
    moveShots();
    moveFoes();
    moveFrags();
    moveBackground();
    break;
  case GAMEOVER:
    moveGameover();
    moveBoss();
    moveFoes();
    moveFrags();
    moveBackground();
    break;
  case PAUSE:
    movePause();
    break;
  }
  moveScreenShake();
}
Пример #2
0
static void move() {
  switch ( status ) {
  case TITLE:
    moveTitleMenu();
    moveBackground();
    addBullets();
    moveFoes();
    break;
  case IN_GAME:
    moveBackground();
    addBullets();
    moveShots();
    moveShip();
    moveFoes();
    moveFrags();
    moveBonuses();
    break;
  case GAMEOVER:
    moveGameover();
    moveBackground();
    addBullets();
    moveShots();
    moveFoes();
    moveFrags();
    break;
  case STAGE_CLEAR:
    moveStageClear();
    moveBackground();
    moveShots();
    moveShip();
    moveFrags();
    moveBonuses();
    break;
  case PAUSE:
    movePause();
    break;
  }
}
Пример #3
0
void NGLScene::timerEvent( QTimerEvent *_event)
{
	// the usual process is to check the event timerID and compare it to
	// any timers we have started with startTimer
	if (_event->timerId() == m_updateShipTimer)
	{

		if(m_playbackActive == true)
		{
			if(m_currentPlaybackFrame <= 0)
			{
				m_ship->setPos(m_keyRecorder.getStartPosition());
			}
			if(m_currentPlaybackFrame < m_keyRecorder.size())
			{
				m_keysPressed=m_keyRecorder[m_currentPlaybackFrame];
				++m_currentPlaybackFrame;
			}
			else
			{
				m_playbackActive=false;
				m_currentPlaybackFrame=0;
			}

		}
		else if (m_recording== true)
		{
			m_keyRecorder.addFrame(m_keysPressed);
		}
	 moveShip();
	}
	if (_event->timerId() == m_redrawTimer)
	{
		update();
	}
}
Пример #4
0
// the main function
void _main(void) {
    unsigned int difficulty = NORMAL;
    short int key=0;
    short int keys[8];
    unsigned int level_num = 1;
    unsigned short int score = 0;
    int done = 0;
    unsigned int money = 0;
    int cannon_level = 1;
    int missile_level = 0;
    char map[12][MAP_SIZE];

    // seed the random numbers
    randomize();
    // get the key masks
    getKeyMasks(keys);


    INT_HANDLER interrupt1 = GetIntVec(AUTO_INT_1);  // this will save auto int 1

    // draw title screen and wait for keypress
    GrayOn();
    drawTitle(2);
    ngetchx();

    //draw background title screen and menu
    drawTitle(1);
    drawWords(difficulty);
    POSITION pointer = {10,0};
    drawPointer(pointer);
    // the menu loop
    while (1) {
        key = ngetchx();
        if (key == KEY_ENTER && pointer.y != OPTIONS) {
            if (pointer.y == PLAY) break;
            if (pointer.y == HIGH_SCORES) printHiScores();
            if (pointer.y == HELP) doHelp();
            if (pointer.y == ABOUT) {
                SetIntVec(AUTO_INT_1,interrupt1);
                GrayOff();
                exit(0);
            }
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawWords(difficulty);
            pointer=(POSITION) {
                10,0
            };
            drawPointer(pointer);
        }
        if (key == KEY_LEFT && pointer.y == OPTIONS && difficulty < VERY_EASY) {
            difficulty+=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_RIGHT && pointer.y == OPTIONS && difficulty > IMPOSSIBLE)  {
            difficulty-=1;
            GraySetAMSPlane(LIGHT_PLANE);
            clrscr();
            GraySetAMSPlane(DARK_PLANE);
            clrscr();
            drawTitle(1);
            drawPointer(pointer);
            drawWords(difficulty);
        }
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
        if (key == KEY_UP && pointer.y > 0) pointer.y--;
        if (key == KEY_DOWN && pointer.y < 4) pointer.y++;
        if (key == KEY_UP || key == KEY_DOWN) drawPointer(pointer);
    }
    key = 0;
    // turn off gray, so we can destroy auto-int-1 and not mess it up
    GrayOff();

    // DESTROY auto-interrupt 1 so as not to mess up _rowread
    SetIntVec(AUTO_INT_1,DUMMY_HANDLER);

    // turn gray back on
    GrayOn();

    // randomize the map
    randomMap(difficulty, map, level_num);
    //the main game loop
    while (!quit() && !done) {
        done = 0;
        int fin = 0;
        int win = 0;
        int forward = 0;
        int map_x_location = 0;
        int laser = 0;
        int justLaser = 0;
        int missile = 0;
        int justMissile = 0;
        int missileSlow = 2;
        POSITION laserPos;
        POSITION oldLaserPos;
        POSITION missilePos;
        POSITION oldMissilePos;
        POSITION oldShip;
        POSITION ShipPos = {0,5};

        // we need to disable gray temporarily to do the shop screen...
        GrayOff();
        SetIntVec(AUTO_INT_1, interrupt1);
        shop(&money, &cannon_level, &missile_level);
        SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
        GrayOn();

        // draws the level
        Draw_Map(map_x_location, map, ShipPos, laserPos, laser, missilePos, missile);


        // the loop for the action in the level
        while (!quit()) {

            // if the user has a missile out, deal with it
            if (missile && missileSlow == 2) {
                missileSlow = 1;
                oldMissilePos = missilePos;
                missilePos.x++;
                missilePos.y+=missile;
                if (missilePos.x > map_x_location + 20) missile = 0;
                if (missilePos.y < 0 || missilePos.y > 12) {
                    missile = 0;
                    eraseMissile(missilePos, map_x_location);
                }
                if (blowWall(missilePos,map)) {
                    if (map[missilePos.y][missilePos.x] < 4) {
                        map[missilePos.y][missilePos.x]-=3;
                        if (map[missilePos.y][missilePos.x] == 0) {
                            score++;
                            money+=BLOCK_VALUE;
                        }
                    }
                    if (map[missilePos.y][missilePos.x] < 0) map[missilePos.y][missilePos.x] = 0;
                    missile = 0;
                    justMissile = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser,missilePos,missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justMissile && missile == 1) {
                    moveMissile(oldMissilePos,missilePos,map_x_location);
                } else if (missile == 1) {
                    drawMissile(missilePos,map_x_location);
                    justMissile = 0;
                } else if (!justMissile && missile == -1) {
                    moveUpMissile(oldMissilePos, missilePos, map_x_location);
                } else if (missile == -1) {
                    drawUpMissile(missilePos, map_x_location);
                    justMissile = 0;
                }

            } else {
                missileSlow++;
            }

            // if the user has a laser shot that is still going, continue it
            if (laser) {
                oldLaserPos = laserPos;
                laserPos.x++;
                if (laserPos.x > map_x_location + 20) laser=0;
                if (blowWall(laserPos,map)) {
                    if (map[laserPos.y][laserPos.x] < 4) {
                        map[laserPos.y][laserPos.x]-=cannon_level;
                        if (map[laserPos.y][laserPos.x] <= 0) {
                            score++;
                            money+=BLOCK_VALUE;
                            map[laserPos.y][laserPos.x] = 0;
                        }
                    } else if (map[laserPos.y][laserPos.x] == 4 && cannon_level == 4) {
                        map[laserPos.y][laserPos.x] = 1;
                    }
                    laser = 0;
                    justLaser = 0;
                    Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
                }
                // if the shot was just fired, then there wont be one to erase
                if (!justLaser && laser) {
                    moveLaser(oldLaserPos,laserPos,map_x_location);
                } else if (laser) {
                    drawLaser(laserPos,map_x_location);
                    justLaser = 0;
                }
            }

            // scroll the screen forward one block every (difficulty) time through the main loop
            if (forward == difficulty) {
                map_x_location++;
                ShipPos.x++;
                forward = 0;
                if (map_x_location >= MAP_SIZE - 20) {
                    win = 1;
                    level_num++;
                    break;
                }
                // if you ran into a wall, quit
                if (detectWall(ShipPos,map)) {
                    win = 1;
                    score /= 2 ;
                    break;
                }
                Draw_Map(map_x_location,map,ShipPos,laserPos,laser, missilePos, missile);
            } else {
                forward++;
            }

            // if you ran into a wall, quit
            if (detectWall(ShipPos,map)) {
                win = 1;
                score = 0;
                break;
            }

            if (_rowread(~((short)(1<<1))) & (1<<6) && _rowread(~((short)(1<<2))) & (1<<6)) {
                win = 1;
                level_num++;
                break;
            }

            // get keypresses
            key = _rowread(ARROW_ROW);

            // if the user pressed right, move the ship right
            if (key & keys[RIGHT]) {
                oldShip = ShipPos;
                ShipPos.x++;
                if (ShipPos.x > map_x_location + 18) ShipPos.x--;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                }	else {
                    win = 1;
                    score = 0;
                    break;
                }
            }
            // If the user pressed left, move the ship left
            if (key & keys[LEFT]) {
                oldShip = ShipPos;
                ShipPos.x--;
                if (ShipPos.x < map_x_location) ShipPos.x++;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed up, move the ship up
            if (key & keys[UP]) {
                oldShip = ShipPos;
                if (ShipPos.y - 1 < 0) {
                    ShipPos.y = 0;
                } else {
                    ShipPos.y--;
                }
                if (!detectWall(ShipPos,map))	{
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if the user pressed down, move the ship down
            if (key & keys[DOWN]) {
                oldShip = ShipPos;
                ShipPos.y++;
                if (ShipPos.y > 10) ShipPos.y = 10;
                if (!detectWall(ShipPos,map)) {
                    moveShip(oldShip,ShipPos,map_x_location);
                } else {
                    win = 1;
                    score = 0;
                    break;
                }
            }

            // if 2nd was pushed, fire the laser
            if (key & keys[SECOND]) {
                if (!laser) {
                    justLaser = 1;
                    laser = 1;
                    laserPos.x = ShipPos.x + 1;
                    laserPos.y = ShipPos.y;
                }
            }

            // if diamond was pushed fire the downward missiles
            if (key & keys[DIAMOND]) {
                if (missile_level == 3 || missile_level == 1) {
                    if (!missile) {
                        justMissile = 1;
                        missile = 1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            // if shift was pushed fire the upward missiles
            if (key & keys[SHIFT]) {
                if (missile_level == 2 || missile_level == 3) {
                    if (!missile) {
                        justMissile = 1;
                        missile = -1;
                        missileSlow = 2;
                        missilePos.x = ShipPos.x;
                        missilePos.y = ShipPos.y;
                    }
                }
            }

            /*if (key & keys[ALPHA]) {
            score += 10;
            }*/
            // slow down the program because _rowread is too fast
            delay();
        }



        // back to the overall game loop
        if (win) {
            if (level_num <= LEVEL_NUM) {
                won(difficulty, map, level_num);
            } else {
                fin = 1;
                break;
            }
        }
    }

    // the user left, either by winning or quitting, so make sure everything is reset so the calc will be fine
    GrayOff();
    SetIntVec(AUTO_INT_1,interrupt1);
    hiScoresGo(score, difficulty, level_num);
}
Пример #5
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
    
    SDL_Event event;
    bool done = false;
    
    glViewport(0, 0, 640, 360);
    
    ShaderProgram program(RESOURCE_FOLDER"vertex_textured.glsl", RESOURCE_FOLDER"fragment_textured.glsl");
    
    GLuint p1Texture = LoadTexture("p1_front.png");
    GLuint shipTexture = LoadTexture("enemyRed1.png");
    GLuint tileTexture = LoadTexture("tileStone_full.png");
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    projectionMatrix.setOrthoProjection(-320.0f, 320.0f, -180.0f, 180.0f, -1.0f, 1.0f);
    
    glUseProgram(program.programID);
    
    while (!done) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
                done = true;
            }
        }
        
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        
        program.setModelMatrix(shipMatrix);
        program.setProjectionMatrix(projectionMatrix);
        program.setViewMatrix(shipView);
        
        glBindTexture(GL_TEXTURE_2D, shipTexture);
        glVertexAttribPointer(program.positionAttribute, 2, GL_FLOAT, false, 0, ship_vertices);
        glEnableVertexAttribArray(program.positionAttribute);
        
        glVertexAttribPointer(program.texCoordAttribute, 2, GL_FLOAT, false, 0, ship_texCoords);
        glEnableVertexAttribArray(program.texCoordAttribute);
        
        glDrawArrays(GL_TRIANGLES, 0, 6);
        
        moveShip(6.0);
        
        program.setModelMatrix(modelMatrix);
        program.setViewMatrix(viewMatrix);
        glBindTexture(GL_TEXTURE_2D, tileTexture);
        glVertexAttribPointer(program.positionAttribute, 2, GL_FLOAT, false, 0, tile_vertices);
        glEnableVertexAttribArray(program.positionAttribute);
        
        glVertexAttribPointer(program.texCoordAttribute, 2, GL_FLOAT, false, 0, tile_texCoords);
        glEnableVertexAttribArray(program.texCoordAttribute);
        
        glDrawArrays(GL_TRIANGLES, 0, 6);
        
        glBindTexture(GL_TEXTURE_2D, p1Texture);
        glVertexAttribPointer(program.positionAttribute, 2, GL_FLOAT, false, 0, p1_vertices);
        glEnableVertexAttribArray(program.positionAttribute);
        
        glVertexAttribPointer(program.texCoordAttribute, 2, GL_FLOAT, false, 0, p1_texCoords);
        glEnableVertexAttribArray(program.texCoordAttribute);
        
        glDrawArrays(GL_TRIANGLES, 0, 6);
        
        glDisableVertexAttribArray(program.positionAttribute);
        glDisableVertexAttribArray(program.texCoordAttribute);
        SDL_GL_SwapWindow(displayWindow);
    }
    
    SDL_Quit();
    return 0;
}
Пример #6
0
/* moves both the ships */
void moveAllShips(void)
{
	moveShip(&directionKeys_ship_1, &speed_ship_1, &rotateShip_1, &translateShip_1);
	moveShip(&directionKeys_ship_2, &speed_ship_2, &rotateShip_2, &translateShip_2);
}