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

Last change on this file since 3423 was 3423, checked in by Sam Hocevar, 11 years ago
  • Toying around with the old ttyvaders version.
  • 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 3423 2009-04-28 16:55:01Z 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
21caca_canvas_t *ship_sprite;
22
23/* Init tunnel */
24player * create_player(game *g)
25{
26    player *p = malloc(sizeof(player));
27    if(p == NULL)
28        exit(1);
29
30    p->x = g->w / 2;
31    p->y = g->h - 3;
32    p->vx = 0;
33    p->vy = 0;
34    p->weapon = 0;
35    p->special = MAX_SPECIAL;
36    p->life = MAX_LIFE;
37    p->dead = 0;
38
39    ship_sprite = caca_create_canvas(0, 0);
40    caca_import_file(ship_sprite, "data/ship.txt", "utf8");
41
42    return p;
43}
44
45void free_player(player *p)
46{
47    free(p);
48}
49
50void draw_player(game *g, player *p)
51{
52    if(p->dead)
53        return;
54
55    caca_set_frame(ship_sprite, 0);
56    caca_blit(g->cv, p->x, p->y, ship_sprite, NULL);
57}
58
59void update_player(game *g, player *p)
60{
61    if(p->dead)
62        return;
63
64    if(p->life <= 0)
65    {
66        add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);
67        p->dead = 1;
68        return;
69    }
70
71    /* Update weapon stats */
72    if(p->weapon)
73        p->weapon--;
74
75    if(p->special < MAX_SPECIAL)
76        p->special++;
77
78    /* Update life */
79    if(p->life < MAX_LIFE)
80        p->life++;
81
82    /* Update coords */
83    p->x += p->vx;
84
85    if(p->vx < 0)
86        p->vx++;
87    else if(p->vx > 0)
88        p->vx--;
89
90    if(p->x < 1)
91        p->x = 1;
92    else if(p->x > g->w - 7)
93        p->x = g->w - 7;
94}
95
Note: See TracBrowser for help on using the repository browser.