Browse Source

* ship has vx and vy.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@58 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 22 years ago
parent
commit
7acf82d0d3
3 changed files with 22 additions and 15 deletions
  1. +2
    -2
      src/common.h
  2. +3
    -3
      src/main.c
  3. +17
    -10
      src/player.c

+ 2
- 2
src/common.h View File

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: common.h,v 1.11 2002/12/23 10:06:27 sam Exp $
* $Id: common.h,v 1.12 2002/12/23 13:13:04 sam Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -102,7 +102,7 @@ typedef struct
typedef struct
{
int x, y;
int dir;
int vx, vy;
int weapon, nuke;

} player;


+ 3
- 3
src/main.c View File

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: main.c,v 1.12 2002/12/23 12:47:36 sam Exp $
* $Id: main.c,v 1.13 2002/12/23 13:13:04 sam Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -98,7 +98,7 @@ static void start_game (game *g)
skip = 1;
break;
case 'h':
g->p->dir = -3;
g->p->vx = -2;
break;
case 'j':
if( g->p->y < g->h - 2 ) g->p->y += 1;
@@ -107,7 +107,7 @@ static void start_game (game *g)
if( g->p->y > 1 ) g->p->y -= 1;
break;
case 'l':
g->p->dir = 3;
g->p->vx = 2;
break;
case 'n':
if( g->p->nuke == 0 )


+ 17
- 10
src/player.c View File

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: player.c,v 1.4 2002/12/22 18:44:12 sam Exp $
* $Id: player.c,v 1.5 2002/12/23 13:13:04 sam Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,7 +31,8 @@ player * create_player( game *g )

p->x = g->w / 2;
p->y = g->h - 2;
p->dir = 0;
p->vx = 0;
p->vy = 0;
p->weapon = 0;
p->nuke = 0;

@@ -71,18 +72,24 @@ void update_player( game *g, player *p )
p->nuke--;
}

if( p->dir < 0 )
p->x += p->vx;

if( p->vx < 0 )
{
p->vx++;
}
else if( p->vx > 0 )
{
if( p->dir == -3 && p->x > -2 ) p->x -= 1;
else if( p->x > -1 ) p->x -= 1;
p->vx--;
}

p->dir++;
if( p->x < 1 )
{
p->x = 1;
}
else if( p->dir > 0 )
else if( p->x > g->w - 7 )
{
if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
else if( p->x < g->w - 7 ) p->x += 1;
p->dir--;
p->x = g->w - 7;
}
}


Loading…
Cancel
Save