This repository has been archived by the owner on Mar 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstory.c
88 lines (81 loc) · 1.86 KB
/
story.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "headers.h"
char *get_story_line(char *story)
{
static char *last_pos;
char *new_pos;
if (!last_pos)
new_pos = story;
else
new_pos = strchr(last_pos, '\n');
if (new_pos)
{
new_pos++;
last_pos = new_pos;
return (new_pos);
}
return (NULL);
}
void draw_beep_boop(char *story_line, char *beep_boop)
{
int to_beep_or_not_to_boop;
int line_length;
char *temp;
char temp_line[COLS + 1];
int y;
temp = beep_boop;
to_beep_or_not_to_boop = 0;
if (story_line[3] == 'o')
{
temp = strchr(beep_boop, 'Z') + 2;
to_beep_or_not_to_boop = 1;
}
else if (story_line[3] != 'e')
to_beep_or_not_to_boop = 2;
line_length = ft_strlen_nl(temp, COLS);
if (to_beep_or_not_to_boop != 2)
y = 4;
else
y = (LINES - get_amount_of_lines(beep_boop)) / 2;
while (line_length > 1)
{
strncpy(temp_line, temp, line_length);
temp_line[line_length] = '\0';
if (to_beep_or_not_to_boop == 1)
mvprintw(y, COLS - 10 - line_length, temp_line);
else if (to_beep_or_not_to_boop == 2)
mvprintw(y, (COLS - line_length) / 2, temp_line);
else
mvprintw(y, 10, temp_line);
temp = temp + line_length + 1;
line_length = ft_strlen_nl(temp, COLS);
y++;
}
}
int draw_story(char *story, char *beep_boop, unsigned int frame)
{
static int part;
static char *story_line;
static int line_length;
char *temp;
int centered_x;
if (frame == 0 || frame % 50 == 0)
{
temp = get_story_line(story);
if (!temp)
return (-1);
line_length = ft_strlen_nl(temp, COLS);
if (story_line)
free(story_line);
story_line = (char *)malloc(sizeof(char) * (line_length + 1));
strncpy(story_line, temp, line_length);
story_line[line_length] = '\0';
part++;
if (story_line[0] == '$')
write(1, "\a", 1);
}
if (story_line[0] == '$')
draw_beep_boop(story_line, beep_boop);
else
mvprintw(LINES - 4, (COLS - line_length) / 2, story_line);
return (part);
}