void chicken() // This function defines the chicken's behaviour { my.animPercentage = integer(random(100)); // set the frame the animation is started on to a random value so the chickens are not in synch while(1) // start the chicken's looping function. The following commands will be executed every tick in the game. { // cycle through the animation my.animPercentage += 2 * time_step; // animPercentage determines how far through the animation we are (think of it as frame number) // // It is increased here by a small amount that is multiplied by the speed the game runs at. // // This ensures that the animation will run at the same speed for all players no matter how fast their computer is. if (my.animPercentage > 100) // when animPercentage reaches 100 we have played all the way through the animation. If this is the case { // we need to reset some variables and choose a new animation to play: my.animPercentage -= 100; // reset animPercentage my.eggLaid = 0; // reset the eggLaid variable (this is a marker that prevents the chicken from laying more than 1 egg per animation) // // choose which animation to play next: my.animCycle = integer(random(3)); // generate a random number and assign it to the variable animCycle if (my.animCycle == 2) // if animCycle is 2 the chicken will lay an egg, and { snd_play(chickenSound, 100, 0); // we need to start the egg laying sound now. } } switch (my.animCycle) // this is where the animation actually gets played: { case 0: // if animCycle is 0 play the breathe animation ent_animate(me,"breathe",my.animPercentage,ANM_CYCLE); break; case 1: // if animCycle is 1 play the breathe and blink animation ent_animate(me,"blink",my.animPercentage,ANM_CYCLE); break; case 2: // if animCycle is 2: if ((my.animPercentage > 70) && (my.eggLaid == 0)) // are we more than 70% through the animation and we haven't made an egg? { ent_create ("egg.mdl", vector (my.x - 30, my.y, my.z - 50), egg); // create an egg entity slightly behind and below the chicken my.eggLaid = 1; // set the eggLaid variable to 1 so we don't do this every tick from now on } ent_animate(me,"layEgg",my.animPercentage,ANM_CYCLE); // play the layEgg animation break; } wait(1); // wait for the other entities to get updated so we don't crash the game. } }
BOOL crLottiUpdateFly (ENTITY* e) { VECTOR v, w; vec_set(&w, e->crAccel); vec_scale(&w, time_step); vec_add(e->crSpeed, &w); vec_set(&v, e->crSpeed); vec_scale(&v, time_step); vec_add(e->x, &v); VECTOR feet; feet.x = feet.y = 0; feet.z = 0.5 * e->min_z; vec_rotate(feet, e->pan); vec_add(feet, e->x); ent_animate(e, "drown", 5 * total_ticks + e->crInit, ANM_CYCLE); effect(credits_fire, 2, feet, e->crSpeed); // explode near screen border VECTOR v; vec_set(&v, e->x); vec_to_screen(&v, camera); return (v.x < e->crPercent * screen_size.x || v.x > (1 - e->crPercent) * screen_size.x || v.y < e->crPercent * screen_size.y || v.y > (1 - e->crPercent) * screen_size.y); }
BOOL crLottiUpdateAttack (ENTITY* e) { ent_animate(e, "attack", 5 * total_ticks + e->crInit, ANM_CYCLE); e->crTime -= time_step; return (e->crTime <= 0); }
BOOL crLottiUpdateIdle (ENTITY* e) { ent_animate(e, "idle", 5 * total_ticks + e->crInit, ANM_CYCLE); e->crTime -= time_step; return (g_bCreditsAllExplode || (e->crTime < 0 && e->crExploder)); }
BOOL crLottiUpdateRaise (ENTITY* e) { e->z = e->alpha - 125; e->pan = e->skill1 - (100 - e->alpha) * 5.4; ent_animate(e, "idle", 5 * total_ticks + e->crInit, ANM_CYCLE); return (e->alpha >= 100); }
action ebWarghost () { g_entEbWarghost = my; my->material = g_mtlBossGhost; lvlLavaSuperReset (); var deadRotate = 0; var origScale = my->scale_x; var deadScale = origScale; BOOL isSpining = false; while (1) { // pos { VECTOR vecPos; vecPos.x = my->x; vecPos.y = 1024; vecPos.z = 150; if (player != NULL) { vecPos.x = player->x; vecPos.z = player->z; } vec_lerp(my->x, my->x, &vecPos, time_step * 0.025); } // ang { VECTOR vecLookAt, vecLook; vec_set(&vecLookAt, my->x); vecLookAt.y -= 1000; if (player != NULL) { vecLookAt.x = player->x; vecLookAt.y = player->y; } vec_diff(&vecLook, &vecLookAt, my->x); vec_to_angle(my->pan, &vecLook); if (!isEbWarghostAlive()) { setPlayerControls(false); setPlayerPan(my); deadRotate += 10 * time_step; deadScale += 0.3 * time_step; g_sndEbVol = clamp(g_sndEbVol - g_sndEbVolDec * time_step, 0, 100); snd_tune(g_fhLvlLavastageSong, g_sndEbVol, 3, 0); if (!isSpining) { snd_play(g_sndBossSpin, 100, 0); snd_play(g_sndBossDeadSpeech, 100, 0); isSpining = true; } } my->pan += deadRotate; my->scale_x = my->scale_y = my->scale_z = deadScale; if (my->scale_x / origScale > 3) break; } if (g_ebDoHit) ent_animate(my, "jump", g_ebDoHitPercent, ANM_CYCLE); else ent_animate(my, "attack", total_ticks % 100, ANM_CYCLE); wait(1); } snd_play(g_sndBossSplatter, 100, 0); VECTOR vecPos, vecDir; int i, j, numVerts = ent_status(my, 0); snd_play(g_sndBossDead, 100, 0); set(my, INVISIBLE); for (i = 0; i < numVerts; i++) { vec_for_vertex(&vecPos, my, i+1); vec_diff(&vecDir, &vecPos, my->x); vec_normalize(&vecDir, 1); effEbBlood(&vecPos, &vecDir, 25+random(100), false, 1, 4 + random(4)); } while (redness < 100) { redness = clamp(redness + g_rednessInc * time_step, 0, 100); g_sndEbVol = clamp(g_sndEbVol - g_sndEbVolDec * time_step, 0, 100); snd_tune(g_fhLvlLavastageSong, g_sndEbVol, 5, 0); wait(1); } wait(-1); proc_mode = PROC_GLOBAL; ptr_remove(my); creditsInit(); }
void ebHandWatch () { updateHandChopped(my); ebDoSparkle(my, 2000); snd_play(g_sndSparkle, 100, 0); set(my, PASSABLE); my->ambient = 75; var moveAnim = 10; var t = maxv(g_facTimeEbHandWatchMin, g_facTimeEbHandWatch * (5 + random(3))) * 16; vec_scale(my->scale_x, g_handScale); var ground, height; var heightSub = 32; g_ebHand = my; snd_play(g_sndHandFly, 100, 0); // move with player set(player, FLAG2); while (t > 0) { VECTOR vecBoneGround, vecTraceStart, vecTraceEnd; vec_for_bone(&vecBoneGround, my, "ground"); vec_set(&vecTraceStart, my->x); vecTraceStart.y = vecBoneGround.y; vec_set(&vecTraceEnd, &vecTraceStart); vecTraceEnd.z -= 2000; height = player->z + 250; if (c_trace(&vecTraceStart, &vecTraceEnd, IGNORE_ME | USE_POLYGON | IGNORE_FLAG2 ) > 0) { ground = hit.z; height = ground + (my->z - vecBoneGround.z); } VECTOR v; vec_set(&v, player->x); v.z = height; vec_lerp(my->x, my->x, &v, 0.25 * time_step); ent_animate(my, "idleH", 50 + sin(total_ticks * moveAnim) * 50, ANM_CYCLE); t -= time_step; doHandChopBlood(my); wait(1); } g_facTimeEbHandWatch *= g_facTimeEbHandWatchDec; reset(player, FLAG2); // drop g_handDropping = true; g_ebHand->skill1 = 1; // joints = on g_ebHand->skill2 = 1; // joints death = on g_playerDontScanFlag2 = true; g_playerNoYou = true; ebCreateHandJoints(g_ebHand); set(player, ZNEAR); t = 0; BOOL bSndHandDrop = true; while (t < 100) { VECTOR vecBoneGround; vec_for_bone(&vecBoneGround, g_ebHand, "ground"); height = ground + (g_ebHand->z - vecBoneGround.z) - heightSub; VECTOR v; vec_set(&v, g_ebHand->x); v.z = height; vec_lerp(g_ebHand->x, g_ebHand->x, &v, 0.25 * time_step); t = clamp(t + 5 * time_step, 0, 100); ent_animate(g_ebHand, "drop", t, 0); doHandChopBlood(my); if (t > 90 && bSndHandDrop) { bSndHandDrop = false; snd_play(g_sndHandDrop, 100, 0); } wait(1); } g_handDropping = false; g_ebHand->skill2 = 0; // joints death = off t = maxv(g_facTimeEbHandDroppedMin, g_facTimeEbHandDropped * (3+random(2)) * 16); g_fingerChopped = false; // wait while (t > 0 && !g_fingerChopped) { ent_animate(g_ebHand, "down", (total_ticks * 4), ANM_CYCLE); t -= time_step; doHandChopBlood(my); wait(1); } g_facTimeEbHandDropped *= g_facTimeEbHandDroppedDec; snd_play(g_sndHandUp, 100, 0); reset(player, ZNEAR); g_ebHand->skill1 = 0; // up while (t < 100) { VECTOR vecBoneGround; vec_for_bone(&vecBoneGround, g_ebHand, "ground"); height = ground + (g_ebHand->z - vecBoneGround.z) - heightSub; VECTOR v; vec_set(&v, g_ebHand->x); v.z = height; vec_lerp(g_ebHand->x, g_ebHand->x, &v, 0.25 * time_step); t = clamp(t + 2 * time_step, 0, 100); ent_animate(g_ebHand, "up", t, 0); doHandChopBlood(my); wait(1); } g_playerDontScanFlag2 = false; g_playerNoYou = false; t = 1.5 * 16; snd_play(g_sndHandBliss, 100, 0); // go away while (t > 0) { t -= time_step; g_ebHand->z += 10 * time_step; g_ebHand->y -= 20 * time_step; g_ebHand->roll += 5 * time_step; doHandChopBlood(my); wait(1); } set(g_ebHand, INVISIBLE); ebDoSparkle(g_ebHand, 2000); snd_play(g_sndSparkle, 100, 0); wait(1); ent_create(NULL, nullvector, ebHandsBgFly); ptr_remove(g_ebHand); }
void ebHandFly () { updateHandChopped(my); set(my, PASSABLE); my->ambient = 75; VECTOR startPos, targetPos; vec_set(&startPos, my->x); ebDoSparkle(my, 2000); var t = 0; var distX = 500; var moveDist = 200; var moveTime = 0.5; var moveLerp = 0.2; var moveAnim = 2; vec_scale(my->scale_x, g_handScale); var targetRoll = -90; // Stone rain var randomStoneRain = 0; var randomStoneModel = 0; while (my->skill1 == 0) { if (t <= 0) { vec_set(&targetPos, vector(25+random(moveDist), 0, 0)); vec_rotate(&targetPos, vector(random(360),random(360),random(360))); vec_add(&targetPos, &startPos); t += moveTime * 16; } else t -= time_step; VECTOR nuPos; vec_set(&nuPos, &targetPos); if (player != NULL) nuPos.x += player->x; vec_lerp(my->x, my->x, &nuPos, moveLerp * time_step); ent_animate(my, "idleH", (total_ticks * moveAnim) % 100, ANM_CYCLE); my->roll += (targetRoll - my->roll) * 0.05 * clamp(time_step, 0.001, 1); doHandChopBlood(my); if (!isEbWarghostAlive()) { startPos.z -= 10 * time_step; targetPos.z -= 10 * time_step; targetRoll -= 10 * time_step; } // Stone rain randomStoneRain = random(1000); if (randomStoneRain > 950) { randomStoneModel = integer(random(2)); switch(randomStoneModel) { case 0: ent_create("stein1.mdl", vector(player.x - 500 + random(1000), player.y, my.z + 300 + random(50)), ebHandStone); break; case 1: ent_create("stein2.mdl", vector(player.x - 500 + random(1000), player.y, my.z + 300 + random(50)), ebHandStone); break; case 2: ent_create("stein3.mdl", vector(player.x - 500 + random(1000), player.y, my.z + 300 + random(50)), ebHandStone); break; } } // -- end stone rain wait(1); } while (my->skill2 > 0) { my->skill2 -= time_step; my->z += 10 * time_step; my->y -= 20 * time_step; my->roll += 2 * time_step; doHandChopBlood(my); wait(1); } set(my, INVISIBLE); ebDoSparkle(my, 2000); wait(1); ptr_remove(my); }