Example #1
0
File: ship.c Project: kiddos/meteor
void ship_shoot_bullet(ship *s) {
  if (s != NULL) {
    const point start = point_init(s->center.x, s->center.y);
    if (s->bullets == NULL) {
      s->bullets = bullet_init(start, s->direction, s->attr.damage);
    } else {
      bullet_add(s->bullets, start, s->direction, s->attr.damage);
      s->bullet_count = bullet_get_count(s->bullets);
    }

    // shooting bullet cost mana
    if (s->attr.mana - SHIP_BULLET_MANA >= 0)
      s->attr.mana -= SHIP_BULLET_MANA;
  } else {
    error_message("ship object null pointer");
  }
}
Example #2
0
/* Bästa Snyggkoden™ i stan! */
int player_loop(DARNIT_KEYS *keys) {
	SHAPE_COPY *shape;
	DARNIT_KEYS set;
	static int shoot_key=0;
	static int grenade_key=0;
	int dir;
	if (!player)
		return 0;
	shape=shapesprite_get_current_shape(player->shape);
	
	if(keys->up)
		player->gun_angle=-200;
	else if(keys->down)
		player->gun_angle=200;
	else
		player->gun_angle=0;
	
	if(keys->a&&!shoot_key) {
		int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0);
		player->bullet=bullet_add(player->bullet, x, y, player->gun_angle, model.bullet, BULLET_OWNER_PLAYER);
		d_sound_play(sound.shoot, 0, 127, 127, 0);
		particle_emitter_new(30, 100, 8000, 10000, 255, 0, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100);
		particle_emitter_new(30, 100, 8000, 10000, 255, 255, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100);
	}
	if(keys->b&&(!grenade_key)&&player->grenades)
		grenade_time=d_time_get();
	if((grenade_key&&!keys->b)||(grenade_time&&d_time_get()>=GRENADE_LIFE+grenade_time)) {
		int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0);
		if(player->grenades) {
			player->grenade=grenade_add(player->grenade, x, y, player->gun_angle, grenade_time+GRENADE_LIFE-d_time_get(), model.grenade);
			player->grenades--;
		}
		grenade_time=0;
	}
	shoot_key=keys->a;
	grenade_key=keys->b;
	
	if (keys->left)
		player->vel_x -= (PLAYER_ACCELERATION * d_last_frame_time()) / 1000;
	else if (keys->right)
		player->vel_x += (PLAYER_ACCELERATION * d_last_frame_time()) / 1000;
	else if (player->vel_x) {
		if (abs(player->vel_x) < (PLAYER_ACCELERATION * d_last_frame_time()) / 1000)
			player->vel_x = 0;
		else
			player->vel_x += ((player->vel_x < 0 ? 1 : -1) * (PLAYER_FRICTION) * d_last_frame_time()) / 1000;
	}
	if (abs(player->vel_x) > PLAYER_SPEED_X_MAX)
		player->vel_x = (player->vel_x < 0 ? -1 : 1) * PLAYER_SPEED_X_MAX;
	
	if (keys->l && !player->vel_y) {
		set = d_keys_zero();
		set.l = 1;
		d_keys_set(set);
		player->vel_y -= PLAYER_JUMP_ACCELERATION;
	}

	player->vel_y += PLAYER_GRAVITY * d_last_frame_time();

	if (abs(player->vel_y) > PLAYER_SPEED_Y_MAX)
		player->vel_y = (player->vel_y < 0 ? -1 : 1) * PLAYER_SPEED_Y_MAX;

	dir=map_collide_dir(shape->coord, shape->lines, player->x / 1000, player->y / 1000, player->vel_x);
	if(dir==MAP_SLOPE_UP) {
		player->x += player->vel_x * d_last_frame_time()/ 1000;
		player->y-=abs(player->vel_x) * d_last_frame_time() / 1000;
	} else if(dir==MAP_SLOPE_VERTICAL) {
		player->x-=player->vel_x/ 200;
		player->vel_x*=-1;
		player->y+=2000;
	} else if(dir!=MAP_SLOPE_VERTICAL) {
		if (dir != -1)
			player->y-=50;
		player->x += player->vel_x * d_last_frame_time() / 1000;
	}
	if (player->x < 32000)
		player->x = 32000;
	
	if (!map_collide(shape->coord, shape->lines, player->x / 1000, player->y / 1000) || player->vel_y < 0)
		player->y += player->vel_y * d_last_frame_time() / 1000;
	else {
		player->vel_y = 0;
	}

	if (player->y / 1000 >= PLAYER_KILLZONE||map_enemy_collide(shapesprite_get_current_shape(player->shape), player->x, player->y)) {
		player_kill();
		return -1;
	}

	if (player->x < camera_x + 32000)
		player->x = camera_x + 32000;
	if(player->vel_x) {
		shapesprite_animate(player->shape);
	}
	
	if(boss_shooting&&((player->x-camera_x)>300000)&&((boss_shooting-d_time_get())>1000)) {
		player->health--;
		if(player->health<0) {
			player_kill();
			return 1;
		}
	}
	
	map_check_powerup(player->x/1000/*+camera_x/1000*/, player->y/1000);
	score++;

	return 1;
}