avocados/avocado.py

51 lines
1.5 KiB
Python
Raw Normal View History

2014-08-30 17:59:20 +02:00
#!/usr/bin/env python3
2014-08-30 18:20:49 +02:00
import pygame
import random
2014-08-30 17:59:20 +02:00
class Avocado:
2014-08-30 20:47:21 +02:00
def __init__(self, screen, color, filename='img/AvoCado_0.png'):
print('New avocado is ' + ','.join(str(color)))
2014-08-30 20:50:24 +02:00
self.screen = screen
2014-08-30 20:47:21 +02:00
self.screen_width, self.screen_height = screen.get_size()
2014-08-30 18:20:49 +02:00
self.x = random.randint(0, self.screen_width)
self.y = 0 # change this to start somewhere above the screen
2014-08-30 17:59:20 +02:00
self.w = 100
self.y = 100
2014-08-30 18:20:49 +02:00
self.i = pygame.image.load(filename).convert_alpha()
2014-08-30 18:50:21 +02:00
self.image = pygame.transform.scale(self.i, (30, 30))
2014-08-30 18:20:49 +02:00
self.pycard = self.image.get_rect()
2014-08-30 19:01:48 +02:00
self.init_pos()
2014-08-30 18:20:49 +02:00
self.step_x = 10
self.step_y = 10
self.is_falling = True
2014-08-30 17:59:20 +02:00
2014-08-30 19:01:48 +02:00
def init_pos(self):
2014-08-30 18:43:19 +02:00
self.pycard.x = random.randint(0, self.screen_width)
2014-08-30 19:01:48 +02:00
self.pycard.y = random.randint(20, 70)
2014-08-30 18:43:19 +02:00
2014-08-30 17:59:20 +02:00
def collides(self, click):
"""
Checks whether this object collides with the given position
in click
"""
return True
#if collision then self.destroy()
def destroy(self):
"""destroys this object"""
2014-08-30 18:20:49 +02:00
def move(self):
if self.pycard.right > self.screen_width or self.pycard.left < 0:
self.step_x = -self.step_x
if self.pycard.bottom > self.screen_height or self.pycard.top < 0:
print('platch')
return False
self.is_falling = False
self.pycard.x += self.step_x
self.pycard.y += self.step_y
return True