[ADD] begin of collision
This commit is contained in:
3
push
Executable file
3
push
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
git push
|
||||||
|
SemvdH
|
||||||
|
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
|
||||||
13
src/main.c
13
src/main.c
@@ -179,14 +179,19 @@ void draw()
|
|||||||
sprites_draw_player(player_x, player_y, PLAYER_SCALE);
|
sprites_draw_player(player_x, player_y, PLAYER_SCALE);
|
||||||
// vita2d_draw_rectangle(x2_pos, y2_pos, (float)10, (float)10, RGBA8(169, 60, 23, 255));
|
// vita2d_draw_rectangle(x2_pos, y2_pos, (float)10, (float)10, RGBA8(169, 60, 23, 255));
|
||||||
|
|
||||||
char text[80] = "process time: ";
|
vita2d_draw_rectangle(300, 50, 30, 30, RGBA8(255, 0, 255, 255));
|
||||||
sprintf(text, "%f", simple_enemies[5].x);
|
|
||||||
|
size_t collision_player = toolbox_is_collision(player_x, player_y - (PLAYER_SCALE * SHIP_HEIGHT)/2,SHIP_WIDTH * PLAYER_SCALE, SHIP_HEIGHT * PLAYER_SCALE, 300+15,50+15,30,30);
|
||||||
|
if (collision_player)
|
||||||
|
{
|
||||||
|
vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0, 255, 0, 255), 1.0f, "collision");
|
||||||
|
} else {
|
||||||
|
vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0, 255, 0, 255), 1.0f, "no col");
|
||||||
|
}
|
||||||
|
|
||||||
char fps[15] = "fps: ";
|
char fps[15] = "fps: ";
|
||||||
sprintf(fps, "%d", timing_get_fps(deltaTime));
|
sprintf(fps, "%d", timing_get_fps(deltaTime));
|
||||||
|
|
||||||
vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0, 255, 0, 255), 1.0f, text);
|
|
||||||
|
|
||||||
vita2d_pvf_draw_text(pvf, 700, 80, RGBA8(0, 255, 0, 255), 1.0f, fps);
|
vita2d_pvf_draw_text(pvf, 700, 80, RGBA8(0, 255, 0, 255), 1.0f, fps);
|
||||||
|
|
||||||
char timertext[100];
|
char timertext[100];
|
||||||
|
|||||||
@@ -7,3 +7,12 @@ float toolbox_random_float(float a, float b)
|
|||||||
float r = random * diff;
|
float r = random * diff;
|
||||||
return a + r;
|
return a + r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2)
|
||||||
|
{
|
||||||
|
//TODO make it work
|
||||||
|
return x1 < x2 + width2 / 2 &&
|
||||||
|
x1 + width1 / 2 > x2 &&
|
||||||
|
y1 < y2 + height2 / 2 &&
|
||||||
|
y1 + heigth1 / 2 > y2;
|
||||||
|
}
|
||||||
@@ -10,4 +10,19 @@
|
|||||||
*/
|
*/
|
||||||
float toolbox_random_float(float a, float b);
|
float toolbox_random_float(float a, float b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief checks if a collision has happened between 2 ractancles (bounding boxes)
|
||||||
|
*
|
||||||
|
* @param x1 the center x of the first object
|
||||||
|
* @param y1 the center y of the first object
|
||||||
|
* @param width1 the width of the first object
|
||||||
|
* @param heigth1 the heigth of the first object
|
||||||
|
* @param x2 the center x of the second object
|
||||||
|
* @param y2 the center y of the second object
|
||||||
|
* @param width2 the width of the second object
|
||||||
|
* @param height2 the heigth of the second object
|
||||||
|
* @return size_t 0 if no collision, 1 if there is a collision.
|
||||||
|
*/
|
||||||
|
size_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2);
|
||||||
|
|
||||||
#endif // !TOOLBOX_H
|
#endif // !TOOLBOX_H
|
||||||
Reference in New Issue
Block a user