Sign in to follow this  
ColKowalski

Introduction and a question to boot.

Recommended Posts

Hi, I'm new to the forums themselves, but I have been using GD as a resource for a while. A little about myself: I've been playing games since I was a kid. Now I'm about to start computer science at uni and my passion for games hasn't gone away. That's why I'm here :) Now, let's get to business :P I'm using allegro for now to familiarise myself with timers, blitting etc. but one thing has been annoying me. all the blitting functions only take int values which makes it pretty restrictive as to what values you are allowed to use. For example, you can't make the speed of an object .5 or even divide anythinge too because you'll end up with decimals. I was thinking of writing a rounding function but I bet that's the completely wrong way of doing things. Col.

Share this post


Link to post
Share on other sites
Rounding is a bad idea. Firstly it won't accomplish what you think it would accomplish. Secondly the coordinate plane that makes up your screen is integer where the upper left corner is (0,0). That is why the blit routines don't take a decimal value. To accomplish your speed your best bet is to use a vector because not only does it contain the speed of the sprite but it also contains the direction in which the sprite is moving. Yes vectors do allow for decimal values be it float or double. Since I assume you are using C++ because of allegro you can obtain the vector type by using #include<vector> I wish I could give you a example of it in use but I moved away from C++ when C# and MDX came out. Now that MDX is gone I am using C# and XNA.

Share this post


Link to post
Share on other sites
I have made a vector struct for that purpose but when I try to use its members in the blitting function it still passes the float value while it needs an int.

void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);

Share this post


Link to post
Share on other sites
It's been (wow) almost 3 years since I touched C++ and my retention sucks horribly but I believe you should be looking into casts to get that float to turn into an int. Or, you could just do away with the precision (do you really need it for your movement?) and create a vector of integers so the types match.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this