-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.py
105 lines (90 loc) · 3.36 KB
/
map.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
#! /usr/bin/python
import os, sys, random
import pygame
from pygame.locals import *
from block import *
class Map(object):
def __init__(self, surface, x, y, width, height, blocks):
self.surface = surface
self.x = x
self.y = y
self.width = width
self.height = height
self.blocks = pygame.sprite.Group()
self.block_images = blocks;
self.generated = False
#print "Map initialized", self.x, self.y
def draw(self, screen):
self.blocks.draw(screen)
def get_width(self):
return self.x*self.width*64+self.width*64
def get_height(self):
return self.y*self.height*64+self.height*64
def get_block_top(self, x, y):
for block in self.blocks.sprites():
if block.rect.x == x and block.rect.y == y-64:
return block
return False
def get_block_bottom(self, x, y):
for block in self.blocks.sprites():
if block.rect.x == x and block.rect.y == y+64:
return block
return False
def get_block_left(self, x, y):
for block in self.blocks.sprites():
if block.rect.x == x-64 and block.rect.y == y:
return block
return False
def get_block_right(self, x, y):
for block in self.blocks.sprites():
if block.rect.x == x+64 and block.rect.y == y:
return block;
return False
def get_blocks(self):
return self.blocks
def generate_atmosphere(self):
self.generated = True
def generate_surface(self):
for x in range(0, self.width):
for y in range(self.height/2, self.height):
self.generate_block(x, y)
self.generated = True
def generate_beneath_surface(self):
for x in range(0, self.width):
for y in range(0, self.height):
self.generate_block(x, y)
self.generated = True
def generate_block(self, x, y):
#print "Generate block", self.x*self.width*64+x*64, self.y*self.height*64+y*64
ice = random.randint(0, 4)
if ice == 1:
self.blocks.add(Block("ice-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[0]))
elif ice == 2:
self.blocks.add(Block("ice-two-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[1]))
elif ice == 3:
close_block = "diff"
for block in self.blocks.sprites():
if block.rect.y == self.height*(y-1):
if block.block != "ice-block" and block.block != "ice-two-block":
close_block == "same"
if block.rect.x == self.width*(x-1):
if block.block != "ice-block" and block.block != "ice-two-block":
close_block == "same"
if close_block == "same":
odd_ice = random.randint(0, 10)
if odd_ice <= 4:
if odd_ice > 0 and odd_ice <= 2:
self.blocks.add(Block("ice-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[0]))
else:
self.blocks.add(Block("ice-two-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[1]))
else:
self.blocks.add(Block("oil-pocket-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[2]))
else:
odd_ice = random.randint(0, 10)
if odd_ice <= 8:
if odd_ice > 0 and odd_ice <= 4:
self.blocks.add(Block("ice-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[0]))
else:
self.blocks.add(Block("ice-two-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[1]))
else:
self.blocks.add(Block("oil-pocket-block", self.x*self.width*64+x*64, self.y*self.height*64+y*64, self.block_images[2]))