rotate_angle problem
Neil Black

I can't get rotate_angle to work! It compiles fine but when I run it the game crashes. Here's the code.

1#include <allegro.h>
2 
3BITMAP* buffer;
4BITMAP* Ship;
5int Rot_Angle;
6 
7 
8 
9void Init_Stuff(){
10 // Set up the game
11 allegro_init();
12 install_keyboard();
13 set_color_depth(16);
14 set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
15
16 buffer = create_bitmap(640, 480);
17
18 Ship = load_bitmap( "Ship.bmp", NULL);
19 Rot_Angle = 64;
20}
21 
22int main(){
23
24 clear_keybuf();
25
26 rotate_sprite(screen, Ship, 10, 10, 64);
27 rotate_sprite(screen, Ship, 50, 10, 128);
28 rotate_sprite(screen, Ship, 90, 10, 174);
29
30 readkey();
31}
32END_OF_MAIN();

That's as far as I got, because rotate_sprite wouldn't work. When I take out the rotate_sprite statements, it doesn't crash. I just noticed I put a semi-colon on END_OF_MAIN(), but I don't think that's the problem.

gnolam

You're not checking if Ship was loaded successfully. Check it. I'm betting it's 1) failing 2) because Ship.bmp is in the wrong directory.

Also, you need to itofix() those (Allegro) angles. But you shouldn't really store things in Allegro degrees anyway - use radians in floats/doubles and convert when passing the angle argument to rotate_sprite().

Neil Black

How do I convert, and how do I use itofix()?

The bitmap is fine, it works with draw_sprite()

gnolam

Ok, in that case it's crashing because you're never actually calling Init_Stuff(). :P
Add error checking. Now.
You also aren't destroying your loaded and created bitmaps like you should...

Quote:

How do I convert

The conversion factor to convert an angle in angle system 1 into angle system 2 is equal to the period for angle system 2 divided by the period for angle system 1. For radians -> allegro degrees, this is <math>\frac{256}{2\pi}</math>
In other words, allegro_angle = ftofix(radian_angle*256.0f/(2.0f*M_PI));

Quote:

and how do I use itofix()?

It's in the manual.

[EDIT]
Various edits to fix mistakes caused by sleep deprivation.

Neil Black

How do I do error checking, and how do I destroy loaded and created bitmaps? Links to tutorials would be good.

gnolam
Possumdude0 said:

How do I do error checking, and how do I destroy loaded and created bitmaps? Links to tutorials would be good.

There are examples. There's a manual. There are even examples in the manual. Please read them.

Neil Black

I don't know what to look for in the manual. I mean, now I know I could look up destroying bitmaps, but before I didn't even know I needed to do that. Then I figured you could easily point me to some information, since you seem to have some experience and know what you're talking about.

But I guess I'll just sift through that huge manual for the tiny bit of information I need.

gnolam
I said:

There are examples.

Possumdude0 said:

Then I figured you could easily point me to some information, since you seem to have some experience and know what you're talking about.

I just did. At some point, you will have to start looking for information on your own. We can't spoon-feed you everything.
"Give a man a fish and you have fed him for today. Teach a man to fish and you have fed him for a lifetime."

Neil Black

Unless over-fishing kills off all his food, or he loses his fishing pole, or runs out of bait. ;)

Seriously, I just don't know enough to know what information to look for. I checked out destroy bitmap in the manual. Do I call it for every bitmap at the end of my program?

Also, when you said look in the manual, I thought you meant that big long text document that came with allegro, I didn't know the manual here was sorted out with links and stuff for easy searching. I learn something new every day! :)

Thanks.

gnolam
Quote:

Also, when you said look in the manual, I thought you meant that big long text document that came with allegro

You should also have a HTML version.

Neil Black

I haven't seen one, but it may be in there somewhere, I'll look next time I can (sometime in the next 3 days, stupid work cutting into my slacking off time!)

EDIT:
Yep, I've got the HTML version.

Oh yeah, it's working now, too :)

Thread #590926. Printed from Allegro.cc