forked from sd16spring/InteractiveProgramming
/
level.py
108 lines (84 loc) · 2.5 KB
/
level.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
from pygame.locals import *
from spritesheet_functions import SpriteSheet
import random
class Level(object):
"""This builds the level as a text mapping of the tiles
attributes: None"""
def __init__(self, x=0):
self.x = x
def choose(self,side):
res = ''
r = random.randint(0,100)
if r < self.threshold:
res += side
else:
res += 'W'
return res
def random_gen(self,count):
#probably should take size
#15 strings of 20 characters
#generate top wall
self.threshold = 13. - (count*1.5)
twall = ''
for x in range(20):
if x < 1 or x > 18:
twall+= 'W'
else:
twall += self.choose('T')
#generate bottom wall
bwall = ''
for x in range(20):
if x < 1 or x > 18:
bwall += 'W'
else:
bwall += self.choose('B')
#generate middle walls
middlewalls = []
for x in range(13):
wall = ''
if x < 2 or x > 10:
wall += self.choose('L')
wall += '..................'
wall += self.choose('R')
else:
wall += self.choose('L')
wall += '..'
for y in range(14):
wall += random.choice(['.','.','.','.','W'])
wall += '..'
wall += self.choose('R')
middlewalls.append(wall)
walls = []
walls.append(twall)
for wall in middlewalls:
walls.append(wall)
walls.append(bwall)
return walls
class WallSprite(pygame.sprite.Sprite):
"""This is the class for all of the wall sprites
attributes: image"""
def __init__(self):
super(WallSprite, self).__init__()
sprite_sheet = SpriteSheet('images/tilesets/walls.png')#3 x 4
horiz = [0, 32, 64]
vert= [0, 32, 64, 96]
self.image = sprite_sheet.get_image(random.choice(horiz),random.choice(vert),32,32)
class DoorSprite(pygame.sprite.Sprite):
"""This is the class for all of the door sprites
attributes: image"""
def __init__(self):
super(DoorSprite, self).__init__()
sprite_sheet = SpriteSheet('images/tilesets/doors.png')#4 x 1
horiz = [0, 32, 64, 96]
vert= [0]
self.image = sprite_sheet.get_image(random.choice(horiz),random.choice(vert),32,32)
class FloorSprite(pygame.sprite.Sprite):
"""This is the class for all of the floor sprites
attributes: image"""
def __init__(self):
super(FloorSprite, self).__init__()
sprite_sheet = SpriteSheet('images/tilesets/floors.png')#7x6
horiz = [0, 32, 64, 96, 128, 160, 192]
vert= [0, 32, 64, 96, 128, 160]
self.image = sprite_sheet.get_image(random.choice(horiz),random.choice(vert),32,32)