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>",1$ $SP,"<2>",2$ $SP,"<3>",3$ $SP,"<4>",4$ $SP,"<5>",5$ #define LANDSCAPE_TYPES 4 $SP,"<6>",6$ $SP,"<7>",7$ $SP,"<8>",8$ $SP,"<9>",9$ $BG$ CSprite *l_imgs[LANDSCAPE_TYPES]= {$IB,"",6$,$IB,"",7$,$IB,"",8$,$IB,"",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;iwin_pixel_bottom+32) SpritePlot3(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->win_pixel_bottom+32) { if (tempm->dead && tTcorpse_timeout) if (!(RandU16&15)) { if (tempm->friendly) SpritePlot3(dc,tempm->x,yy,0,$IB,"",4$); else SpritePlot3(dc,tempm->x,yy,0,$IB,"",5$); } } } for (i=0,tempm=m;iy-scroll_y)&(MAP_HEIGHT-1); if (-32<=yy<=Fs->win_pixel_bottom+32) { if (!tempm->dead) { if (tempm->friendly) SpritePlot3(dc,tempm->x,yy,0,$IB,"",2$); else SpritePlot3(dc,tempm->x,yy,0,$IB,"",3$); } } } SpritePlotRotZ3b(dc,x,y,0,$IB,"",1$,é); if (tf) { t1=tf; dc->color=RED; if (game_over && Blink) GrPutS(dc,task->win_pixel_width/2-9*FONT_WIDTH/2, task->win_pixel_height/2,"Game Over"); } else { t1=tT; if (!enemy_left || !friendly_left) game_over=TRUE; } dc->color=BROWN; GrPrintF(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); GrPrintF(dc,0,8,"Total Score:%,d High Score:%,d", total_score,best_score); } #define MONO_MAN_WIDTH 32 #define MONO_MAN_HEIGHT 32 U0 CheckCollisions() { I64 i,x,y; Man *tempm; Shot *temps; CDC *dc2 =DCNew(DCT_COLOR8,GR_WIDTH,GR_HEIGHT), *friend=DCNew(DCT_COLOR8,MONO_MAN_WIDTH,MONO_MAN_HEIGHT), *enemy =DCNew(DCT_COLOR8,MONO_MAN_WIDTH,MONO_MAN_HEIGHT); DCFill(friend); SpritePlot3(friend,MONO_MAN_WIDTH/2,MONO_MAN_HEIGHT/2,0,$IB,"",2$); DCFill(enemy); SpritePlot3(enemy ,MONO_MAN_WIDTH/2,MONO_MAN_HEIGHT/2,0,$IB,"",3$); dc2->color=WHITE; 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) GrBlot(dc2,x-MONO_MAN_WIDTH/2,y-MONO_MAN_HEIGHT/2,friend); else GrBlot(dc2,x-MONO_MAN_WIDTH/2,y-MONO_MAN_HEIGHT/2,enemy); if (dc2->collision_cnt) { tempm->dead=TRUE; tempm->corpse_timeout=tT+30.0; if (tempm->friendly) { friendly_fire++; friendly_left--; Snd(200); } else { enemy_left--; Snd(50); } snd_death_timeout=tT+0.01; } } } } DCDel(friend); DCDel(enemy); 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->win_pixel_width>>1; y=0.9*Fs->win_pixel_height; finish_line=scroll_y+y; dx=0; dy=0; é=0; for (i=0;iwin_pixel_width-100)*RandU32/MAX_U32+50; ls[i].y=(MAP_HEIGHT-100)*RandU32/MAX_U32+50; ls[i].img=l_imgs[RandU16%(LANDSCAPE_TYPES-2)]; } ls[0].img=l_imgs[LANDSCAPE_TYPES-2]; //mountain ls[1].img=l_imgs[LANDSCAPE_TYPES-2]; //mountain ls[2].img=l_imgs[LANDSCAPE_TYPES-1]; //castle for (i=0,tempm=m;ifriendly=TRUE; if (!(i&7)) { xx=(Fs->win_pixel_width-200)*RandU32/MAX_U32; yy=(MAP_HEIGHT-200)*RandU32/MAX_U32; } } else { tempm->friendly=FALSE; if (!(i&31)) { xx=(Fs->win_pixel_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=tT+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 && tT>snd_shot_timeout) { snd_shot_timeout=0; Snd(0); } for (i=0;i>32>=Fs->win_pixel_width|| s[i].y>>32>=Fs->win_pixel_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->win_pixel_width) x-=Fs->win_pixel_width; while (x<0) x+=Fs->win_pixel_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*(tT-t0) -shots_fired; if (game_over) { tf=tT; 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<