Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
test
Lily Pitiot879b0d7be753
diff --git a/games/dinorun/README.md b/games/dinorun/README.mdindex b4a5abad..584a1b0d 100644--- a/games/dinorun/README.md+++ b/games/dinorun/README.md@@ -10,13 +10,13 @@ This C game uses the original *rectangle-defined pixel art* decoded from [Lily's| Key | Action ||---|---|-| **OK**, EXE, Up / 8 | Jump / start / restart |+| **OK** | Jump / start / restart (holding OK can jump again on landing) || **Down** / 2 (hold) | Duck (and fall faster mid-air) |-| **Back** or Backspace | Pause / resume |+| **Clear / Backspace** | Pause / resume |+| **Back** (undo arrow) or **Home** | Exit to NumPlay / calculator || **SHIFT** at title | Help screen |-| **HOME** | Exit back to calculator |-Physics now follows the Python original: **49-pixel jump apex**, 10–14 px/frame cactus speed, 5–14 px/frame bird speed, score advancing by one each frame, and night/day switching every 300 points. Actual real-time speed can still vary with the calculator and rendering cost.+Physics and object sprites follow the Python original: **49-pixel jump apex**, a 10–14 px/frame cactus speed, a 5–14 px/frame bird/cloud speed, the original random spawn thresholds, and day/night every 300 points. The right-facing Python bird sprites are **horizontally mirrored** here so they face the same direction they move (left). The original art shapes are otherwise unchanged. The frame is paced to **100 ms minimum** rather than C's previous 33 ms; it approximates MicroPython's much slower drawing cost, which varies between calculator models and must be checked on actual hardware.The game features the original pixel cacti, flying bird frames, scrolling clouds, moon/stars, gradually increasing speed, day/night changes, high-score storage (`dinorun.sav`) and instant restart.diff --git a/games/dinorun/docs/game.png b/games/dinorun/docs/game.pngindex 534d0a9c..21a678e9 100644Binary files a/games/dinorun/docs/game.png and b/games/dinorun/docs/game.png differdiff --git a/games/dinorun/docs/shot.png b/games/dinorun/docs/shot.pngindex 534d0a9c..21a678e9 100644Binary files a/games/dinorun/docs/shot.png and b/games/dinorun/docs/shot.png differdiff --git a/games/dinorun/docs/title.png b/games/dinorun/docs/title.pngindex 72521ca6..c2efb5cc 100644Binary files a/games/dinorun/docs/title.png and b/games/dinorun/docs/title.png differdiff --git a/games/dinorun/src/main.c b/games/dinorun/src/main.cindex db60f94a..df8b3295 100644--- a/games/dinorun/src/main.c+++ b/games/dinorun/src/main.c@@ -1,7 +1,8 @@/* Dino Run — C gameplay for NumWorks / NumPlay with geometry converted from* the Python Chrome Dino sprites. See dino_sprites.h for source/rights note.* 320x240, RGB565, 16-row bands; physics follows the Python frame steps.- * Keyboard: OK/Up/Exe jump, Down duck, Back/Backspace pause, Home exit.+ * Keyboard: OK jump, Down duck, Clear/Backspace pause, Back exits.+ * Pixel steps follow the original Python logic; rendering uses a paced game clock.*/#include <eadk.h>#include <stdbool.h>@@ -25,25 +26,37 @@ const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level")))#define BAND 16#define KEY(k) (1ull << (k))#define RGB(c) (uint16_t)((((c) >> 8) & 0xF800u) | (((c) >> 5) & 0x07E0u) | (((c) >> 3) & 0x1Fu))-#define JUMP (KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_up) | KEY(eadk_key_eight))+/* Unlike the old test build, Back returns immediately to NumPlay / Home. */+#define JUMP KEY(eadk_key_ok)#define DUCK (KEY(eadk_key_down) | KEY(eadk_key_two))-#define PAUSE (KEY(eadk_key_back) | KEY(eadk_key_backspace))+#define PAUSE KEY(eadk_key_backspace)+#define EXIT (KEY(eadk_key_back) | KEY(eadk_key_home) | KEY(eadk_key_on_off))+/* The Python original sleeps 30 ms *after* slow Kandinsky drawing. Its effective+ * frame period is much longer than 30 ms; cap native speed at ~10 fps so the+ * same 10-pixel/frame obstacles do not scroll 3x too fast. This is a timing+ * approximation: only a real calculator comparison can measure Python FPS. */+#define GAME_FRAME_MS 100#define SAVE_NAME "dinorun.sav"typedef uint16_t color;typedef struct { int16_t x, y; uint8_t w, h, kind; } obstacle;+typedef struct { int16_t x, y; } decoration;enum { TITLE, HELP, PLAY, PAUSED, DEAD };enum { CACTUS, LARGE_CACTUS, BIRD };static color pixels[W * BAND];static int band_y, scene;static color bg, ink, faint;-static obstacle obstacles[8];+static obstacle obstacles[12];+static decoration clouds[3], dust[5], pebbles[2];+static int cloud_count, dust_count, pebble_count;+static int cloud_clock, cloud_delay, dust_clock, dust_delay, pebble_clock, pebble_delay;static int count, dino_y, dino_vy, duck, score, high_score, speed;/* Python values: H=-13 for jump, gravity ad=2 (+7 each duck frame),* cacti move Q=10..14 px/frame, birds move T=5..14 px/frame.* The simulation uses one step per frame, just like the source. */static int gravity_units, cactus_meter, bird_meter;+static int bird_speed;static uint32_t rng=0xA319F4B5u, ticks, distance_px;static bool new_record;@@ -51,7 +64,10 @@ static uint32_t random32(void) {rng ^= rng << 13; rng ^= rng >> 17; rng ^= rng << 5;return rng;}-static int randint(int n) { return (int)(random32() % (uint32_t)n); }+static int randint(int n) { return n>0 ? (int)(random32() % (uint32_t)n) : 0; }+/* MicroPython randint(a,b) is inclusive. */+static int randrange(int lo, int hi) { return lo + randint(hi-lo+1); }+static int imax(int a,int b) { return a>b?a:b; }static void rect(int x, int y, int w, int h, color c) {if (w <= 0 || h <= 0) return;@@ -121,109 +137,154 @@ static void sprite(const dino_sprite_rect *pieces, unsigned n,}#define SPRITE(name, x, y, c) sprite(name, COUNT_OF(name), x, y, c)+/* Mirrored about a 21-pixel bounding box. The imported aB/an bird images+ * face right even though the Python game moves them left; keeping each pixel+ * but reversing its X coordinate fixes the "flying backward" appearance. */+static void bird_sprite(const dino_sprite_rect *pieces, unsigned n,+ int x,int y,color c) {+ for(unsigned i=0;i<n;i++)+ rect(x+21-pieces[i].x-pieces[i].w,+ y+pieces[i].y,pieces[i].w,pieces[i].h,c);+}static void dino(int x,int y,bool crouch,int step) {- if (crouch) {- if (step & 1) SPRITE(DINO_DUCK_1,x,y,ink);- else SPRITE(DINO_DUCK_2,x,y,ink);- } else if (y < DY) {+ /* Original J%5: 2 frames of pose 1, 3 frames of pose 2. */+ bool first=(step%5)<2;+ if(crouch) {+ /* The original Python draws aj (21 rects), NOT V (aj + 7 fills).+ * V is preserved in the header but use only its aj prefix here. */+ if(first) sprite(DINO_DUCK_1,COUNT_OF(DINO_DUCK_1)-7,x,y,ink);+ else SPRITE(DINO_DUCK_2,x,y,ink);+ } else if(y<DY) {SPRITE(DINO_JUMP,x,y,ink);- } else if (step & 1) {+ } else if(first) {SPRITE(DINO_RUN_1,x,y,ink);} else {SPRITE(DINO_RUN_2,x,y,ink);}}-static void cactus(obstacle *o) {- /* In the Python source S is drawn at (cactus position, F=190), and- * occupies x=[-20,-6], y=[-14,+9]. Use o->x/o->y as its top-left. */- SPRITE(CACTUS_ORIGINAL,o->x+20,o->y+14,ink);- if (o->kind==LARGE_CACTUS)- SPRITE(CACTUS_ORIGINAL,o->x+16+20,o->y+14,ink);+ /* o->x is the ORIGINAL Python d[] anchor; sprite S extends 20px left. */+ SPRITE(CACTUS_ORIGINAL,o->x,DY,ink);+ if(o->kind==LARGE_CACTUS) SPRITE(CACTUS_ORIGINAL,o->x+20,DY,ink);}-static void bird(obstacle *o) {- /* Python aB/an: original flapping bird poses. */- /* Original sprite coordinates use the bird's y directly. */- if ((ticks/5)&1) SPRITE(BIRD_WING_DOWN,o->x,o->y,ink);- else SPRITE(BIRD_WING_UP,o->x,o->y,ink);+ /* Exact aB/an rectangles and original two/three-frame flap cadence,+ * mirrored only so its beak points in its direction of travel (left). */+ if(((ticks? ticks-1:0)%5)<2) bird_sprite(BIRD_WING_DOWN,COUNT_OF(BIRD_WING_DOWN),o->x,o->y,ink);+ else bird_sprite(BIRD_WING_UP,COUNT_OF(BIRD_WING_UP),o->x,o->y,ink);}-static void scenery(void) {rect(0,GROUND,W,1,ink);- if ((score/300)&1) {- /* aC is the original crescent moon; aG/aw are the stars. */- SPRITE(MOON_ORIGINAL,241,24,ink);- for(int i=0;i<18;i++) {- int x=(i*87+23-(int)(distance_px/9)%720+720)%720-20;- int y=20+(i*43)%127;- if (i&1) SPRITE(STAR_ORIGINAL_1,x,y,ink);- else SPRITE(STAR_ORIGINAL_2,x,y,ink);- }- } else {- /* at: the very same outlined cloud as in the Python version. */- for(int i=0;i<5;i++) {- int x=(i*143+330-(int)(distance_px/6)%690+690)%690-65;- int y=44+(i*29)%88;- SPRITE(CLOUD_ORIGINAL,x,y,faint);+ if((score/300)&1) {+ /* Fixed moon and star placements match the original nighttime scene. */+ SPRITE(MOON_ORIGINAL,50,90,faint);+ static const int16_t stars[][3] = {+ {100,100,1},{20,110,0},{60,40,1},{140,20,0},+ {130,75,1},{60,140,0},{260,120,1},{180,90,0},+ {220,70,1},{280,60,0},{250,20,1},{160,110,0}+ };+ for(unsigned i=0;i<sizeof(stars)/sizeof(stars[0]);i++) {+ if(stars[i][2]) SPRITE(STAR_ORIGINAL_1,stars[i][0],stars[i][1],faint);+ else SPRITE(STAR_ORIGINAL_2,stars[i][0],stars[i][1],faint);}}- /* av and W: original little ground tufts/dots. */- for(int i=0;i<16;i++) {- int x=(i*58+17-(int)(distance_px%960)+960)%960;- if(x>W+22)continue;- if(i&1) SPRITE(GROUND_DETAIL_1,x,GROUND-5,faint);- else SPRITE(GROUND_DETAIL_2,x,GROUND-5,ink);- }-}-static bool overlap(int x,int y,int w,int h,int xx,int yy,int ww,int hh) {- return x<xx+ww && x+w>xx && y<yy+hh && y+h>yy;+ /* Clouds at 5 px/frame, like Python's j[] list, visible in both palettes. */+ for(int i=0;i<cloud_count;i++)+ SPRITE(CLOUD_ORIGINAL,clouds[i].x,clouds[i].y,faint);+ /* Moving ground specks and tufts use the original W/av sprite lists. */+ for(int i=0;i<dust_count;i++) rect(dust[i].x,dust[i].y,2,1,ink);+ for(int i=0;i<pebble_count;i++)+ SPRITE(GROUND_DETAIL_1,pebbles[i].x,DY,ink);}+/* Match the original Python aM, ay and ap collision predicates, which operate+ * on sprite anchor positions (not on the old approximated C bounding boxes). */static bool collision(void) {- int y=(dino_y+128)/256;- /* Aligned with the original Python sprite outlines, not the old 40px art. */- int x=DX+1, top=y-11, w=18,h=19;- if (duck && y>=DY) {x=DX+1;top=y-3;w=25;h=12;}+ int y=dino_y/256;for(int i=0;i<count;i++) {- obstacle *o=&obstacles[i];- int ox=o->x+1, oy=o->y+1, ow=o->w-2, oh=o->h-2;- if(o->kind==BIRD) {ox=o->x+2;oy=o->y+2;ow=19;oh=14;}- if(overlap(x,top,w,h,ox,oy,ow,oh))return true;+ const obstacle *o=&obstacles[i];+ if(o->kind==BIRD) {+ if(DX<o->x+14 && DX+30>o->x && y<o->y+14 && y+20>o->y)+ return true;+ } else {+ int width=duck?26:14;+ if(o->x-20<DX+width && o->x-8>DX && DY-20<y && DY>y-(duck?12:20))+ return true;+ if(o->kind==LARGE_CACTUS &&+ o->x+20-20<DX+width && o->x+20-8>DX && DY-20<y && DY>y-(duck?12:20))+ return true;+ }}return false;}static void start_game(void) {- scene=PLAY;count=0;score=0;speed=10;distance_px=0;+ scene=PLAY;count=0;score=0;speed=10;bird_speed=5;distance_px=0;cactus_meter=0;bird_meter=0;gravity_units=2;+ cloud_count=dust_count=pebble_count=0;+ cloud_clock=dust_clock=pebble_clock=0;+ cloud_delay=randrange(30,70);dust_delay=randrange(1,2);+ pebble_delay=randrange(30,50);duck=0;dino_y=DY*256;dino_vy=0;ticks=0;new_record=false;}-/* Python Chrome Dino uses counters E (cactus) and q (birds), with random- * thresholds and 1-in-4 / 1-in-7 spawn chances. No obstacles initially. */+/* The original Python's E/q counters and inclusive random thresholds. */static void spawn(void) {- int difficulty=(int)(ticks/60); /* original variable a */- int last_x=-1000, birds=0;+ int difficulty=(int)(ticks/60); /* B has not advanced yet this frame */+ int cactus_count=0, bird_count=0, last_cactus=-10000;for(int i=0;i<count;i++) {- if (obstacles[i].kind==BIRD) birds++;- else if(obstacles[i].x>last_x)last_x=obstacles[i].x;+ if(obstacles[i].kind==BIRD) bird_count++;+ else {cactus_count++;last_cactus=obstacles[i].x;}}- cactus_meter+=1+randint(4+difficulty/3);- int threshold=20+randint(40+21);- if(count<6 && cactus_meter>=threshold && randint(4)==0 && last_x<210) {- int amount=(randint(6)==0)?2+randint(2):1;- for(int i=0;i<amount && count<8;i++) {- obstacle *o=&obstacles[count++];- *o=(obstacle){(int16_t)(350+i*20),DY-14,14,23,CACTUS};+ int gap=130+difficulty*4+randrange(0,60);+ int min_threshold=imax(20,cactus_meter/2-difficulty);+ int max_threshold=min_threshold+40+randrange(0,20);+ if(cactus_count<3 && cactus_meter>=randrange(min_threshold,max_threshold)+ && randrange(1,4)==1 && (cactus_count==0 || last_cactus<350-gap)) {+ int amount=randrange(1,6)==6 ? randrange(2,3) : 1;+ for(int i=0;i<amount && count<12;i++) {+ int x=amount>1 ? 350+20*(i+1) : 350;+ obstacles[count++]=(obstacle){(int16_t)x,DY,14,23,CACTUS};}- cactus_meter=0;+ if(amount==1) cactus_meter=0; /* original does not reset E for cactus groups */}- /* Original birds appear after 300 points, with positions y=150..180. */- bird_meter++;- int ready=40;- if(score>300 && birds==0 && count<8 && bird_meter>=ready+randint(40) && randint(7)==1) {- obstacle *o=&obstacles[count++];- *o=(obstacle){400,(int16_t)(150+randint(31)),21,18,BIRD};+ int p=imax(40,bird_meter/2);+ if(bird_count<1 && count<12 && bird_meter>=randrange(p,p+40)+ && score>300 && randrange(1,7)==2) {+ /* The Python also appends a cactus far behind the flying bird. */+ if(count<11) obstacles[count++]=(obstacle){650,DY,14,23,CACTUS};+ obstacles[count++]=(obstacle){400,(int16_t)randrange(150,180),21,18,BIRD};bird_meter=0;}+ if(cloud_count<3 && cloud_clock>=cloud_delay) {+ clouds[cloud_count++]=(decoration){320,(int16_t)randrange(50,120)};+ cloud_clock=0;+ cloud_delay=randrange(imax(1,20-difficulty),imax(1,60-difficulty));+ }+ if(dust_count<5 && dust_clock>=dust_delay) {+ dust[dust_count++]=(decoration){320,(int16_t)randrange(197,203)};+ dust_clock=0;+ dust_delay=randrange(1,3);+ }+ if(pebble_count<2 && pebble_clock>=pebble_delay) {+ pebbles[pebble_count++]=(decoration){500,0};+ pebble_clock=0;+ pebble_delay=randrange(imax(1,20-difficulty),imax(1,60-difficulty));+ }+}+static void advance_decorations(void) {+ for(int i=0;i<cloud_count;) {+ clouds[i].x-=bird_speed;+ if(clouds[i].x<=-50) {for(int j=i+1;j<cloud_count;j++)clouds[j-1]=clouds[j];cloud_count--;}+ else i++;+ }+ for(int i=0;i<dust_count;) {+ dust[i].x-=speed;+ if(dust[i].x<=-10) {for(int j=i+1;j<dust_count;j++)dust[j-1]=dust[j];dust_count--;}+ else i++;+ }+ for(int i=0;i<pebble_count;) {+ pebbles[i].x-=speed;+ if(pebbles[i].x<=-20) {for(int j=i+1;j<pebble_count;j++)pebbles[j-1]=pebbles[j];pebble_count--;}+ else i++;+ }}static void lose(void) {scene=DEAD;@@ -234,38 +295,36 @@ static void lose(void) {}}static void update(bool jump,bool down) {- ticks++;- score=(int)ticks; /* Python's O increases by one every game frame. */+ /* Python increments score at the start, then advances difficulty after+ * processing movement on every 60th frame. */+ score++;speed=10+(int)(ticks/180); if(speed>14)speed=14;-- /* The original program updates position first, then acceleration, so a- * new jump goes: -13,-11,-9,-7,-5,-3,-1,+1,... = 49 px rise. */+ bird_speed=5+(int)(ticks/180); if(bird_speed>14)bird_speed=14;+ spawn();+ /* The original Python uses H=-13, then applies H+=ad (ad starts at 2).+ * The C value is scaled by 256 only for consistency with the old tests. */if(jump && dino_y>=DY*256 && !down) dino_vy=-13*256;- duck=down && dino_y>=DY*256;+ duck=down; /* The Python also renders its duck pose while airborne. */dino_y+=dino_vy;- if(dino_y<DY*256) {- dino_vy+=gravity_units*256;- } else {- dino_y=DY*256;- dino_vy=0;- }- /* Holding Down increases falling acceleration by 7 each frame, just- * like Python's ad += 7; release resets it to 2. */+ if(dino_y<DY*256) dino_vy+=gravity_units*256;+ else {dino_y=DY*256;dino_vy=0;}if(down)gravity_units+=7;else gravity_units=2;- distance_px+=(uint32_t)speed;for(int i=0;i<count;) {- int move=(obstacles[i].kind==BIRD)?5+(int)(ticks/180):speed;- if(move>14)move=14;+ int move=obstacles[i].kind==BIRD ? bird_speed : speed;obstacles[i].x-=(int16_t)move;- if(obstacles[i].x+obstacles[i].w<-24) {- for(int j=i+1;j<count;j++)obstacles[j-1]=obstacles[j];- count--;- } else i++;+ bool gone=(obstacles[i].kind==BIRD?obstacles[i].x<=-30:obstacles[i].x<=-10);+ if(gone) {for(int j=i+1;j<count;j++)obstacles[j-1]=obstacles[j];count--;}+ else i++;}- spawn();+ advance_decorations();if(collision())lose();+ distance_px+=(uint32_t)speed;+ int difficulty=(int)(ticks/60);+ cactus_meter+=randrange(1,4+difficulty/3);+ bird_meter++;cloud_clock++;dust_clock++;pebble_clock++;+ ticks++;}static void frame(void) {bool night=((score/300)&1)!=0;@@ -280,15 +339,15 @@ static void frame(void) {for(int i=0;i<count;i++) {if(obstacles[i].kind==BIRD)bird(&obstacles[i]);else cactus(&obstacles[i]);}- dino(DX,(dino_y+128)/256,duck,ticks/5);+ dino(DX,dino_y/256,duck,(int)(ticks? ticks-1:0));text_at(11,11,"HI",2,faint);number(47,11,high_score,5,2,ink);number(245,11,(unsigned)score,5,2,ink);} else {/* The original title character is the separately encoded 3x sprite. */SPRITE(DINO_MENU_LARGE,120,150,ink);centered(40,"CHROME DINO",3,ink);- centered(202,scene==HELP?"OK OR UP JUMP":"PRESS OK TO PLAY",2,ink);- centered(225,scene==HELP?"DOWN DUCK, BACK PAUSE":"SHIFT FOR HELP",1,faint);+ centered(202,scene==HELP?"OK TO JUMP":"PRESS OK TO PLAY",2,ink);+ centered(225,scene==HELP?"DOWN DUCK CLEAR PAUSE":"SHIFT FOR HELP",1,faint);if(scene!=HELP) {text_at(9,230,"BEST",1,faint);number(46,230,high_score,5,1,ink);}}if(scene==DEAD) {@@ -299,12 +358,30 @@ static void frame(void) {} else if(scene==PAUSED) {rect(75,70,170,76,bg);centered(82,"PAUSED",3,ink);- centered(119,"BACK TO RESUME",1,ink);+ centered(115,"CLEAR TO RESUME",1,ink);+ centered(129,"BACK TO EXIT",1,ink);}eadk_display_push_rect((eadk_rect_t){0,(uint16_t)band_y,W,BAND},pixels);}}+/* Separated out so native host tests can verify controls as well as physics.+ * Returns true when Back/Home requests leaving the app/NumPlay. */+static bool handle_input(uint64_t keys,uint64_t hit) {+ if(keys&EXIT) return true;+ if(scene==TITLE || scene==HELP) {+ if(hit&JUMP) start_game();+ else if(hit&KEY(eadk_key_shift)) scene=scene==TITLE?HELP:TITLE;+ } else if(scene==PLAY) {+ if(hit&PAUSE) scene=PAUSED;+ else update((keys&JUMP)!=0,(keys&DUCK)!=0);+ } else if(scene==PAUSED) {+ if(hit&PAUSE) scene=PLAY;+ } else if(scene==DEAD) {+ if(hit&JUMP) start_game();+ }+ return false;+}int main(void) {np_app_begin();uint32_t len=0;@@ -318,23 +395,12 @@ int main(void) {uint64_t held=eadk_keyboard_scan();for(;;) {uint32_t now=(uint32_t)eadk_timing_millis();- uint64_t keys=eadk_keyboard_scan(),hit=keys & ~held;+ uint64_t keys=eadk_keyboard_scan(),hit=keys&~held;held=keys;- if(keys&(KEY(eadk_key_home)|KEY(eadk_key_on_off)))break;- if(scene==TITLE || scene==HELP) {- if(hit&JUMP) start_game();- else if(hit&KEY(eadk_key_shift))scene=scene==TITLE?HELP:TITLE;- } else if(scene==PLAY) {- if(hit&PAUSE)scene=PAUSED;- else update((hit&JUMP)!=0,(keys&DUCK)!=0);- } else if(scene==PAUSED) {- if(hit&PAUSE)scene=PLAY;- } else if(scene==DEAD) {- if(hit&JUMP)start_game();- }+ if(handle_input(keys,hit)) break;frame();uint32_t elapsed=(uint32_t)eadk_timing_millis()-now;- if(elapsed<33)eadk_timing_msleep(33-elapsed);+ if(elapsed<GAME_FRAME_MS) eadk_timing_msleep(GAME_FRAME_MS-elapsed);}return np_app_end();}diff --git a/games/dinorun/tests/test_dino.c b/games/dinorun/tests/test_dino.cindex de793c6e..e9cfb5ce 100644--- a/games/dinorun/tests/test_dino.c+++ b/games/dinorun/tests/test_dino.c@@ -27,42 +27,90 @@ static void screenshot(const char *f) {fclose(fp);}int main(int argc,char **argv) {- scene=TITLE;dino_y=DY*256;score=0;+ scene=TITLE; dino_y=DY*256;score=0;frame();- if(argc>=2)screenshot(argv[1]);+ if(argc>=2) screenshot(argv[1]);++ /* Reference: original Python H=-13, gravity=+2, 49 px at frame 7. */start_game();assert(scene==PLAY && score==0 && count==0);- /* Python H=-13, ad=2: first frame -13, apex -49 at frame 7. */int y=dino_y;+ cactus_meter=bird_meter=-100000;update(true,false);assert(dino_y==y-13*256);- for(int t=0;t<6;t++)update(false,false);+ for(int t=0;t<6;t++) update(false,false);assert(dino_y==y-49*256);- for(int t=0;t<7;t++)update(false,false);- assert(dino_y==DY*256);- assert(score==14 && speed==10);- /* The old C game was -2600/+155 (over 80 px) and scrolled at 4 px.- * In Python speed is 10 at start, 11 after ~180 frames and 14 max. */- start_game();- ticks=179; cactus_meter=-9999; bird_meter=-9999;+ for(int t=0;t<7;t++) update(false,false);+ assert(dino_y==DY*256 && score==14 && speed==10);++ /* Python: speed changes AFTER the 180th frame, not before it. */+ start_game();ticks=179;cactus_meter=bird_meter=-100000;+ update(false,false);assert(speed==10 && bird_speed==5 && score==1);+ update(false,false);assert(speed==11 && bird_speed==6 && score==2);+ /* At difficulty >= 12, cacti have 14-pixel steps; birds have 9. */+ ticks=720;update(false,false);assert(speed==14 && bird_speed==9);+ /* Every frame advances birds left (5 to 14px) and not right. */+ start_game();cactus_meter=bird_meter=-100000;+ obstacles[0]=(obstacle){280,DY,14,23,CACTUS};+ obstacles[1]=(obstacle){270,165,21,18,BIRD};count=2;update(false,false);- assert(speed==11 && score==180);- update(false,true);assert(duck && gravity_units==9);+ assert(obstacles[0].x==270 && obstacles[1].x==265);++ /* Sprites are exact geometry mirrored only along X for birds. */+ bg=RGB(0xFFFFFF);ink=RGB(0x535353);band_y=0;+ for(int i=0;i<W*BAND;i++) pixels[i]=bg;+ bird_sprite(BIRD_WING_DOWN,COUNT_OF(BIRD_WING_DOWN),80,4,ink);+ assert(pixels[(4-0)*W+95]==ink); /* Source first rect x=4..6 => mirrored x=15..17. */+ assert(pixels[(4-0)*W+84]==bg);++ /* Python ducking changes gravitational acceleration, even in the air. */+ start_game();cactus_meter=bird_meter=-100000;+ update(true,false);update(false,true);+ assert(duck && gravity_units==9 && dino_y<DY*256);update(false,false);assert(!duck && gravity_units==2);- /* Force a collision, test the game-over state and restart. */- high_score=0;count=1;obstacles[0]=(obstacle){DX+12,DY-14,14,23,CACTUS};+ /* Cloud motion follows bird/cloud speed, not cactus speed. */+ start_game();cactus_meter=bird_meter=-100000;+ clouds[0]=(decoration){200,80};cloud_count=1;cloud_clock=-99999;+ update(false,false);assert(clouds[0].x==195);++ /* Controls: Clear pauses and resumes; Back exits immediately. */+ start_game();+ assert(!handle_input(PAUSE,PAUSE) && scene==PAUSED);+ uint32_t before=ticks;+ assert(!handle_input(0,0) && ticks==before);+ assert(!handle_input(PAUSE,PAUSE) && scene==PLAY && ticks==before);+ assert(handle_input(KEY(eadk_key_back),KEY(eadk_key_back)) && scene==PLAY);+ scene=TITLE;+ assert(handle_input(KEY(eadk_key_back),KEY(eadk_key_back)));+ scene=PAUSED;+ assert(handle_input(KEY(eadk_key_home),KEY(eadk_key_home)));++ /* Original Python cactus collision: d[] x anchor and y position. */+ start_game();high_score=0;+ count=1; obstacles[0]=(obstacle){DX+22,DY,14,23,CACTUS};+ assert(collision());update(false,false);assert(scene==DEAD && high_score==score);start_game();assert(scene==PLAY && score==0 && count==0);- for(int i=0;i<160;i++){- if(scene==DEAD)start_game();- update((i%31)==1,false);- }++ /* Simulate a long random run and verify all bounded game arrays stay safe.+ * This also checks that scores, difficulty and every spawn type co-exist. */start_game();- score=328; ticks=1312;distance_px=2100;+ for(int i=0;i<2500;i++) {+ if(scene==DEAD) start_game();+ update((i%17)<4, (i%29)>24);+ assert(count>=0 && count<=12);+ assert(cloud_count>=0 && cloud_count<=3);+ assert(dust_count>=0 && dust_count<=5);+ assert(pebble_count>=0 && pebble_count<=2);+ }++ /* Both sprite variants and the sky can render safely in all 240 rows. */+ start_game();score=328;ticks=1312;count=3;- obstacles[0]=(obstacle){244,DY-14,14,23,CACTUS};- obstacles[1]=(obstacle){289,DY-14,30,23,LARGE_CACTUS};+ obstacles[0]=(obstacle){244,DY,14,23,CACTUS};+ obstacles[1]=(obstacle){289,DY,30,23,LARGE_CACTUS};obstacles[2]=(obstacle){152,GROUND-28,21,18,BIRD};+ clouds[0]=(decoration){170,70};cloud_count=1;frame();if(argc>=3)screenshot(argv[2]);- printf("Host test passed: Python jump (49px), speed, crouch, collision, restart, rendering.\n");+ printf("Host tests passed: Python jump & speed, bird direction, mirrored sprites, sky, collisions, Back exit, Clear pause.\n");return 0;}