Commit 88f47d8435c7b0395ff6b63e205c569f6b1ceda4
1 parent
fd489b9a
Renamed variables
Showing
3 changed files
with
24 additions
and
24 deletions
03-bullet/cannon.c
@@ -11,14 +11,14 @@ int main() { | @@ -11,14 +11,14 @@ int main() { | ||
11 | while(1) | 11 | while(1) |
12 | { | 12 | { |
13 | double delta_angle= 2.0 * (M_PI/180.0); | 13 | double delta_angle= 2.0 * (M_PI/180.0); |
14 | - int x1 = 150 * cos(angle-delta_angle); | ||
15 | - int y1 = 150 * sin(angle-delta_angle); | ||
16 | - int x2 = 150 * cos(angle+delta_angle); | ||
17 | - int y2 = 150 * sin(angle+delta_angle); | 14 | + int x1_barrel = 150 * cos(angle-delta_angle); |
15 | + int y1_barrel = 150 * sin(angle-delta_angle); | ||
16 | + int x2_barrel = 150 * cos(angle+delta_angle); | ||
17 | + int y2_barrel = 150 * sin(angle+delta_angle); | ||
18 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | 18 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); |
19 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | 19 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); |
20 | - gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1, gfx_screenHeight() - y1, | ||
21 | - gfx_screenWidth() / 2 + x2, gfx_screenHeight() - y2, YELLOW); | 20 | + gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1_barrel, gfx_screenHeight() - y1_barrel, |
21 | + gfx_screenWidth() / 2 + x2_barrel, gfx_screenHeight() - y2_barrel, YELLOW); | ||
22 | 22 | ||
23 | int x_bullet = bullet_distance * cos(angle); | 23 | int x_bullet = bullet_distance * cos(angle); |
24 | int y_bullet = bullet_distance * sin(angle); | 24 | int y_bullet = bullet_distance * sin(angle); |
04-shoot/cannon.c
@@ -13,14 +13,14 @@ int main() { | @@ -13,14 +13,14 @@ int main() { | ||
13 | while(1) | 13 | while(1) |
14 | { | 14 | { |
15 | double delta_angle= 2.0 * (M_PI/180.0); | 15 | double delta_angle= 2.0 * (M_PI/180.0); |
16 | - int x1 = 150 * cos(angle-delta_angle); | ||
17 | - int y1 = 150 * sin(angle-delta_angle); | ||
18 | - int x2 = 150 * cos(angle+delta_angle); | ||
19 | - int y2 = 150 * sin(angle+delta_angle); | 16 | + int x1_barrel= 150 * cos(angle-delta_angle); |
17 | + int y1_barrel = 150 * sin(angle-delta_angle); | ||
18 | + int x2_barrel = 150 * cos(angle+delta_angle); | ||
19 | + int y2_barrel = 150 * sin(angle+delta_angle); | ||
20 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | 20 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); |
21 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | 21 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); |
22 | - gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1, gfx_screenHeight() - y1, | ||
23 | - gfx_screenWidth() / 2 + x2, gfx_screenHeight() - y2, YELLOW); | 22 | + gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1_barrel, gfx_screenHeight() - y1_barrel, |
23 | + gfx_screenWidth() / 2 + x2_barrel, gfx_screenHeight() - y2_barrel, YELLOW); | ||
24 | 24 | ||
25 | if(is_shooting) | 25 | if(is_shooting) |
26 | { | 26 | { |
05-target/cannon.c
@@ -11,22 +11,22 @@ int main() { | @@ -11,22 +11,22 @@ int main() { | ||
11 | int is_shooting = 0; | 11 | int is_shooting = 0; |
12 | double fire_angle; | 12 | double fire_angle; |
13 | 13 | ||
14 | - int target_x = 0; | ||
15 | - int target_y = 40; | 14 | + int x_target = 0; |
15 | + int y_target = 40; | ||
16 | while(1) | 16 | while(1) |
17 | { | 17 | { |
18 | double delta_angle= 2.0 * (M_PI/180.0); | 18 | double delta_angle= 2.0 * (M_PI/180.0); |
19 | - int x1 = 150 * cos(angle-delta_angle); | ||
20 | - int y1 = 150 * sin(angle-delta_angle); | ||
21 | - int x2 = 150 * cos(angle+delta_angle); | ||
22 | - int y2 = 150 * sin(angle+delta_angle); | 19 | + int x1_barrel= 150 * cos(angle-delta_angle); |
20 | + int y1_barrel = 150 * sin(angle-delta_angle); | ||
21 | + int x2_barrel = 150 * cos(angle+delta_angle); | ||
22 | + int y2_barrel = 150 * sin(angle+delta_angle); | ||
23 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | 23 | gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); |
24 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | 24 | gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); |
25 | - gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1, gfx_screenHeight() - y1, | ||
26 | - gfx_screenWidth() / 2 + x2, gfx_screenHeight() - y2, YELLOW); | 25 | + gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1_barrel, gfx_screenHeight() - y1_barrel, |
26 | + gfx_screenWidth() / 2 + x2_barrel, gfx_screenHeight() - y2_barrel, YELLOW); | ||
27 | 27 | ||
28 | 28 | ||
29 | - gfx_filledRect(target_x - 10, target_y - 10, target_x + 10, target_y + 10, MAGENTA); | 29 | + gfx_filledRect(x_target - 10, y_target - 10, x_target + 10, y_target + 10, MAGENTA); |
30 | 30 | ||
31 | if(is_shooting) | 31 | if(is_shooting) |
32 | { | 32 | { |
@@ -41,9 +41,9 @@ int main() { | @@ -41,9 +41,9 @@ int main() { | ||
41 | if(is_shooting) | 41 | if(is_shooting) |
42 | bullet_distance += 5.0; | 42 | bullet_distance += 5.0; |
43 | 43 | ||
44 | - target_x += 3; | ||
45 | - if(target_x > gfx_screenWidth()) | ||
46 | - target_x = 0; | 44 | + x_target += 3; |
45 | + if(x_target > gfx_screenWidth()) | ||
46 | + x_target = 0; | ||
47 | 47 | ||
48 | if(gfx_isKeyDown(SDLK_RIGHT)) | 48 | if(gfx_isKeyDown(SDLK_RIGHT)) |
49 | angle -= 1.0 * (M_PI/180.0); | 49 | angle -= 1.0 * (M_PI/180.0); |