-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacles.py
74 lines (65 loc) · 2.26 KB
/
obstacles.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
import random
import pygame
import sys
import notes
import globals
from pygame.locals import *
class Obstacle(notes.Note):
"""
Obstacle class as a type of Note
Attributes:
staff_loc : int
note_type : int (Type of note for random generation)
Methods:
move_left() : moves obstacles across the screen
hide() : hides the obstacle by drawing a black rectangle over it
"""
def __init__(
self, note_type, staff_loc, x=globals.WIDTH - 20, offset_x=0, offset_y=-22
):
"""
Assign an obstacle note based upon a note_type argument provided.
This is done so we can randomly generate obstacles later on in the game
"""
self.note_type = note_type
self.staff_loc = staff_loc
# FIXME: Change the offset x values so that all the notes align up properly on the left edge
image = "assets/images/"
size_y = 66
if note_type == 0:
image += "whole-note.png"
offset_y = 0
size_y = 24
elif note_type == 1:
image += "half-note.png"
elif note_type == 2:
image += "qtr-note.png"
elif note_type == 3:
image += "eight-note.png"
elif note_type == 4:
image += "eight-line.png"
elif note_type == 5:
image += "sixteenth-notes.png"
image = pygame.image.load(image)
super().__init__(
image, x, globals.STAFFPOS[staff_loc], offset_x, offset_y, size_y=size_y
)
colorImage = pygame.Surface(self.orig_image.get_size()).convert_alpha()
colorImage.fill((255, 100, 100, 255))
self.image.blit(colorImage, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
def move_left(self, surface, speed=1):
"""
Move the obstacle across the screen
"""
# draw a black rect over the obstacle's previous position
pygame.draw.rect(surface, (0, 0, 0), self.rect)
# move the obstacle left by 1 pixel
self.x -= speed
self.rect.move_ip(-speed, 0)
# draw the obstacle at its new position
self.draw(surface)
def hide(self, surface):
"""
Hide the obstacle
"""
pygame.draw.rect(surface, (0, 0, 0), self.rect)