-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.py
158 lines (123 loc) · 8.11 KB
/
World.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import pygame
from cvslayout import import_cvs_layout
from tile import StaticTile
from npc import NPC
import random
class world_creator: #constructs the world
def __init__(self,world_type,surface,x,y):
self.display_surface = surface
plain_layout = import_cvs_layout(world_type['plain'])
self.plain_layout_sprite = self.create_tile_group(plain_layout,'plain')
rock_layout = import_cvs_layout(world_type['rock'])
self.rock_layout_sprite = self.create_tile_group(rock_layout,'rock')
sand_layout = import_cvs_layout(world_type['sand'])
self.sand_layout_sprite = self.create_tile_group(sand_layout,'sand')
snow_layout = import_cvs_layout(world_type['snow'])
self.snow_layout_sprite = self.create_tile_group(snow_layout,'snow')
water_layout = import_cvs_layout(world_type['water'])
self.water_layout_sprite = self.create_tile_group(water_layout,'water')
tree_layout = import_cvs_layout(world_type['tree'])
self.tree_layout_sprite = self.create_tile_group(tree_layout,'tree')
cactus_layout = import_cvs_layout(world_type['cactus'])
self.cactus_layout_sprite = self.create_tile_group(cactus_layout,'cactus')
wood_plank_layout = import_cvs_layout(world_type['wood_plank'])
self.wood_plank_layout_sprite = self.create_tile_group(wood_plank_layout,'wood_plank')
grass_weed_layout = import_cvs_layout(world_type['grass_weed'])
self.grass_weed_layout_sprite = self.create_tile_group(grass_weed_layout,'grass_weed')
ice_spike_layout = import_cvs_layout(world_type['ice_spike'])
self.ice_spike_layout_sprite = self.create_tile_group(ice_spike_layout,'ice_spike')
self.objectList = [self.plain_layout_sprite,self.rock_layout_sprite,self.sand_layout_sprite,self.water_layout_sprite,self.snow_layout_sprite,self.wood_plank_layout_sprite,self.cactus_layout_sprite,self.tree_layout_sprite,self.ice_spike_layout_sprite,self.grass_weed_layout_sprite]
self.collideable = [self.rock_layout_sprite,self.water_layout_sprite,self.tree_layout_sprite,self.ice_spike_layout_sprite]
self.relativePositionX = x
self.relativePositionY = y
def create_tile_group(self,l,t):
TILE_SIZE = 64
sprite_group = pygame.sprite.Group()
for row_index, row in enumerate(l):
for column_index, val in enumerate(row):
if val != '-1':
x = (column_index - 27) * TILE_SIZE #shifts the board to the middle x
y = (row_index - 27) * TILE_SIZE #the center is a translation of a 1:2 ratio (9,18)
if t == 'rock':
randomnum = random.randint(0,1)
if randomnum == 0: texture = pygame.image.load('Sprites/rockdesign1.png').convert()
else: texture = pygame.image.load('Sprites/rockdesign2.png').convert()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'rock', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'water':
randomnum = random.randint(0,2)
if randomnum == 0: texture = pygame.image.load('Sprites/water1.png').convert_alpha()
elif randomnum == 1: texture = pygame.image.load('Sprites/water2.png').convert_alpha()
else: texture = pygame.image.load('Sprites/water3.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'water', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'wood_plank':
texture = pygame.image.load('Sprites/wood_plank1.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'wood_plank', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'plain':
randomnum = random.randint(0,3)
if randomnum == 0: texture = pygame.image.load('Sprites/grassdesign1.png').convert()
elif randomnum == 1: texture = pygame.image.load('Sprites/grassdesign2.png').convert()
else: texture = pygame.image.load('Sprites/grassdesign3.png').convert()
#sprite = Tile(32,x,y)
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'plain',(x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'sand':
randomnum = random.randint(0,2)
if randomnum == 1: texture = pygame.image.load('Sprites/sand1.png').convert()
elif randomnum == 2: texture = pygame.image.load('Sprites/sand2.png').convert()
else: texture = pygame.image.load('Sprites/sand3.png').convert()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'sand', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'snow':
randomnum = random.randint(0,2)
if randomnum == 1: texture = pygame.image.load('Sprites/snow1.png').convert()
else: texture = pygame.image.load('Sprites/snow2.png').convert()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'snow', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'ice_spike':
texture = pygame.image.load('Sprites/iceSpike.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'ice_spike', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'cactus':
texture = pygame.image.load('Sprites/cactus1.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'cactus', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == "grass_weed":
randomnum = random.randint(0,1)
if randomnum == 1: texture = pygame.image.load('Sprites/grassweed.png').convert_alpha()
else: texture = pygame.image.load('Sprites/grassweed2.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE,x,y,texture,'grass_weed', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
if t == 'tree':
texture = pygame.image.load('Sprites/tree1.png').convert_alpha()
sprite = StaticTile(TILE_SIZE,TILE_SIZE*2,x,y,texture,'tree', (x-576)//TILE_SIZE,(y-320)//TILE_SIZE)
sprite_group.add(sprite)
#for al in sprite_group.sprites():
#print(al.get_coords())
return sprite_group
def getObjectList(self):
return self.objectList
def getCollideableList(self):
return self.collideable
def updateRelative(self,x,y):
self.relativePositionX += x
self.relativePositionY += y
def getRelativeX(self):
return self.relativePositionX
def getRelativeY(self):
return self.relativePositionY
def run(self):
for list in self.objectList:
list.draw(self.display_surface)
#self.plain_layout_sprite.draw(self.display_surface) #draws the tile group on said surface
#self.rock_layout_sprite.draw(self.display_surface) #draws the tile group on said surface
#self.plain_layout_sprite.draw(self.display_surface) #draws the tile group on said surface
#self.rock_layout_sprite.draw(self.display_surface) #draws the tile group on said surface
#self.layout_sprite.update(1)
def update_layout(self,x,y):
for list in self.objectList:
list.update(x,y)
#self.plain_layout_sprite.update(x,y)
#self.rock_layout_sprite.update(x,y)