source: ttyvaders/trunk/src/player.c @ 1460

Last change on this file since 1460 was 1460, checked in by Sam Hocevar, 13 years ago
  • Bwarf, typo in the no warranty clause.
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/*
2 *  ttyvaders     Textmode shoot'em up
3 *  Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: player.c 1460 2006-12-12 01:49:48Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#include <stdlib.h>
18
19#include "common.h"
20
21cucul_canvas_t *ship_sprite;
22
23/* Init tunnel */
24player * create_player(game *g)
25{
26    cucul_buffer_t *b;
27
28    player *p = malloc(sizeof(player));
29    if(p == NULL)
30        exit(1);
31
32    p->x = g->w / 2;
33    p->y = g->h - 3;
34    p->vx = 0;
35    p->vy = 0;
36    p->weapon = 0;
37    p->special = MAX_SPECIAL;
38    p->life = MAX_LIFE;
39    p->dead = 0;
40
41    b = cucul_load_file("data/ship.caca");
42    ship_sprite = cucul_import_canvas(b, "");
43    cucul_free_buffer(b);
44
45    return p;
46}
47
48void free_player(player *p)
49{
50    free(p);
51}
52
53void draw_player(game *g, player *p)
54{
55    if(p->dead)
56        return;
57
58    cucul_set_canvas_frame(ship_sprite, 0);
59    cucul_blit(g->cv, p->x, p->y, ship_sprite, NULL);
60}
61
62void update_player(game *g, player *p)
63{
64    if(p->dead)
65        return;
66
67    if(p->life <= 0)
68    {
69        add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);
70        p->dead = 1;
71        return;
72    }
73
74    /* Update weapon stats */
75    if(p->weapon)
76        p->weapon--;
77
78    if(p->special < MAX_SPECIAL)
79        p->special++;
80
81    /* Update life */
82    if(p->life < MAX_LIFE)
83        p->life++;
84
85    /* Update coords */
86    p->x += p->vx;
87
88    if(p->vx < 0)
89        p->vx++;
90    else if(p->vx > 0)
91        p->vx--;
92
93    if(p->x < 1)
94        p->x = 1;
95    else if(p->x > g->w - 7)
96        p->x = g->w - 7;
97}
98
Note: See TracBrowser for help on using the repository browser.