Skip to content

Commit 8af3cd4

Browse files
committed
Add separate animation speed parameter to alien_march
-N <ticks> controls how often alien sprites alternate frames, independently from scroll speed (-S). Defaults to same as -S.
1 parent 9e0cac2 commit 8af3cd4

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

pixelwall/design_alien_march.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ typedef struct {
105105
int dir;
106106
int tick;
107107
int speed;
108+
int anim_tick;
109+
int anim_speed;
108110
int frame;
109-
int anim_counter;
110111
bool colorful;
111112
Color color;
112113
Color alien_colors[NUM_SPRITES];
@@ -116,6 +117,7 @@ static void PrintHelp() {
116117
printf(" -C Enable colored mode\n");
117118
printf(" -R Reverse direction (scroll right)\n");
118119
printf(" -S <ticks> Scroll speed, higher = slower (default: %d)\n", DEFAULT_SPEED);
120+
printf(" -N <ticks> Animation speed, higher = slower (default: same as -S)\n");
119121
printf(" -A <color> Alien 1 color (R,G,B, default: 255,85,85)\n");
120122
printf(" -G <color> Alien 2 color (R,G,B, default: 85,255,255)\n");
121123
printf(" -K <color> Alien 3 color (R,G,B, default: 255,255,85)\n");
@@ -129,27 +131,34 @@ static void *Create(Grid *grid, int argc, char *argv[]) {
129131
ad->color = GREEN;
130132
ad->dir = 1;
131133
ad->speed = DEFAULT_SPEED;
134+
ad->anim_speed = -1;
132135
ad->colorful = false;
133136
ad->alien_colors[0] = (Color){255, 85, 85, 255};
134137
ad->alien_colors[1] = (Color){85, 255, 255, 255};
135138
ad->alien_colors[2] = (Color){255, 255, 85, 255};
136139

137140
int opt;
138141
optind = 1;
139-
while ((opt = getopt(argc, argv, ":d:CRS:A:G:K:")) != -1) {
142+
while ((opt = getopt(argc, argv, ":d:CRS:N:A:G:K:")) != -1) {
140143
switch (opt) {
141144
case 'C': ad->colorful = true; break;
142145
case 'R': ad->dir = -1; break;
143146
case 'S':
144147
ad->speed = atoi(optarg);
145148
if (ad->speed < 1) ad->speed = 1;
146149
break;
150+
case 'N':
151+
ad->anim_speed = atoi(optarg);
152+
if (ad->anim_speed < 1) ad->anim_speed = 1;
153+
break;
147154
case 'A': ad->alien_colors[0] = ParseColor(optarg); break;
148155
case 'G': ad->alien_colors[1] = ParseColor(optarg); break;
149156
case 'K': ad->alien_colors[2] = ParseColor(optarg); break;
150157
}
151158
}
152159

160+
if (ad->anim_speed < 0) ad->anim_speed = ad->speed;
161+
153162
return ad;
154163
}
155164

@@ -183,11 +192,12 @@ static void UpdateFrame(Grid *grid, void *data) {
183192
if (ad->tick >= ad->speed) {
184193
ad->tick = 0;
185194
ad->offset += ad->dir;
186-
ad->anim_counter++;
187-
if (ad->anim_counter >= 4) {
188-
ad->anim_counter = 0;
189-
ad->frame = (ad->frame + 1) % NUM_FRAMES;
190-
}
195+
}
196+
197+
ad->anim_tick++;
198+
if (ad->anim_tick >= ad->anim_speed) {
199+
ad->anim_tick = 0;
200+
ad->frame = (ad->frame + 1) % NUM_FRAMES;
191201
}
192202
}
193203

0 commit comments

Comments
 (0)