![]() |
|
shot and diagonal movents |
dengue
Member #12,790
April 2011
|
hi ,i dont speak very well english(i speak spanish) so i will try be very puntual in the things that i need help.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Dengue said: The first problem is that i have adaptet de diagonal movent but i can't adapt the movent to diagonal imagenes, i dont know how do it, You need to keep track of position, speed, and the angle of your object : 1#include <math.h>
2
3typedef struct Moveable {
4 float x; // x position
5 float y; // y position
6 float xvel; // x velocity
7 float yvel; // y velocity
8 float speed; // total speed
9 float angle; // angle in degrees
10};
11
12Moveable NewMoveable(int x , int y , float speed , float angle) {
13 Moveable m;
14 m.x = x;
15 m.y = y;
16 SetSpeedAndAngle(&m , speed , angle);
17 return m;
18}
19
20void SetSpeedAndAngle(Moveable* m , float speed , float angle) {
21 m->speed = speed;
22 m->angle = angle;
23 m->xvel = speed*cos(angle*((2.0f*M_PI)/360.0f));
24 m->yvel = speed*sin(angle*((2.0f*M_PI)/360.0f));
25}
26
27void Move(Moveable* m) {
28 m->x += m->xvel;
29 m->y += m->yvel;
30}
Example usage : Moveable m = NewMoveable(x , y , 25.0f/60.0f , 45.0);// Moves 25 pixels per second down and right
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
weapon_S
Member #7,859
October 2006
![]() |
I can't really figure out what you are doing at the moment, but it seems you use a fixed set of bitmaps. And you seem to have player input combined with updating the ship. You might want to look into storing the player's (and bullet's) directions as an angle and using rotate_sprite. Then it will also get a speed. (And only in the 'update' part of the program, the speed will have effect.) Some other remarks. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
I didn't see the attached file before, but after looking at it I have a few comments : main.cpp said: Don't use delete on a pointer that you didn't use new to create. Use destroy_bitmap on imagenes[0] thru imagenes[8] instead. Your MoverX and MoverY functions should not draw anything to the screen, they should only change the position of your objects. Separate logic and drawing. You don't clear_to_color on your buffer, so your program must look pretty messy right now. You use draw_sprite to draw the buffer, but you should use blit instead. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Desmond Taylor
Member #11,943
May 2010
![]() |
Thanks Edgar Reynaldo, That code that you posted helped me Thanks again |
dengue
Member #12,790
April 2011
|
thanks Edgar Reynaldo and weapon_S, i am reading the articles of the angles and i am editing my code, thanks a lot
|
|