diff --git a/src/common.h b/src/common.h index 70b2843..171c542 100644 --- a/src/common.h +++ b/src/common.h @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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; diff --git a/src/main.c b/src/main.c index 65dccf8..006c9b0 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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 ) diff --git a/src/player.c b/src/player.c index a6c5016..5363ef4 100644 --- a/src/player.c +++ b/src/player.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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; } }