-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroad.py
30 lines (22 loc) · 888 Bytes
/
road.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
from util import absolute_path_for
import pygame
class Road:
def __init__(self, screen):
texture = pygame.image.load(absolute_path_for('/assets/sprites/asphalt.jpg'))
self.screen = screen
self.height = texture.get_height()
self.texture = pygame.transform.scale(texture, (500, self.height))
self.position = 0
def display(self):
self.screen.blit(self.texture, (0, self.position))
self.screen.blit(self.texture, (0, self.position + self.height))
def scroll(self, speed):
if speed > 0:
self.position += abs(speed)
elif speed < 0:
self.position -= abs(speed)
if self.position < -self.height:
self.position = 0
elif self.position + self.height > self.height:
self.position = -self.height
self.display()