Death NPC

main
Cameron Murphy Reikes 2 years ago
parent 113753dcab
commit 78fb1bc1b4

120
main.c

@ -127,7 +127,7 @@ typedef BUFF(char, MAX_SENTENCE_LENGTH) Sentence;
// even indexed dialogs (0,2,4) are player saying stuff, odds are the character from GPT // even indexed dialogs (0,2,4) are player saying stuff, odds are the character from GPT
typedef BUFF(Sentence, 2*6) Dialog; // six back and forths. must be even number or bad things happen (I think) typedef BUFF(Sentence, 2*12) Dialog; // six back and forths. must be even number or bad things happen (I think)
typedef enum NpcKind typedef enum NpcKind
{ {
@ -151,11 +151,15 @@ typedef struct Entity
bool is_npc; bool is_npc;
NpcKind npc_kind; NpcKind npc_kind;
Dialog player_dialog; Dialog player_dialog;
Sentence to_say;
#ifdef WEB #ifdef WEB
int gen_request_id; int gen_request_id;
#endif #endif
bool aggressive; bool aggressive;
double shotgun_timer; double shotgun_timer;
// only for death npc
bool going_to_target;
Vec2 target_goto;
// character // character
bool is_character; bool is_character;
@ -206,6 +210,8 @@ typedef struct Arena
Entity *player = NULL; // up here, used in text backend callback Entity *player = NULL; // up here, used in text backend callback
void make_space_and_append(Dialog *d, Sentence *s) void make_space_and_append(Dialog *d, Sentence *s)
{ {
if(d->cur_index >= ARRLEN(d->data)) if(d->cur_index >= ARRLEN(d->data))
@ -237,10 +243,15 @@ void add_new_npc_sentence(Entity *npc, char *sentence)
{ {
if(sentence[i] == '*') if(sentence[i] == '*')
{ {
if(strcmp(match_buffer.data, "fights player") == 0) if(strcmp(match_buffer.data, "fights player") == 0 && npc->npc_kind == OLD_MAN)
{ {
npc->aggressive = true; npc->aggressive = true;
} }
if(strcmp(match_buffer.data, "moves") == 0 && npc->npc_kind == DEATH)
{
npc->going_to_target = true;
npc->target_goto = AddV2(npc->pos, V2(0.0, -TILE_SIZE*1.5f));
}
BUFF_CLEAR(&match_buffer); BUFF_CLEAR(&match_buffer);
inside_star = false; inside_star = false;
} }
@ -261,6 +272,18 @@ void add_new_npc_sentence(Entity *npc, char *sentence)
} }
// from_point is for knockback
void request_do_damage(Entity *to, Vec2 from_point, float damage)
{
if(to == NULL) return;
if(to->npc_kind != DEATH)
{
to->damage += damage;
to->aggressive = true;
to->vel = MulV2F(NormV2(SubV2(to->pos, from_point)), 5.0f);
}
}
// just straight up gpt generation function, calls to golang backend // just straight up gpt generation function, calls to golang backend
char *get_ai_response(char* prompt); char *get_ai_response(char* prompt);
@ -1569,55 +1592,58 @@ void draw_dialog_panel(Entity *talking_to)
float padding = 5.0f; float padding = 5.0f;
dialog_panel.upper_left = AddV2(dialog_panel.upper_left, V2(padding, -padding)); dialog_panel.upper_left = AddV2(dialog_panel.upper_left, V2(padding, -padding));
dialog_panel.lower_right = AddV2(dialog_panel.lower_right, V2(-padding, padding)); dialog_panel.lower_right = AddV2(dialog_panel.lower_right, V2(-padding, padding));
float new_line_height = dialog_panel.lower_right.Y; if(aabb_is_valid(dialog_panel))
int i = 0;
//BUFF_ITER(Sentence, &talking_to->player_dialog)
BUFF_ITER_EX(Sentence, &talking_to->player_dialog, talking_to->player_dialog.cur_index-1, it >= &talking_to->player_dialog.data[0], it--)
{ {
bool player_talking = i % 2 != 0; // iterating backwards float new_line_height = dialog_panel.lower_right.Y;
Color *colors = calloc(sizeof(*colors), it->cur_index); int i = 0;
bool in_astrix = false; //BUFF_ITER(Sentence, &talking_to->player_dialog)
for(int char_i = 0; char_i < it->cur_index; char_i++) BUFF_ITER_EX(Sentence, &talking_to->player_dialog, talking_to->player_dialog.cur_index-1, it >= &talking_to->player_dialog.data[0], it--)
{ {
bool set_in_astrix_false = false; bool player_talking = i % 2 != 0; // iterating backwards
if(it->data[char_i] == '*') Color *colors = calloc(sizeof(*colors), it->cur_index);
bool in_astrix = false;
for(int char_i = 0; char_i < it->cur_index; char_i++)
{ {
if(in_astrix) bool set_in_astrix_false = false;
if(it->data[char_i] == '*')
{ {
set_in_astrix_false = true; if(in_astrix)
} {
else set_in_astrix_false = true;
{ }
in_astrix = true; else
{
in_astrix = true;
}
} }
} if(player_talking)
if(player_talking)
{
colors[char_i] = BLACK;
}
else
{
if(in_astrix)
{ {
colors[char_i] = colhex(0xffdf24); colors[char_i] = BLACK;
} }
else else
{ {
colors[char_i] = colhex(0x345e22); if(in_astrix)
{
colors[char_i] = colhex(0xffdf24);
}
else
{
colors[char_i] = colhex(0x345e22);
}
} }
if(set_in_astrix_false) in_astrix = false;
} }
if(set_in_astrix_false) in_astrix = false; float measured_line_height = draw_wrapped_text(true, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->data, colors, 0.5f, true, dialog_panel);
new_line_height += (new_line_height - measured_line_height);
draw_wrapped_text(false, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->data, colors, 0.5f, true, dialog_panel);
free(colors);
i++;
} }
float measured_line_height = draw_wrapped_text(true, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->data, colors, 0.5f, true, dialog_panel);
new_line_height += (new_line_height - measured_line_height);
draw_wrapped_text(false, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->data, colors, 0.5f, true, dialog_panel);
free(colors); dbgrect(dialog_panel);
i++;
} }
dbgrect(dialog_panel);
} }
} }
@ -1819,6 +1845,10 @@ void frame(void)
if(it->is_npc) if(it->is_npc)
{ {
if(it->npc_kind == DEATH && it->going_to_target)
{
it->pos = LerpV2(it->pos, dt*5.0f, it->target_goto);
}
if(it->aggressive) if(it->aggressive)
{ {
draw_dialog_panel(it); draw_dialog_panel(it);
@ -1875,13 +1905,10 @@ void frame(void)
Entity *from_bullet = it; Entity *from_bullet = it;
BUFF_ITER(Overlap, &over) if(it->e != from_bullet) BUFF_ITER(Overlap, &over) if(it->e != from_bullet)
{ {
if(!it->is_tile) if(!it->is_tile && !(it->e->npc_kind == DEATH))
{ {
// knockback and damage // knockback and damage
Entity *hit = it->e; request_do_damage(it->e, from_bullet->pos, 0.2f);
if(hit->is_npc) hit->aggressive = true;
hit->vel = MulV2F(NormV2(SubV2(hit->pos, from_bullet->pos)), 5.0f);
hit->damage += 0.2f;
*from_bullet = (Entity){0}; *from_bullet = (Entity){0};
} }
} }
@ -1997,14 +2024,9 @@ void frame(void)
Overlapping overlapping_weapon = get_overlapping(cur_level, weapon_aabb); Overlapping overlapping_weapon = get_overlapping(cur_level, weapon_aabb);
BUFF_ITER(Overlap, &overlapping_weapon) BUFF_ITER(Overlap, &overlapping_weapon)
{ {
if(!it->is_tile) if(!it->is_tile && it->e != player)
{ {
Entity *e = it->e; request_do_damage(it->e, player->pos, 0.2f);
if(e->is_character)
{
e->aggressive = true;
e->damage += 0.2f;
}
} }
} }

@ -28,7 +28,7 @@ func index(w http.ResponseWriter, req *http.Request) {
ctx := context.Background() ctx := context.Background()
req := gogpt.CompletionRequest{ req := gogpt.CompletionRequest{
Model: "curie:ft-personal-2023-03-03-20-15-12", Model: "curie:ft-personal-2023-03-03-21-31-16",
MaxTokens: 80, MaxTokens: 80,
Prompt: promptString, Prompt: promptString,
Temperature: 0.9, Temperature: 0.9,

Loading…
Cancel
Save