This post is a portion of Part 6 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 6.0 – Bitmaps
- 6.1 – Creating Bitmaps
- 6.2 – Loading Premade Bitmaps
- 6.3 – Rotating, Scaling, Tinting Bitmaps
The final video of Part 6, in this video, we look at three functions that allow us to modify bitmaps in game.
Rotating source code can be found here.
Scaling source code can be found here.
Tinting source code can be found here.
Since you released this part on rotating im trying to figure out how to implement mouse look feature in my code using al_draw_rotated_bitmap and al_fixatan2. Got no much luck so far. first issue i got is when im moving mouse to edge angles of display it keeps rotating my object. Second, i cant figure how to do positive calculation on bottom side using:
float playerAngle = al_fixatan2(mouse_x * pos_y – pos_x * pos_y, mouse_x * pos_x + mouse_y * pos_y) % (2*ALLEGRO_PI); // Im using divide instead of modulus so it can build solution.
I know its my lack of knowing math and programming, but im actually Food Science Technician IRL who just loves games 🙂
If anyone would like to look into code i wrote let me know and i’ll link it up.
Can you email me your full source code? I think that will help me help you.
Mailed you with source code. Also i made today question here: http://gamedev.stackexchange.com/questions/17864/allegro-5-mouse-look
Im really going to learn this hard way like everything.
I watched your tutorial on rotation, and it helped me very much! I was wondering, however, if you knew how one would go about rotating a bitmap about it’s center while it’s moving across the screen? If you could help my out on this one, it would be very much appreciated.
Im happy to say that i solved this on very strange and unprofessional way.
angRadians = atan2(double(mouse_y) – double(pos_y), double(mouse_x) – double(pos_x));
playerAngle = angRadians * 0.995929659;
First of, i used math.h because allegro fixed math made me verbally curse compiler that i use. Second, 0.995929659 is random number that is close to (3 / PI) and it makes no sense but works.
Glad to hear it. Sorry I haven’t gotten to your email yet.
MIKE,
When I compile the source code, with the definitions width 1280 and height 1024, the window get out of range and I can not move that. I could minimize the parameters, but the ideia of the movements of the balls get lost.
One more thing, how i get fullscreen on Allegro 5.
Thanks!
I had the same problem, but just a little search on the web, you could resolve it!
1) Problem with the out range of window:
After creating a display, put this function al_set_window_position(display, x, y), where x and y are the upper left of the screen, where will start to draw the display, for instance: al_set_window_position(display, 100, 100).
2) For a full screen:
Before creating a display, put this function:
al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW).
But this function, according to Allegro Manual, does not make any adjustment of the screen resolution. So, it’s better to look for others functions more trustful.
Hey, I’m making a space shooter game like the one on the site, but I’m adding in the ability for the ship to rotate using the ‘A’ and ‘D’ keys. In addition, I’ve also switched the movement of the ship over to the mouse.
At this point, I’m trying to get the bullets to fire from the current position that the ship is facing. Is there some type of mathematical process or ALLEGRO function that I can use to determine the location of the ship’s front once it has been rotated? If I can figure that out, I should be able to make the bullets always shoot from the front.
Thanks.
I do not believe there is an Allegro function, but what you are talking about is angular calculations (trigonometry). Basically, you need to take a portion of your velocity and split it between the x plane and the y plane. I cover the formula to do this in my gravity demo (Part 8 I think – Sprites). Basically, if you know the angle, in radians, and the velocity, you can use sin and cos to calculate the percentage of x and y movement.
Hey do you think you can hep me with this code?
http://codepad.org/5S3UZ4wc
Its supposed to be able to have the user draw a path and then draw the bitmap along that path but for some reason it isnt drawing the bitmap at all – or the animation.
Mike, please could you help me?
I would like to start making applications for my iPhone. In C + + I have more experience and I would like to use them. Please write me an e-mail @ marek.buday@pobox.sk. Thank you.
Hi, I’ve noticed that you’ve used al_map_rgba in source code and you say in the video that alpha is between 0 and 1. However according to allegro 5.0.7 manual alpha is between 0 and 255.
Please remember that these videos were made for 5.0.1. They have have changed the function since then.
I see
Hello,
Could you explain these lines:
x = width / 2 - imageWidth / 2;
y = height / 2 - imageHeight /2;
Thanks 😉
That places the exact middle of the image in the exact middle of the screen
Could anyone please tell me how do I find a bounding box of rotating bitmap ? Im in a little bit of hurry and Im stuck right here, so I need help asap