AcctRegSetDftEntry("TempleOS/TimeOut","I64 best_score=0;\n"); AcctRegExeBranch("TempleOS/TimeOut"); #define MAP_HEIGHT 4096 #define SHOT_LEN 10 #define SHOT_SPEED 5 #define MAX_SHOTS 128 class Shot { I64 x,y,dx,dy,dx2,dy2; Bool dead,pad[7]; } s[MAX_SHOTS]; I64 shots_fired; I64 x,y,dx,dy,scroll_y,finish_line; F64 é; F64 t0,tf,snd_shot_timeout,snd_death_timeout; #define PHASES_GROUPS 10 #define MAX_ENEMY (PHASES_GROUPS*100) #define MAX_FRIENDLY (PHASES_GROUPS*20) #define MAX_MAN (MAX_FRIENDLY+MAX_ENEMY) class Man { I64 x,y; F64 corpse_timeout; Bool friendly,dead,pad[6]; } m[MAX_MAN]; I64 total_score,friendly_fire,enemy_by_friendly,friendly_left,enemy_left, main_loop_pass; Bool game_over; $BG,14$ $SP,"<1>",BI=1$ $SP,"<2>",BI=2$ $SP,"<3>",BI=3$ $SP,"<4>",BI=4$ $SP,"<5>",BI=5$ #define LANDSCAPE_TYPES 4 $SP,"<6>",BI=6$ $SP,"<7>",BI=7$ $SP,"<8>",BI=8$ $SP,"<9>",BI=9$ $BG$ CSprite *landscape_imgs[LANDSCAPE_TYPES]= {$IB,"",BI=6$,$IB,"",BI=7$,$IB,"",BI=8$,$IB,"",BI=9$}; #define MAX_LANDSCAPE 64 class LandScapeItem { I64 x,y; U8 *img; } ls[MAX_LANDSCAPE]; U0 DrawIt(CTask *task,CDC *dc) { I64 i,yy; F64 t1; Man *tempm; Shot *temps; for (i=0;ipix_bottom+32) Sprite3(dc,ls[i].x,yy,0,ls[i].img); } dc->pen_width=3; dc->color=BROWN; GrLine3(dc,0, (finish_line-scroll_y)&(MAP_HEIGHT-1),0, GR_WIDTH,(finish_line-scroll_y)&(MAP_HEIGHT-1),0); dc->color=LTRED; for (i=0,temps=s;idead) GrLine(dc,temps->x>>32,temps->y>>32, (temps->x+temps->dx*SHOT_LEN)>>32, (temps->y+temps->dy*SHOT_LEN)>>32); for (i=0,tempm=m;iy-scroll_y)&(MAP_HEIGHT-1); if (-32<=yy<=Fs->pix_bottom+32) { if (tempm->dead && tScorpse_timeout) if (!(RandU16&15)) { if (tempm->friendly) Sprite3(dc,tempm->x,yy,0,$IB,"",BI=4$); else Sprite3(dc,tempm->x,yy,0,$IB,"",BI=5$); } } } for (i=0,tempm=m;iy-scroll_y)&(MAP_HEIGHT-1); if (-32<=yy<=Fs->pix_bottom+32) { if (!tempm->dead) { if (tempm->friendly) Sprite3(dc,tempm->x,yy,0,$IB,"",BI=2$); else Sprite3(dc,tempm->x,yy,0,$IB,"",BI=3$); } } } SpriteZ3B(dc,x,y,0,$IB,"",BI=1$,é); if (tf) { t1=tf; dc->color=RED; if (game_over && Blink) GrPrint(dc,task->pix_width/2-9*FONT_WIDTH/2, task->pix_height/2,"Game Over"); } else { t1=tS; if (!enemy_left || !friendly_left) game_over=TRUE; } dc->color=BROWN; GrPrint(dc,0,0,"Enemy:%d Friends:%d Friendly Fire:%d Time:%6.2f Shots:%d", enemy_left,friendly_left,friendly_fire,t1-t0,shots_fired); GrPrint(dc,0,8,"Total Score:%,d High Score:%,d", total_score,best_score); } U0 CheckCollisions() { I64 i,x,y; Man *tempm; Shot *temps; CDC *dc2=DCNew(GR_WIDTH,GR_HEIGHT); dc2->color=LTRED; for (i=0,temps=s;idead) GrLine(dc2,temps->x>>32,temps->y>>32, (temps->x+temps->dx*SHOT_LEN)>>32, (temps->y+temps->dy*SHOT_LEN)>>32); dc2->color =ROP_COLLISION; dc2->bkcolor=BLACK; for (i=0,tempm=m;idead) { x=tempm->x; y=(tempm->y-scroll_y)&(MAP_HEIGHT-1); if (0<=xcollision_cnt=0; if (tempm->friendly) Sprite3(dc2,x,y,0,$IB,"",BI=2$); else Sprite3(dc2,x,y,0,$IB,"",BI=3$); if (dc2->collision_cnt) { tempm->dead=TRUE; tempm->corpse_timeout=tS+30.0; if (tempm->friendly) { friendly_fire++; friendly_left--; Snd(200); } else { enemy_left--; Snd(50); } snd_death_timeout=tS+0.01; } } } } DCDel(dc2); } U0 Init() { I64 i,xx,yy; Man *tempm; snd_shot_timeout=snd_death_timeout=0; Snd(0); total_score=0; game_over=FALSE; main_loop_pass=0; scroll_y=MAP_HEIGHT-100; x=Fs->pix_width>>1; y=0.9*Fs->pix_height; finish_line=scroll_y+y; dx=0; dy=0; é=0; for (i=0;ipix_width-100)*RandU32/MAX_U32+50; ls[i].y=(MAP_HEIGHT-100)*RandU32/MAX_U32+50; ls[i].img=landscape_imgs[RandU16%(LANDSCAPE_TYPES-2)]; } ls[0].img=landscape_imgs[LANDSCAPE_TYPES-2]; //mountain ls[1].img=landscape_imgs[LANDSCAPE_TYPES-2]; //mountain ls[2].img=landscape_imgs[LANDSCAPE_TYPES-1]; //castle for (i=0,tempm=m;ifriendly=TRUE; if (!(i&7)) { xx=(Fs->pix_width-200)*RandU32/MAX_U32; yy=(MAP_HEIGHT-200)*RandU32/MAX_U32; } } else { tempm->friendly=FALSE; if (!(i&31)) { xx=(Fs->pix_width-200)*RandU32/MAX_U32; yy=(MAP_HEIGHT-200)*RandU32/MAX_U32; } } tempm->dead=FALSE; tempm->x=xx+64*RandI32/MAX_I32+100; tempm->y=yy+64*RandU32/MAX_I32-64+100; tempm->corpse_timeout=0; } for (i=0;ix=j<<32; j=y-24.0*Cos(é); temps->y=j<<32; temps->dx2=(SHOT_SPEED*Sin(é)+dx)*0x100000000; temps->dy2=-SHOT_SPEED*Cos(é)*0x100000000; a=Arg(temps->dx2,temps->dy2); temps->dx=Cos(a)*0x100000000; temps->dy=Sin(a)*0x100000000; shots_fired++; temps->dead=FALSE; if (!snd_death_timeout) { Snd(1000); snd_shot_timeout=tS+0.0005; } } U0 MenMove(I64 phase_group) { I64 i,j,d,closest,closest_d; for (i=phase_group;itext_attr=YELLOW<<4+CYAN; Init; DocCursor; DocClear; Fs->draw_it=&DrawIt; gun_on=FALSE; try { while (TRUE) { next_update_jiffy=sys_jiffies+JIFFY_FREQ/100; while (msg_code=ScanMsg(&p1,&p2, 1<snd_death_timeout) { snd_death_timeout=0; Snd(0); } } else if (snd_shot_timeout && tS>snd_shot_timeout) { snd_shot_timeout=0; Snd(0); } for (i=0;i>32>=Fs->pix_width|| s[i].y>>32>=Fs->pix_height) s[i].dead=TRUE; } } dx=0; if (Bt(key_down_bitmap,SC_CURSOR_LEFT)) { é=-15.0*ã/180.0; dx=-2; } else if (Bt(key_down_bitmap,SC_CURSOR_RIGHT)) { é=15.0*ã/180.0; dx=2; } x+=dx; while (x>=Fs->pix_width) x-=Fs->pix_width; while (x<0) x+=Fs->pix_width; //It takes too much CPU do do all these all the time. nobound_switch (main_loop_pass&7) { case 0: nobound_switch (main_loop_pass>>3&7) { case 0: if (--y<20) game_over=TRUE; case 2: case 4: case 6: MenFight(main_loop_pass>>4%PHASES_GROUPS); break; case 1: case 3: case 5: case 7: MenMove (main_loop_pass>>4%PHASES_GROUPS); break; } case 4: break; case 2: case 6: if (gun_on) FireShot; break; case 1: case 3: case 5: case 7: CheckCollisions; break; } main_loop_pass++; scroll_y--; SleepUntil(next_update_jiffy); total_score=5*(MAX_ENEMY-enemy_left) +10*enemy_by_friendly -200*friendly_fire -10*(tS-t0) -shots_fired; if (game_over) { tf=tS; Sleep(500); FlushMsgs; while (!ScanKey(&p1)&&friendly_left) { total_score+=500; Snd(2000); Sleep(150); Snd(0); Sleep(50); friendly_left--; } total_score+=500*friendly_left; if (total_score>best_score) best_score=total_score; if (!p1) p1=GetChar(,FALSE); if (p1==CH_ESC||p1==CH_SHIFT_ESC) goto to_done; gun_on=FALSE; Init; } } to_done: GetMsg(,,1<