3

I am making a PacMan type game but I don't know how to make a ghost move towards PacMan using screen.blit().

I have edited the code from a book called mission Python to make my map and I got the player working.

But on the game I'm editing, the mission Python book because the enemies do not chase the player, they move in a set pattern. I am 7 years old

Here is my code:

import time as tim
import random
import math  
ghost_x = 1
ghost_y = 2
def moveright():
    if ghost_x < pac_x:
        if room_map[ghost_y][ghost_x + 1] in items_pac_may_stand_on:
            ghost_x += 1
#deleted unnecessary lines (rooms that you can't go into, I deleted them because there is too much code and you can't have too much code)
scenery = {
    31: [[3,5,3], [3,5,4], [3,6,4], [3,5,4], [3,7,4], [3,8,4], [3,9,4], [3,5,5], [3,9,7], [3,8,17], [82,ghost_y,ghost_x], [82,1,1], [3,1,3], [3,2,2], [3,8,15], [3,7,15], [3,6,15], [3,5,15], [3,9,8], [3,9,9], [3,6,8], [3,7,8], [3,8,8], [3,5,8], [3,5,7], [3,5,9], [3,5,11], [3,8,12], [3,9,12], [3,5,12], [3,6,12], [3,7,12], [3,5,13], [3,9,17], [3,9,15], [3,9,15], [3,9,16], [3,7,17], [3,6,17], [3,5,17], [3,5,20], [3,5,21], [3,5,19], [3,6,19], [3,7,19], [3,7,20], [3,7,21], [3,8,21], [3,9,21], [3,9,20], [3,9,19]],
}
def move_ghost():
    screen.blit(images.goee, ghost_x, ghost_y)
    
ghost_x = random.randint(5, 10)
clock.schedule_interval(move_ghost, 0.5)

It outputs:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pgzero/clock.py", line 168, in tick
    cb()
  File "\/home/pi/escape/yarooyayayeetyeet.py.py.py.py,py.py.yp.py", line 21, in move_ghost
    screen.blit(images.goee, ghost_x, ghost_y)
TypeError: blit() takes 3 positional arguments but 4 were given
  • 2
    Divide the screen into 4 quadrants relative to Pac-man. If the ghost is below and left then they can move either up or right, whichever is possible. If both or neither then select at random. – stark Aug 15 '20 at 12:11
  • 1
    I have that step done, I need to get the ghost to actually go to what the variables say –  Aug 15 '20 at 13:11
  • 2
    I don't understand the question. What does the "variables" say, and what is the current behavior? – user202729 Aug 15 '20 at 13:40
  • 1
    what is the output? – Psychzander Aug 15 '20 at 13:51
  • "Variables say"means it's the thing I assigned the variables to be, i am doing the ghost that follows you around but you can lead them into walls to stop them until there isn't a wall in it's way. –  Aug 15 '20 at 13:52
  • 1
    You're asking two questions at once. One is about the TypeError, another is about how to make the ghost chases the character. – user202729 Aug 15 '20 at 14:03
  • 1
    About the TypeError, read [python - TypeError: method() takes 1 positional argument but 2 were given - Stack Overflow](https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given?rq=1). – user202729 Aug 15 '20 at 14:03
  • 1
    About the other one, you have to decide on an algorithm yourself. Another user commented above "If both or neither then select at random." -- do you think that that algorithm is good? Do you know how to implement that? What's the problem? – user202729 Aug 15 '20 at 14:04
  • I put my age as my parents told me to, they said it is so people are not too technical when answering. My Dad has also said I must show him each post before posting it. –  Aug 15 '20 at 14:22
  • 1
    It's better not to include personal information on Stack Exchange. Anything that isn't directly related to the issue may be removed from the post. – Braiam Aug 15 '20 at 14:27
  • 2
    @user14032941 I think you'll need to read [this](https://stackoverflow.com/legal/terms-of-service#age) – Scratte Aug 15 '20 at 16:04

0 Answers0