Regarding Allegro

Hi, i am trying to create a galaxian similar game by using c++ and allegro. The problem right now is the in order for the alien to move slowly, i have to use the rest() function, which also decreases the user ship movement speed as all drawing and updating functions are in the same while loop. Are there any suggestions of how to solve this problem?

Thanks in Advance
I've never used Allegro, but surely when you move an object using any graphical library API, you specify a distance or a speed on the function call?
Would have to see the code, know which library you are using (A3 *outdated*, A4 or the new A5), or you could go to Allegro.cc to get help. I'm part of the community there too, but the guys there use Allegro more than I do.
Last edited on by closed account z6A9GNh0
Specific to Allegro? I'm unsure. In general? You can do it by getting a vector of the direction you want your object to move, normalize it, multiply it by a specified movement rate and use the resulting vector to update the coordinates of your object.

Here's a rough example (Object, Point2D, and Vector2D are ficticious):
1
2
3
4
5
6
7
8
9
10
11
12
13
Object alien;

double moveRate = 2.5;

Point2D a = {10.0, 5.0}; // x, y
Point2D b = {20.0, 20.0}; // x, y
Vector2D moveDir = b - a; // Vector from Point A to Point B

moveDir = moveDir.Normalize();
moveDir *= moveRate; 

alien.x += moveDir.x;
alien.y += moveDir.y;


The movement rate is what will dictate how much the alien moves in the desired direction every tick.
Last edited on
Thanks for the suggestions guys.
I don't have the specific cold right now, just working on the framing. and i am using allegro A4

The overall structure probably look something like this:

main() {
while(!key[KEY_ESC]){
call update function on alien
call update function on user ship

draw alien
draw user ship
rest(100)
}
}
I know that i can change how fast an object moves by increasing the x and y distance, but that is not what im looking for. I want to keep that the same for both the alien and user ship (let's say 10 pixels each iteration), but still have them moved at different speed (maybe by using a different function than rest()?).
Any ideas?

Thanks in advance

What you're looking for is what I said. The vector is what will ultimately dictate not only how many pixels per tick an object will move, but also what direction it moves. Vectors are very important in many games so you should definitely read up on them (and I don't mean the C++ std::vector class). I could try explaining it, but I'm afraid I'd wind up making them sound more confusing than they really are.


Topic archived. No new replies allowed.