Thread: Animated pictures

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    Animated pictures

    I'm trying to change the way sprites are animated. They currently use 1 or more small drawings and rotated to make the effect. I want to add more animation pictures to generate a better effect. Below is the original code for smoke. I've tried several ways to add several new 128x128 textures, can someone help me with this code, so I can do all the sprites, which are mostly very small.

    Code:
    void DrawSmokeHW(SpriteData* pSpriteData, RenderInfo *render, SmokeNode* pSmokeNode, long count)
    {
    	HWSprite*	pHwsprite;
    	long		sprite_type = pSpriteData->Type+2;	// use straight sprite
    	float		x1, y1, x2, y2;
    	long		w1, w2;
    	long		width1, width2;
    	long		dx, dy;
    	long		text_id;
    	float		xf, yf;
    	float		dxf, dyf;
    	float		wf;
    	float		dw;
    	float		inv_count;
    
    	SetPerspectiveLinearWidth(1024);
    
    	if (pSpriteData->Alpha > 0.0f)
    	{
    		text_id = aSpriteTextureId[sprite_type];
    		if (text_id >= 0)
    		{
    			dx = render->ScreenX - pSmokeNode->NextScreenX;
    			dy = render->ScreenY - pSmokeNode->NextScreenY;
    
    			if (dx != 0 || dy != 0)
    			{
    				pHwsprite = &(HWSpriteList[sprite_type]);
    
    				// this is used later...
    
    				width1 = (long)(HW_TRAIL_SCALE * pSpriteData->Size / (float)((render->Dist>>ShiftAmount3D)+1)); 
    				width2 = (long)(HW_TRAIL_SCALE * pSmokeNode->NextSize / (float)((pSmokeNode->NextDist>>ShiftAmount3D)+1));
    			
    				if (width1 > 0 || width2 > 0)
    				{
    					if (GameSetup.EffectsDetail > LOW_DETAIL)
    					{
    						if (Abs(dx) > Abs(dy))
    						{
    							if (dx > 0)
    							{
    								x1 = pSmokeNode->NextScreenX;
    								y1 = pSmokeNode->NextScreenY;
    								w1 = width2;
    
    								x2 = render->ScreenX;
    								y2 = render->ScreenY;
    								w2 = width1;
    							}
    							else if (dx < 0)
    							{
    								x1 = render->ScreenX;
    								y1 = render->ScreenY;
    								w1 = width1;
    
    								x2 = pSmokeNode->NextScreenX;
    								y2 = pSmokeNode->NextScreenY;
    								w2 = width2;
    							}
    
    							// set cordinates
    							spt[0].XP = x1;
    							spt[0].YP = y1 - w1;
    							spt[0].ZR = ZCOORD;
    
    							spt[1].XP = x2;
    							spt[1].YP = y2 - w2;
    							spt[1].ZR = ZCOORD;
    
    							spt[2].XP = x2;
    							spt[2].YP = y2 + w2;
    							spt[2].ZR = ZCOORD;
    
    							spt[3].XP = x1;
    							spt[3].YP = y1 + w1;
    							spt[3].ZR = ZCOORD;
    						}
    						else
    						{
    							if (dy > 0)
    							{
    								x1 = pSmokeNode->NextScreenX;
    								y1 = pSmokeNode->NextScreenY;
    								w1 = width2;
    
    								x2 = render->ScreenX;
    								y2 = render->ScreenY;
    								w2 = width1;
    							}
    							else if (dy < 0)
    							{
    								x1 = render->ScreenX;
    								y1 = render->ScreenY;
    								w1 = width1;
    
    								x2 = pSmokeNode->NextScreenX;
    								y2 = pSmokeNode->NextScreenY;
    								w2 = width2;
    							}
    
    							// set cordinates
    							spt[0].XP = x1 + w1;
    							spt[0].YP = y1;
    							spt[0].ZR = ZCOORD;
    
    							spt[1].XP = x2 + w2;
    							spt[1].YP = y2;
    							spt[1].ZR = ZCOORD;
    
    							spt[2].XP = x2 - w2;
    							spt[2].YP = y2;
    							spt[2].ZR = ZCOORD;
    
    							spt[3].XP = x1 - w1;
    							spt[3].YP = y1;
    							spt[3].ZR = ZCOORD;
    						}
    
    						SetHwSpriteFrame(sprite_type, pSpriteData->Frame); 
    
    						SetTextureSpace16(text_id);
    
    						set_sprite_texture_coord(pHwsprite, 0);
    							
    						//--- Draw Sprite 
    						SpriteAlpha = (UBYTE)(255.0f * pSpriteData->Alpha);
    
    						DrawClippedPolyR(4, List, FLAT_TEXTURE_TRANS_ALPHA, 0);
    
    						SpriteAlpha = default_alpha;
    					}
    
    					// make sure to use this scatter smoke flag!
    					if (count > 1)
    					{
    						sprite_type = pSpriteData->Type;
    						text_id = aSpriteTextureId[sprite_type];
    						if (text_id >= 0)
    						{
    							pHwsprite = &(HWSpriteList[sprite_type]);
    							SetTextureSpace16(text_id);
    							SetHwSpriteFrame(sprite_type, pSpriteData->Frame); 
    
    							inv_count = 1.0f / (float)count;
    
    							xf = (float)pSmokeNode->NextScreenX;
    							yf = (float)pSmokeNode->NextScreenY;
    
    							dxf = (float)dx * inv_count;
    							dyf = (float)dy * inv_count;
    							
    							wf = (float)width2;
    							dw = ((float)width1 - wf) * inv_count;
    
    							while (--count) 
    							{
    								xf += dxf;
    								yf += dyf;
    								wf += dw;
    
    								DrawSpriteHW(pHwsprite, xf, yf, wf, pSpriteData->Alpha, (UBYTE)(count&0x03));				
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    
    	return;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The thing to do would be to construct a small program which contains the essence of the problem to be solved (draws small sprites).

    For one thing, it might enable you to post a complete self-contained program when asking for help. Posting one function out of a very large program, without all the supporting struct declarations just doesn't work for us.

    For another, you'll be able to focus specifically on the job at hand.
    Also, the turn-around time on edit-compile-test will be that much shorter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Jesus Christ! Bless GOD, Jesus Christ, The Holy Spirit, and Mary# Then bless my real mom Huong Thi Thuyen Vu. Honours to my real mom Huong Thi Thuyen Vu. Honours to my real dad Nguyen Binh Thuy. Congratulations to my real two sisters Nguyen Khoa Thi and Nguyen Khoa Thuyen. I've been programming for almost 4 years now. I have 2 years officially of college credits and almost 2 years independent at home work and experiences. Animations are one of the most amazing things you can do with a computer screen. However you need inter-disciplinary studies to accomplish a few things. Some computers come with sprites so it is easy. Other computers requires you to make your very own sprite system. I'll take you from the barest minimum. Let's say you wanted smokes. The barest you need is two sprites. The first sprite for the initial image. The second sprite for the change in smoke movement. You would alternate between the two images and you have smoking. I don't want to do your homework for you however I suggest Borland Turbo C 2.0 user's guide and reference guide. Make sure you get the one with the compiler software. I need to warn you it is for a very old system called "MS-DOS". However you learn best when you are taken back to the basics. Windows should be easier to understand once you learn the basics. However I program specifically for MS-DOS environment using DOSBox 0.74 so don't quote me on it. Thank you Jesus Christ. P.S. My one sister is a programmer by trade. She graduated from a University for programming and is working now for over 10 years in the computer business. Thank you Jesus Christ.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Tien Nguyen View Post
    I suggest Borland Turbo C 2.0 user's guide and reference guide. Make sure you get the one with the compiler software.
    Worst advice given on this forum, ever.

    Quote Originally Posted by Tien Nguyen View Post
    However you learn best when you are taken back to the basics.
    How do you know how the OP learns best?

    Quote Originally Posted by Tien Nguyen View Post
    Windows should be easier to understand once you learn the basics.
    Wrong. If you want to learn Windows, then learn Windows. Don't waste your time on other archaic, obsolete, and completely useless systems.

    Quote Originally Posted by Tien Nguyen View Post
    However I program specifically for MS-DOS environment
    I feel so sorry for you right now. I don't understand why anyone would want to do this voluntarily.

    Quote Originally Posted by Tien Nguyen View Post
    Thank you Jesus Christ.
    We get it. You're a Christian. It serves no purpose to fill up half your post with stuff like this. It helps no one, least of all, the one asking for help. Try to keep your posts concise and relevant.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    AGAIN

    The above link is to a program that I made for MS-DOS. However it should work for 32-bit versions of Windows XP. It shows an example how Borland Turbo C 2.01 is used to animate an object. You can use the a-key for left movement. d-key moves right. w-key moves up. s-key moves down. q-key quits the program. Once again it took me an equivalent of a 4-year degree from a prestigeous college. So don't rust it. Take your time and just work and study from the bottom up. Once I tried to skip steps and stunted my grow for years until I went back and did the basics.

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by Tien Nguyen View Post
    The above link ...
    If it took you four years at a "prestigeous(sic) college" to learn this than you're even more stupid than your mindless religious rant already proved.

  7. #7
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    haha actually it took me since I was 9 years old. I first bought a Commodore 64 through my parents. They got me a magazine and I just enterred machine language in all numbers. Some cool pictures flew across the screen and that's how I got started. I'm just mediocre. There are people out there who made games and produce it on discs for sale with fancy artworks and all. However I love what I'm doing. Programming is my life. There is not a day that goes by when I don't just get out of bed and type a few lines. So you got me wrong. I'm the stupidest person ever to exist past present and future hehe Maybe thirty years and growing and never graduated. Just messing around with programming. haha

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by algorism View Post
    If it took you four years at a "prestigeous(sic) college" to learn this than you're even more stupid than your mindless religious rant already proved.
    Keep in mind that a "prestigious college" in that corner of the world will still teach MS-DOS and Turbo C, and nothing about Linux, Windows, or modern C and C++ standards. So this is just par for the course. They're churning out developers by the thousands, who still don't know anything about developing software for the modern world.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by Elkvis View Post
    Keep in mind that a "prestigious college" in that corner of the world will still teach MS-DOS and Turbo C, and nothing about Linux, Windows, or modern C and C++ standards. So this is just par for the course. They're churning out developers by the thousands, who still don't know anything about developing software for the modern world.
    You may be right. However I don't know much about Windows programming. I've had a few brief experiments something along the lines of VisualBasics, and even SDL graphics integration. But for what we are considering I do have to confess I am confined to the ancient world long forgotten many eons ago that is somehow in existance in the modern era.

  10. #10
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Well, I promised that I would take you from beginning to end of animation at least for MS-DOS using Borland Turbo C 2.01. In modern systems you can use DOSBox 0.74 for Apple, Linux, and Windows to replace MS-DOS. Anyways here is the source code, which does contain somewhat assembly prefaces.

    Code:
    #pragma inline
    #include <dos.h>
    #include <conio.h>
    
    void setgfx()
    {
    _AL = 19;
    _AH = 0;
    geninterrupt(0x10);
    }
    
    void settxt()
    {
    _AL = 3;
    _AH = 0;
    geninterrupt(0x10);
    }
    
    void plotxyc(int x, int y, int c)
    {
    _CX = x;
    _DX = y;
    _AL = c;
    _AH = 0x0c;
    geninterrupt(0x10);
    }
    
    void plotcrossbow(int xpos, int ypos, int cpos)
    {
    int bow[2][12][12] =
    {
    
    {
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
    },
    
    {
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
    {  0,  0,  0,  0, 12, 12, 12, 12,  0,  0,  0,  0},
    {  0,  0,  0, 12,  0,  0,  0,  0, 12,  0,  0,  0},
    {  0,  0,  0, 12,  0,  0,  0,  0, 12,  0,  0,  0},
    {  0,  0, 12,  0, 12,  0,  0, 12,  0, 12,  0,  0},
    {  0,  0, 12,  0,  0, 14, 14,  0,  0, 12,  0,  0},
    {  0,  0, 12,  0,  0, 14, 14,  0,  0, 12,  0,  0},
    {  0,  0, 12,  0, 12,  0,  0, 12,  0, 12,  0,  0},
    {  0,  0,  0, 12,  0,  0,  0,  0, 12,  0,  0,  0},
    {  0,  0,  0, 12,  0,  0,  0,  0, 12,  0,  0,  0},
    {  0,  0,  0,  0, 12, 12, 12, 12,  0,  0,  0,  0},
    {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
    }
    
    };
    
    int xp, yp;
    
    for(xp = 0; xp < 12; xp++)
    {
    for(yp = 0; yp < 12; yp++)
    {
    plotxyc(xpos+xp, ypos+yp, bow[cpos][yp][xp]);
    }
    }
    
    }
    
    int main()
    {
    int xpoint, ypoint, cpoint, rcpoint;
    int xdot, ydot, bdot, cdot, ddot;
    int xbow, ybow, cbow;
    int left, right, bottom, top;
    int xsight, ysight, setsight = 0;
    
    char keypress;
    
    setgfx();
    
    left = 12;
    right = 320-24;
    bottom = 200-24;
    top = 12;
    
    xbow = right;
    ybow = bottom;
    cbow = 1;
    
    xpoint = 0;
    ypoint = 100;
    cpoint = 1;
    rcpoint = 15;
    
    xdot = 0;
    ydot = 80;
    bdot = 0;
    cdot = 14;
    ddot = 0;
    
    keypress = '';
    
    start:;
    xpoint++;
    if(xpoint >= 320)
    {
    xpoint = 0;
    }
    
    cpoint++;
    if(cpoint >= 15)
    {
    cpoint = 1;
    }
    
    rcpoint--;
    if(rcpoint <= 1)
    {
    rcpoint = 15;
    }
    
    plotxyc(xdot, ydot, cdot);
    ddot++;
    if(ddot > 24)
    {
    ddot = 0;
    plotxyc(xdot, ydot, bdot);
    xdot++;
    if(xdot >= 320)
    {
    xdot = 0;
    }
    }
    
    
    
    
    
    plotxyc(xpoint, ypoint, cpoint);
    plotxyc(320-xpoint, ypoint+24, rcpoint);
    
    if(kbhit())
    {
    keypress = getch();
    
    if(keypress == 'q')
    {
    goto exitprg;
    }
    
    if(keypress == 'a')
    {
    xbow--;
    if(xbow < left)
    {
    xbow = left;
    }
    }
    
    if(keypress == 'd')
    {
    xbow++;
    if(xbow > right)
    {
    xbow = right;
    }
    }
    
    if(keypress == 's')
    {
    ybow++;
    if(ybow > bottom)
    {
    ybow = bottom;
    }
    }
    
    if(keypress == 'w')
    {
    ybow--;
    if(ybow < top)
    {
    ybow = top;
    }
    }
    
    }
    
    if(keypress == ' ')
    {
    if(setsight == 0)
    {
    setsight = 1;
    xsight = xbow;
    ysight = ybow;
    }
    }
    
    if(setsight == 1)
    {
    ysight++;
    if(ysight > bottom)
    {
    setsight = 0;
    plotcrossbow(xsight, ysight, 0);
    }
    else
    {
    plotcrossbow(xsight, ysight, cbow);
    }
    }
    
    if(keypress != '')
    {
    keypress = '';
    plotcrossbow(xbow, ybow, cbow);
    }
    
    goto start;
    
    exitprg:;
    
    getch();
    settxt();
    return(0);
    }
    Once again, I apologize for my informal style. It's a bad habit since 30 years ago. It's like my parents just has to have a pizza from time to time haha.

  11. #11
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    If you NOTICE, it uses a matrix consistent to 12x12 for a sprite. We have to define our own matrix to make it into a sprite because DOS doesn't have sprites. The graphing uses a cartesian co-ordinate system in x-axis and y-axis. You have a possible color range of 0 to 256 combos from a pallete of millions. However pallete coloring is a little complex at the moment.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Tien Nguyen View Post
    Code:
    #include <dos.h>
    #include <conio.h>
    Both of these headers are nonstandard and should not be used. Turbo C was already obsolete 20 years ago. Get a real compiler, such as GCC or MSVC.

    Quote Originally Posted by Tien Nguyen View Post
    Code:
    goto start;
    NO! BAD! Do not use goto! Use a proper loop construct if you need to repeat something.

    Also consider indenting your code. It's essentially impossible to follow without indentation. Use Col. Gibbon's original post as an example of good indentation and formatting.

    You need to stop trying to give advice on this thread. Your knowledge is outdated and is not helpful in any way.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  13. #13
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by Elkvis View Post
    Both of these headers are nonstandard and should not be used. Turbo C was already obsolete 20 years ago. Get a real compiler, such as GCC or MSVC.



    NO! BAD! Do not use goto! Use a proper loop construct if you need to repeat something.

    Also consider indenting your code. It's essentially impossible to follow without indentation. Use Col. Gibbon's original post as an example of good indentation and formatting.

    You need to stop trying to give advice on this thread. Your knowledge is outdated and is not helpful in any way.
    I do not doubt you that it is outdated. However Borland Turbo C 2.01 is based on K&R standards and that is a heavy positive. It is just tailored to DOS. Throughout my manuals there are sections that continue to be current. Other sections are specific for MS-DOS. For instance Windows using one of the NETBasics languages has images you can move and define automatically. While MS-DOS doesn't have such a thing and the colors are less. I've programmed in Windows before with one of the Windows language. Moving an image from one corner to the other. Anyways if I was a C programmer and that I am I like to see how things are done in other languages too. Although I don't use it being a programmer I like those things.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > However Borland Turbo C 2.01 is based on K&R standards and that is a heavy positive.
    K&R C is an obsolete relic.
    The minimum standard for any compiler should be C89.

    > It is just tailored to DOS.
    Another obsolete relic.
    You yourself have said the only way to make it work on a new OS is to use an emulator like DOSBox.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by Salem View Post
    > However Borland Turbo C 2.01 is based on K&R standards and that is a heavy positive.
    K&R C is an obsolete relic.
    The minimum standard for any compiler should be C89.

    > It is just tailored to DOS.
    Another obsolete relic.
    You yourself have said the only way to make it work on a new OS is to use an emulator like DOSBox.
    Jesus Christ! Bless GOD, Jesus Christ, Mary, and The Holy Spirit# Then bless my real mom Huong Thi Thuyen Vu. Honours to my real mom Huong Thi Thuyen Vu. Honours to my real dad Nguyen Binh Thuy. Congratulations to my real two sisters Nguyen Khoa Thi and Nguyen Khoa Thuyen. Here is another one. Like I said I like to do these INTROs for fun. I don't like to make games too much because that takes a lot longer. This one continues to work in modern 32 bit versions of XP. Just so you know people in the business continue to use XP now adays because it costs so much for a company to upgrade all over the world. However they don't spread it. It's like you have an oldie of your's and you keep it because it is passed from generation to generation in the family. A 1950 Mercedes Benz continues to be a beaut even now!

    ANFUN

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animated
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 05-12-2007, 09:21 PM
  2. Animated text
    By stuart_cpp in forum C++ Programming
    Replies: 36
    Last Post: 07-08-2006, 02:45 PM
  3. Animated gifs
    By Joe100 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-17-2003, 06:41 PM
  4. Animated Game
    By momegao in forum C++ Programming
    Replies: 0
    Last Post: 05-02-2003, 06:55 PM
  5. Animated avatars.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-05-2002, 05:02 PM

Tags for this Thread