cannon.c
1.48 KB
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
#include "primlib.h"
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
if (gfx_init())
exit(3);
gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE);
gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW);
gfx_line(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2, gfx_screenHeight() - 150, YELLOW);
gfx_updateScreen();
double angle = 90.0 * (M_PI/180.0);
double bullet_distance = 170.0;
while(1)
{
double delta_angle= 2.0 * (M_PI/180.0);
int x1 = 150 * cos(angle-delta_angle);
int y1 = 150 * sin(angle-delta_angle);
int x2 = 150 * cos(angle+delta_angle);
int y2 = 150 * sin(angle+delta_angle);
gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE);
gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW);
gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1, gfx_screenHeight() - y1,
gfx_screenWidth() / 2 + x2, gfx_screenHeight() - y2, YELLOW);
int x_bullet = bullet_distance * cos(angle);
int y_bullet = bullet_distance * sin(angle);
gfx_filledCircle(gfx_screenWidth() / 2 + x_bullet, gfx_screenHeight() - y_bullet, 10, RED);
gfx_updateScreen();
bullet_distance += 1.0;
if(gfx_isKeyDown(SDLK_RIGHT))
angle -= 1.0 * (M_PI/180.0);
if(gfx_isKeyDown(SDLK_LEFT))
angle += 1.0 * (M_PI/180.0);
SDL_Delay(100);
};
return 0;
}