delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/25/20:58:26

Message-ID: <33885A26.1C685A99@directnet.com.br>
Date: Sun, 25 May 1997 12:26:30 -0300
From: Cristovao Braga <overlord AT directnet DOT com DOT br>
MIME-Version: 1.0
To: dingfam AT imag DOT net
CC: DJGPP list <djgpp AT delorie DOT com>
Subject: Re: Moving a Rotated Sprite
References: <6795 AT campus DOT directnet DOT com DOT br>

Hello, there.

I'm going to tell you how I got my pacman clone working. I think it has
a lot to do with what you want, although the game type is completely
different. It is set as a tile based game, so if your racing game is of
the same kind...

I have the monsters and pacman held in a structure with the following
information: the tile they are in and the offset in respect to the
centre of the tile (pixels). Each tile is 20x20 pixels and each game
cycle (ghost or pacman or whatever) they move 1 pixel in the direction
they are going. When the offset for either x or y is -10 it is set to
+10 and the ghost/pacman goes to the tile to the left/top, similarly
when the offset reaches +10.

To draw them, their upper left corner is given by the formulas:
xpos = 40 + 20 * x + x_off
ypos = 40 + 20 * y + y_off,
where 40 is the distance from the border of the screen, 20 is the size
of the tile, x the position on the board and x_off the offset. You'll
probably have to make adjustments due to the rotation and to display
only part of the board on the screen.

Doing it that way, I get all them to move smoothly, partly because they
only move vertically or horizontally. If your cars are going to move on
free direction, you might want to use floats or fixed point for the
offsets (floats should be faster on the pentium and above).

I can send the game with sources to you or anyone who wants, that's
about 300k with no executables.

Regards,

Cristovao Barbosa Braga Dalla Costa.

dingfam AT imag DOT net wrote:
> 
> heya
>   I'm working on a 2D racing game with Allegro, and I want to use the
> rotate_sprite() function to spin the cars around. So far, I've had no
> problems with this. However, what I want to know is how do I move the
> rotated cars forwards and backwards relative to their current position.
> 
> If you need any more information, just email me.
> 
> Any help is apprectiated,
> chris

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019