You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

69 lines
1.2 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 - 3;
  9. p->dir = 0;
  10. p->weapon = 0;
  11. return p;
  12. }
  13. void free_player( player *p )
  14. {
  15. free( p );
  16. }
  17. void draw_player( game *g, player *p )
  18. {
  19. GFX_GOTO( p->x + 2, p->y - 2 );
  20. GFX_COLOR( GREEN );
  21. GFX_WRITE( '/' );
  22. GFX_WRITE( '\\' );
  23. GFX_GOTO( p->x + 1, p->y - 1 );
  24. GFX_WRITE( '(' );
  25. GFX_COLOR( YELLOW );
  26. GFX_WRITE( '(' );
  27. GFX_WRITE( ')' );
  28. GFX_COLOR( GREEN );
  29. GFX_WRITE( ')' );
  30. GFX_GOTO( p->x, p->y );
  31. GFX_COLOR( GREEN );
  32. GFX_WRITE( 'I' );
  33. GFX_WRITE( '<' );
  34. GFX_WRITE( '_' );
  35. GFX_WRITE( '_' );
  36. GFX_WRITE( '>' );
  37. GFX_WRITE( 'I' );
  38. }
  39. void update_player( game *g, player *p )
  40. {
  41. if( p->weapon )
  42. {
  43. p->weapon--;
  44. }
  45. if( p->dir < 0 )
  46. {
  47. if( p->dir == -3 && p->x > -2 ) p->x -= 1;
  48. else if( p->x > -1 ) p->x -= 1;
  49. p->dir++;
  50. }
  51. else if( p->dir > 0 )
  52. {
  53. if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
  54. else if( p->x < g->w - 7 ) p->x += 1;
  55. p->dir--;
  56. }
  57. }