forked from virt-mirrors/wayneko
make cat brain a tiny bit more readable
This commit is contained in:
parent
3fce21cc51
commit
3062b34f95
1 changed files with 113 additions and 108 deletions
221
wayneko.c
221
wayneko.c
|
@ -549,11 +549,71 @@ static bool animation_can_run_left (void)
|
||||||
return surface.neko_x > neko_x_advance;
|
return surface.neko_x > neko_x_advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_run_left (void)
|
||||||
|
{
|
||||||
|
current_neko = current_neko == NEKO_RUN_LEFT_1 ? NEKO_RUN_LEFT_2 : NEKO_RUN_LEFT_1;
|
||||||
|
animation_ticks_until_next_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool animation_can_run_right (void)
|
static bool animation_can_run_right (void)
|
||||||
{
|
{
|
||||||
return surface.neko_x < surface.width - neko_size;
|
return surface.neko_x < surface.width - neko_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_run_right (void)
|
||||||
|
{
|
||||||
|
current_neko = current_neko == NEKO_RUN_RIGHT_1 ? NEKO_RUN_RIGHT_2 : NEKO_RUN_RIGHT_1;
|
||||||
|
animation_ticks_until_next_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_advance_left (void)
|
||||||
|
{
|
||||||
|
surface.prev_neko_x = surface.neko_x;
|
||||||
|
surface.neko_x -= neko_x_advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_advance_right (void)
|
||||||
|
{
|
||||||
|
surface.prev_neko_x = surface.neko_x;
|
||||||
|
surface.neko_x += neko_x_advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_stare (bool quick)
|
||||||
|
{
|
||||||
|
current_neko = NEKO_STARE;
|
||||||
|
animation_ticks_until_next_frame = quick ? 5 : 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_yawn (void)
|
||||||
|
{
|
||||||
|
current_neko = NEKO_YAWN;
|
||||||
|
animation_ticks_until_next_frame = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_think (void)
|
||||||
|
{
|
||||||
|
current_neko = NEKO_THINK;
|
||||||
|
animation_ticks_until_next_frame = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_shock (void)
|
||||||
|
{
|
||||||
|
current_neko = NEKO_SHOCK;
|
||||||
|
animation_ticks_until_next_frame = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_sleep (void)
|
||||||
|
{
|
||||||
|
current_neko = current_neko == NEKO_SLEEP_1 ? NEKO_SLEEP_2 : NEKO_SLEEP_1;
|
||||||
|
animation_ticks_until_next_frame = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void animation_neko_do_scratch (void)
|
||||||
|
{
|
||||||
|
current_neko = current_neko == NEKO_SCRATCH_1 ? NEKO_SCRATCH_2 : NEKO_SCRATCH_1;
|
||||||
|
animation_ticks_until_next_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns true if new frame is needed. */
|
/** Returns true if new frame is needed. */
|
||||||
static bool animation_next_state (void)
|
static bool animation_next_state (void)
|
||||||
{
|
{
|
||||||
|
@ -569,160 +629,105 @@ static bool animation_next_state (void)
|
||||||
switch (rand() % 24)
|
switch (rand() % 24)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
current_neko = NEKO_SCRATCH_1;
|
animation_neko_do_scratch();
|
||||||
return true;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
current_neko = NEKO_SLEEP_1;
|
animation_neko_do_sleep();
|
||||||
animation_ticks_until_next_frame = 10;
|
break;
|
||||||
return true;
|
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
current_neko = NEKO_YAWN;
|
animation_neko_do_yawn();
|
||||||
animation_ticks_until_next_frame = 5;
|
break;
|
||||||
return true;
|
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
current_neko = NEKO_THINK;
|
animation_neko_do_think();
|
||||||
animation_ticks_until_next_frame = 15;
|
break;
|
||||||
return true;
|
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if (!animation_can_run_left())
|
if (!animation_can_run_left())
|
||||||
return false;
|
return false;
|
||||||
current_neko = NEKO_RUN_LEFT_1;
|
animation_neko_advance_left();
|
||||||
surface.prev_neko_x = surface.neko_x;
|
animation_neko_do_run_left();
|
||||||
surface.neko_x -= neko_x_advance;
|
break;
|
||||||
return true;
|
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
if (!animation_can_run_right())
|
if (!animation_can_run_right())
|
||||||
return false;
|
return false;
|
||||||
current_neko = NEKO_RUN_RIGHT_1;
|
animation_neko_advance_right();
|
||||||
surface.prev_neko_x = surface.neko_x;
|
animation_neko_do_run_right();
|
||||||
surface.neko_x += neko_x_advance;
|
break;
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
return true;
|
||||||
|
|
||||||
case NEKO_RUN_RIGHT_1:
|
case NEKO_RUN_RIGHT_1:
|
||||||
case NEKO_RUN_RIGHT_2:
|
case NEKO_RUN_RIGHT_2:
|
||||||
|
if ( animation_can_run_right() && rand() % 4 != 0 )
|
||||||
|
{
|
||||||
|
animation_neko_do_run_right();
|
||||||
|
animation_neko_advance_right();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
animation_neko_do_stare(false);
|
||||||
|
return true;
|
||||||
|
|
||||||
case NEKO_RUN_LEFT_1:
|
case NEKO_RUN_LEFT_1:
|
||||||
case NEKO_RUN_LEFT_2:
|
case NEKO_RUN_LEFT_2:
|
||||||
if ( current_neko == NEKO_RUN_LEFT_1 || current_neko == NEKO_RUN_LEFT_2 )
|
if ( animation_can_run_left() && rand() % 4 != 0 )
|
||||||
{
|
{
|
||||||
if (!animation_can_run_left())
|
animation_neko_do_run_left();
|
||||||
{
|
animation_neko_advance_left();
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
animation_neko_do_stare(false);
|
||||||
if (!animation_can_run_right())
|
|
||||||
{
|
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( rand() % 4 == 0 )
|
|
||||||
{
|
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (current_neko)
|
|
||||||
{
|
|
||||||
case NEKO_RUN_RIGHT_1: current_neko = NEKO_RUN_RIGHT_2; break;
|
|
||||||
case NEKO_RUN_RIGHT_2: current_neko = NEKO_RUN_RIGHT_1; break;
|
|
||||||
case NEKO_RUN_LEFT_1: current_neko = NEKO_RUN_LEFT_2; break;
|
|
||||||
case NEKO_RUN_LEFT_2: current_neko = NEKO_RUN_LEFT_1; break;
|
|
||||||
default: /* unreachable. */ break;
|
|
||||||
}
|
|
||||||
surface.prev_neko_x = surface.neko_x;
|
|
||||||
if ( current_neko == NEKO_RUN_LEFT_1 || current_neko == NEKO_RUN_LEFT_2 )
|
|
||||||
surface.neko_x -= neko_x_advance;
|
|
||||||
else
|
|
||||||
surface.neko_x += neko_x_advance;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case NEKO_SLEEP_1:
|
case NEKO_SLEEP_1:
|
||||||
case NEKO_SLEEP_2:
|
case NEKO_SLEEP_2:
|
||||||
|
if ( rand() % 4 == 0 )
|
||||||
|
{
|
||||||
|
if ( rand() % 2 == 0 )
|
||||||
|
animation_neko_do_shock();
|
||||||
|
else
|
||||||
|
animation_neko_do_stare(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
animation_neko_do_sleep();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
|
||||||
case NEKO_SCRATCH_1:
|
case NEKO_SCRATCH_1:
|
||||||
case NEKO_SCRATCH_2:
|
case NEKO_SCRATCH_2:
|
||||||
if ( rand() % 4 == 0 )
|
if ( rand() % 4 == 0 )
|
||||||
{
|
animation_neko_do_stare(false);
|
||||||
if ( current_neko == NEKO_SLEEP_1 || current_neko == NEKO_SLEEP_2 )
|
|
||||||
{
|
|
||||||
if ( rand() % 2 == 0 )
|
|
||||||
{
|
|
||||||
current_neko = NEKO_SHOCK;
|
|
||||||
animation_ticks_until_next_frame = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 5;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
animation_neko_do_scratch();
|
||||||
switch (current_neko)
|
return true;
|
||||||
{
|
|
||||||
case NEKO_SLEEP_1: current_neko = NEKO_SLEEP_2; break;
|
|
||||||
case NEKO_SLEEP_2: current_neko = NEKO_SLEEP_1; break;
|
|
||||||
case NEKO_SCRATCH_1: current_neko = NEKO_SCRATCH_2; break;
|
|
||||||
case NEKO_SCRATCH_2: current_neko = NEKO_SCRATCH_1; break;
|
|
||||||
default: /* unreachable. */ break;
|
|
||||||
}
|
|
||||||
if ( current_neko == NEKO_SLEEP_1 || current_neko == NEKO_SLEEP_2 )
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case NEKO_THINK:
|
case NEKO_THINK:
|
||||||
if ( rand() %2 == 0 )
|
if ( rand() %2 == 0 )
|
||||||
{
|
animation_neko_do_stare(false);
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
animation_neko_do_shock();
|
||||||
current_neko = NEKO_SHOCK;
|
return true;
|
||||||
animation_ticks_until_next_frame = 3;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case NEKO_YAWN:
|
case NEKO_YAWN:
|
||||||
if ( rand() %2 == 0 )
|
if ( rand() %2 == 0 )
|
||||||
{
|
animation_neko_do_stare(false);
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
animation_neko_do_sleep();
|
||||||
current_neko = NEKO_SLEEP_1;
|
return true;
|
||||||
animation_ticks_until_next_frame = 10;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case NEKO_SHOCK:
|
case NEKO_SHOCK:
|
||||||
default:
|
animation_neko_do_stare(true);
|
||||||
current_neko = NEKO_STARE;
|
|
||||||
animation_ticks_until_next_frame = 5;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(false); /* unreachable. */
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************
|
/*************
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue