forked from Johnny-Q/htn_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel_manager.py
More file actions
59 lines (49 loc) · 2.15 KB
/
level_manager.py
File metadata and controls
59 lines (49 loc) · 2.15 KB
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
from obstacle import Obstacle
import pygame
import os
import random
from helpers import HEIGHT, WIDTH, getX, getY, BG_ACC_HEIGHT
class LevelManager:
#size objects small to start
def __init__(self):
self.OBS_WIDTH, self.OBS_HEIGHT = 50, 50
DISHES = pygame.image.load(os.path.join('Assets', 'pictures', 'obstacles', 'dishes.png'))
BOOKS = pygame.image.load(os.path.join('Assets', 'pictures', 'obstacles', 'books.png'))
PIANO = pygame.image.load(os.path.join('Assets', 'pictures', 'obstacles', 'piano.png'))
self.pos_obstacles = [DISHES, BOOKS, PIANO]
self.obstacles = []
def createObstacle(self):
index = random.randint(0, 2)
obstacle_image = self.pos_obstacles[index]
lane = random.randint(0, 2)
x = [600, 810, 950]
obstacle = Obstacle(obstacle_image, getX(x[lane]), getY(652), lane, 1, index == 2)
# if(lane == 0):
#Obstacle obj(obstacle_type, lane, img, left_x, left_y, 0)
#Obstacle obj(obstacle, lane) #def __init__(self, game_window, img, x, y, lane, depth) -> None:
self.obstacles.append(obstacle)
return obstacle
def update(self, WIN, game_objs):
for obj in self.obstacles:
obj.depth += 5
obj.y += 5
if obj.lane == 0:
obj.x += 7*(25-739)/(2160-652)
if obj.lane == 2:
obj.x += 10*(1509-893)/(2160-652)
#obj.width +=1
#check if object is off screen
if obj.y >= 1080 - self.OBS_HEIGHT:
self.obstacles.remove(obj)
game_objs.remove(obj)
def collisionCheck(self, player):
for obj in self.obstacles:
# print(obj.y, getY(BG_ACC_HEIGHT-500))
if player.lane == obj.lane and getY(BG_ACC_HEIGHT - 1000) <= obj.y and obj.y <= getY(BG_ACC_HEIGHT - 990):
if obj.isPiano and player.moveState==4:
return False
if player.moveState == 3 and not obj.isPiano: #allow jump over objects
return False
print('collision')
return True
return False