-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.py
More file actions
39 lines (34 loc) · 1.32 KB
/
Copy pathobjects.py
File metadata and controls
39 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import random
import pygame
from screen_config import SCREEN_WIDTH, SCREEN_HEIGHT
class CoinsAndBombs:
def __init__(self):
self.obj = []
self.speed = 4
def move(self):
for i in range(len(self.obj)):
self.obj[i][1] += self.speed
def create(self):
if random.random() < 0.03:
x = random.randint(0, SCREEN_WIDTH)
num = random.randint(1, 10)
if num % 2 == 0:
self.obj.append([x, 0, False])
else:
self.obj.append([x, 0, True])
def clear(self):
self.obj = [pos for pos in self.obj if pos[1] < SCREEN_HEIGHT]
def draw(self, screen):
for pos in self.obj:
if pos[2]:
coin_img = pygame.image.load("gold-coin.png")
coin_img = pygame.transform.scale(coin_img, (20, 20))
coin_img_location = coin_img.get_rect()
coin_img_location.center = pos[0], pos[1]
screen.blit(coin_img, coin_img_location)
else:
bomb_img = pygame.image.load("bomb_circle.png")
bomb_img = pygame.transform.scale(bomb_img,(30,30))
bomb_img_location = bomb_img.get_rect()
bomb_img_location.center = pos[0], pos[1]
screen.blit(bomb_img,bomb_img_location)