summaryrefslogtreecommitdiffstats
path: root/Weekly Challenges/Week 1/Bouncing DVD Logo.py
blob: 7e7b822bd2db222ba398e1946d28d184d59bd1d9 (plain)
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
import pygame
import random

pygame.init()

SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
dimensions = (SCREEN_WIDTH, SCREEN_HEIGHT)

screen = pygame.display.set_mode(dimensions)

position = pygame.Vector2(0, 0)
velocity = pygame.Vector2(0.2, 0.1)

dvd_logo = pygame.image.load("dvd.png")
dvd_logo = pygame.transform.scale(dvd_logo, (dvd_logo.get_width() // 5, dvd_logo.get_height() // 5))
dvd_height = dvd_logo.get_height()
dvd_width = dvd_logo.get_width()

clock = pygame.time.Clock()

COLOURS = [(0, 0, 255), (255, 0, 255), (255, 0, 0), (255, 128, 0), (255, 255, 255), (255, 255, 0), (0, 255, 0)]


def randomizeColour():
    dvd_logo.fill((0, 0, 0), special_flags=pygame.BLEND_MULT)
    dvd_logo.fill(random.choice(COLOURS), special_flags=pygame.BLEND_ADD)



def check_edges():
    global velocity
    if (position.y < 0 and velocity.y < 0) or (position.y + dvd_height > SCREEN_HEIGHT and velocity.y > 0):
        velocity.y *= -1
        randomizeColour()

    if (position.x < 0 and velocity.x < 0) or (position.x + dvd_width > SCREEN_WIDTH and velocity.x > 0):
        velocity.x *= -1
        randomizeColour()

randomizeColour()
is_running = True
while is_running:

    screen.fill((0, 0, 0))

    screen.blit(dvd_logo, position)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    position += velocity * clock.get_time()
    check_edges()
    pygame.display.update()
    clock.tick(60)

pygame.quit()

#two dvds, use class, not same colour twice, sound effects, reach corner counter, bounce off each other