Esempio n. 1
0
CObject *CGame::add_enemy_car(int type,long y)
{
	CObject *o=0;
	int i,j;
	int left=0,right=dx;
	bool coll,last_coll;

	if (type==0) o=(CObject *)new CEnemyNormalCarObject(0,y,enemy_tiles[1],0,this);
	if (type==1) o=(CObject *)new CEnemyRacerCarObject(0,y,enemy_tiles[0],0,this);
	if (type==2) o=(CObject *)new CEnemySlidderCarObject(0,y,enemy_tiles[2],0,this);
	if (type==3) o=(CObject *)new CEnemyTruckObject(0,y,enemy_tiles[3],0,this);
	if (type==4) o=(CObject *)new CFuelObject(0,y,extra_tiles[0],this);
	if (type==5) o=(CObject *)new CEnemyFastCarObject(0,y,enemy_tiles[0],0,this);

	if (o==0) return 0;

	/* Find a proper 'x': */ 
	coll=last_coll=false;
	for(i=0,j=0;i<dx && j<2;i+=4) {
		coll=(object_collision(i,0,o,CONSTITUTION_SOLID|CONSTITUTION_CAR)!=0 ? true:false);

		if (j==0 && last_coll && !coll) {
			left=i;
			j=1;
		} /* if */ 

		if (j==1 && !last_coll && coll) {
			right=i-4;
			j=2;
		} /* if */ 
		last_coll=coll;
	} /* for */ 

	if (left==0 || right==dx || left>right) {
		delete o;
		return 0;
	} /* if */ 

	if (type==0 ||
		type==1 ||
		type==2 ||
		type==5) {
		CEnemyCarObject *po=(CEnemyCarObject *)o;
		po->x=int(left+8+(rand()%(right-left-16)));
		if (abs(po->x-left)<abs(po->x-right)) {
			po->following_right_border=false;
			po->distance_to_border=(po->x-left);
		} else {
			po->following_right_border=true;
			po->distance_to_border=(right-po->x);
		} /* if */ 
	} /* if */ 
	if (type==3) o->x=int(left+8+(rand()%(right-left-16)));
	if (type==4) o->x=(left+right)/2;

	objects.Insert(o);

	return o;
} /* CGame::add_enemy_car */ 
Esempio n. 2
0
CObject *CGame::add_obstacle(int type,long y)
{
	CObject *o=0;
	int i,j;
	int left=0,right=dx;
	bool coll,last_coll;

	if (type==0) o=(CObject *)new CObject(0,y,extra_tiles[6],CONSTITUTION_OIL,this);
	if (type==1) o=(CObject *)new CObject(0,y,extra_tiles[7],CONSTITUTION_WATER,this);
	if (type==2) o=(CObject *)new CObject(0,y,extra_tiles[8],CONSTITUTION_SOLID,this);

	if (o==0) return 0;

	/* Find a proper 'x': */ 
	coll=last_coll=false;
	for(i=0,j=0;i<dx && j<2;i+=4) {
		coll=(object_collision(i,0,o,CONSTITUTION_SOLID)!=0 ? true:false);

		if (j==0 && last_coll && !coll) {
			left=i;
			j=1;
		} /* if */ 

		if (j==1 && !last_coll && coll) {
			right=i-4;
			j=2;
		} /* if */ 
		last_coll=coll;
	} /* for */ 

	if ((right-left)<80) {
		/* There's no space: */ 
		delete o;
		return 0;
	} /* if */ 

	o->x=int(left+8+(rand()%(right-left-16)));
	objects.Insert(o);

	return o;
} /* CGame::add_obstacle */ 
Esempio n. 3
0
void update_gamestate(Outbreak * outbreak) {
  if (!outbreak->paused) {
    object_update_position(outbreak->player);
    if (object_offscreen(outbreak->player)) {
      set_object_x(outbreak->player, (object_direction_x(outbreak->player) == DIRECTION_LEFT) ? 0 : SCREEN_WIDTH - object_width(outbreak->player));
    }
    if (ball_magnetized(outbreak->ball)) {
      set_object_x(outbreak->ball, object_x(outbreak->player) + (object_width(outbreak->player) - object_width(outbreak->ball)) / 2.0f);
    }

    object_update_x(outbreak->ball);
    if (object_offscreen(outbreak->ball)) {
      set_object_x(outbreak->ball, (object_direction_x(outbreak->ball) == DIRECTION_LEFT) ? 0 : SCREEN_WIDTH - object_width(outbreak->ball));
      object_bounce_x(outbreak->ball);
    } else if (object_collision(outbreak->player, outbreak->ball)) {
      object_rollback_x(outbreak->ball);
      object_bounce_x(outbreak->ball);
    } else {
      int i;
      for (i = 0; i < outbreak->num_blocks; i++) {
        if (object_collision(outbreak->ball, outbreak->blocks[i])) {
          hit_block(outbreak->blocks[i]);
          if (outbreak->blocks[i]->health == 0) {
            remove_block(outbreak, outbreak->blocks[i]);
          }
          object_rollback_x(outbreak->ball);
          object_bounce_x(outbreak->ball);
          break;
        }
      }
    }

    object_update_y(outbreak->ball);
    if (object_y(outbreak->ball) >= SCREEN_HEIGHT) {
      outbreak->quit = TRUE;
    } else if (object_y(outbreak->ball) < 0) {
      set_object_y(outbreak->ball, 0);
      object_bounce_y(outbreak->ball);
    } else if (object_collision(outbreak->player, outbreak->ball)) {
      object_rollback_y(outbreak->ball);
      object_bounce_y(outbreak->ball);
      set_object_angle(outbreak->ball, object_angle(outbreak->ball) - ((object_x(outbreak->ball) - object_x(outbreak->player)) - (object_width(outbreak->player) + object_width(outbreak->ball)) / 2.0f) * PADDLE_CURVINESS);
    } else {
      int i;
      for (i = 0; i < outbreak->num_blocks; i++) {
        if (object_collision(outbreak->ball, outbreak->blocks[i])) {
          hit_block(outbreak->blocks[i]);
          if (outbreak->blocks[i]->health == 0) {
            remove_block(outbreak, outbreak->blocks[i]);
          }
          object_rollback_y(outbreak->ball);
          object_bounce_y(outbreak->ball);
          break;
        }
      }
    }

    if (!ball_magnetized(outbreak->ball)) {
      set_object_speed(outbreak->ball, object_speed(outbreak->ball) + BALL_ACCELERATION);
    }
  }
}