Author Topic: free pascal graphic program help  (Read 2538 times)


  • Newbie
  • Posts: 1
free pascal graphic program help
« on: June 11, 2018, 11:42:11 pm »
Hello everyone, I have sort of a problem. I am student of technical school and for our finish exam in programming we got make a game. So games are not hard to make, but I got real confused. I need to make a person who is running and picking apples, but there are some type of ghosts or animals. When the character picks apples, the energy increases and when ghost catches him it loses energy. Here is the code since where I encountered error and then I will explain the problem:

    if (x=x1) and (y=y1) then
               case k of
   until (k='k');

Energy is not yet functional, but the problem is with apples. Draw3 draws a black apple (not visible on the screen), draw2 draws a green apple. So when I move the character arround draw2 draws green apple. When I put my character over the draw3 (x and y are coordinates of character; x1 and y1 are coordinates of apple) apple should disappear, but it is not happening.

Can anyone help me? If you help me with this code, please, write your own or just give me some suggestion. Thanks!


  • Hero Member
  • *****
  • Posts: 3443
    • Personal webpage
Re: free pascal graphic program help
« Reply #1 on: June 12, 2018, 11:20:23 am »
There's not enough of your code to tell you.
Conscience is the debugger of the mind


  • Full Member
  • ***
  • Posts: 108
  • Beers: 1567
Re: free pascal graphic program help
« Reply #2 on: June 12, 2018, 11:45:33 am »
Hello, jazavac,

You should use the # button to mark you are writing code. This way, code looks better.

Code: Pascal  [Select][+][-]
  1.   repeat
  2.     outtextxy(150, 10, 'energy=100');
  3.     if (x = x1) and (y = y1) then
  4.       draw3
  5.     else
  6.     begin
  7.       draw2;
  8.     end;
  9.     k := readkey;
  10.     cleardevice;
  11.     case k of
  12.       'a':
  13.       begin
  14.         x := x - 10;
  15.         draw;
  16.         Dec(energija);
  17.       end;
  18.       'd':
  19.       begin
  20.         x := x + 10;
  21.         draw;
  22.         Dec(energija);
  23.       end;
  24.       's':
  25.       begin
  26.         y := y + 10;
  27.         draw;
  28.         Dec(energy);
  29.       end;
  30.       'w':
  31.       begin
  32.         y := y - 10;
  33.         draw;
  34.         Dec(energy);
  35.       end;
  36.     end;
  37.   until (k = 'k');
  38.   closegraph;

I think you may be doing something wrong in draw/draw2/draw3. When your player eats an apple, you must change x1, y1 (i.e. x1:=-1, y1:=-1, where -1 means no apple,  or maybe change the apple's coordinates to move it to another place). But we don't know what are you doing in draw/draw2/draw3.
To err is human, but to really mess things up, you need a computer.


  • Hero Member
  • *****
  • Posts: 1052
    • Burdjia
Re: free pascal graphic program help
« Reply #3 on: June 13, 2018, 11:49:17 am »
Do not use cryptic names for your stuff.  You should try "DrawApples" instead of "Draw2" or whatever.

Also you should use parameters instead of global variables.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal


TinyPortal © 2005-2018