Solved

animation help

Posted on 1998-05-27
9
687 Views
Last Modified: 2008-02-01
I would like to learn how to animate in Pascal using its standard stuff.
{
uses graph;
detectgraph(gd,gm);
initgraph(gd,gm,'c:\tp\bgi');
}
i would like to start with a tree with a few apples, and one
of them falls down, and maybe gets squished(sp?).  

Some color would be cool, if possible.  I would really like to see this
example done, so I can learn how I can achieve animation for myself.
Thanks!

jw--for me this is a hard task, but i understand it is just a for..do loop and is quite easy...but i cant do it..please
help me with source!
0
Comment
Question by:weinrj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:siabod
ID: 1217048
In 320x200 mode, do something like this :


Const
 sprite : Array[16] of Byte = (1,1,1,1,1,4,4,1,1,4,4,1,1,1,1,1);


Procedure putsprite(Inx, Iny : Word);
Var x,y : Word;
Begin
 For X:=1 to 4 do
  For Y:=1 to 4 do
     Begin
      PutPixel(Inx+X,Iny+Y, sprite[X+(Y*4)]);
     End;
End;

Procedure dropsprite;
Var Y : Word;
Begin
 For Y:=0 to 100 do
  PutSprite(10,Y);
End;

(well this is pretty ugly code,
'cos the sprite isn't cleared when moved, but it will start you up)

hope it helps you, regards, siabod
0
 
LVL 4

Expert Comment

by:siabod
ID: 1217049
If you want the sprite to animate, you'll have to make several sprite, like in a cartoon, display them after each other.
0
 
LVL 2

Expert Comment

by:kellyjj
ID: 1217050
I would look on the internet for a program called 'gpe'  It stands for Game Programmer's Encyclopieda.   All the examples are done either in assembler or pascal.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:siabod
ID: 1217051
Yes, also a good resoource is SWAG (software archival group)
its all pascal and contains loads of good stuff.
0
 

Author Comment

by:weinrj
ID: 1217052
{ This is what I have done already }
{ I know this isnt the best method of doing things, and it looks like ****, but it works, kind    of....But, if you got any ideas to improve on it, please let me know....Also, I could use help in improving the tree and the apple....}

{ PS- once i have an apple, how do i putImage apple to coordinates, so i dont have too redraw the damn thing.....?  Thanks }
program dragonKuso;

uses crt, graph;

var gd, gm, i ,x : integer;

begin
  detectGraph(gd, gm);
  initgraph(gd, gm, 'c:\tp\bgi');
  setFillStyle(solidFill, blue);
  floodFill(0,0,blue);
  setColor(14);
  circle(50,50,20);
  setFillStyle(solidFill, 14);
  floodFill(50,50,14);
  setcolor(10);
  setlinestyle(solidLn,0,thickwidth);
  line(0, 475, 650, 475);
  setLineStyle(DottedLn, 0, NormWidth);
  SetLineStyle(UserBitLn, $C3, ThickWidth);
  line(Pred(0), Pred(473), Succ(650), Succ(471));
  setLineStyle(solidLn, 0, thickWidth);
  setfillstyle(interleavefill,brown);
  bar(300,200,330,480);
  setlinestyle(solidln,0,normwidth);
  setcolor(green);
  setfillstyle(interleavefill,green);
  fillellipse(250,200,50,50);
  fillellipse(275,275,67,47);
  fillellipse(400,190,65,40);
  fillellipse(390,140,35,35);
  fillellipse(375,250,67,67);
  fillellipse(375,200,45,68);
  fillellipse(350,250,50,64);
  fillellipse(350,190,49,54);
  fillellipse(290,135,80,50);
  fillellipse(340,300,85,75);
  fillellipse(275,180,58,67);
  fillellipse(214,190,57,68);


  delay(1000); {reset video/timer initializationing }
{ appletree end....apple fall begin }
  setcolor(red);
  for i:= 1 to 190 do
     begin
        setcolor(red);
       for x:=1 to 2 do
          begin
            setlinestyle(solidLn, 0, normWidth);
            setFillStyle(solidFill, red);
            FillEllipse(200, 277 + i, 10, 10);
            fillEllipse(208, 277 + i, 10, 10);
            setLinestyle(solidln, 0, thickWidth);
            Arc (210, 267 + i, 90, 185, 8);
            setcolor(blue);
          end;
     end;
{ apple end }
{ draw squshed Žpfel }
  setColor(red);
  setFillStyle(solidFill, red);
  fillEllipse(200, 467, 10, 10);
  fillellipse(208, 467, 10, 10);
  setLineStyle(solidln, 0, thickWidth);
  setColor(brown);
  arc(210, 457, 90, 185, 8);
  setColor(red);
  setLineStyle(solidln, 0, normWidth);
  delay(100);
  setColor(blue);
  setFillStyle(solidFill, blue);
  fillEllipse(200, 467, 16, 11);
  fillellipse(208, 467, 16, 11);
  setLineStyle(solidln, 0, thickWidth);
  setColor(blue);
  arc(210, 457, 90, 185, 8);
  setcolor(10);
  setlinestyle(solidLn,0,thickwidth);
  line(0, 475, 650, 475);
  setLineStyle(DottedLn, 0, NormWidth);
  SetLineStyle(UserBitLn, $C3, ThickWidth);
  line(Pred(0), Pred(473), Succ(650), Succ(471));
  setcolor(red);
{ PieSlice(X, Y, StAngle, EndAngle, Radius) }
  setFillStyle(solidFill,red);
  pieslice(200,467,100,140,15);
  delay(100);

   sound(220);
   delay(100);
   sound(100);
   delay(75);
   sound(150);
   delay(50);
   nosound;

  pieslice(200,467,190,220,18);
  delay(100);
  pieslice(210,465,40,80,16);
  delay(100);
  pieslice(213,465,280,310,17);
  delay(75);
  pieslice(222, 462, 280, 310, 19);
  setcolor(14);
  outTextXY(232, 460, 'SPLAT!');

 ReadLn;
 CloseGraph;
end.

  outtextxy(395, 450,'press any key to int 21h...');
  readln;
  closegraph;
end.
0
 
LVL 4

Expert Comment

by:siabod
ID: 1217053
sorry for not commenting for a few days, i've been rather bussy buying a house :)... uhm i'll post you something in a few hours
0
 
LVL 1

Accepted Solution

by:
winsumpu earned 100 total points
ID: 1217054
the source code i've given down here will lshow you on how to load a picture into memory then later u animate the picture from the memory by using the command getimage and putimage.
** but remember u need alot of memory if it's related with a big graphic loaded into memory. i'll try to get for u few more example mean while give me ur e-mail address ok.

uses crt, graph;

var
   MaxX, MaxY  : word;     { The maximum resolution of the screen }
   MaxColor    : word;     { The maximum color value available }
   GraphDriver : integer;  { The Graphics device driver }
   GraphMode   : integer;  { The Graphics mode value }
   ErrorCode   : integer;  { Reports any graphics errors }


function RandColor : word;
{ Returns a Random non-zero color value that is within the legal
  color range for the selected device driver and graphics mode.
  MaxColor is set to GetMaxColor by Initialize }
begin
  RandColor := Random(MaxColor)+1;
end; { RandColor }

procedure WaitToGo;
{ Wait for the user to abort the program or continue }
const
  Esc = #27;
var
  Ch : char;
begin
  repeat until KeyPressed;
  Ch := ReadKey;
  if ch = #0 then ch := readkey;      { trap function keys }
  if Ch = Esc then
    Halt(0)                           { terminate program }
  else
    ClearDevice;                      { clear screen, go on with demo }
end; { WaitToGo }

procedure PutImagePlay;
{ Demonstrate the GetImage and PutImage commands }

const
  r  = 20;
  StartX = 100;
  StartY = 50;

var
  CurPort : ViewPortType;

procedure MoveSaucer(var X, Y : integer; Width, Height : integer);
var
  Step : integer;
begin
  Step := Random(2*r);
  if Odd(Step) then
    Step := -Step;
  X := X + Step;
  Step := Random(r);
  if Odd(Step) then
    Step := -Step;
  Y := Y + Step;

  { Make saucer bounce off viewport walls }
  with CurPort do
  begin
    if (x1 + X + Width - 1 > x2) then
      X := x2-x1 - Width + 1
    else
      if (X < 0) then
        X := 0;
    if (y1 + Y + Height - 1 > y2) then
      Y := y2-y1 - Height + 1
    else
      if (Y < 0) then
        Y := 0;
  end;
end; { MoveSaucer }

var
  Pausetime : word;
  Saucer    : pointer;
  X, Y      : integer;
  ulx, uly  : word;
  lrx, lry  : word;
  Size      : word;
  I         : word;
begin
  ClearDevice;

  { PaintScreen }
  ClearDevice;
  GetViewSettings(CurPort);

  { DrawSaucer }
  Ellipse(StartX, StartY, 0, 360, r, (r div 3)+2);
  Ellipse(StartX, StartY-4, 190, 357, r, r div 3);
  Line(StartX+7, StartY-6, StartX+10, StartY-12);
  Circle(StartX+10, StartY-12, 2);
  Line(StartX-7, StartY-6, StartX-10, StartY-12);
  Circle(StartX-10, StartY-12, 2);
  SetFillStyle(SolidFill, getMaxColor);
  FloodFill(StartX+1, StartY+4, GetColor);

  { ReadSaucerImage }
  ulx := StartX-(r+1);
  uly := StartY-14;
  lrx := StartX+(r+1);
  lry := StartY+(r div 3)+3;

  Size := ImageSize(ulx, uly, lrx, lry);
  GetMem(Saucer, Size);
  GetImage(ulx, uly, lrx, lry, Saucer^);
  PutImage(ulx, uly, Saucer^, XORput);               { erase image }

  { Plot some "stars" }
  for I := 1 to 1000 do
    PutPixel(Random(getmaxX), Random(getmaxY), RandColor);
  X := MaxX div 2;
  Y := MaxY div 2;
  PauseTime := 70;

  { Move the saucer around }
  repeat
    PutImage(X, Y, Saucer^, XORput);                 { draw image }
    Delay(PauseTime);
    PutImage(X, Y, Saucer^, XORput);                 { erase image }
    MoveSaucer(X, Y, lrx - ulx + 1, lry - uly + 1);  { width/height }
  until KeyPressed;
  FreeMem(Saucer, size);
  WaitToGo;
end; { PutImagePlay }


procedure Initialize;
{ Initialize graphics and report any errors that may occur }
var
  InGraphicsMode : boolean; { Flags initialization of graphics mode }
  PathToDriver   : string;  { Stores the DOS path to *.BGI & *.CHR }
begin
  { when using Crt and graphics, turn off Crt's memory-mapped writes }
  PathToDriver := 'C:\TP\BGI';
  repeat
    GraphDriver := Detect;                { use autodetection }
    InitGraph(GraphDriver, GraphMode, PathToDriver);
    ErrorCode := GraphResult;             { preserve error return }
    if ErrorCode <> grOK then             { error? }
    begin
      Writeln('Graphics error: ', GraphErrorMsg(ErrorCode));
      if ErrorCode = grFileNotFound then  { Can't find driver file }
      begin
        Writeln('Enter full path to BGI driver or type <Ctrl-Break> to quit:');
        Readln(PathToDriver);
        Writeln;
      end
      else
        Halt(1);                          { Some other error: terminate }
    end;
  until ErrorCode = grOK;
  Randomize;                { init random number generator }
  MaxColor := GetMaxColor;  { Get the maximum allowable drawing color }
  MaxX := GetMaxX;          { Get screen resolution values }
  MaxY := GetMaxY;
end; { Initialize }



begin
     Initialize;
     randomize;
     MaxColor := GetMaxColor;  { Get the maximum allowable drawing color }
     MaxX := GetMaxX;          { Get screen resolution values }
     MaxY := GetMaxY;

     PutImagePlay;
end.

0
 

Author Comment

by:weinrj
ID: 1217055
:-)
0
 
LVL 1

Expert Comment

by:winsumpu
ID: 1217056
thanx for the points given
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Let's take a look back at the commercialization of the internet to understand why keeping it open and neutral is in our best interest as a society.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question