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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "SDL.h"
#include "particalSystem.h"
#include "log.h"
#define TEST_ALL
int main(int argc, char** argv){
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window;
SDL_Renderer* render;
SDL_CreateWindowAndRenderer(800, 800, SDL_WINDOW_SHOWN, &window, &render);
SDL_Event event;
bool isquit = false;
SDL_Vector gravity = {0, 0};
SDL_Color color = {0, 255, 0, 255};
SDL_Color explodecolor = {255, 0, 0, 255};
SDL_Vector direct = {5, -5};
SDL_Point position = {400, 400};
SDL_Point explodePositon = {300, 300};
int partical_hp = 50;
PS_World world;
world = PS_CreateWorld(gravity, render);
PS_ParticalLauncher launcher = PS_CreateLauncher(position, direct, partical_hp, 30, color, &world, 10);
while(!isquit){
SDL_SetRenderDrawColor(render, 100, 100, 100, 255);
SDL_RenderClear(render);
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT)
isquit = true;
if(event.type == SDL_KEYDOWN){
switch(event.key.keysym.sym){
case SDLK_SPACE:
PS_Explode(&world, explodecolor, explodePositon, 100);
break;
case SDLK_d:
launcher.shoot_dir = Vec_Rotate(&launcher.shoot_dir, 5);
break;
case SDLK_a:
launcher.shoot_dir = Vec_Rotate(&launcher.shoot_dir, -5);
break;
case SDLK_w:
launcher.partical_hp+=2;
break;
case SDLK_s:
if(launcher.partical_hp > 0)
launcher.partical_hp-=2;
break;
}
}
}
PS_ShootPartical(&launcher); //发射粒子
PS_WorldUpdate(&world); //世界更新
SDL_SetRenderDrawColor(render, 255, 0, 0, 255);
SDL_RenderDrawLine(render, launcher.position.x, launcher.position.y, launcher.position.x+launcher.shoot_dir.x*50, launcher.position.y+launcher.shoot_dir.y*50);
SDL_RenderPresent(render);
SDL_Delay(30);
}
PS_DestroyLauncher(&launcher);
PS_DestroyWorld(&world);
SDL_DestroyRenderer(render);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
|