aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-02-24 16:38:42 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-02-24 16:38:42 +0100
commit0b338bbd007048551526ab4fa4130d53b414e650 (patch)
tree1eabc6fcd6954de07cf1304435b1f70fd58e29f2 /main.c
parentf26a86bcc78c1946f55b6a399039e3bd8fb5dd16 (diff)
fire and movement animations
Diffstat (limited to 'main.c')
-rw-r--r--main.c68
1 files changed, 10 insertions, 58 deletions
diff --git a/main.c b/main.c
index 89e5edd..b34ea61 100644
--- a/main.c
+++ b/main.c
@@ -53,8 +53,8 @@ int main( int argc, char* args[] ) {
SDL_SetTextureColorMod(textd.tex, 0, 0, 0);
SDL_Surface* imagesmall = SDL_LoadBMP("content/gfsmall.bmp");
- SDL_Texture* txsmall = SDL_CreateTextureFromSurface(rend, imagesmall);
- SDL_SetTextureColorMod(txsmall, 0, 0, 0);
+ textd.tex_small = SDL_CreateTextureFromSurface(rend, imagesmall);
+ SDL_SetTextureColorMod(textd.tex_small, 0, 0, 0);
SDL_Surface* sprites = SDL_LoadBMP("content/sprites.bmp");
SDL_Texture* txsprites = SDL_CreateTextureFromSurface(rend, sprites);
@@ -107,6 +107,10 @@ int main( int argc, char* args[] ) {
float mlast[2] = {0, 0};
+ // fxs
+ fxs fx;
+ fx_init(&fx);
+
// sockets
net_client netc;
net_server nets;
@@ -150,21 +154,13 @@ int main( int argc, char* args[] ) {
float delta[2] = { mkb.mx-mlast[0], mkb.my-mlast[1] };
vec2_sub(gst.cam, gst.cam, delta);
}
- /*
- if (mkb_search(&mkb, SDL_SCANCODE_E)) {
- map *m; army *ar;
- gst_get_maparmy(&gst, &m, &ar);
- army_move(&info, ar, m);
- army_fire(&info, ar, m);
- }*/
hud_process(&gs, &_hud, &mkb, &info,
gst.army_bp+0, &gst.map_editor, &textd, &gst,
&netc, &nets, sounds);
- if (gst.state == 1) {
- gst_process(&gst, &info, tot_time);
- }
+ gst_process(&gst, &info, &fx, tot_time);
+ fx_process(&fx, tot_time);
render = true;
unprocessed_time -= FRAME_TIME;
@@ -176,53 +172,9 @@ int main( int argc, char* args[] ) {
SDL_SetRenderDrawColor(rend, 255, 255, 255, 255);
SDL_RenderClear(rend);
- float ts = 32;
- int posx = gst.cam[0];
- int posy = gst.cam[1];
-
- map *m; army *ar;
- gst_get_maparmy(&gst, &m, &ar);
-
- // render map
- for (int y=0; y<m->sy; y++) {
- for (int x=0; x<m->sx; x++) {
- float px = x*ts;
- float py = y*ts;
- SDL_Rect srcRect = { 1*ts, 0*ts, ts, ts };
- SDL_Rect dstRect = { (int)px-posx, (int)py-posy, ts, ts };
- SDL_RenderCopy(rend, txsprites, &srcRect, &dstRect);
- }
- }
+ gst_render(rend, txsprites, &textd, &gst, &info, tot_time);
- // render enemies
- for (int i=0; i<ar->uslen; i++) {
- if (ar->us[i].hp <= 0) continue;
- float x = ar->us[i].pos[0];
- float y = ar->us[i].pos[1];
- SDL_Rect srcRect = { ar->us[i].info.chassis*ts, ts, ts, ts };
- SDL_Rect dstRect = { (int)x-posx, (int)y-posy, ts, ts };
- SDL_RenderCopy(rend, txsprites, &srcRect, &dstRect);
-
- float amt = ar->us[i].hp
- / info_unit_get_health(&info, &ar->us[i].info);
- SDL_Rect hprect = {
- (int)x-posx, (int)y-posy+ts-5,
- ts*amt, 6 };
- int sw = 1 ? ar->us[i].owner : 0;
- SDL_SetRenderDrawColor(rend, 255*sw, 255*(1-sw), 0, 255);
- SDL_RenderFillRect(rend, &hprect);
-
- SDL_SetTextureColorMod(txsmall, sw*100, 100*(1-sw), 0);
- char shp[32]; sprintf(shp, "%.0f", ar->us[i].hp);
- float php[2] = { (int)x-posx, (int)y-posy+ts-5 };
- render_text_small(rend, shp, php, txsmall);
-
- SDL_SetTextureColorMod(txsmall, 255, 160, 0);
- char sch[32]; sprintf(sch, "%.0f", ar->us[i].charge);
- float pch[2] = { (int)x-posx, (int)y-posy+ts+1 };
- render_text_small(rend, sch, pch, txsmall);
- SDL_SetTextureColorMod(txsmall, 0, 0, 0);
- }
+ fx_render(rend, &fx, gst.cam, tot_time);
hud_render(&_hud, rend, &textd, &mkb, &info, txsprites, &gst,
tot_time);