source: ttyvaders/trunk/player.c @ 12

Last change on this file since 12 was 12, checked in by Sam Hocevar, 18 years ago
  • First commit. Scrolling works, some weaponry, controls, tunnel blowing, the nuke is still ugly, almost no collision detection. Nice demo :)
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
16    return p;
17}
18
19void free_player( player *p )
20{
21    free( p );
22}
23
24void draw_player( game *g, player *p )
25{
26    GFX_GOTO( p->x + 2, p->y - 2 );
27    GFX_COLOR( GREEN );
28    GFX_WRITE( '/' );
29    GFX_WRITE( '\\' );
30    GFX_GOTO( p->x + 1, p->y - 1 );
31    GFX_WRITE( '(' );
32    GFX_COLOR( YELLOW );
33    GFX_WRITE( '(' );
34    GFX_WRITE( ')' );
35    GFX_COLOR( GREEN );
36    GFX_WRITE( ')' );
37    GFX_GOTO( p->x, p->y );
38    GFX_COLOR( GREEN );
39    GFX_WRITE( 'I' );
40    GFX_WRITE( '<' );
41    GFX_WRITE( '_' );
42    GFX_WRITE( '_' );
43    GFX_WRITE( '>' );
44    GFX_WRITE( 'I' );
45}
46
47void update_player( game *g, player *p )
48{
49    if( p->weapon )
50    {
51        p->weapon--;
52    }
53
54    if( p->dir < 0 )
55    {
56        if( p->dir == -3 && p->x > -2 ) p->x -= 1;
57        else if( p->x > -1 ) p->x -= 1;
58
59        p->dir++;
60    }
61    else if( p->dir > 0 )
62    {
63        if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
64        else if( p->x < g->w - 7 ) p->x += 1;
65        p->dir--;
66    }
67}
68
Note: See TracBrowser for help on using the repository browser.