Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

animation help

Posted on 1998-05-27
9
Medium Priority
?
695 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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