Exemple #1
0
void gameLogic() {
	if (danmakux.player->x < 0) {
		if (danmakux.player->focused) danmakux.player->x += danmakux.player->focusspeed;
		else danmakux.player->x += danmakux.player->speed;
	}
	if (danmakux.player->x > danmakux.width-danmakux.player->width) {
		if (danmakux.player->focused) danmakux.player->x -= danmakux.player->focusspeed;
		else danmakux.player->x -= danmakux.player->speed;
	}
	if (danmakux.player->y < 0) {
		if (danmakux.player->focused) danmakux.player->y += danmakux.player->focusspeed;
		else danmakux.player->y += danmakux.player->speed;
	}
	if (danmakux.player->y > danmakux.height-danmakux.player->height) {
		if (danmakux.player->focused) danmakux.player->y -= danmakux.player->focusspeed;
		else danmakux.player->y -= danmakux.player->speed;
	}
	for (std::list<PlayerBullet>::iterator i = danmakux.playerbullets.begin(); i != danmakux.playerbullets.end(); i++) {
		if ((*i).x+(*i).width < 0 || (*i).y+(*i).height < 0 || (*i).x > danmakux.width || (*i).y > danmakux.height || (*i).dead) {
			plblt_close(&(*i));
			i = danmakux.playerbullets.erase(i);
			continue;
		}
		for (std::list<Enemy>::iterator j = danmakux.enemies.begin(); j != danmakux.enemies.end(); j++) {
			if (rect_intersects(&(*j).hitbox, &(*i).hitbox)) {
				(*j).health -= (*i).damage;
				plblt_close(&(*i));
				i = danmakux.playerbullets.erase(i);
				for (std::list<EnemyBullet>::iterator k = (*j).bullets.begin(); k != (*j).bullets.end(); k++) {
					if (circ_intersects(&(*k).hitbox, &danmakux.player->hitbox)) {
						danmakux.player->health -= (*k).damage;
						enblt_close(&(*k));
						k = (*j).bullets.erase(k);
					}
					if ((*k).x < 0 || (*k).y < 0 || (*k).x > danmakux.width || (*k).y > danmakux.height) {
						enblt_close(&(*k));
						k = (*j).bullets.erase(k);
					}
				}
				if ((*j).health <= 0) {
					(*j).dead = true;
					addItem("powerup");
				}
				if ((*j).dead && (*j).bullets.empty()) {
					enem_close(&(*j));
					j = danmakux.enemies.erase(j);
				}
			}
		}
	}
	if (danmakux.player->health <= 0) {
		danmakux.player->dead = true;
		//dying procedure
	}
	for (std::list<Item>::iterator i = danmakux.items.begin(); i != danmakux.items.end(); i++) {
		if ((*i).type == "wall") {
			if (danmakux.player->moveu && danmakux.player->y < (*i).y+(*i).height && danmakux.player->x > (*i).x && danmakux.player->x < (*i).x+(*i).width) {
				if (danmakux.player->focused) {
					danmakux.player->y += danmakux.player->focusspeed;
				}
				else {
					danmakux.player->y += danmakux.player->speed;
				}
			}
			if (danmakux.player->moved && danmakux.player->y > (*i).y && danmakux.player->x > (*i).x && danmakux.player->x < (*i).x+(*i).width) {
				if (danmakux.player->focused) {
					danmakux.player->y -= danmakux.player->focusspeed;
				}
				else {
					danmakux.player->y -= danmakux.player->speed;
				}
			}
			if (danmakux.player->movel && danmakux.player->x < (*i).x+(*i).width && danmakux.player->y > (*i).y && danmakux.player->y < (*i).y+(*i).height) {
				if (danmakux.player->focused) {
					danmakux.player->x += danmakux.player->focusspeed;
				}
				else {
					danmakux.player->x += danmakux.player->speed;
				}
			}
			if (danmakux.player->mover && danmakux.player->x > (*i).x && danmakux.player->y > (*i).y && danmakux.player->y < (*i).y+(*i).height) {
				if (danmakux.player->focused) {
					danmakux.player->x -= danmakux.player->focusspeed;
				}
				else {
					danmakux.player->x -= danmakux.player->speed;
				}
			}
		}
		if (rect_intersects(&(*i).hitbox, &danmakux.player->pickupbox)) {
			if ((*i).type == "powerup") {
				runFunction(&danmakux.player->script, "powerup");
			}
			item_close(&(*i));
			i = danmakux.items.erase(i);
		}
	}
}
Exemple #2
0
bool enblt_hit(EnemyBullet *blt, Player *p) {
	if (!blt->dead) {
		if (circ_intersects(&blt->hitbox, &p->hitbox)) return true;
	}
	return false;
}