-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
88 lines (60 loc) · 1.59 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pygame
import random
from player import Player
from coin import Coin
pygame.init()
size = (500, 500)
bg_color = (255, 255, 255)
fps = 60
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
done = False
player = Player()
sprites = pygame.sprite.RenderPlain( (player) )
pygame.key.set_repeat(1, fps/2)
from random import randint
coins = pygame.sprite.Group()
def addcoin():
coin = Coin()
coin.rect.x = randint(0, 500)
coin.rect.y = randint(0, 500)
coins.add(coin)
for i in range(0,10):
addcoin()
font = pygame.font.Font(None, 24) # second is size of font
MAX_COINS = 30
while not done:
screen.fill(bg_color)
hit = pygame.sprite.spritecollide(player, coins, True) # true removes coin
if random.randint(0,100) is 95:
addcoin()
for c in coins.sprites():
c.float()
coins.draw(screen) # ADDED
player.give_money( len(hit) )
text = font.render(str(player.coins), 1, (0,0,0) ) # antialias, color
screen.blit(text, text.get_rect()) # draws it on screen
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
player.move_down()
if event.key == pygame.K_LEFT:
player.move_left()
if event.key == pygame.K_RIGHT:
player.move_right()
if event.key == pygame.K_UP:
player.move_up()
elif event.type == pygame.KEYUP:
pass
elif event.type == pygame.MOUSEMOTION:
pass
elif event.type == pygame.MOUSEBUTTONUP:
pass
elif event.type == pygame.MOUSEBUTTONDOWN:
pass
sprites.draw(screen)
clock.tick(fps)
pygame.display.flip()
pygame.quit()