def __init__(self, x, y, name, *groups, width=None, height=None, props={}, Map=None, picture=None, type_="", logic=None): Object.__init__(self, *groups + Type.groups) width = width if width else getattr(Type, "width", 0) height = height if height else getattr(Type, "height", 0) Map = Type.Map if not Map else Map type_ = type_ if type_ else Type.type if not (width or height) and Map.gid_point: Obj = Orientation.point(x, y, Map.in_map, name, True) elif not (width and height) and Map.gid_line: Obj = Orientation.line( q_points(x, y, x + width, y + height, Map.in_map), Map.in_map, name, True) else: Obj = Orientation.rect(x, y, width, height, Map.in_map, name, True) picture = picture if picture else Type.picture Orientation.map_obj.__init__(self, name, type_, join(props, Type.props), picture, Map, Obj) self.logic = logic if logic else Type.logic for lc in self.logic.lc: lc.bind(self) for f in self.logic[0]: f(self)
def __init__(self, name, Type, props, picture, Map, obj): super().__init__(name, Type, props, None, Map, obj) self.Pictures = [pygame.image.load("doc/art/drw/enm/" + str(x + 1) + ".bmp") for x in range(3)] for picture in self.Pictures: picture.set_colorkey((255, 255, 255)) self.obj.width, self.obj.height = self.width, self.height =\ self.Pictures[0].get_size() self.pictures = {c: [pic.copy() for pic in self.Pictures] for c in Map.col} for y in range(self.height): for x in range(self.width): for n, picture in enumerate(self.Pictures): if picture.get_at((x, y)) == (0, 0, 0): for col in self.Map.col: self.pictures[col][n].set_at((x, y), col) self.fy = 0 self.ground = False self.state = 0 self.new = False self.last = [self.x, self.y] self.history = [] self.centre = Orientation.point(self.x + self.width / 2, self.y + self.height / 2, self.Map, quiet=True) self.view = Orientation.circle(self.centre, 200, self.Map.in_map) self.pl = self.Map.clone_obj("player", "type") self.plats = self.pl.plats self.jump = None
def __init__(self, name, Type, props, picture, Map, obj): super().__init__(name, Type, props, None, Map, obj) self.Pictures = [pygame.image.load("doc/art/drw/ply/" + str(x + 1) + ".bmp") for x in range(3)] for picture in self.Pictures: picture.set_colorkey((255, 255, 255)) self.obj.width, self.obj.height = self.width, self.height =\ self.Pictures[0].get_size() self.pictures = {c: [pic.copy() for pic in self.Pictures] for c in Map.col} for y in range(self.height): for x in range(self.width): for n, picture in enumerate(self.Pictures): if picture.get_at((x, y)) == (0, 0, 0): for col in self.Map.col: self.pictures[col][n].set_at((x, y), col) self.fy = 0 self.plats = [] self.key = self.Map.game.key self.ground = False self.state = 0 self.new = True self.history = [] self.last = [self.x, self.y, 0] self.point = Orientation.point(self.x + self.width / 2, self.y + self.height / 2, self.Map.in_map) self.sh = self.Map.height
def __init__(self, x, y, w, h, Map): self.x = x self.y = y self.w = w self.h = h self.Map = Map self.Map.write_on(self.tiles(), "walls", 0, "wall", True) self.bridges = {1: [], 2: [], 3: []} self.obj = Orientation.rect(self.x * 10, self.y * 10, self.w * 10, self.h * 10, self.Map.in_map) self.WIDTH = self.Map.t_width self.HEIGHT = self.Map.t_height
def __init__(self, x, y, name, *groups, width=None, height=None, props={}, Map=None, picture=None, type_="", logic=None): Object.__init__(self, *groups + Type.groups) width = width if width else getattr(Type, "width", 0) height = height if height else getattr(Type, "height", 0) Map = Type.Map if not Map else Map type_ = type_ if type_ else Type.type if not (width or height) and Map.gid_point: Obj = Orientation.point(x, y, Map.in_map, name, True) elif not (width and height) and Map.gid_line: Obj = Orientation.line(q_points(x, y, x + width, y + height, Map.in_map), Map.in_map, name, True) else: Obj = Orientation.rect(x, y, width, height, Map.in_map, name, True) picture = picture if picture else Type.picture Orientation.map_obj.__init__(self, name, type_, join(props, Type.props), picture, Map, Obj) self.logic = logic if logic else Type.logic for lc in self.logic.lc: lc.bind(self) for f in self.logic[0]: f(self)
def __init__(self): self.pictures = [] for x in range(3): pic = self.picture[x] self.pictures.append([pic, pygame.transform.rotate(pic, 90), pygame.transform.rotate(pic, 180), pygame.transform.rotate(pic, 270)]) self.Dir = 0 self.size = 1 self.w = self.h = self.SIZES[self.size] self.picture = self.pictures[self.size][self.Dir] for layer in self.Map.layers: if layer.name == "walls": self.walls = layer.mapping self.obj = Orientation.rect(self.x, self.y, self.w, self.h, self.Map.in_map) self.screen = self.Map.screen
import pygame from Mind import Orientation pygame.init() screen = pygame.display.set_mode((500, 500)) Map = Orientation.tiled_map("first_level") running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((255, 255, 255)) Map.blit() pygame.display.flip() pygame.quit()
import pygame from Mind import Orientation pygame.init() screen = pygame.display.set_mode((500, 500)) Map = Orientation.moving_map("first_level", 300, 300) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((255, 255, 255)) Map.blit() pygame.display.flip() pygame.quit()
from Mind import Orientation, Existence import pygame pygame.init() screen = pygame.display.set_mode((400, 400)) pygame.display.set_caption('test, arrows for moving') player = Existence.mov_type(None, pygame.font.SysFont(None, 50).render('A', 1, (255, 0, 0)), logic=Existence.Subject) Map = Orientation.tiled_map('first_level', [{}, {}, {"player": player}]) p = Map.clone_obj("player") running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: p.move(0, -10) if event.key == pygame.K_RIGHT: p.move(10, 0) if event.key == pygame.K_DOWN: p.move(0, 10) if event.key == pygame.K_LEFT: p.move(-10, 0) screen.fill((255, 255, 255)) Map.blit()
def opt_size(self): """Optimizes size of object. Size will be picture size. """ self.obj = Orientation.rect(self.x, self.y, self.picture.get_width(), self.picture.get_height(), self.Map.in_map)
import pygame from Mind import Orientation pygame.init() pygame.display.set_caption("test, arrows for moving") screen = pygame.display.set_mode((400, 400)) Map = Orientation.moving_map("first_level", 300, 300) Map.set_position(*Map.get_camera_pos()) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Map.move(0, -10) if event.key == pygame.K_RIGHT: Map.move(10, 0) if event.key == pygame.K_DOWN: Map.move(0, 10) if event.key == pygame.K_LEFT: Map.move(-10, 0) Map.set_position(*Map.get_camera_pos()) screen.fill((255, 255, 255)) Map.blit()
from Mind import Orientation import pygame pygame.init() screen = pygame.display.set_mode((400, 400)) pygame.display.set_caption('test, arrows for moving') Map = Orientation.moving_map('first_level', 200, 200) Map.set_edge(Map.edge_width - 10, Map.edge_height - 10) Map.offset(10, 10) Map.move(0, 0) font = pygame.font.SysFont(None, 50) a = font.render('A', 1, (255, 0, 0)) p = Orientation.map_obj("", "", {}, a, Map, Orientation.point(*Map.get_position() + (Map.in_map,))) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Map.move(0, -10) if event.key == pygame.K_RIGHT: Map.move(10, 0) if event.key == pygame.K_DOWN: Map.move(0, 10)
from Mind import Orientation import pygame pygame.init() screen = pygame.display.set_mode((400, 400)) pygame.display.set_caption('test, arrows for moving') Map = Orientation.moving_map('first_level', 200, 200) Map.set_edge(Map.edge_width - 10, Map.edge_height - 10) Map.offset(10, 10) Map.move(0, 0) font = pygame.font.SysFont(None, 50) a = font.render('A', 1, (255, 0, 0)) p = Orientation.map_obj( "", "", {}, a, Map, Orientation.point(*Map.get_position() + (Map.in_map, ))) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Map.move(0, -10) if event.key == pygame.K_RIGHT: Map.move(10, 0)
import pygame from Mind import Orientation pygame.init() screen = pygame.display.set_mode((500, 500)) Map = Orientation.tiled_map("first_level") Map.set_camera_pos(300, 300) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((255, 255, 255)) Map.blit() pygame.display.flip() pygame.quit()
def opt_size(self): """Optimizes size of object. Size will be picture size. """ self.obj = Orientation.rect(self.x, self.y, self.picture.get_width(), self.picture.get_height(), self.Map.in_map)
def __init__(self, game): self.game = game self.screen = self.game.screen self.keyboard = self.game.keyboard self.important = {"game": self.game, "keyboard": self.keyboard} pl_pics = [pygame.image.load("doc/art/player/s.png"), pygame.image.load("doc/art/player/m.png"), pygame.image.load("doc/art/player/b.png")] ch_pics = [pygame.image.load("doc/art/chev/s.png"), pygame.image.load("doc/art/chev/m.png"), pygame.image.load("doc/art/chev/b.png")] ent_pics = [pygame.image.load("doc/art/enter/s.png"), pygame.image.load("doc/art/enter/m.png"), pygame.image.load("doc/art/enter/b.png")] tab_pics = [pygame.image.load("doc/art/tab/s.png"), pygame.image.load("doc/art/tab/m.png"), pygame.image.load("doc/art/tab/b.png")] self.Map = Orientation.visual_map(self.WIDTH, self.HEIGHT, path="doc/art", decode=[{}, {}, { "player": Existence.mov_type(None, pl_pics, props=self.important, logic=Existence.Subject + entity.Entity + entity.Player), "chev": Existence.mov_type(None, ch_pics, props=self.important, logic=entity.Entity), "enter": Existence.mov_type(None, ent_pics, props=self.important, logic=entity.Entity), "tab": Existence.mov_type(None, tab_pics, props=self.important, logic=entity.Entity) }], tilesize=(10, 10), size_in_tiles=True) self.Map.create_tileset("map/wall.bmp", "wall") self.Map.create_layer("walls") self.rooms = [] self.Map.rooms = self.rooms self.bridges = [] self.bridgesA = [] self.bridgesB = [] self.bridgesC = [] self.fill = 0 for x in range(self.ROOMS): w = random.randint(5, 10) h = random.randint(5, 10) self.rooms.append(generate.Room(random.randrange(self.WIDTH - w + 1), random.randrange(self.HEIGHT - h + 1), w, h, self.Map)) if x: bridge = generate.Bridge(self.rooms[-2], self.rooms[-1], 3, self.Map) self.bridges.append(bridge) self.bridgesA.append(bridge) self.rooms[-2].connect(bridge) self.rooms[-1].connect(bridge) self.rooms_n = self.ROOMS self.A_n = self.ROOMS - 1 for x in range(self.B_BRIDGES): room1 = random.choice(self.rooms) room2 = random.choice(self.rooms) while room1 == room2: room2 = random.choice(self.rooms) bridge = generate.Bridge(room1, room2, 2, self.Map) self.bridges.append(bridge) self.bridgesB.append(bridge) room1.connect(bridge) room2.connect(bridge) self.B_n = self.B_BRIDGES for x in range(self.C_BRIDGES): room1 = random.choice(self.rooms) room2 = random.choice(self.rooms) while room1 == room2: room2 = random.choice(self.rooms) bridge = generate.Bridge(room1, room2, 1, self.Map) self.bridges.append(bridge) self.bridgesC.append(bridge) room1.connect(bridge) room2.connect(bridge) self.C_n = self.C_BRIDGES X, Y = random.choice(list(random.choice(self.rooms).tiles())) self.Map.create_objectgroup("live") o1 = self.Map.decode[2]["player"](X*10, Y*10, "player", Map=self.Map) self.Map.assign_object("live", o1) X, Y = random.choice(list(random.choice(self.rooms).tiles())) o = self.Map.decode[2]["chev"](X*10, Y*10, "chev", Map=self.Map) self.Map.assign_object("live", o) X, Y = random.choice(list(random.choice(self.rooms).tiles())) o = self.Map.decode[2]["enter"](X*10, Y*10, "enter", Map=self.Map) self.Map.assign_object("live", o) X, Y = random.choice(list(random.choice(self.rooms).tiles())) o = self.Map.decode[2]["tab"](X*10, Y*10, "tab", Map=self.Map) self.Map.assign_object("live", o) self.up_layer = self.Map.layers[0] self.background = pygame.Surface((self.WIDTH * 10, self.HEIGHT * 10)) self.background.fill((0, 0, 50)) self.Map.images[0].screen = self.background self.up_layer.set_pos(0, 0) self.up_layer.get_tiles = self.get_tiles self.up_layer.blit() self.Map.layers[0] = FakeLayer(0, 0, self.background, self.screen) o1.move(0, 0) for bridge in self.bridges: bridge.check() self.rooms[0].set_centre(self)