source: ttyvaders/trunk/player.c @ 16

Last change on this file since 16 was 16, checked in by Sam Hocevar, 18 years ago
  • moved nuke from explosions to weapons.
  • used a cool Bresenham algorithm to draw the nuke circles.
  • nuke collides with aliens.
File size: 1.2 KB
Line 
1
2#include <stdlib.h>
3
4#include "common.h"
5
6/* Init tunnel */
7player * create_player( game *g )
8{
9    player *p = malloc(sizeof(player));
10
11    p->x = g->w / 2;
12    p->y = g->h - 3;
13    p->dir = 0;
14    p->weapon = 0;
15    p->nuke = 0;
16
17    return p;
18}
19
20void free_player( player *p )
21{
22    free( p );
23}
24
25void draw_player( game *g, player *p )
26{
27    GFX_GOTO( p->x + 2, p->y - 2 );
28    GFX_COLOR( GREEN );
29    GFX_WRITE( '/' );
30    GFX_WRITE( '\\' );
31    GFX_GOTO( p->x + 1, p->y - 1 );
32    GFX_WRITE( '(' );
33    GFX_COLOR( YELLOW );
34    GFX_WRITE( '(' );
35    GFX_WRITE( ')' );
36    GFX_COLOR( GREEN );
37    GFX_WRITE( ')' );
38    GFX_GOTO( p->x, p->y );
39    GFX_COLOR( GREEN );
40    GFX_WRITE( 'I' );
41    GFX_WRITE( '<' );
42    GFX_WRITE( '_' );
43    GFX_WRITE( '_' );
44    GFX_WRITE( '>' );
45    GFX_WRITE( 'I' );
46}
47
48void update_player( game *g, player *p )
49{
50    if( p->weapon )
51    {
52        p->weapon--;
53    }
54
55    if( p->nuke )
56    {
57        p->nuke--;
58    }
59
60    if( p->dir < 0 )
61    {
62        if( p->dir == -3 && p->x > -2 ) p->x -= 1;
63        else if( p->x > -1 ) p->x -= 1;
64
65        p->dir++;
66    }
67    else if( p->dir > 0 )
68    {
69        if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
70        else if( p->x < g->w - 7 ) p->x += 1;
71        p->dir--;
72    }
73}
74
Note: See TracBrowser for help on using the repository browser.