blob: 99e5abc21e12164e446224ece9ef3a401ad6693e (
plain)
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
|
#include "pong.h"
#include "screen.h"
inline void UpdatePosition(vector_t * const position, const vector_t velocity) {
position->x += velocity.x ;
position->y += velocity.y ;
}
/* CheckMoveableCollision: Implementation of AABB collision for moveable objects */
bool CheckMoveableCollision(const struct moveable_t m1, const struct moveable_t m2) {
const vector_t m1p = m1.position;
const vector_t m2p = m2.position;
const bool checkX = m1p.x + m1.width > m2p.x,
checkY = m1p.y + m1.height > m2p.y && m1p.y < m2p.y + m2.height;
return checkX && checkY;
}
bool CheckLeftWallCollision(const struct moveable_t m) {
return m.position.x < 0 ;
}
bool CheckRightWallCollision(const struct moveable_t m) {
return m.position.x + m.width > SCREEN_WIDTH;
}
bool CheckGroundCollision(const struct moveable_t m) {
return m.position.y + m.height > SCREEN_HEIGHT;
}
bool CheckCeilingCollision(const struct moveable_t m) {
return m.position.y < 0;
}
void Reset(ball_t * const ball) {
ball->position = (vector_t) {SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1};
ball->velocity = (vector_t){1, 1};
}
|