選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

68 行
1.1 KiB

  1. #include <stdlib.h>
  2. #include "common.h"
  3. /* Init tunnel */
  4. player * create_player( game *g )
  5. {
  6. player *p = malloc(sizeof(player));
  7. p->x = g->w / 2;
  8. p->y = g->h - 2;
  9. p->dir = 0;
  10. p->weapon = 0;
  11. p->nuke = 0;
  12. return p;
  13. }
  14. void free_player( player *p )
  15. {
  16. free( p );
  17. }
  18. void draw_player( game *g, player *p )
  19. {
  20. gfx_goto( p->x + 2, p->y - 2 );
  21. gfx_color( GREEN );
  22. gfx_putstr( "/\\" );
  23. gfx_goto( p->x + 1, p->y - 1 );
  24. gfx_putchar( '(' );
  25. gfx_color( YELLOW );
  26. gfx_putstr( "()" );
  27. gfx_color( GREEN );
  28. gfx_putchar( ')' );
  29. gfx_goto( p->x, p->y );
  30. gfx_color( GREEN );
  31. gfx_putstr( "I<__>I" );
  32. }
  33. void update_player( game *g, player *p )
  34. {
  35. if( p->weapon )
  36. {
  37. p->weapon--;
  38. }
  39. if( p->nuke )
  40. {
  41. p->nuke--;
  42. }
  43. if( p->dir < 0 )
  44. {
  45. if( p->dir == -3 && p->x > -2 ) p->x -= 1;
  46. else if( p->x > -1 ) p->x -= 1;
  47. p->dir++;
  48. }
  49. else if( p->dir > 0 )
  50. {
  51. if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
  52. else if( p->x < g->w - 7 ) p->x += 1;
  53. p->dir--;
  54. }
  55. }