Commit e4ed3f7359b6c60440ff2134622bb5cb11e66bc4
1 parent
8e77dce9
Added cannon with moving barrel.
Showing
2 changed files
with
46 additions
and
0 deletions
01-cannon/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 | + int x = 150 * cos(angle); | |
| 18 | + int y = 150 * sin(angle); | |
| 19 | + gfx_filledRect(0, 0, gfx_screenWidth() - 1, gfx_screenHeight() - 1, BLUE); | |
| 20 | + gfx_filledCircle(gfx_screenWidth() / 2, gfx_screenHeight(), 100, YELLOW); | |
| 21 | + gfx_line(gfx_screenWidth() / 2, gfx_screenHeight() , gfx_screenWidth() / 2 + x, gfx_screenHeight() - y, YELLOW); | |
| 22 | + gfx_updateScreen(); | |
| 23 | + int key=gfx_getkey(); | |
| 24 | + if (key == SDLK_RIGHT) | |
| 25 | + angle -= 1.0 * (M_PI/180.0); | |
| 26 | + if (key == SDLK_LEFT) | |
| 27 | + angle += 1.0 * (M_PI/180.0); | |
| 28 | + }; | |
| 29 | + return 0; | |
| 30 | +} | ... | ... |
01-cannon/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 | ... | ... |