diff options
author | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-24 18:01:08 +0100 |
---|---|---|
committer | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-24 18:01:08 +0100 |
commit | dad432566a5c74f86dc4ba874e631115e0f469d1 (patch) | |
tree | 0e282e874ef48658d87e82041afe7bba1db3704a | |
parent | 0b338bbd007048551526ab4fa4130d53b414e650 (diff) |
level selector and fx fic
-rw-r--r-- | build/army/balance 1000 melee.txt | bin | 21560 -> 21560 bytes | |||
-rw-r--r-- | build/army/balance 1000.txt | bin | 21560 -> 21560 bytes | |||
-rw-r--r-- | build/content/templates/default.txt | 16 | ||||
-rw-r--r-- | build/test.exe | bin | 791607 -> 794781 bytes | |||
-rw-r--r-- | design/notes.txt | 3 | ||||
-rw-r--r-- | gst/fxs.c | 5 | ||||
-rw-r--r-- | gst/gst.c | 10 | ||||
-rw-r--r-- | gst/info.c | 1 | ||||
-rw-r--r-- | hud/hud.c | 60 | ||||
-rw-r--r-- | hud/hud.h | 4 | ||||
-rw-r--r-- | hud/hud_views.c | 74 | ||||
-rw-r--r-- | hud/hud_views.h | 3 | ||||
-rw-r--r-- | 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 Binary files differindex b45bbea..0672fd9 100644 --- a/build/army/balance 1000 melee.txt +++ b/build/army/balance 1000 melee.txt diff --git a/build/army/balance 1000.txt b/build/army/balance 1000.txt Binary files differindex b74045b..cecec84 100644 --- a/build/army/balance 1000.txt +++ b/build/army/balance 1000.txt 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 Binary files differindex 2fddb01..785d8e1 100644 --- a/build/test.exe +++ b/build/test.exe 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: @@ -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], @@ -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;j<MAXUNITS; counts[j]=0, j++); - // for every unit count how many shots - for (int i=0; i<ar->uslen; i++) { for (int j=0; j<dmgslen; j++) { unit *u = ar->us+i; if (dmgs[j].u == u) { counts[i]++; } } } + + // then spawn a bullet for every shot int curr[MAXUNITS]; for (int j=0;j<MAXUNITS; curr[j]=0, j++); for (int i=0; i<ar->uslen; 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; } @@ -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) { @@ -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; i<MAXLEVEL; i++) { + float p[2] = { + pos[0]+size[0]-5-MAXLEVEL*9-1 + 9*i, + pos[1]+size[1]-5-9-1 -1 }; + float s[2] = { 10, 10 }; + if (pt_rect(mp, p, s)) { return i; } + } + return -1; +} + void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb, infos *info, army *ar, map *m, txtd *t, Mix_Chunk *sounds[]) { @@ -300,20 +311,32 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb, float possc[2] = { h->fnu.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); @@ -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; i<MAXLEVEL; i++) { + int sel = 0; + if (lvl == i) { + SDL_SetRenderDrawColor(rend, 240, 250, 240, 255); + sel = 1; + } else { + SDL_SetRenderDrawColor(rend, 140, 140, 140, 255); + sel = 0; + } + SDL_Rect rect = { + px-MAXLEVEL*9-1 + 9*i, + py-9-1-sel*2, + 10, + 10+sel*2 }; + SDL_RenderFillRect(rend, &rect); + SDL_SetRenderDrawColor(rend, 0, 0, 0, 255); + SDL_RenderDrawRect(rend, &rect); + } +} + + void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py, infos *info, int chassis, int lvl, SDL_Texture *sprites) { @@ -86,11 +110,20 @@ void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py, LABEL_F3(px+10, py+h, "MAX WEIGHT", 0, ch->weight_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<len; i++) { if (type == 'i') { - sprintf(str+cur, "%d", (int)(intptr_t)(arr+i*sizeof(int))); + sprintf(str+cur, "%d", ((int)(intptr_t)(arr))[i]); cur = strlen(str); } if (type == 'c') { |