|
Animation movement and figting |
Pontus Wallberg
Member #7,196
May 2006
|
Hello. Im making a game in C++, but I have rused in to some problems that I hope you can help me with or give advice about what I can do. 1. The first thing I want to do is making it look like the main character is moving, like changing pictures between like 4-5 pictures if I press the UP-Key, and another 4-5picuters when hitting the DOWN-key. You get the idea i hope? Because now it looks like the character i sliding on the map, because it's 1 picture for each key. Any tips ? Code? 2. The second thing I want to do is making figthing possible. Right now the main char can run in to eniemes randomly placed on the map, then it starts a new window, kind of looking like Pokemon style, the main char on side och the enimie on the other. So in this place I want to be able to attack of course perhaps something else like run och defence. But in order for this to happen I must make HP points/bar Exp points/bar and hitpower like that stuff. I have been making some classes for Main char and Enimies, but I dont get it to work and have no Idea how to make a HP / Exp bar. So any tips on this ? I would be greatful for any tips you have on either qeustion. You should perhaps have my code: #include <allegro.h> BITMAP *Buffer; bool Quit = false; textout_ex(Buffer, font, "Attack", MenuX+15, MenuY+18, makecol(0, 0, 0), -1); draw_sprite(Buffer, theMouse, mouse_x, mouse_y); rectfill(Buffer, 218, 88, 422, 193, makecol(0, 0, 0)); rectfill(Buffer, 229, 99, 411, 121, makecol(0, 0, 0)); if(mouseOver1) rectfill(Buffer, 230, 100, 410, 120, makecol(130, 130, 130)); textout_ex(Buffer, font, "Exit to Windows", 240, 107, makecol(0, 0, 0), -1); if(mouse_x>(230) && mouse_y>(100) && mouse_x<(410) && mouse_y<(120) && mouse_b & 1) Quit=true; void setLocs(int newXloc, int newYloc){ xLoc=newXloc; yLoc=newYloc-1; }; void setLvl(int prevLvl, int lvl) if(fadeInt<253 && FaDe)fadeInt+=3; rectfill(blackscreen, 0, 0, SCREEN_W, SCREEN_H, makecol(0, 0, 0)); draw_sprite(screen, Buffer, 0, 0); }; if(Quit) battleOn=false; if(char_pan<0 && !menuToggle)char_pan++; drawMenu(); int frames = 0; void increeseXloc() bool BtnUp = true; menuToggle = false; if (allegro_init() != 0) if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { loadingScreen = load_bitmap("load.bmp", NULL); char_up = load_bitmap("char_up.bmp", NULL); blackscreen = create_bitmap(SCREEN_W, SCREEN_H); theMouse = load_bitmap("mouse.bmp", NULL); setLvl(0, 1); Buffer = create_bitmap(640, 480); int dir = 3; install_int(fps, 1000); srand(time(NULL)); while(!Quit) if(loading)draw_sprite(screen, loadingScreen, 0, 0); drawMainMenu(); draw_sprite(Buffer, Bakgrund, 0, 0); //moveChar(); if(xLoc==4 && yLoc==-1 && yPic==(48*-1) && level==1 && enterLvl) setLvl(1, 2); if(xLoc!=0 && xLoc!=9 && yLoc!=-1 && yLoc!=8) if(resting) enterLvl = true; if(charDir==1){draw_sprite(Buffer, char_left, xPic, yPic);} if(enemyContact()&&resting) textout_ex(Buffer, font, "CONTACT!", 10, 30, makecol(0, 0, 0), -1); drawMenu(); acquire_screen(); if(key[KEY_A] && !menuToggle) if(key[KEY_LEFT] && !menuToggle) //Pundus |
kdevil
Member #1,075
March 2001
|
1) Say you have an array of bitmaps for the character: BITMAP *walking[FRAMES]; float walkingcount; const float animation_speed = 0.5; int walkingframe; //each time the character moves forward: walkingcount += animation_speed; if (walkingcount >= FRAMES) walkingcount = 0; walkingframe = int(walkingcount); //when drawing: draw_sprite(somebuffer, walking[walkingframe], x, y); 2) I didn't look at the code (use the [CODE] [/CODE] tags!), but a quick and simple HP bar would be something like:
----- |
umperio
Member #3,474
April 2003
|
And what about editing your post to use the code tag? |
Michael Faerber
Member #4,800
July 2004
|
Quote: HTML Mockup Code As a nitpicker, I have to say that the forums don't use HTML! -- |
Pontus Wallberg
Member #7,196
May 2006
|
Ok, I didn't know about the code tags, this is my first post on allegro. I just want to ask something about kdevils answer on the first question. Ok say that I make that array, how do declare the array to the diffrent Bitmaps, I mean where in the code do should I load the the diffrent Bitmaps? And also should I make 4 diffrents arrays for each UP,DOWN,LEFT,RIGTH key? Thx for the answer man and I will use the code tags next time. //Pundus |
umperio
Member #3,474
April 2003
|
Quote: I will use the code tags next time. You can still edit your first post and use the code tags now. |
Pontus Wallberg
Member #7,196
May 2006
|
Its says that its to big if i put it between code tags, max is 64 kb and the my post i 110 kb with the code tags. |
Mokkan
Member #4,355
February 2004
|
Maybe attach the source file instead? And to answer your latest question, you can use a multidimensional array... so like, frames[LEFT][0], frames[LEFT][1], etc... maybe that's what you want? You might do that for each action, like walkframes[LEFT][0], and punchframes[LEFT][0].
|
kdevil
Member #1,075
March 2001
|
Yeah, you could use multidimensional arrays. As for loading the bitmaps: //instead of char_right = load_bitmap("char_right.bmp", NULL); walking[RIGHT][0] = load_bitmap("char_right0.bmp", NULL); walking[RIGHT][1] = load_bitmap("char_right1.bmp", NULL); walking[RIGHT][2] = load_bitmap("char_right2.bmp", NULL); //etc...
----- |
Onewing
Member #6,152
August 2005
|
Ick, that sounds like a lot of maintenance to me. I use a sprite class that has a BITMAP for a picture containning all the character motions and one BITMAP that is used for storing the single image. Every time I change where I'm grabbing from off the set-of-pictures-bitmap, I update the single-motion bitmap. This way, outside of the class, I only have to worry about the single-motion bitmap (and I don't really have to worry about that either, considering the class takes care of drawing itself too). This isn't a new method or anything. ------------ |
kdevil
Member #1,075
March 2001
|
True, my example certainly isn't the best way to deal with sprites. I'd instead use a datafile, a sprite class like you said, or something else that requires less "copy & paste", but as a simple example it works well enough. ----- |
LennyLen
Member #5,313
December 2004
|
Some things I picked up from your code... int rs = 0; while(rs<=100) { data[rs]=0; rs++; } This is the same as: for (int rs = 0; rs < 100; rs++) data[rs] = 0; Also, your version will crash when rs == 100. You only declared data as an array of 100 ints, which is data[0..99]. This applies to your resetEnemyData() function as well. Your setLvl() function is extremely inelegant. I can't suggest a better method, since I'm not sure what you're doing, and the code is too messy (especially without indentation) for me to bother deciphering it. But, with 35 lines in a row of data[##] = 1;, you really need to look at finding a better way. I also noticed that your main() function is 140 lines long. You should break it up into smaller sections, such as setup routines, input routines, output routines. Then group related functions together in their own files and link them together rather than having one huge source file.
|
Pontus Wallberg
Member #7,196
May 2006
|
Hello again guys! I really appreciate all the help you have gave me. I have just one more question, I'm going to make it possible to attack the enemies when they pop up. Should I make a class for the enemies, where I declare the HP, Strength, Level, Hitpower? I just one some pointers where to begin, it always the hardest. //Pundus |
|