Пример #1
0
void handler() {
	process_keys();
	update_projectiles();
	update_animations();
	step_monsters();

	game.player.light->update_flicker();
	process_sight();
	draw_lights(game.fov_light, &game.map.block, game.map.lights);
	{
		lightsource *k = game.map.lights.head();
		for (; k; k = k->next()) {
			k->update_flicker();
			draw_light(game.fov_light, &game.map.block, k);
		}
	}

	u32 keys = keysHeld();
	u32 down = keysDown();
	touchPosition touch = touchReadXY();
	if (down & KEY_TOUCH && keys & KEY_R && touch.px != 0 && touch.py != 0) {
		luxel *l = torch.buf.luxat(torch.buf.scroll.x + touch.px/8, torch.buf.scroll.y + touch.py/8);
		iprintf("c:%d,%d,%d v:%d, low:%d\n", l->lr, l->lg, l->lb, l->lval, torch.get_low_luminance());
	}

	refresh(&game.map.block);

	if (game.player.hp <= 0) {
		playerdeath();
		game.player.clear();
		new_game();
	}

	if (game.cooldown <= 0) game.player.regenerate();

	statusbar();
}
Пример #2
0
void gameLoop()
{
    // Set our game data
    shipRow         = 55;
    shipCol         = 0;
    enemyCol        = 225;
    enemy_num       = 0;
    projectile_num  = 0;
    time_diff       = 0;
    kills           = 0;

    REG_DISPCNT = MODE3 | BG2_ENABLE;

    EntityClass player_ship;
    initialize_entity( &player_ship, SHIP_WIDTH, SHIP_HEIGHT, shipRow, shipCol );

    EntityClass enemy;
    initialize_entity( &enemy, 0, 0, 0, 0 );
    enemies[max_enemies+1] = enemy;

    while (lives != 0)
    {
        // Check if player won the level.
        if( kills == 10 )
        {
            state = WIN;
            break;
        }

        // Draw background
        drawImage3( 0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT, background );

        // Draw ship
        draw_entity( &player_ship, ship );

        // Generate enemy
        if( time_diff <= 0 && enemy_num < 10 )
        {
            time_diff = 75;
            int rand_row = ( rand() % (120+1-20) ) + 20;
            generate_enemy( rand_row, enemyCol );
        }

        // Draw Enemy
        update_enemies();

        // Draw each projectile
        update_projectiles();

        // Check if player is dead.
        if( is_player_dead( &player_ship ) == 1 )
        {
            lives--;
            gameLoop();
        }

        check_collisions();
        remove_old_projectiles();
        remove_old_enemies();

        // Draw lives
        for( int i = 0; i < lives; i++ )
        {
            drawImage3( 140, 170 + ( i * 25 ), SHIP_WIDTH, SHIP_HEIGHT, ship );
        }

        waitForVblank();

        // If player hits 'select' return to titleScreen and start game over.
        if( KEY_DOWN_NOW( BUTTON_SELECT ) )
        {
            state = TITLE;
            break;
        }

        // Player Actions
        if( KEY_DOWN_NOW( BUTTON_DOWN ) )
        {
            if( get_row( &player_ship ) < 121 )
                move_entity( &player_ship, 2, 0 );
        }

        if( KEY_DOWN_NOW( BUTTON_UP ) )
        {
            if( get_row( &player_ship ) > 20 )
                move_entity( &player_ship, -2, 0 );
        }

        if( KEY_DOWN_NOW( BUTTON_A ) )
        {
            while( KEY_DOWN_NOW( BUTTON_A ) ) {
                ;
            }
            fire_weapon( &player_ship );
        }

        time_diff--;
    }

    if( lives == 0 )
    {
        state = GAME_OVER;
    }
    else if( state == WIN )
        return;
}
Пример #3
0
void WeaponSystem::update(long time, float dt)
{
	update_guns(time, dt);
	update_projectiles(time, dt);
}