0

This is the full code for the very bad game example.

import pgzrun
from random import randint
from pgzero.builtins import Actor, animate, keyboard

apple = Actor('apple')

def draw():
    screen.clear()
    apple.draw()

def place_apple():
    apple.x = randint(10, 800)
    apple.y = randint(10, 600)

def on_mouse_down(pos):
    if apple.collidepont(pos):
        print("Good shot!")
        place_apple()
    else:
        print("You missed!")
        quit()

place_apple()
pgzrun.go()

the screen.clear() isn't working and apple = actor("apple") also isn't working. I have no idea why. Please help me!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    [Pygame Zero](https://pygame-zero.readthedocs.io/en/stable/) is not [PyGame](https://www.pygame.org/news). You have to use the [tag:pgzero] tag instead of the [tag:pygame] tag. – Rabbid76 Apr 26 '21 at 16:57

2 Answers2

0

try this:

from pgzero.actor import Actor
from pgzero.keyboard import keyboard

not sure if it helps.

Are you using mu editor or pycharm ??

Do you have an apple image in the correct path ?

0

i tried the same instructions and found that adding the import pygame solved the issue.

import pgzrun
from random import randint
import pygame

WIDTH  = 800
HEIGHT = 600
pig = Actor('pig')
schaap = Actor('schaap')
zombie = Actor('zombie')
konijn = Actor('konijn')

def draw():    
    screen.clear
    screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
    pig.draw()
    schaap.draw()
    zombie.draw()
    konijn.draw()

def plaats_pig():    
    pig.x = randint(10,800)
    pig.y = randint(10,600)

def plaats_schaap():    
    schaap.x = randint(20,800)
    schaap.y = randint(20,600)

def plaats_zombie():    
    zombie.x = randint(70,800)
    zombie.y = randint(70,600)

def plaats_konijn():    
    konijn.x = randint(100,800)
    konijn.y = randint(100,600)


def on_mouse_down(pos):
    if pig.collidepoint(pos):
        sounds.schiet.play()    
        plaats_pig()
    elif schaap.collidepoint(pos):
        sounds.schiet.play()    
        plaats_schaap()
    elif zombie.collidepoint(pos):
        sounds.schiet.play()    
        plaats_zombie()
    elif konijn.collidepoint(pos):
        sounds.schiet.play()    
        plaats_konijn()
    else:
        sounds.mis.play()
        print('lekker puhh, mis')  
    

plaats_pig()
plaats_schaap()
plaats_zombie()
plaats_konijn()
pgzrun.go()
Mwalima
  • 11
  • 1