-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
46 lines (35 loc) · 1.02 KB
/
base.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
# Importing the required libraries
import os
import pygame
# Global Variables
# Images
BASE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "base.png")))
class Base:
"""
Class which defines the base (or) ground
"""
# Base class Attributes
VEL = 5
WIDTH = BASE_IMG.get_width()
IMG = BASE_IMG
def __init__(self, y):
self.y = y
self.x1 = 0
self.x2 = self.WIDTH
def move(self):
"""
Method which moves the base image, which gives us a
visual impression that the bird is moving along the x-axis.
"""
self.x1 -= self.VEL
self.x2 -= self.VEL
if self.x1 + self.WIDTH < 0:
self.x1 = self.x2 + self.WIDTH
if self.x2 + self.WIDTH < 0:
self.x2 = self.x1 + self.WIDTH
def draw(self, win):
"""
Method which draws the base image on to the pygame window
"""
win.blit(self.IMG, (self.x1, self.y))
win.blit(self.IMG, (self.x2, self.y))