1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
void Collide(Map boxes[], int size, Player &player, bool keys[], Particle particles[], int &particleNum, int maxParticles, Enemy enemy[], int maxEnemies, float *cameraPos) {
for (int i = 0; i < size; i++) {
if (player.x + player.boundX > boxes[i].x &&
player.x - player.boundX < boxes[i].x + boxes[i].width &&
player.y + player.boundY >= boxes[i].y &&
player.y - player.boundY < boxes[i].y + boxes[i].height &&
boxes[i].solid && boxes[i].active) {
if (player.y + player.boundY >= boxes[i].y && player.prevY + player.boundY <= boxes[i].y && player.alive) {
if (boxes[i].image == 6 && player.velY > 0) {
for (int r = 0; r < 300; r++)
NewParticles(particles, maxParticles, player.x, player.y, particleNum, 1, rand() % 255, rand() % 255, rand() % 255,
rand() % 20 - 10, rand() % 20 - 10, rand() % 5 + 2, 1, rand() % 2, 1);
player.deadTimer = 100;
player.alive = false;
}
if (player.frame >= 4 && player.frame <= 5 || !keys[LEFT] && !keys[RIGHT] && abs(player.velX) < 1 ||player.frame == 6)
player.frame = 0;
if (abs(player.velX) > 1 && !player.frame >= 1 && !player.frame <= 3)
player.frame = 1;
player.velY = 0;
player.jump = true;
player.y = boxes[i].y - player.boundY;
if (keys[RIGHT] && player.velX > 2 || keys[LEFT] && player.velX < -2)
if (rand() % 10 == 0)
NewParticles(particles, maxParticles, player.x, player.y + player.boundY - 1, particleNum, 1, boxes[i].color1, boxes[i].color2, boxes[i].color3, 50, 20, 1, 1, true, 1);
}
else if (player.x + player.boundX > boxes[i].x && player.prevX + player.boundX <= boxes[i].x && boxes[i].image != 6) {
player.velX = 0;
player.x = boxes[i].x - player.boundX;
if (keys[RIGHT] && player.velY > 0) {
player.velY = 0;
player.jump = true;
if (rand() % 10 == 0)
NewParticles(particles, maxParticles, player.x + player.boundX, player.y + player.boundY - 1, particleNum, 1, boxes[i].color1, boxes[i].color2, boxes[i].color3, 50, 20, 1, 1, true, 1);
}
}
else if (player.x - player.boundX < boxes[i].x + boxes[i].width && player.prevX - player.boundX >= boxes[i].x + boxes[i].width && boxes[i].image != 6) {
player.velX = 0;
player.x = boxes[i].x + boxes[i].width + player.boundX;
if (keys[LEFT] && player.velY > 0) {
player.velY = 0;
player.jump = true;
if (rand() % 10 == 0)
NewParticles(particles, maxParticles, player.x - player.boundX, player.y + player.boundY - 1, particleNum, 1, boxes[i].color1, boxes[i].color2, boxes[i].color3, 50, 20, 1, 1, true, 1);
}
}
else if (player.y - player.boundY < boxes[i].y + boxes[i].height && player.prevY - player.boundY <= boxes[i].y + boxes[i].height && boxes[i].image != 6 && player.velY < -1) {
player.velY = 0;
player.y = boxes[i].y + boxes[i].height + player.boundY;
}
}
}
|