-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathObstacle.py
41 lines (33 loc) · 1.25 KB
/
Obstacle.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
import random
import pygame as pg
from constants import *
class Obstacle:
def __init__(self, surface: pg.Surface):
# randomly choose an obstacle
obstacle_type = random.randint(1, 3)
# trees
if obstacle_type == 1:
self.width = TREES_WIDTH
self.height = TREES_HEIGHT
self.img = pg.image.load('assets/trees.png').convert_alpha()
# rock
elif obstacle_type == 2:
self.width = ROCK_WIDTH
self.height = ROCK_HEIGHT
self.img = pg.image.load('assets/rock.png').convert_alpha()
# grass
else:
self.width = GRASS_WIDTH
self.height = GRASS_HEIGHT
self.img = pg.image.load('assets/grass.png').convert_alpha()
self.rect = pg.rect.Rect(surface.get_width(), surface.get_height() -
self.height, self.width,
self.height)
self.jumping = False
self.velocity = 0
self.color = random.choice(COLORS)
self.speed = random.randint(MIN_SPEED, MAX_SPEED)
def show(self, surface: pg.Surface):
surface.blit(self.img, self.rect)
def update_coords(self, dt):
self.rect.move_ip(-self.speed * dt, 0)