From dad432566a5c74f86dc4ba874e631115e0f469d1 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Wed, 24 Feb 2021 18:01:08 +0100 Subject: level selector and fx fic --- build/army/balance 1000 melee.txt | Bin 21560 -> 21560 bytes build/army/balance 1000.txt | Bin 21560 -> 21560 bytes build/content/templates/default.txt | 16 ++++++-- build/test.exe | Bin 791607 -> 794781 bytes design/notes.txt | 3 +- gst/fxs.c | 5 ++- gst/gst.c | 10 +++-- gst/info.c | 1 + hud/hud.c | 60 ++++++++++++++++++++++------- hud/hud.h | 4 ++ hud/hud_views.c | 74 +++++++++++++++++++++++++++++++++--- hud/hud_views.h | 3 ++ json/jsonparse.c | 6 +-- 13 files changed, 152 insertions(+), 30 deletions(-) diff --git a/build/army/balance 1000 melee.txt b/build/army/balance 1000 melee.txt index b45bbea..0672fd9 100644 Binary files a/build/army/balance 1000 melee.txt and b/build/army/balance 1000 melee.txt differ diff --git a/build/army/balance 1000.txt b/build/army/balance 1000.txt index b74045b..cecec84 100644 Binary files a/build/army/balance 1000.txt and b/build/army/balance 1000.txt differ diff --git a/build/content/templates/default.txt b/build/content/templates/default.txt index b5bff58..a57fce5 100644 --- a/build/content/templates/default.txt +++ b/build/content/templates/default.txt @@ -71,13 +71,13 @@ }, { "name": "1000 tank boi", - "chassis": "11", + "chassis": "5", "brain": "0", "battery": "0", "weapons": [ 18, 16, -1, -1, -1, -1, -1, -1 ], "armor": [ 0, 0, 0, -1, -1, -1, -1, -1 ], - "augs": [ 8, 8, -1, -1, -1, -1, -1, -1 ], - "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] + "augs": [ 8, 8, -1, -1, 2, -1, -1, -1 ], + "levels": [ 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }, { "name": "1000 melee bot friendo", @@ -98,5 +98,15 @@ "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ], "augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ], "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] + }, + { + "name": "dongo", + "chassis": "13", + "brain": "0", + "battery": "0", + "weapons": [ 0, 2, -1, -1, -1, -1, -1, -1 ], + "armor": [ 1, 0, 1, -1, 3, -1, -1, -1 ], + "augs": [ 1, -1, 2, -1, 0, -1, -1, -1 ], + "levels": [ 0, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] } ] \ No newline at end of file diff --git a/build/test.exe b/build/test.exe index 2fddb01..785d8e1 100644 Binary files a/build/test.exe and b/build/test.exe differ diff --git a/design/notes.txt b/design/notes.txt index ecd9a30..89776e6 100644 --- a/design/notes.txt +++ b/design/notes.txt @@ -1,6 +1,7 @@ tasks: (date) [ ] implement healing beam (issued on 24:02:21) +[ ] implement battery recharge beam (issued on 24:02:21) [ ] implement net hud and minilobby (issued on 18:02:21) [ ] implement brain behaviour (issued on 18:02:21) [ ] implement lobby cost constraints (issued on 18:02:21) @@ -65,7 +66,7 @@ implement fire animation: calculate target position by interpolating when needed spawn explosion what is a bullet? sprite? line? -> for now a line - +-> done implement move animation: diff --git a/gst/fxs.c b/gst/fxs.c index 2078a89..ad4d15a 100644 --- a/gst/fxs.c +++ b/gst/fxs.c @@ -39,7 +39,10 @@ void fx_render (SDL_Renderer *rend, fxs *fx, float cam[], float time) { b->from[1] *(1-amt) + b->to[1] *amt }; float head[2]; vec2_sub(head, b->from, b->to); - vec2_norm(head); vec2_mul(head, head, 10); + float mag = 10; + float dist = amt*vec2_mag(head); + if (dist < 10) { mag = dist; } + vec2_norm(head); vec2_mul(head, head, mag); SDL_SetRenderDrawColor(rend, b->color[0], b->color[1], diff --git a/gst/gst.c b/gst/gst.c index 6842826..9ded823 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -89,16 +89,18 @@ void gst_spawn_bullets (gamestate *gst, fxs *fx, a_dmg dmgs[], int dmgslen, gst_get_maparmy(gst, &m, &ar); bullet b; + + // for every unit count how many shots int counts[MAXUNITS]; for (int j=0;juslen; i++) { for (int j=0; jus+i; if (dmgs[j].u == u) { counts[i]++; } } } + + // then spawn a bullet for every shot int curr[MAXUNITS]; for (int j=0;juslen; i++) { @@ -111,9 +113,10 @@ void gst_spawn_bullets (gamestate *gst, fxs *fx, a_dmg dmgs[], int dmgslen, b.to[0] = t->pos[0]+16; b.to[1] = t->pos[1]+16; float n = (float)curr[i]/counts[i]; + float travel_time = 0.1; float shot_time = time + n*gst->turnspeed; b.starttime = shot_time; - b.endtime = shot_time + 0.1; + b.endtime = shot_time + travel_time; if (u->owner == 0) { b.color[0] = 0; b.color[1] = 255; b.color[2] = 0; } else { @@ -155,7 +158,6 @@ void gst_process (gamestate *gst, infos *info, fxs *fx, float t) { a_dmg dmgs[1024*8]; int fire = army_fire(info, ar, m, dmgs); army_upkeep(info, ar, m); - printf("%d, %d\n", move, fire); if (move == 0 && fire == 0) { gst->turn_until_finish--; } else { gst->turn_until_finish = 5; } diff --git a/gst/info.c b/gst/info.c index 0eaecb3..c12c620 100644 --- a/gst/info.c +++ b/gst/info.c @@ -533,6 +533,7 @@ void info_chassis_parse (char *json, info_chassis *c, jsmntok_t *t, int r, if (strcmp(key, "slot_weapon") == 0) { int rt = json_parse_subtokens(json, t, r, i+1); json_parse_array(json, c->slot_weapon, t+i+2, rt-1, 'i'); + printf("%d %d %d\n", c->slot_weapon[0], c->slot_weapon[1], c->slot_weapon[2]); i += rt; } if (strcmp(key, "slot_armor") == 0) { diff --git a/hud/hud.c b/hud/hud.c index 2f4eca4..30b6486 100644 --- a/hud/hud.c +++ b/hud/hud.c @@ -282,6 +282,17 @@ void hud_open_sel (graphic_settings *gs, hud *h, h->sc.rect_back.h = size[1]; } +int hud_mouse_level (float *mp, float *pos, float *size) { + for (int i=0; ifnu.rect_chassis.x, h->fnu.rect_chassis.y }; float sizesc[2] = { h->fnu.rect_chassis.w, h->fnu.rect_chassis.h }; if (pt_rect(mousepos, possc, sizesc)) { - h->fnu.sel = 0; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_chassis); + int lvl = hud_mouse_level(mousepos, possc, sizesc); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_CHASSIS] = lvl; + else { + h->fnu.sel = 0; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_chassis); + } } float possb[2] = { h->fnu.rect_battery.x, h->fnu.rect_battery.y }; float sizesb[2] = { h->fnu.rect_battery.w, h->fnu.rect_battery.h }; if (pt_rect(mousepos, possb, sizesb)) { - h->fnu.sel = 1; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_battery); + int lvl = hud_mouse_level(mousepos, possb, sizesb); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_BATTERY] = lvl; + else { + h->fnu.sel = 1; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_battery); + } } float possbr[2] = { h->fnu.rect_brain.x, h->fnu.rect_brain.y }; float sizesbr[2] = { h->fnu.rect_brain.w, h->fnu.rect_brain.h }; if (pt_rect(mousepos, possbr, sizesbr)) { - h->fnu.sel = 5; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_brain); + int lvl = hud_mouse_level(mousepos, possbr, sizesbr); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_BRAIN] = lvl; + else { + h->fnu.sel = 5; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_brain); + } } if (h->fnu.uinfo.chassis != -1) { int lc = h->fnu.uinfo.levels[LEVEL_CHASSIS]; @@ -325,8 +348,12 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb, float sizesa[2] = { h->fnu.rect_armor[i].w, h->fnu.rect_armor[i].h }; if (pt_rect(mousepos, possa, sizesa)) { - h->fnu.sel = 2; h->fnu.ind = i; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_armor[i]); + int lvl = hud_mouse_level(mousepos, possa, sizesa); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_ARMOR+i] = lvl; + else { + h->fnu.sel = 2; h->fnu.ind = i; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_armor[i]); + } } } for (int i=0; @@ -337,8 +364,12 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb, float sizesa[2] = { h->fnu.rect_weapons[i].w, h->fnu.rect_weapons[i].h }; if (pt_rect(mousepos, possa, sizesa)) { - h->fnu.sel = 3; h->fnu.ind = i; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_weapons[i]); + int lvl = hud_mouse_level(mousepos, possa, sizesa); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_WEAPONS+i] = lvl; + else { + h->fnu.sel = 3; h->fnu.ind = i; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_weapons[i]); + } } } for (int i=0; @@ -349,8 +380,12 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb, float sizesa[2] = { h->fnu.rect_augs[i].w, h->fnu.rect_augs[i].h }; if (pt_rect(mousepos, possa, sizesa)) { - h->fnu.sel = 4; h->fnu.ind = i; h->state = 2; - hud_open_sel(gs, h, t, info, &h->fnu.rect_augs[i]); + int lvl = hud_mouse_level(mousepos, possa, sizesa); + if (lvl != -1) h->fnu.uinfo.levels[LEVEL_AUGS+i] = lvl; + else { + h->fnu.sel = 4; h->fnu.ind = i; h->state = 2; + hud_open_sel(gs, h, t, info, &h->fnu.rect_augs[i]); + } } } } @@ -1027,7 +1062,6 @@ void hud_render_overlay_game (overlay_game *og, MKb *mkb, void hud_render_overlay_battle (overlay_battle *ob, MKb *mkb, SDL_Renderer* rend, txtd *t, infos *info, gamestate *gst, float time) { - SDL_SetRenderDrawColor(rend, 240, 240, 240, 255); SDL_RenderFillRect(rend, &ob->rect_back); SDL_SetRenderDrawColor(rend, 0, 0, 0, 255); diff --git a/hud/hud.h b/hud/hud.h index 90119cc..1901620 100644 --- a/hud/hud.h +++ b/hud/hud.h @@ -78,6 +78,10 @@ typedef struct { } hud; void hud_init(graphic_settings *gs, hud *h, txtd *t); + +void hud_map_sel (info_unit *u, infos *info, int sel, int ind, + int8_t **n, int *bound, int size[]); + void hud_resize (graphic_settings *gs, hud *h, txtd *t); void hud_process (graphic_settings *gs, hud *h, MKb *mkb, infos *info, army *ar, map *m, txtd *t, gamestate *gst, diff --git a/hud/hud_views.c b/hud/hud_views.c index 7b6d7f7..86e0722 100644 --- a/hud/hud_views.c +++ b/hud/hud_views.c @@ -74,6 +74,30 @@ void render_view_stats (SDL_Renderer* rend, txtd *t, int px, int py, h += 5; } + +void render_view_level (SDL_Renderer *rend, int px, int py, int lvl) { + // position is of bottom right corner + for (int i=0; iweight_max, 1); h += 15; LABEL_F3(px+10, py+h, "HP", 0, ch->hp, 1); h += 15; LABEL_F3(px+10, py+h, "SPEED", 2, ch->speed, 1); h += 15; - LABEL_F3(px+10, py+h, "UPKEEP", 2, ch->upkeep, 1); h += 15; + LABEL_F3(px+10, py+h, "UPKEEP", 2, ch->upkeep, 1); h += 20; + + LABEL_I3(px+10, py+h, "WEAPON SLOTS", ch->slot_weapon, 1); h += 15; + LABEL_I3(px+10, py+h, "ARMOR SLOTS", ch->slot_armor, 1); h += 15; + LABEL_I3(px+10, py+h, "AUGMENT SLOTS", ch->slot_aug, 1); h += 15; SDL_Rect srcRect = { chassis*32, 32, 32, 32 }; SDL_Rect dstRect = { px+300-32-10, py+10, 32, 32 }; SDL_RenderCopy(rend, sprites, &srcRect, &dstRect); + + info_unit u; int8_t *_; int __; int size[2]; + hud_map_sel(&u, info, 0, 0, &_, &__, size); + size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select a chassis...", pname, t, 1); @@ -113,6 +146,9 @@ void render_view_battery (SDL_Renderer* rend, txtd *t, int px, int py, strcpy(srech, "NOT RECHARGEABLE"); } else { strcpy(srech, "RECHARGEABLE"); } render_text_scaled(rend, srech, prech, t, 1); + + float size[2] = {145, 145}; size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select a battery...", pname, t, 1); @@ -124,10 +160,13 @@ void render_view_armor (SDL_Renderer* rend, txtd *t, int px, int py, infos *info, int armor, int lvl) { if (armor != -1) { - float pname[2] = { px+10, py+10 }; - char sname[64]; sprintf(sname, "%s", info->armors[armor].name); - render_text_scaled(rend, sname, pname, t, 1); - char sa[64]; int j=0; + info_armor *arm = info->armors+armor; + int h = 10; + + LABEL(px+10, py+h, arm->name, 1); h += 20; + LABEL_F3(px+10, py+h, "WEIGHT", 0, arm->weight, 1); h += 20; + + /*char sa[64]; int j=0; char temp[16] = "red: "; strcpy(sa+j, temp); j += strlen(temp); @@ -143,6 +182,9 @@ void render_view_armor (SDL_Renderer* rend, txtd *t, int px, int py, sa[j] = '\0'; float pa[2] = { px+10, py+25 }; render_text_scaled(rend, sa, pa, t, 1); + */ + float size[2] = { 150, 50 }; size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select an armor...", pname, t, 1); @@ -169,6 +211,10 @@ void render_view_armor_detail (SDL_Renderer* rend, txtd *t, int px, int py, } h += 15; } + info_unit u; int8_t *_; int __; int size[2]; + hud_map_sel(&u, info, 2, 0, &_, &__, size); + size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { render_view_weapon(rend, t, px, py, info, armor, lvl); } @@ -192,10 +238,14 @@ void render_view_weapon (SDL_Renderer* rend, txtd *t, int px, int py, LABEL_F3(px+10, py+h, "DAMAGE", 0, weap->damage, 1); h += 15; LABEL_F3(px+10, py+h, "RANGE", 0, weap->range, 1); h += 15; LABEL_F3(px+10, py+h, "COOLDOWN", 0, weap->cooldown, 1); h += 15; + + float size[2] = { 200, 110 }; size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select a weapon...", pname, t, 1); } + } void render_view_weapon_detail (SDL_Renderer* rend, txtd *t, @@ -230,6 +280,10 @@ void render_view_weapon_detail (SDL_Renderer* rend, txtd *t, LABEL_F3(px+10, py+h, "CHARGE PER SHOT",0,weap->charge_per_shot, 1); h += 15; } + info_unit u; int8_t *_; int __; int size[2]; + hud_map_sel(&u, info, 3, 0, &_, &__, size); + size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { render_view_weapon(rend, t, px, py, info, weapon, lvl); } @@ -245,6 +299,9 @@ void render_view_aug (SDL_Renderer* rend, txtd *t, int px, int py, LABEL(px+10, py+h, augm->name, 1); h += 20; LABEL_F3(px+10, py+h, "WEIGHT", 0, augm->weight, 1); h += 15; + + float size[2] = { 150, 50 }; size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select an augment...", pname, t, 1); @@ -319,6 +376,10 @@ void render_view_aug_detail (SDL_Renderer* rend, txtd *t, int px, int py, } } } + info_unit u; int8_t *_; int __; int size[2]; + hud_map_sel(&u, info, 4, 0, &_, &__, size); + size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { render_view_aug(rend, t, px, py, info, aug, lvl); } @@ -333,6 +394,9 @@ void render_view_brain (SDL_Renderer* rend, txtd *t, int px, int py, char sname[64]; sprintf(sname, "%s", info->brains[brain].name); render_text_scaled(rend, sname, pname, t, 1); + + float size[2] = { 145, 145 }; size[0] -= 5; size[1] -= 5; + render_view_level(rend, px+size[0], py+size[1], lvl); } else { float pname[2] = { px+10, py+10 }; render_text_scaled(rend, "select a controller...", pname, t, 1); diff --git a/hud/hud_views.h b/hud/hud_views.h index 50311d2..747c348 100644 --- a/hud/hud_views.h +++ b/hud/hud_views.h @@ -15,6 +15,9 @@ void render_view_stats (SDL_Renderer* rend, txtd *t, int px, int py, infos *info, info_unit *tm); +void render_view_level (SDL_Renderer *rend, int px, int py, int lvl); + + void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py, infos *info, int chassis, int lvl, SDL_Texture *sprites); diff --git a/json/jsonparse.c b/json/jsonparse.c index 9ac845c..4b5096c 100644 --- a/json/jsonparse.c +++ b/json/jsonparse.c @@ -15,11 +15,11 @@ void json_parse_array(char *json, void *temp, jsmntok_t *t, int r, char type) { if (t[i].type == JSMN_PRIMITIVE) { char val[32]; substr_token(json, val, t+i); if (type == 'i') { - int *p = (int*)(intptr_t)temp+sizeof(int)*i; + int *p = (int*)(intptr_t)temp+i; *p = atoi(val); } if (type == 'c') { - int8_t *p = (int8_t*)(intptr_t)temp+sizeof(int8_t)*i; + int8_t *p = (int8_t*)(intptr_t)temp+i; *p = atoi(val); } if (type == 'f') { @@ -35,7 +35,7 @@ void json_dump_array (char *str, void *arr, int len, char type) { sprintf(str+cur, "[ "); cur = strlen(str); for (int i=0; i