Commit 7804d394236ac210f51f3c1d8845d3695664df6d
1 parent
35e4e70f
Cannon with wide barrel
Showing
2 changed files
with
50 additions
and
0 deletions
02-cannon_wide/cannon.c
0 → 100644
| 1 | +#include "primlib.h" | |
| 2 | +#include <stdlib.h> | |
| 3 | +#include <unistd.h> | |
| 4 | + | |
| 5 | +int main(int argc, char *argv[]) { | |
| 6 | + if (gfx_init()) | |
| 7 | + exit(3); | |
| 8 | + | |
| 9 | + gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | |
| 10 | + gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | |
| 11 | + gfx_line(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2, gfx_screenHeight() - 150, YELLOW); | |
| 12 | + gfx_updateScreen(); | |
| 13 | + | |
| 14 | + double angle = 90.0 * (M_PI/180.0); | |
| 15 | + while(1) | |
| 16 | + { | |
| 17 | + double delta_angle= 2.0 * (M_PI/180.0); | |
| 18 | + int x1 = 150 * cos(angle-delta_angle); | |
| 19 | + int y1 = 150 * sin(angle-delta_angle); | |
| 20 | + int x2 = 150 * cos(angle+delta_angle); | |
| 21 | + int y2 = 150 * sin(angle+delta_angle); | |
| 22 | + gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | |
| 23 | + gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | |
| 24 | + gfx_filledTriangle(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x1, gfx_screenHeight() - y1, | |
| 25 | + gfx_screenWidth() / 2 + x2, gfx_screenHeight() - y2, YELLOW); | |
| 26 | + gfx_updateScreen(); | |
| 27 | + int key=gfx_getkey(); | |
| 28 | + if (key == SDLK_RIGHT) | |
| 29 | + angle -= 1.0 * (M_PI/180.0); | |
| 30 | + if (key == SDLK_LEFT) | |
| 31 | + angle += 1.0 * (M_PI/180.0); | |
| 32 | + }; | |
| 33 | + return 0; | |
| 34 | +} | ... | ... |
02-cannon_wide/makefile
0 → 100755
| 1 | +TARGET=cannon | |
| 2 | + | |
| 3 | +all: $(TARGET) | |
| 4 | + | |
| 5 | +%.o:%.c | |
| 6 | + gcc -g -I.. -Wall -pedantic `sdl2-config --cflags` -c $< -o $@ | |
| 7 | + | |
| 8 | +%: %.c ../primlib.o %.c | |
| 9 | + gcc -g -I.. -Wall -pedantic `sdl2-config --cflags` ../primlib.o $< -o $@ -lSDL2_gfx `sdl2-config --libs` -lm | |
| 10 | + | |
| 11 | +../primlib.o: ../primlib.c ../primlib.h | |
| 12 | + | |
| 13 | +$(TARGET): $(TARGET).c ../primlib.h | |
| 14 | + | |
| 15 | +clean: | |
| 16 | + -rm $(TARGET) | |
| 0 | 17 | \ No newline at end of file | ... | ... |