Пример #1
0
void run_game() {

  // Create player 1
  std::list<Link> player1;
  Link p1start = {5, MAX_BOARD_Y / 2, 'X', 1};
  player1.push_back(p1start);

  // Create player 2
  std::list<Link> player2;
  Link p2start = {MAX_BOARD_X - 5, MAX_BOARD_Y / 2, 'O', 2};
  player2.push_back(p2start);

  clear();
  print_board();
  print_snake(player1);
  print_snake(player2);

  // Wait for initial direction input
  int p1direction;
  int p2direction;
  bool p1sel = false;
  bool p2sel = false;
  while(!(p1sel && p2sel)) {
    if (kbhit()) {
      int input = getch();
      if (!p1sel) {
        p1sel = get_init_dir(p1direction, input, 1);
      }
      if (!p2sel) {
        p2sel = get_init_dir(p2direction, input, 2);
      }
    }
  }

  int loser = 0;
  while(loser == 0) {
    game_frame(player1, p1direction, player2, p2direction);
    loser = check_collisions(player1, player2);
    if (loser == 0) {
      loser = check_collisions(player2, player1);
    }
  }
  if (!play_again(loser)) {
    return;
  }
  else {
    run_game();
  }
}
Пример #2
0
/* No params, just use curDir */
void move() {
	int nx, ny;
	switch (curDir) {
		case RIGHT:
			nx = snake->x+1;
			ny = snake->y;
			break;
		case LEFT:
			nx = ((int)(snake->x))-1;
			ny = snake->y;
			break;
		case UP:
			nx = snake->x;
			ny = ((int)(snake->y))-1;
			break;
		case DOWN:
			nx = snake->x;
			ny = snake->y+1;
			break;
	}
		
	if(nx < 0) nx = MAX_LEN; if(nx > MAX_LEN) nx = 0;
	if(ny < 0) ny = MAX_HEI; if(ny > MAX_HEI) ny = 0;

	add_head(nx, ny);

	check_collisions();
	
	if(!no_pop) pop_tail();
	else no_pop--;
}
Пример #3
0
// seg000:0EA8
// returns 1 if level is restarted, 0 otherwise
int __pascal far play_kid_frame() {
	loadkid_and_opp();
	load_fram_det_col();
	check_killed_shadow();
	play_kid();
	if (upside_down && Char.alive >= 0) {
		upside_down = 0;
		need_redraw_because_flipped = 1;
	}
	if (is_restart_level) {
		return 1;
	}
	if (Char.room != 0) {
		play_seq();
		fall_accel();
		fall_speed();
		load_frame_to_obj();
		load_fram_det_col();
		set_char_collision();
		bump_into_opponent();
		check_collisions();
		check_bumped();
		check_gate_push();
		check_action();
		check_press();
		check_spike_below();
		if (resurrect_time == 0) {
			check_spiked();
			check_chomped_kid();
		}
		check_knock();
	}
	savekid();
	return 0;
}
Пример #4
0
void Multi_State::clock_tick() {
	// Defines what will happen each tick.
	player1.move(p1dir);
	player2.move(p2dir);

	check_collisions();

	if (p1parts_to_add != 0) {
		// If theres body to add, add one
		player1.add_parts(1);
		p1parts_to_add--;
	}

	if (p2parts_to_add != 0) {
		player2.add_parts(1);
		p2parts_to_add--;
	}

	carrot_tick++; // Is added every tick
	if (carrot_tick == 10) { // When it updates every 10th tick
		carrot = rotten_carrots.at(rotten_carrots.size() - 1);
		rotten_carrots.pop_back();
		do {
			sprite_x = get_engine()->rand_x();
			sprite_y = get_engine()->rand_y();
		} while (!is_free(sprite_x, sprite_y));
		carrot.x = sprite_x;
		carrot.y = sprite_y;
		std::vector<Obstacles>::iterator it;
		it = rotten_carrots.begin();
		// After we've removed the carrot we add it to the first position
		rotten_carrots.insert(it, carrot);
		carrot_tick = 0;
	}
}
Пример #5
0
bool GameScreen::run()
{
	running = true;
	Island input_islands[NUM_PLAYERS][MAX_ISLANDS][2];
	//draw_initial(); TODO:GUI
	Team winning_team = NEUTRAL;
	while(running)
	{
		increase_islands();
		for(int player =0; player <= NUM_PLAYERS; player++)
		{
			check_input(input_islands[player], player);
			launch_squadrons(input_islands[player], player);
		}
		check_collisions();
		check_landings();
		winning_team = check_winning_team();
		if(winning_team != NEUTRAL)
		{
			running = false;
		}
		//redraw() TODO:GUI
	}
	return true;
}
Пример #6
0
void update()
{
	
	if(game_state == PAUSE)
		return;
	if (game_state != DEAD && game_state != INTER_LEVEL )
		PLAYER_update();
	LEVEL_update();
	ACTOR_update(actor_pool, dt);	
	ACTOR_update(particle_pool, dt);
	BOARD_update();	
	if(game_state != INTER_LEVEL)
		check_collisions();
	pal_update();

	if(game_state == INTRO)
	{
		game_counter++;
		if(game_counter % 500 == 0)
		{
			test_calculate_boss();
		}
	}

}
Пример #7
0
// handle input
void input(Level &level, Player &player) {
    SDL_Event ev;
    GLCoord newpos(player.pos);
    const Uint8 *keystate = SDL_GetKeyboardState(NULL);
    float speed = 0.1;
    if(keystate[SDL_SCANCODE_LSHIFT] || keystate[SDL_SCANCODE_RSHIFT])
        speed = 0.5;

    if(keystate[SDL_SCANCODE_W])
        move(newpos, GLCoord(0, speed, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_A])
        move(newpos, GLCoord(-speed, 0, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_S])
        move(newpos, GLCoord(0, -speed, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_D])
        move(newpos, GLCoord(speed, 0, 0), player.cameraDirection);

    if(keystate[SDL_SCANCODE_LEFT])
        player.cameraDirection -= GLCoord(0, 0, 5);
    if(keystate[SDL_SCANCODE_RIGHT])
        player.cameraDirection += GLCoord(0, 0, 5);
    if(player.cameraDirection.z < 0)
        player.cameraDirection.z += 360;
    if(player.cameraDirection.z >= 360)
        player.cameraDirection.z -= 360;
    if(player.collisions) {
        newpos = check_collisions(level, player.pos, newpos);
    }
    player.pos = newpos;
    while(SDL_PollEvent(&ev)) {
        switch(ev.type) {
        case SDL_KEYDOWN:
            switch(ev.key.keysym.sym) {
            case SDLK_c:
                if(player.collisions) {
                    player.pos.z = 50;
                    glDisable(GL_FOG);
                }
                else {
                    player.pos.z = 0.5;
                    glEnable(GL_FOG);
                }
                player.collisions = !player.collisions;
                break;
            case SDLK_p:
                place(level, player.pos, player.cameraTarget - player.pos);
                break;
            case SDLK_x:
                dig(level, player.pos, player.cameraTarget - player.pos);
                break;
            case SDLK_q:
                clean_ui();
                exit(0);
            }
            break;
        }
    }
}
Пример #8
0
BOOL Collision::World ( D3DXVECTOR3 o_pos, D3DXVECTOR3 n_pos, D3DXVECTOR3 eRadius, D3DXVECTOR3* out_pos, int cut, float fThreshold )
{
	g_fCollisionThreshold = fThreshold;

	clipped = FALSE;
	onfloor = FALSE, onceil = FALSE;
	cutoff     = 0;
	cutoff_max = cut;

	Collision::Opt ( o_pos, n_pos, eRadius );

	if ( eRadius.x == eRadius.y && eRadius.x == eRadius.z )
	{
	
	}
	else
	{
		o_pos.x /= eRadius.x;
		o_pos.y /= eRadius.y;
		o_pos.z /= eRadius.z;
		n_pos.x /= eRadius.x;
		n_pos.y /= eRadius.y;
		n_pos.z /= eRadius.z;
	}

	
	D3DXVECTOR3 pos = check_collisions ( o_pos, n_pos - o_pos, eRadius );

	if ( eRadius.x == eRadius.y && eRadius.x == eRadius.z )
	{

	}
	else
	{
		pos.x *= eRadius.x;
		pos.y *= eRadius.y;
		pos.z *= eRadius.z;
	}

	if ( out_pos != NULL )
		*out_pos = pos;

	return clipped;
}
Пример #9
0
int
mmv_execute(mmv_t *mmv)
{
    if (!(mmv->op & APPEND)) {
        check_collisions(mmv);
    }

    findorder(mmv);
    if (mmv->op & (COPY | LINK)) {
        nochains(mmv);
    }
    scandeletes(mmv, baddel);
    goonordie(mmv);
    if (!(mmv->op & APPEND) && mmv->delstyle == ASKDEL) {
        scandeletes(mmv, skipdel);
    }
    doreps(mmv);
    return (mmv->failed ? 2 : mmv->nreps == 0 && (mmv->paterr || mmv->badreps));
}
Пример #10
0
void				update_ball(t_ball *ball, t_list_node *bricks)
{
	int				i;
	t_game			*game;

	game = get_game();
	i = 0;
	while (i < 10)
	{
		ball->x += (ball->speedx) / 10.0f;
		ball->y += (ball->speedy) / 10.0f;
		handle_bounds(ball);
		if (!INVINCIBLE_MODE && is_ball_outside(ball))
		{
			game->cur_level->lives--;
			reset_ball(ball);
		}
		check_collisions(ball, bricks);
		i++;
	}
}
Пример #11
0
void sphere_t::update(float dt) {
  dt = glm::clamp(dt, 0.0f, 0.01f);

  const glm::vec3 fgrav = {0.0f, -9.8f, 0.0f};
  const glm::vec3 fnorm = -fgrav;

  glm::vec3 momentum = state.mass * state.crnt_vel;

  // sum forces
  state.force = fgrav;
  bool colliding = check_collisions();
  if (colliding)
    state.force += fnorm;

  state.accl = (state.force / state.mass);
  state.crnt_vel = (state.prev_vel + state.accl) * dt;
  pos += state.crnt_vel * dt;

  state.prev_vel = state.crnt_vel;
  mat = glm::translate(glm::mat4(1.0f), pos);
}
Пример #12
0
void tsimulator::update_positions()
{
	TRACE;

	/* Create a new state. */
	detail::tstate state{
			unit::ttime{static_cast<unit::ttime::type>(states_.size())}};

	/* Update the positions of all celestial bodies. */
	for(const auto& sun : universe_.suns()) {
		state.suns.emplace_back(sun.id(), sun.position(state.time));
		sun_positions_[sun.id()] = sun.grid(state.time);
	}
	for(const auto& moon : universe_.moons()) {
		state.moons.emplace_back(moon.id(), moon.position(state.time));
		moon_positions_[moon.id()] = moon.grid(state.time);
	}

	/* Add the state to the list of states. */
	states_.push_back(std::move(state));

	check_collisions();
}
Пример #13
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;
}
Пример #14
0
_nc_resolve_uses2(bool fullresolve, bool literal)
/* try to resolve all use capabilities */
{
    ENTRY *qp, *rp, *lastread = 0;
    bool keepgoing;
    unsigned i;
    int unresolved, total_unresolved, multiples;

    DEBUG(2, ("RESOLUTION BEGINNING"));

    /*
     * Check for multiple occurrences of the same name.
     */
    multiples = 0;
    for_entry_list(qp) {
	int matchcount = 0;

	for_entry_list(rp) {
	    if (qp > rp
		&& check_collisions(qp->tterm.term_names,
				    rp->tterm.term_names,
				    matchcount + 1)) {
		if (!matchcount++) {
		    (void) fprintf(stderr, "\t%s\n", rp->tterm.term_names);
		}
		(void) fprintf(stderr, "and\t%s\n", qp->tterm.term_names);
		if (!remove_collision(rp->tterm.term_names,
				      qp->tterm.term_names)) {
		    ++multiples;
		}
	    }
	}
    }
    if (multiples > 0)
	return (FALSE);

    DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES"));

    /*
     * First resolution stage: compute link pointers corresponding to names.
     */
    total_unresolved = 0;
    _nc_curr_col = -1;
    for_entry_list(qp) {
	unresolved = 0;
	for (i = 0; i < qp->nuses; i++) {
	    bool foundit;
	    char *child = _nc_first_name(qp->tterm.term_names);
	    char *lookfor = qp->uses[i].name;
	    long lookline = qp->uses[i].line;

	    foundit = FALSE;

	    _nc_set_type(child);

	    /* first, try to resolve from in-core records */
	    for_entry_list(rp) {
		if (rp != qp
		    && _nc_name_match(rp->tterm.term_names, lookfor, "|")) {
		    DEBUG(2, ("%s: resolving use=%s (in core)",
			      child, lookfor));

		    qp->uses[i].link = rp;
		    foundit = TRUE;
		}
	    }

	    /* if that didn't work, try to merge in a compiled entry */
	    if (!foundit) {
		TERMTYPE thisterm;
		char filename[PATH_MAX];

		memset(&thisterm, 0, sizeof(thisterm));
		if (_nc_read_entry(lookfor, filename, &thisterm) == 1) {
		    DEBUG(2, ("%s: resolving use=%s (compiled)",
			      child, lookfor));

		    TYPE_MALLOC(ENTRY, 1, rp);
		    rp->tterm = thisterm;
		    rp->nuses = 0;
		    rp->next = lastread;
		    lastread = rp;

		    qp->uses[i].link = rp;
		    foundit = TRUE;
		}
	    }

	    /* no good, mark this one unresolvable and complain */
	    if (!foundit) {
		unresolved++;
		total_unresolved++;

		_nc_curr_line = (int) lookline;
		_nc_warning("resolution of use=%s failed", lookfor);
		qp->uses[i].link = 0;
	    }
	}
    }
    if (total_unresolved) {
	/* free entries read in off disk */
	_nc_free_entries(lastread);
	return (FALSE);
    }

    DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));

    /*
     * OK, at this point all (char *) references in `name' members
     * have been successfully converted to (ENTRY *) pointers in
     * `link' members.  Time to do the actual merges.
     */
    if (fullresolve) {
	do {
	    TERMTYPE merged;

	    keepgoing = FALSE;

	    for_entry_list(qp) {
		if (qp->nuses > 0) {
		    DEBUG(2, ("%s: attempting merge",
			      _nc_first_name(qp->tterm.term_names)));
		    /*
		     * If any of the use entries we're looking for is
		     * incomplete, punt.  We'll catch this entry on a
		     * subsequent pass.
		     */
		    for (i = 0; i < qp->nuses; i++)
			if (qp->uses[i].link->nuses) {
			    DEBUG(2, ("%s: use entry %d unresolved",
				      _nc_first_name(qp->tterm.term_names), i));
			    goto incomplete;
			}

		    /*
		     * First, make sure there is no garbage in the
		     * merge block.  As a side effect, copy into
		     * the merged entry the name field and string
		     * table pointer.
		     */
		    _nc_copy_termtype(&merged, &(qp->tterm));

		    /*
		     * Now merge in each use entry in the proper
		     * (reverse) order.
		     */
		    for (; qp->nuses; qp->nuses--)
			_nc_merge_entry(&merged,
					&qp->uses[qp->nuses - 1].link->tterm);

		    /*
		     * Now merge in the original entry.
		     */
		    _nc_merge_entry(&merged, &qp->tterm);

		    /*
		     * Replace the original entry with the merged one.
		     */
		    FreeIfNeeded(qp->tterm.Booleans);
		    FreeIfNeeded(qp->tterm.Numbers);
		    FreeIfNeeded(qp->tterm.Strings);
#if NCURSES_XNAMES
		    FreeIfNeeded(qp->tterm.ext_Names);
#endif
		    qp->tterm = merged;
		    _nc_wrap_entry(qp, TRUE);

		    /*
		     * We know every entry is resolvable because name resolution
		     * didn't bomb.  So go back for another pass.
		     */
		    /* FALLTHRU */
		  incomplete:
		    keepgoing = TRUE;
		}
	    }
	} while
	    (keepgoing);

	DEBUG(2, ("MERGES COMPLETED OK"));
    }

    /*
     * We'd like to free entries read in off disk at this point, but can't.
     * The merge_entry() code doesn't copy the strings in the use entries,
     * it just aliases them.  If this ever changes, do a
     * free_entries(lastread) here.
     */

    DEBUG(2, ("RESOLUTION FINISHED"));

    if (fullresolve)
	if (_nc_check_termtype != 0) {
	    _nc_curr_col = -1;
	    for_entry_list(qp) {
		_nc_curr_line = (int) qp->startline;
		_nc_set_type(_nc_first_name(qp->tterm.term_names));
		/*
		 * tic overrides this function pointer to provide more verbose
		 * checking.
		 */
		if (_nc_check_termtype2 != sanity_check2) {
		    SCREEN *save_SP = SP;
		    SCREEN fake_sp;
		    TERMINAL fake_tm;
		    TERMINAL *save_tm = cur_term;

		    /*
		     * Setup so that tic can use ordinary terminfo interface
		     * to obtain capability information.
		     */
		    memset(&fake_sp, 0, sizeof(fake_sp));
		    memset(&fake_tm, 0, sizeof(fake_tm));
		    fake_sp._term = &fake_tm;
		    fake_tm.type = qp->tterm;
		    _nc_set_screen(&fake_sp);
		    set_curterm(&fake_tm);

		    _nc_check_termtype2(&qp->tterm, literal);

		    _nc_set_screen(save_SP);
		    set_curterm(save_tm);
		} else {
		    fixup_acsc(&qp->tterm, literal);
		}
	    }
	    DEBUG(2, ("SANITY CHECK FINISHED"));
	}
Пример #15
0
_nc_entry_match(char *n1, char *n2)
{
    return check_collisions(n1, n2, 0);
}
Пример #16
0
//used while game_state = game
void CWorldModel::update_game()
{
	/*
	while traversing the vector different letters are used to move through different parts
	k is ued for the bullets
	j is used for the enemies
	i is used for the entities e.g. the walls and floors
	e is used for the explosions
	the player and boss because there is only one of each are called explicitly using ePlayer and eBoss
	*/

	//go through the vector starting at the bullets and stopping when you reach the explosions since they are the next type of entity
	for(int k=entities[eBullet];k<entities[eExplosion];k++)
	{
		//is the bullets side = the playes side e.g a fireball
		if(entityV[k]->get_side() == eSidePlayer)
		{
			//if the player has fired and there is a fireball not being used
			if (entityV[entities[ePlayer]]->get_fired() && !entityV[k]->get_active())
			{
				//shoot the fireball using x,y and direction from the player
				entityV[k]->shoot(entityV[entities[ePlayer]]->get_x(),entityV[entities[ePlayer]]->get_y(),entityV[entities[ePlayer]]->get_dir());
				HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
				//stops the player firing two fireballs at the same time
				entityV[entities[ePlayer]]->set_fired(false);
				HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()));

			}//end if
		}else//if not a player bullet
		{
			//go through the vector with the for loop [k] to find enemies
			for(int j=entities[eEnemy];j<entities[eBoss]; j++)
			{
				/*
				if the enemy is trooper(basic) and the bullet is a laser(least powerful)
				if the enemy is a solider(advanced and the bullet is a rocket(medieum power)
				if the enemy is a marine Elite and the bullet is a plasma orb(most powerful)
				*/
				if ((entityV[j]->get_id() == eEnemyTrooper && entityV[k]->get_id() == eBulletLaser) || (entityV[j]->get_id() == eEnemySoldier && entityV[k]->get_id() == eBulletRocket) || (entityV[j]->get_id() == eEnemyMarine  && entityV[k]->get_id() == eBulletPlasma))
				{
					//if the enemy has fired and there is an inactive bullet
					if (entityV[j]->get_fired() && !entityV[k]->get_active())
					{
						//shoot the fireball using x,y and direction from the selected enemy
						entityV[k]->shoot(entityV[j]->get_x(),entityV[j]->get_y(),entityV[j]->get_dir());
						HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
						entityV[j]->set_fired(false);
						HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
					}//end if
				}//end if
			}//end for [j]


			//if the boss has fired and there is a spare rocket
			if (entityV[entities[eBoss]]->get_fired() && !entityV[k]->get_active() && entityV[k]->get_id() == eBulletRocket)
			{
				//shoot the fireball using x,y and direction from the boss
				entityV[k]->shoot(entityV[entities[eBoss]]->get_x(),entityV[entities[eBoss]]->get_y()+20,entityV[entities[eBoss]]->get_dir());
				entityV[entities[eBoss]]->set_fired(false);
				HAPI->StopSound(CSounds::Inst()->get_sound(entityV[k]->get_id()));
				HAPI->PlayASound(CSounds::Inst()->get_sound(entityV[k]->get_id()),true);
			}//end if
		}//end if

	}//end for [k]

		//move through the entire Vector calling the entities update function
		for(unsigned int i=0;i<entityV.size();i++)
		{
			if (entityV[i]->get_active() && i != entities[eBoss])
			entityV[i]->update(); 
		}//end for
		/* 
		if the game has been running for 1 minute then reset the backgound music to the start
		this makes sure then there is always some music playing during the game
		*/
		int gamertime=HAPI->GetTime();
		if(gamertime-lastchange > 60*1000)
		{
			CSounds::Inst()->play_background(level,boss_attack);
			lastchange=gamertime;
		}//end if
	//checks for collisions more on this function later							
	check_collisions();

		//if the player is on screen 5 or the boss is active
		//players can't stop the boss from moving if they leave the screen
		if (screen == 5 || boss_attack)
		{
			entityV[entities[eBoss]]->update();
			boss_attack=true;
		}//end if

		//if the player goes off the right edge of the screen
		if (entityV[entities[ePlayer]]->get_x() > 1024)
		{
			scroll(-1);
			screen++;
			if(screen ==5)//change background music if the player reaches screen 5
				CSounds::Inst()->play_background(level,boss_attack);
		}//end if
			
		//if the player goes off the left side of the screen
		if (entityV[entities[ePlayer]]->get_x() < -32)
		{
			scroll(1);
			screen--;
		}//end if

		//if the boss has no health left
		if (entityV[entities[eBoss]]->get_health() <= 0)
		{	
			score+=100;
			//if the player has killed the level 4 boss
			if (level==4)
			{
				game_state=3;//go to the menu
				HAPI->StopStreamedMedia();
				score+=entityV[entities[ePlayer]]->get_health();//add the remaining players health to the score
				end_cond="YOU WIN";//congratulate the player
			}else//if it is not the level 4 boss which has been killed
				{
					//keep the players health in a sperate variable as the player is abou to go out of scope
					life=entityV[entities[ePlayer]]->get_health();
					//load the next level
					next_level();
				}//end else end if
		}//end if

		//if the players health is reduced to 0
		if (entityV[entities[ePlayer]]->get_health() <=0 )
		{	
			game_state=3;
			HAPI->StopStreamedMedia();//go tot the menu
		}//end if
}//end update_game()
Пример #17
0
static D3DXVECTOR3 check_collisions ( D3DXVECTOR3 src, D3DXVECTOR3 dir, D3DXVECTOR3 eRadius )
{
	cutoff++;

    if ( cutoff > cutoff_max )
		return src;

	collision_data coldat;
    coldat.src = src;
    coldat.dir = dir;
    coldat.dir_len = D3DXVec3Length ( &dir );
	
	//if ( coldat.dir_len < 0.001f )
	//if ( coldat.dir_len < 0.01f )
	if ( coldat.dir_len < g_fCollisionThreshold )
		return src;

    coldat.ndir = coldat.dir / coldat.dir_len;

	coldat.BoundingSphere = eRadius;

	for ( int x = 0; x < numfaces; x++ )
	{
		if ( !col_opt_Q12.check [ x ] )
			continue;

		cache.count  = 3;
		cache.normal = QMAP.v [ QMAP.faces [ x ].first ].n;

		for ( int y = 0; y < QMAP.faces [ x ].count - 2; y++ )
		{
			cache.vertex [ 0 ] = QMAP.v [ QMAP.faces [ x ].first         ].v;
			cache.vertex [ 1 ] = QMAP.v [ QMAP.faces [ x ].first + y + 1 ].v;
			cache.vertex [ 2 ] = QMAP.v [ QMAP.faces [ x ].first + y + 2 ].v;

			check_collision ( coldat );
		}
	}

    if ( coldat.found )
	{
		D3DXVECTOR3 s = src;

		if ( coldat.dist >= 0.001f )
		{
            s += coldat.ndir * ( coldat.dist - 0.001f );
        }

		D3DXVECTOR3 dst = src + dir;
        D3DXVECTOR3 n = s - coldat.nearest_poly;

        D3DXVec3Normalize ( &n, &n );
		float t = intersect ( dst, n, coldat.nearest_poly, n );

        D3DXVECTOR3 newdst = dst + n * t;
        D3DXVECTOR3 newdir = newdst - coldat.nearest_poly;

		clipped = TRUE;

		if ( n.y > 0.3f )
			onfloor = TRUE;
		
		if ( n.y < -0.3f )
			onceil = TRUE;

		if ( onfloor )
		{
			float fMin = -0.002f;
			float fMax =  0.002f;

			float fMinX = -0.0002f;
			float fMaxX =  0.0002f;

			/*
			if ( newdir.y > fMin && newdir.y < fMax )
			{
				if ( newdir.x > fMin && newdir.x < fMax )
					newdir.x = 0.0f;

				//if ( newdir.z > fMin && newdir.z < fMax )
				//	newdir.z = 0.0f;
				
				newdir.y = 0.0f;
			}
			*/

			/*
			if ( newdir.y > fMin && newdir.y < fMax )
			{
				if ( newdir.x > fMinX && newdir.x < fMaxX )
				{
					newdir.x = 0.0f;
					newdir.y = 0.0f;
				}

				//newdir.y = 0.0f;
			}
			*/

			//if ( ( newdir.y > fMin && newdir.y < fMax ) && ( newdir.x > fMinX && newdir.x < fMaxX ) )
			//{
			//	newdir.y = 0.0f;
			//}
		}

		return check_collisions ( s, newdir, eRadius );
    }

	return src + ( coldat.ndir * ( coldat.dir_len - 0.001f ) );
}
Пример #18
0
/**
 * fdisk_assign_device:
 * @cxt: context
 * @fname: path to the device to be handled
 * @readonly: how to open the device
 *
 * Open the device, discovery topology, geometry, detect disklabel and switch
 * the current label driver to reflect the probing result.
 *
 * Note that this function resets all generic setting in context. If the @cxt
 * is nested context then the device is assigned to the parental context and
 * necessary properties are copied to the @cxt. The change is propagated in
 * child->parent direction only. It's impossible to use a different device for
 * primary and nested contexts.
 *
 * Returns: 0 on success, < 0 on error.
 */
int fdisk_assign_device(struct fdisk_context *cxt,
			const char *fname, int readonly)
{
	int fd;

	DBG(CXT, ul_debugobj(cxt, "assigning device %s", fname));
	assert(cxt);

	/* redirect request to parent */
	if (cxt->parent) {
		int rc, org = fdisk_is_listonly(cxt->parent);

		/* assign_device() is sensitive to "listonly" mode, so let's
		 * follow the current context setting for the parent to avoid 
		 * unwanted extra warnings. */
		fdisk_enable_listonly(cxt->parent, fdisk_is_listonly(cxt));

		rc = fdisk_assign_device(cxt->parent, fname, readonly);
		fdisk_enable_listonly(cxt->parent, org);

		if (!rc)
			rc = init_nested_from_parent(cxt, 0);
		if (!rc)
			fdisk_probe_labels(cxt);
		return rc;
	}

	reset_context(cxt);

	fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC);
	if (fd < 0)
		return -errno;

	cxt->readonly = readonly;
	cxt->dev_fd = fd;
	cxt->dev_path = strdup(fname);
	if (!cxt->dev_path)
		goto fail;

	fdisk_discover_topology(cxt);
	fdisk_discover_geometry(cxt);

	if (fdisk_read_firstsector(cxt) < 0)
		goto fail;

	/* detect labels and apply labels specific stuff (e.g geometry)
	 * to the context */
	fdisk_probe_labels(cxt);

	/* let's apply user geometry *after* label prober
	 * to make it possible to override in-label setting */
	fdisk_apply_user_device_properties(cxt);

	/* warn about obsolete stuff on the device if we aren't in
	 * list-only mode and there is not PT yet */
	if (!fdisk_is_listonly(cxt) && !fdisk_has_label(cxt) && check_collisions(cxt) < 0)
		goto fail;

	DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]",
			      fname, readonly ? "READ-ONLY" : "READ-WRITE"));
	return 0;
fail:
	DBG(CXT, ul_debugobj(cxt, "failed to assign device"));
	return -errno;
}
Пример #19
0
void update_world() {
  render_map();
  check_collisions();
}