-
Notifications
You must be signed in to change notification settings - Fork 0
/
collision.cpp
67 lines (59 loc) · 1.92 KB
/
collision.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <sstream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_native_dialog.h>
#include "functions.h"
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
extern ALLEGRO_DISPLAY *display;
extern ALLEGRO_EVENT_QUEUE *event_queue;
extern ALLEGRO_TIMER *timer;
extern Image background1[7], background2[6];
extern Image character;
extern Image sprite;
extern Image block[350];
extern Image run[8];
extern Image jump_bitmap;
extern ALLEGRO_SAMPLE *sample;
extern ALLEGRO_SAMPLE *walks;
extern int posx;
extern int posy;
extern int spriteDirection;
char collision_y(int dy, int time) {
int i;
for (i = 0; i < 350; i++) {
if (block[i].x >= 355 && block[i].x <= 455 && block[i].y <= posy + 165 && block[i].y + 15 >= posy) {
if (dy + time * 0.2 > 0) {
printf("\n1");
posy = block[i].y - 165;
} else {
posy = block[i].y + 50 + time * 0.22;
}
return 't';
}
if (block[i].x >= 355 && block[i].x <= 455 && block[i].y <= posy + 165 && block[i].y + 50 >= posy) {
if (dy + time * 0.2 > 0){
posy = block[i].y + 50 + time * 0.22;
}
return 'b';
}
}
return false;
}
char collision_x() {
int i;
for (i = 0; i < 350; i++) {
if (block[i].y >= posy && block[i].y <= posy + 160 && block[i].x <= 410 && block[i].x >= 345) {
printf("\nr");
return 'l'; // returns 'l' if x collision on left side of block
}
if (block[i].y >= posy && block[i].y <= posy + 160 && block[i].x <= 470 && block[i].x >= 400) {
printf("\nl");
return 'r'; // Returns 'r' if x collision on right side of a block
}
}
return 'n'; // Returns 'n' if no x collision
}