forked from stamaniorec/icy_tower_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatformController.py
49 lines (44 loc) · 1.38 KB
/
PlatformController.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
import pygame
import math
from random import randrange, random
from random import getrandbits
from Platform import Platform
from Constants import SCREEN_WIDTH, SCREEN_HEIGHT, JUMP_VELOCITY, MAX_JUMP
pygame.init()
class PlatformController:
def __init__(self):
self.platform_set = []
self.index = 10
self.last_x = MAX_JUMP
self.score = 0
for i in range(0, self.index):
self.platform_set.append(self.generate_platform(i, self.score))
def generate_platform(self, index, score):
if(score<MAX_JUMP*MAX_JUMP):
change = int(math.sqrt(score))
else:
change = MAX_JUMP-1
width = 200 - randrange(change, change+60)
height = 20
y = 600 - index * 100
while True:
side = bool(getrandbits(1))
if side:
x = randrange(self.last_x-MAX_JUMP , self.last_x-change)
else:
x = randrange(self.last_x+width+change , self.last_x+MAX_JUMP+width)
if x >= 0 and x <= SCREEN_WIDTH - width:
break
self.last_x = x
return Platform(x, y, width, height)
def draw(self, game_display, camera):
for p in self.platform_set:
p.draw(game_display, camera)
def collide_set(self, player):
for i,p in enumerate(self.platform_set):
player.collide_platform(p,i)
def generate_new_platforms(self, camera):
if self.platform_set[-1].y - camera.y > -50:
for i in range(self.index,self.index+10):
self.platform_set.append(self.generate_platform(i, self.score))
self.index += 10