The program is a game I'm making in PYGAME, I want to make it so you play a character (a cat) and run around while a Zombie will be chasing you and if you go to the middle of the screen there'll be a circle there which will protect you because the zombie will be unable to walk into that circle.
If the Zombie somehow catches you, I want it to prompt a message saying YOU LOSE.
Also, this is the thing I'm having problem with right now.. I want it so that when the user press SPACE I want the character (the cat) to double up in size.
here is my code:
bif="bg.jpg" mif="cat.png" wif="Zombie.png" import pygame, sys from pygame.locals import * class FUNCTIONS: #def __init__(self): #a, b = self.mouse_c.size #return a*2, b*2 def RESIZE(self, OBJ): #global a, b #a, b = mouse_c.size #a*2, b*2 #OBJ = pygame.transform.scale(OBJ, (a,B)/>) #return self.OBJ self.OBJ = pygame.transform.scale(self.OBJ, (64,64)) return self.OBJ pygame.init() screen=pygame.display.set_mode((700,525),0,32) background=pygame.image.load(bif).convert() mouse_c=pygame.image.load(mif).convert_alpha() # This is the character zombie=pygame.image.load(wif).convert_alpha() # The zombie/enemy # This is the characters "attributes" x, y = 350, 262 movex, movey = 0, 0 speed = 250 sizex, sizey = 0, 0 a, b = 0, 0 # This is the zombies "attributes" x2, y2 = 0, 0 movex2, movey2 = 0, 0 speed2 = 100 # Clock and using the function clock=pygame.time.Clock() Thing=FUNCTIONS() Funct=Thing.RESIZE(mouse_c) #Making a circle for safe area color=(135,17,70) position=(350, 262) radius=(120) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: # Movements/keys if event.key == K_LEFT: movex-=dm elif event.key == K_RIGHT: movex+=dm elif event.key == K_UP: movey-=dm elif event.key == K_DOWN: movey+=dm elif event.key == K_SPACE: # Scale the character 2x Funct() if event.type == KEYUP: if event.key == K_LEFT: movex=0 elif event.key == K_RIGHT: movex=0 elif event.key == K_UP: movey=0 elif event.key == K_DOWN: movey=0 if x >= 0 and x <= 700: # prevent walking outside screen x += movex else: x = 350 if y >= 0 and y <= 525: # prevent walking outside screen y += movey else: y = 263 #Drawing the circle screen.lock() pygame.draw.circle(screen, color, position, radius) #pygame.draw.rect(screen, color, screen.unlock() # Setting the character/zombie speed milli=clock.tick() seconds=milli/1000.0 dm=seconds*speed dm2=seconds*speed2 # Displaying them screen.blit(background, (0,0)) screen.blit(mouse_c, (x,y)) screen.blit(zombie, (x2,y2)) pygame.display.update()
If you have time, you could help me how to make the Zombie chase the character as well and also how to make the Zombie unable to enter the circle because I know I'll be having trouble with those two.
The actual issue I have here is that I want to rescale a picture through the function inside my class and I want the size to double up in size every time I do it.
As you can see in the code I been trying to make it scale up to 64,64 pixels first because I thought it'd be easier to do one step at a time but even this does not seem to work.
"Traceback (most recent call last):
File "C:\Python27\Cat game v2.2.py", line 47, in <module>
File "C:\Python27\Cat game v2.2.py", line 19, in RESIZE
self.OBJ = pygame.transform.scale(self.OBJ, (64,64))
AttributeError: FUNCTIONS instance has no attribute 'OBJ'"