Guest User

Untitled

a guest
Jul 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.46 KB | None | 0 0
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <pspdebug.h>
  7. #include <psprtc.h>
  8. #include <pspgu.h>
  9. #include <pspgum.h>
  10. #include <pspdisplay.h>
  11. #include "main.h"
  12. #include "actor.h"
  13.  
  14. enum GameMode { MODE_TITLE, MODE_MAINMENU, MODE_CREDITS, MODE_SETTINGS, MODE_ORDER, MODE_DAY };
  15. enum GameMode gameMode;
  16.  
  17. //enum InventoryType { IT_STRAWBERRY,IT_VANILLA,IT_CHOCOLATE,IT_BRAIN,IT_CONE,IT_WHIPPEDCREAM,IT_SPRINKLES,IT_CHERRIES,IT_SHOTGUN,IT_AMMO,IT_APRON,ITMAX };
  18. char *inventoryName[]={"Strawberry","Vanilla","Chocolate","Brain","Cone","Whipped Cream","Sprinkles","Cherries","Shotgun","Ammo","Apron" };
  19. char *inventoryIconName[]={"data/straw16.png","data/van16.png","data/choc16.png","data/brain16.png","data/cone16.png","data/whipped16.png","data/sprinkles16.png","data/cher16.png","data/shotgun16.png","data/ammo16.png", "data/apron16.png" };
  20. Image *inventoryIcon[ITMAX];
  21.  
  22. struct Inventory {
  23. int count;
  24. int capacity;
  25. };
  26.  
  27. struct Message {
  28. char text[256];
  29. int timer;
  30. };
  31.  
  32. struct Game {
  33. // persistent stuff
  34. int level;
  35. int score;
  36. int cash;
  37. struct Inventory inventory[12];
  38. struct Actor staff[8];
  39. int staffCount;
  40. // day specific stuff
  41. struct Actor *activeStaff;
  42. struct Actor customer[8];
  43. int customerCount;
  44. struct Actor zombie[8];
  45. int zombieCount;
  46. struct Dialog *dialog;
  47.  
  48. // transient stuff
  49. struct WavefrontModel *room; // wavefront for drawing
  50. int selected; // currently selected menu item
  51. int timer;
  52. struct Message message[256];
  53. int messageCount;
  54.  
  55. // debug camera
  56. float theta,phi;
  57. float dist;
  58. } game;
  59. // debug camera
  60. int ax,ay;
  61. int dir;
  62.  
  63. ScePspFVector3 from={0,100,50},to={0,50,0},up={0,1,0};
  64. ScePspFMatrix4 view;
  65.  
  66. struct DialogTable creditsTable[]={
  67. {0,NULL,"Game play programming by hardhat"},
  68. {0,NULL,"Sound effect programming by Zack"},
  69. {0,NULL,"Parlor model by Meyitzo"},
  70. {0,NULL,"Actor models: see readmes."},
  71. {0,NULL,"Additional skins by Incomplete"},
  72. {0,NULL,"Sound effects by meanrabbit.com"},
  73. {0,NULL,"Music by Incomplete"},
  74. {0,NULL,"Title screen by Incomplete"},
  75. {1,NULL,"Continue"},
  76. };
  77.  
  78. struct DialogTable settingsTable[]={
  79. {10,NULL,"Sound effect|On"},
  80. {11,NULL,"Music Volume|10"},
  81. {12,NULL,"Temperature|Degrees C"},
  82. {1,NULL,"Return to Main Menu"},
  83. };
  84.  
  85. struct DialogTable orderTable[]={
  86. {-1,NULL,"Item|Inventory|Supplies Cost|Quantity to Order"},
  87. {10,NULL,"Strawberry|25|$10|0"},
  88. {11,NULL,"Chocolate|25|$10|0"},
  89. {12,NULL,"Vanilla|25|$10|0"},
  90. // {13,NULL,"Brain|0|$10|0"},
  91. {14,NULL,"Cones|100|$10|0"},
  92. // {15,NULL,"Shotgun|0|$1000|0"},
  93. // {16,NULL,"Ammo|0|$1|0"},
  94. {17,NULL,"Whipped Cream|0|$30|0"},
  95. {18,NULL,"Sprinkles|0|$30|0"},
  96. {19,NULL,"Cherries|0|$30|0"},
  97. {20,NULL,"Apron|0|$2500|0"},
  98. {-2,NULL,"Total||$2500|"},
  99. {1,NULL,"Start Day"},
  100. };
  101.  
  102. void setMode(int mode)
  103. {
  104. if(gameMode!=mode) {
  105. gameMode=mode;
  106. if(game.dialog) freeDialog(game.dialog);
  107. game.dialog=0;
  108. if(mode==MODE_CREDITS) {
  109. game.dialog=newDialog("Zombie Dessert Credits");
  110. addDialogItemRows(game.dialog,creditsTable,sizeof(creditsTable)/sizeof(struct DialogTable));
  111. } else if(mode==MODE_SETTINGS) {
  112. game.dialog=newDialog("Settings");
  113. addDialogItemRows(game.dialog,settingsTable,sizeof(settingsTable)/sizeof(struct DialogTable));
  114. } else if(mode==MODE_ORDER) {
  115. game.dialog=newDialog("Order Supplies");
  116. addDialogItemRows(game.dialog,orderTable,sizeof(orderTable)/sizeof(struct DialogTable));
  117. selectDialogItem(game.dialog,1);
  118. } else if(mode==MODE_DAY) {
  119. game.selected=0;
  120. }
  121. }
  122. }
  123.  
  124. void newLevel(int level)
  125. {
  126. struct Inventory *inventory=game.inventory;
  127. game.level=level;
  128. if(level==0) {
  129. int i;
  130. for(i=0;i<ITMAX;i++) {
  131. if(i<3) {
  132. inventory[i].count=25;
  133. inventory[i].capacity=75;
  134. } else if(i==IT_CONE) {
  135. inventory[i].count=200;
  136. inventory[i].capacity=600;
  137. } else if(i==IT_APRON) {
  138. inventory[i].count=1;
  139. inventory[i].capacity=1;
  140. } else {
  141. inventory[i].count=0;
  142. inventory[i].capacity=0;
  143. }
  144. }
  145. }
  146. }
  147.  
  148. void newGame()
  149. {
  150. game.level=0;
  151. game.score=0;
  152. game.staffCount=1;
  153. game.activeStaff=game.staff+0;
  154. game.customerCount=0;
  155. game.zombieCount=0;
  156. int i;
  157. for(i=0;i<ITMAX;i++) {
  158. game.inventory[i].capacity=1;
  159. game.inventory[i].count=0;
  160. if(!inventoryIcon[i]) {
  161. inventoryIcon[i]=loadPng(inventoryIconName[i]);
  162. swizzleFast(inventoryIcon[i]);
  163. }
  164. }
  165. game.theta=3.14159265f; //2.54f;
  166. game.phi=0.84f; //0.61f;
  167. game.dist=238; //301;
  168. struct Actor *a=game.staff+0;
  169. newActor(a,"ai","ctf_r");
  170. a->x=32;
  171. a->z=-86;
  172. a->angle=GU_PI/2;
  173. a->playerControlled=1;
  174. game.staffCount=1;
  175. game.zombieCount=0;
  176. game.customerCount=0;
  177. game.timer=0;
  178. if(game.dialog) freeDialog(game.dialog);
  179. game.dialog=0;
  180. newLevel(game.level);
  181. }
  182.  
  183. void startTitle()
  184. {
  185. game.room=loadWavefront("parlor");
  186. newGame();
  187. gameMode=MODE_MAINMENU;
  188. }
  189.  
  190. char *mainMenuText[]={"New Game","Continue Game","Settings","Credits","Quit"};
  191. int mainMenuCount=5;
  192.  
  193. void drawMainMenu()
  194. {
  195. int w,h,x;
  196. int i;
  197. extentMessage(&w,&h,FONT_HEADLINE,"Zombie Dessert");
  198. x=480/2-w/2;
  199. drawMessage(x,14,FONT_HEADLINE,"Zombie Dessert");
  200. for(i=0;i<mainMenuCount;i++) {
  201. int font=i!=game.selected?FONT_SMALL:FONT_SMALLHIGHLIGHT;
  202. extentMessage(&w,&h,font,mainMenuText[i]);
  203. x=480/2-w/2;
  204. drawMessage(x,85+i*16,font,mainMenuText[i]);
  205. }
  206. if(game.selected<0 || game.selected>=mainMenuCount) game.selected=0;
  207. }
  208.  
  209. void drawDay()
  210. {
  211. char msg[256];
  212. int w,h;
  213.  
  214. drawFilledRect(0,0,100,272,GU_RGBA(0,0,0,128));
  215. drawFilledRect(320,0,160,48,GU_RGBA(255,255,255,128));
  216. drawFilledRect(320,0,1,48,GU_RGBA(0,0,0,255));
  217. drawFilledRect(320,0,160,1,GU_RGBA(0,0,0,255));
  218. drawFilledRect(479,0,1,48,GU_RGBA(0,0,0,255));
  219. drawFilledRect(320,47,160,1,GU_RGBA(0,0,0,255));
  220.  
  221. sprintf(msg,"Day %d",game.level+1);
  222. extentMessage(&w,&h,FONT_BODYHIGHLIGHT,msg);
  223. int x=5;
  224. drawMessage(x,15,FONT_BODYHIGHLIGHT, msg);
  225. int i;
  226. int y=0;
  227. for(i=0;i<ITMAX;i++) {
  228. if(inventoryIcon[i] /* && inventory[i].capacity>0 */) {
  229. drawSprite(0,0,16,16,inventoryIcon[i],0,50+y);
  230. char buf[128];
  231. sprintf(buf,"%d of %d",game.inventory[i].count,game.inventory[i].capacity);
  232. drawMessage(18,50+y,FONT_SMALL,buf);
  233. y+=16;
  234. }
  235. }
  236. x=324;
  237. drawMessage(x,2,FONT_MESSAGE,"Add ");
  238. extentMessage(&w,&h,FONT_MESSAGE,"Add ");
  239. drawMessage(x+w,2,FONT_MESSAGE,inventoryName[game.selected]);
  240. for(i=0;i<ITMAX;i++) {
  241. if(game.activeStaff->state&(1<<i)) {
  242. static Image *defaultIcon=0;
  243. if(!defaultIcon) {
  244. defaultIcon=newImage(16,16);
  245. int i;
  246. for(i=0;i<16*16;i++) {
  247. defaultIcon->data[i]=0xffffffc0;
  248. }
  249. }
  250. drawSprite(0,0,16,16,inventoryIcon[i]?inventoryIcon[i]:defaultIcon,x,24);
  251. x+=18;
  252. }
  253. }
  254.  
  255. #if 0
  256. strcpy(msg,"Press START to end day.");
  257. extentMessage(&w,&h,FONT_MESSAGE,msg);
  258. x=480/2-w/2;
  259. drawMessage(x,240,FONT_MESSAGE, msg);
  260. #endif
  261. }
  262.  
  263. int showFps=0;
  264. void draw()
  265. {
  266. u64 oldTick,newTick;
  267.  
  268. pspDebugScreenSetXY(0,1);
  269. sceGuStart(GU_DIRECT,gulist);
  270. // clear screen
  271. sceRtcGetCurrentTick(&oldTick);
  272. sceGuClearColor(GU_RGBA(0x57,0x73,0x9b,255)); //GU_RGBA(0x80,0xc0,0xc0
  273. sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
  274.  
  275. sceGuTexWrap(GU_REPEAT, GU_REPEAT);
  276.  
  277. // move camera.
  278. sceGumMatrixMode(GU_VIEW);
  279. sceGumLoadIdentity();
  280. sceGumLookAt(&from,&to,&up);
  281. gumLoadIdentity(&view);
  282. gumLookAt(&view,&from,&to,&up);
  283. sceGumMatrixMode(GU_MODEL);
  284. sceGumLoadIdentity();
  285.  
  286. sceGuClearColor(GU_RGBA(0x80,0xc0,0xc0,255));
  287. sceGuClearDepth(0);
  288.  
  289. sceGuColor(0xffffffff);
  290. sceGuEnable(GU_LIGHTING);
  291. sceGuEnable(GU_TEXTURE_2D);
  292. drawWavefrontPartial(game.room,0);
  293. sceGuDisable(GU_LIGHTING);
  294. int i;
  295. int used;
  296. for(i=0;i<game.staffCount;i++) {
  297. drawActor(game.staff+i);
  298. }
  299. used=sceGuFinish();
  300. //printf("Used %d;",used);
  301. sceGuSync(0,0);
  302. sceGuStart(GU_DIRECT,gulist);
  303. for(i=0;i<game.customerCount;i++) {
  304. drawActor(game.customer+i);
  305. }
  306. used=sceGuFinish();
  307. //printf("Used %d;",used);
  308. sceGuSync(0,0);
  309. sceGuStart(GU_DIRECT,gulist);
  310. for(i=0;i<game.zombieCount;i++) {
  311. drawActor(game.zombie+i);
  312. }
  313. used=sceGuFinish();
  314. //printf("Used %d;",used);
  315. sceGuSync(0,0);
  316. sceGuStart(GU_DIRECT,gulist);
  317.  
  318. sceGuSpecular(1);
  319. sceGuModelColor(0,0xffffff,0xffffff,0xffffff);
  320. drawWavefrontPartial(game.room,1);
  321. sceGuModelColor(0,0xffffff,0xffffff,0xffffff);
  322.  
  323. if(gameMode==MODE_MAINMENU) drawMainMenu();
  324. else if(gameMode==MODE_DAY) drawDay();
  325. if(game.dialog) drawDialog(game.dialog);
  326.  
  327. if(game.messageCount>0) {
  328. int w=0,h=8;
  329. const char *msg=game.message[0].text;
  330. extentMessage(&w,&h,FONT_MESSAGE,msg);
  331. drawFilledRect(240-w/2-20,136-h/2-20,w+40,h+40,GU_RGBA(0,0,0,64));
  332. drawMessage(240-w/2,136,FONT_MESSAGE,msg);
  333. }
  334.  
  335. // End the frame
  336. used=sceGuFinish();
  337. //printf("Used %d gulist words\n",used);
  338. sceGuSync(0,0);
  339. if(showFps) {
  340. static u64 realOldTick=0;
  341. sceRtcGetCurrentTick(&newTick);
  342. pspDebugScreenSetXY(0,32);
  343. pspDebugScreenPrintf("FPS: %.2f (%.2f)",1000000.0f/(newTick-oldTick),((newTick-oldTick)/1000.0f));
  344. pspDebugScreenPrintf("real: %.2f (%.2f)",1000000.0f/(newTick-realOldTick),((newTick-realOldTick)/1000.0f));
  345. realOldTick=newTick;
  346. pspDebugScreenSetXY(0,1);
  347. pspDebugScreenPrintf("theta: %.2f, phi: %.2f, dist=%.1f",game.theta,game.phi,game.dist);
  348. }
  349. #ifdef DEBUG_TEARING
  350. pspDebugScreenSetXY(42,40);
  351. static int flipCount=0;
  352. pspDebugScreenPrintf("frame %d",flipCount++);
  353. #endif
  354. sceDisplayWaitVblankStart();
  355. //printf("-------------------\n");
  356. drawBuffer=sceGuSwapBuffers();
  357. pspDebugScreenSetOffset((int)drawBuffer);
  358. }
  359.  
  360. struct Target {
  361. float x,z;
  362. float angle;
  363. };
  364. struct Target entranceTarget[]={
  365. {120,-160,GU_PI},
  366. {-190,-160,GU_PI*3/2},
  367. {-190,10,0},
  368. };
  369. struct Target waitingTarget[]={
  370. {-72,-86,-GU_PI/2},
  371. {-72,-46,-GU_PI/2},
  372. {-72,46,-GU_PI/2},
  373. {-72,86,-GU_PI/2},
  374. // queueing
  375. {-120,-86,-GU_PI/2},
  376. {-120,-46,-GU_PI/2},
  377. {-120,46,-GU_PI/2},
  378. {-120,86,-GU_PI/2},
  379. };
  380.  
  381. int compareTargets(struct Target *target,struct Actor *a)
  382. {
  383. return target->x==a->target[0] && target->z==a->target[2];
  384. }
  385.  
  386. struct Target *nextTarget(struct Actor *a)
  387. {
  388. int i;
  389.  
  390. if(a==NULL) return entranceTarget+0;
  391. if(a->wants==PT_NONE) { // time to go.
  392. for(i=0;i<3;i++) {
  393. if(compareTargets(entranceTarget+i,a)) {
  394. if(i==0) return NULL; // disappear
  395. return entranceTarget+i-1;
  396. }
  397. }
  398. return entranceTarget+2;
  399. }
  400. for(i=0;i<3-1;i++) {
  401. if(compareTargets(entranceTarget+i,a)) {
  402. return entranceTarget+i+1;
  403. }
  404. }
  405. if(compareTargets(entranceTarget+2,a)) {
  406. // need to find an empty waiting spot.
  407. for(i=0;i<8;i++) {
  408. int used=0;
  409. int j;
  410. for(j=0;j<game.customerCount;j++) {
  411. used+=compareTargets(waitingTarget+i,game.customer+j);
  412. }
  413. for(j=0;j<game.zombieCount;j++) {
  414. used+=compareTargets(waitingTarget+i,game.zombie+j);
  415. }
  416. if(used==0) return waitingTarget+i;
  417. }
  418. // all of the spots are full it seems.
  419. printf("All waiting spots are full. Trying again in a minute.\n");
  420. a->wants=PT_NONE;
  421. return entranceTarget+2;
  422. }
  423. // we are currently in the lineup maybe?
  424. for(i=0;i<8;i++) {
  425. if(compareTargets(waitingTarget+i,a)) {
  426. if(i<4) return waitingTarget+i; // not change.
  427. // see if we can move up in the line.
  428. int used=0;
  429. int j;
  430. for(j=0;j<game.customerCount;j++) {
  431. used+=compareTargets(waitingTarget+i-4,game.customer+j);
  432. }
  433. for(j=0;j<game.zombieCount;j++) {
  434. used+=compareTargets(waitingTarget+i-4,game.zombie+j);
  435. }
  436. if(used==0) return waitingTarget+i-4; // move up in the line
  437. return waitingTarget+i; // no change.
  438. }
  439. }
  440. return entranceTarget+1; // I'm not sure what's going on, so let's reset.
  441. }
  442.  
  443. void addMessage(const char *message,int timer)
  444. {
  445. if(game.messageCount>9) { // we don't care about the messages, so just overwrite the first one.
  446. strcpy(game.message[0].text,message);
  447. game.message[0].timer=timer;
  448. return;
  449. }
  450. strcpy(game.message[game.messageCount].text,message);
  451. printf(">>>%s\n",message);
  452. game.message[game.messageCount++].timer=timer;
  453. }
  454.  
  455. void newZombie(struct Actor *a)
  456. {
  457. newActor(a,"corpse","gunned");
  458. a->actorType=AT_ZOMBIE;
  459. a->wants=PT_BRAIN;
  460. a->state=(1<<IT_BRAIN)|(1<<IT_CONE);
  461. a->z=entranceTarget[0].z;
  462. a->y=0;
  463. a->x=entranceTarget[0].x;
  464. struct Target *t=nextTarget(0);
  465. if(!t) {
  466. // disable this actor
  467. } else {
  468. setActorTarget(a,t->x,t->z,t->angle);
  469. }
  470. }
  471.  
  472. void newCustomer(struct Actor *a)
  473. {
  474. newActor(a,"civi","civi");
  475. a->actorType=AT_CUSTOMER;
  476. const ProductType pt[]={PT_CHOCOLATE,PT_STRAWBERRY,PT_VANILLA};
  477. const InventoryType it[]={IT_AMMO,IT_BRAIN,IT_CHOCOLATE,IT_STRAWBERRY,IT_VANILLA};
  478. a->wants=pt[(rand()>>16)%3];
  479. a->state=(1<<it[a->wants])|(1<<IT_CONE);
  480. a->z=entranceTarget[0].z;
  481. a->y=0;
  482. a->x=entranceTarget[0].x;
  483. struct Target *t=nextTarget(0);
  484. if(!t) {
  485. // disable this actor
  486. } else {
  487. setActorTarget(a,t->x,t->z,t->angle);
  488. }
  489. }
  490.  
  491. void update(unsigned long elapsed)
  492. {
  493. int i;
  494. for(i=0;i<game.staffCount;i++) {
  495. updateActor(game.staff+i,elapsed);
  496. }
  497. for(i=0;i<game.customerCount;i++) {
  498. updateActor(game.customer+i,elapsed);
  499. struct Actor *a=game.customer+i;
  500. if(a->x==a->target[0] && a->z==a->target[2]) {
  501. struct Target *t=nextTarget(a);
  502. if(!t) {
  503. // disable this actor
  504. newCustomer(a);
  505. } else {
  506. setActorTarget(a,t->x,t->z,t->angle);
  507. }
  508. if(i==2 && (a->x!=a->target[0] || a->z!=a->target[2])) printf("C2: %.2f,%.2f -> %.2f,%.2f\n",a->x,a->z,a->target[0],a->target[2]);
  509. }
  510. }
  511. for(i=0;i<game.zombieCount;i++) {
  512. updateActor(game.zombie+i,elapsed);
  513. struct Actor *a=game.zombie+i;
  514. if(a->x==a->target[0] && a->z==a->target[2]) {
  515. struct Target *t=nextTarget(a);
  516. if(!t) {
  517. // disable this actor
  518. newZombie(a);
  519. } else {
  520. setActorTarget(a,t->x,t->z,t->angle);
  521. }
  522. }
  523. }
  524.  
  525. if(game.zombieCount<4 && game.zombieCount<game.customerCount && game.timer==0) {
  526. game.timer=1000;
  527. struct Actor *a=game.zombie+game.zombieCount;
  528. newZombie(a);
  529. game.zombieCount++;
  530. } else if(game.customerCount<4 && game.timer==0) {
  531. game.timer=1000;
  532. struct Actor *a=game.customer+game.customerCount;
  533. newCustomer(a);
  534. game.customerCount++;
  535. } else {
  536. game.timer-=elapsed;
  537. if(game.timer<0) game.timer=0;
  538. }
  539.  
  540. // message update
  541. if(game.messageCount>0) {
  542. game.message[0].timer-=elapsed;
  543. if(game.message[0].timer<0) {
  544. game.messageCount--;
  545. if(game.messageCount>0) {
  546. memcpy(game.message,game.message+1,sizeof(struct Message)*game.messageCount);
  547. }
  548. }
  549. }
  550.  
  551. if(game.dialog) updateDialog(game.dialog,elapsed);
  552.  
  553. // now update the camera
  554. if(ax!=0) game.theta+=ax/100.0f*elapsed/1000.0f;
  555. if(game.theta>GU_PI) game.theta-=2*GU_PI;
  556. if(game.theta<-GU_PI) game.theta+=2*GU_PI;
  557. if(ay!=0) game.phi+=ay/100.0f*elapsed/1000.0f;
  558. if(game.phi>GU_PI/2) game.phi=GU_PI/2;
  559. if(game.phi<-GU_PI/2) game.phi=-GU_PI/2;
  560. if(dir!=0) game.dist+=dir;
  561. from.x=to.x+game.dist*cosf(game.theta)*cosf(game.phi);
  562. from.y=to.y+game.dist*sinf(game.phi);
  563. from.z=to.z+game.dist*sinf(game.theta)*cosf(game.phi);
  564. }
  565.  
  566. int handleAnalog(int dx,int dy)
  567. {
  568. dx-=100;
  569. if(dx>0 && dx<56) dx=0; else if(dx>0) dx-=56;
  570. if(dx>-20 && dx<20) dx=0; // extra deadzone
  571. dy-=100;
  572. if(dy>0 && dy<56) dy=0; else if(dy>0) dy-=56;
  573. if(dy>-20 && dy<20) dy=0; // extra deadzone
  574.  
  575. ax=dx;
  576. ay=dy;
  577.  
  578. return 0;
  579. }
  580.  
  581. void handleMainMenu(button)
  582. {
  583. switch(button) {
  584. case BT_UP:
  585. playSound(SFX_MENUNEXT);
  586. game.selected--;
  587. if(game.selected<0) game.selected=mainMenuCount-1;
  588. break;
  589. case BT_DOWN:
  590. playSound(SFX_MENUNEXT);
  591. game.selected++;
  592. if(game.selected>=mainMenuCount) game.selected=0;
  593. break;
  594. case BT_START:
  595. case BT_CROSS:
  596. playSound(SFX_MENUSELECT);
  597.  
  598. if(game.selected==2) {
  599. setMode(MODE_SETTINGS);
  600. break;
  601. } else if(game.selected==3) {
  602. setMode(MODE_CREDITS);
  603. break;
  604. } else if(game.selected==4) {
  605. exitRequest=1;
  606. }
  607. newGame();
  608. setMode(MODE_ORDER);
  609. break;
  610. }
  611. }
  612.  
  613. void handleDay(button)
  614. {
  615. int i;
  616.  
  617. handleActor(game.activeStaff,button);
  618. switch(button) {
  619. case BT_LEFT:
  620. playSound(SFX_MENUNEXT);
  621. game.selected=getInventorySelection(game.activeStaff);
  622. break;
  623. case BT_RIGHT:
  624. playSound(SFX_MENUNEXT);
  625. game.selected=getInventorySelection(game.activeStaff);
  626. break;
  627. case BT_UP:
  628. playSound(SFX_MENUNEXT);
  629. game.selected=getInventorySelection(game.activeStaff);
  630. break;
  631. case BT_DOWN:
  632. playSound(SFX_MENUNEXT);
  633. game.selected=getInventorySelection(game.activeStaff);
  634. break;
  635. case BT_SQUARE:
  636. playSound(SFX_MENUNEXT);
  637. game.selected=getInventorySelection(game.activeStaff);
  638. break;
  639. case BT_TRIANGLE:
  640. // grab the shotgun, and arm it
  641. playSound(SFX_LOADGUN);
  642. game.activeStaff->state=(1<<IT_SHOTGUN);
  643. break;
  644. case BT_CROSS:
  645. if(game.activeStaff->actorState==AS_WAITING && game.activeStaff->playerSelection!=BIN_NONE) {
  646. if(getInventorySelection(game.activeStaff)==IT_CONE) {
  647. playSound(SFX_CONE);
  648. game.activeStaff->state=(1<<IT_CONE);
  649. setActorAction(game.activeStaff,MT_POINT);
  650. }
  651. // scoop ice cream/etc.
  652. if(game.activeStaff->state&(1<<IT_CONE)) {
  653. playSound(SFX_SCOOP);
  654. game.activeStaff->state|=(1<<game.selected);
  655. setActorAction(game.activeStaff,MT_POINT);
  656. } else {
  657. playSound(SFX_LOSE);
  658. }
  659. }
  660. break;
  661. case BT_CIRCLE:
  662. // deliver the ice cream/shoot the zombie
  663. for(i=0;i<game.customerCount;i++) {
  664. if(game.activeStaff->state==game.customer[i].state) {
  665. playSound(SFX_WIN);
  666. // Make the match go away.
  667. printf("customer %d going away\n",i);
  668. game.customer[i].state=0;
  669. game.customer[i].wants=PT_NONE;
  670. game.activeStaff->state=0;
  671. break;
  672. }
  673. }
  674. for(i=0;i<game.zombieCount;i++) {
  675. if( game.activeStaff->state==game.zombie[i].state) {
  676. playSound(SFX_WIN);
  677. // Make the match go away.
  678. printf("zombie %d going away\n",i);
  679. game.zombie[i].state=0;
  680. game.zombie[i].wants=PT_NONE;
  681. game.activeStaff->state=0;
  682. }
  683. }
  684. if(game.activeStaff->state&(1<<IT_SHOTGUN)) {
  685. playSound(SFX_BANG);
  686. i=0;
  687. printf("zombie %d is shot\n",i);
  688. } else {
  689. playSound(SFX_LOSE);
  690. printf("no match for order");
  691. }
  692. game.activeStaff->state=0;
  693. break;
  694. case BT_START:
  695. gameMode=MODE_MAINMENU;
  696. break;
  697. }
  698. }
  699.  
  700. void handleDayDown(button)
  701. {
  702. }
  703.  
  704. int handleJoy( enum Buttons button, int up)
  705. {
  706. switch(button) {
  707. case BT_LTRIGGER:
  708. if(up==0) dir=1;
  709. else if(dir==1 && up==1) dir=0;
  710. break;
  711. case BT_RTRIGGER:
  712. if(up==0) dir=-1;
  713. else if(dir==-1 && up==1) dir=0;
  714. showFps=1-showFps;
  715. break;
  716. default:
  717. break;
  718. }
  719. if(up==1) {
  720. int rc=0;
  721. if(gameMode==MODE_MAINMENU) handleMainMenu(button);
  722. else if(gameMode==MODE_DAY) handleDay(button);
  723. else if(game.dialog) rc=handleDialog(game.dialog,button);
  724. if(gameMode==MODE_CREDITS && rc>0) setMode(MODE_MAINMENU);
  725. else if(gameMode==MODE_SETTINGS && rc>0) {
  726. if(rc==1) setMode(MODE_MAINMENU);
  727. else if(rc==10) replaceDialogColumnText(game.dialog,"Deactivated",FONT_SMALL,1,rc);
  728. else if(rc==11) replaceDialogColumnText(game.dialog,"Yes!",FONT_SMALL,1,10);
  729. } else if(gameMode==MODE_ORDER && rc>0) {
  730. if(rc==1) setMode(MODE_DAY);
  731. else if(rc==10) replaceDialogColumnText(game.dialog,"1",FONT_SMALL,3,rc);
  732. else if(rc==11) replaceDialogColumnText(game.dialog,"100",FONT_SMALL,3,10);
  733. }
  734. } else {
  735. if(gameMode==MODE_DAY) handleDayDown(button);
  736. }
  737.  
  738. return 0;
  739. }
Add Comment
Please, Sign In to add comment