Пример #1
0
PARTICLE::PARTICLE(PARTICLE_SYSTEM* part_sys, PARTICLE_DATA& data, AGENT_HANDLER * ah, double x, double y, double rotation, int life, const ATTACK_TYPE * attack_t, int target_gid, int target_uid, int source_gid, int chain_factor) : part_sys(part_sys), x(x), y(y), theta(rotation * M_PI / 180), life(data.life), data(data), attack_t(attack_t), target_gid(target_gid), target_uid(target_uid), source_gid(source_gid), frame_index(0.), expansion(0.), sprite(NULL), prev_frameindex(-10), is_subimg(false), done_damage(false), agent_handler(ah), chain_factor(chain_factor)
{
	// setup chaining
	if (chain_factor < 0) {
		if (attack_t) this->chain_factor = attack_t->chain_factor;
		else chain_factor = 0;
	}

	// set life
	if (life > 0) this->life = life;
	start_len = this->life;
    
	if (data.particle_type == 0) this->life -= data.radius/2; // ligntning has double life
	if (data.particle_type == 1) this->life *= 2; // ligntning has double life
	if (data.particle_type == 2) {
		do_damage();
		chain();
	}
    if (data.particle_type == 3) this->life = data.speed; // static particles

	if (data.type == 2) this->life = 1; // play once and die (life doesn't matter)
	if (data.type == 3) this->frame_index = rand() % data.num_frames; // random start frame
    starting_life = this->life;
    if (data.particle_type == 2) this->life = data.speed;
	full_life = this->life;
}
Пример #2
0
void LRMarker::mark(
    Coord x1, Coord y1, Coord h1, Coord x2, Coord y2, Coord h2
) {
    if (canvas_ !=  nil) {
        if (!marked_) {
            do_damage(
                canvas_,
                left_, right_, x1, y1, y1 + h1, x2, y2, y2 + h2
            );
        } else if (
            (y2 > y1_ || y2 == y1_ && x2 < x1_)
            || (y1 < y2_ || y1 == y2_ && x1 > x2_)
        ) {
            do_damage(
                canvas_,
                left_, right_, x1_, y1_, y1_ + h1_, x2_, y2_, y2_ + h2_
            );
            do_damage(
                canvas_,
                left_, right_, x1, y1, y1 + h1, x2, y2, y2 + h2
            );
        } else {
            do_damage(
                canvas_,
                left_, right_, x1_, y1_, y1_ + h1_, x1, y1, y1 + h1
            );
            do_damage(
                canvas_,
                left_, right_, x2_, y2_, y2_ + h2_, x2, y2, y2 + h2
            );
        }
    }
    x1_ = x1;
    y1_ = y1;
    h1_ = h1;
    x2_ = x2;
    y2_ = y2;
    h2_ = h2;
    marked_ = true;
}
Пример #3
0
void in_range(Tower* tower, GameState* state) {
	if (tower->shoot_interval - tower->frames_since_last_shot == 0) {
		shoot(tower);
	} else {
		register int p;
		for (p = 0; p < tower->ammo; p++) {
			if (tower->projectiles[p].live) {
				Entity proj, en;
				proj.projectile = tower->projectiles[p];
				en.enemy = *tower->projectiles[p].target;
				if (is_colliding(&proj, &en)) {
					do_damage(&tower->projectiles[p], tower->projectiles[p].target);
					if (is_dead(tower->projectiles[p].target, state)) {
						tower->target = NULL;
						tower->projectiles[p].target = NULL;
					}
				}
			}
		}
	}
}
Пример #4
0
void PARTICLE::update(DISPLAY& disp, bool is_draw)
{
    // update
    if (data.particle_type == 3 || data.particle_type == 2) life -= 1;
	else if (data.type != 2) life -= data.speed;

    if (data.particle_type == 0 || (data.particle_type == 1 && life < starting_life/2)) {
        x += data.speed * cos(theta);
        y += data.speed * sin(theta);
    }

    // update frame
    frame_index += data.frame_rate;
    if (frame_index >= data.num_frames) {
        if (data.type == 0) {
            frame_index -= data.num_frames;
        } else if (data.type) {
            frame_index = data.num_frames-1;
            if (data.type == 2) life = 0;
        }
    }

    // update expansion (zoom type)
    if (data.particle_type == 1) {
        if (life < starting_life/2) {
			expansion = life / starting_life;
			if (!done_damage) do_damage();
			if (chain_factor) chain();
		}
        else expansion = (starting_life - life) / starting_life;
    } else if (data.particle_type == 2) {
    	// update expansion (solid type)
		expansion = 1.0;
	}

    // draw
    if (is_draw && is_on_screen(disp)) draw(disp);
}