-2

need code please, this my code:

{
  if (hspeed == 0) 0
  { 

    if (random(3)<1 and place_free(x-4,y)) 
      { 
       hspeed = -4; 
       vspeed = 0;  }

    if (random(3)<1 and place_free(x+4,y))
      { hspeed =  4; vspeed = 0;}
alepuzio
  • 1,382
  • 2
  • 28
  • 38
  • Please, can be more specific about your trouble? Can you put the source code of your try, please? Thanks – alepuzio Oct 24 '18 at 11:13

1 Answers1

0

pacman ghosts don't move at random directions; in pacman you don't even need to move by finite numbers like 4 and check for collisions; you should have a graph of all intersections and build the ai on that. Although from your question i deduce you lack the basics for separating what is seen by what happens in the background.

Hint: most games aren't what the user can see; tetris and minesweeper are just bidimensional arrays, pacman is a graph, card games are stacks and lists. The only "simple" game i can think of where what you see is exactly what happens is pong. https://www.youtube.com/watch?v=qwhXIzNrb9w

Barnack
  • 921
  • 1
  • 8
  • 20