def main(): running = True pygame.init() screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() pygame.display.set_caption('Tetra Master') board = pygame.image.load(utils.dirlock('../data/board.bmp')) _selection = False _hand = pieces.get_hand() _world = worldgen.gen_world() turn = events.Turn() while running: # Initialization clock.tick(60) screen.blit(board,(0,0)) trayjizzle = pygame.font.Font(utils.dirlock("../data/Trajan-Bold.ttf"), 30) monospizzle = pygame.font.SysFont("monospace", 15, True) mx, my = pygame.mouse.get_pos() _mouse_pos = (mx, my) # Drawing pygame.draw.rect(screen, (100,40,80), (150,40, 336, 408)) utils.print_world(_world, screen) display_mouse_coords = monospizzle.render("(" + str(mx) + ", " + str(my) + ")", 1, (255,255,255)) screen.blit(display_mouse_coords, (5,5)) for monster in _hand: screen.blit(monster.image,(monster.xpos, monster.ypos)) if monster.selected == True: current_selected = trayjizzle.render(monster.name + " is selected!", 1, (255,255,255)) screen.blit(current_selected, (100, 100)) for _event in pygame.event.get(): if _event.type == QUIT: running = False elif _event.type == MOUSEBUTTONDOWN: if _world.currentPlayer == True: _hand, _selection = turn.player(_hand, _selection, _mouse_pos, _world) if _world.currentPlayer == False: turn.ai(_world) current_player_text = trayjizzle.render("Current Player: " + ("Player" if _world.currentPlayer else "AI"), 1, (255,255,255)) screen.blit(current_player_text, (50,400)) pygame.display.update()
def on_key_press(self,symbol,modifiers): if symbol in { key.UP, key.NUM_8 }: self._menu.option_up() return True if symbol in { key.DOWN, key.NUM_2 }: self._menu.option_down() return True if symbol == key.ENTER: if self._menu.selection == 0: print("starting new game.") newgamedata = worldgen.gen_world() self._window.change_bottom_mode(MapInterface(self._window,newgamedata)) if self._menu.selection == 1: print("viewing high scores.") if self._menu.selection == 2: print("exiting game.") pyglet.app.exit() return True
def main(): running = True pygame.init() screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() pygame.display.set_caption('Tetra Master') board = pygame.image.load(utils.dirlock('../data/board.bmp')) world = worldgen.gen_world() cards = pieces.get_cards() selection = False while running: clock.tick(60) screen.blit(board, (0, 0)) myfont = pygame.font.Font(utils.dirlock("../data/Trajan-Bold.ttf"), 30) mx, my = pygame.mouse.get_pos() mouse_pos = (mx, my) pygame.draw.rect(screen, (100, 40, 80), (150, 40, 336, 408)) for a in world: for b in a: pygame.draw.rect(screen, (0, 0, 0), (b.xpos, b.ypos, 84, 102)) if b.card: b.draw(b.card.image) screen.blit(b.image, (b.xpos, b.ypos)) for monster in cards: screen.blit(monster.image, (monster.xpos, monster.ypos)) if monster.selected == True: current_selected = myfont.render( monster.name + " is selected!", 1, (255, 255, 255)) screen.blit(current_selected, (100, 100)) for event in pygame.event.get(): if event.type == QUIT: running = False elif event.type == MOUSEBUTTONDOWN: cards, selection = events.watch(cards, selection, mouse_pos, world) pygame.display.update()
def main(): running = True pygame.init() screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() pygame.display.set_caption('Tetra Master') board = pygame.image.load(utils.dirlock('../data/board.bmp')) world = worldgen.gen_world() cards = pieces.get_cards() selection = False while running: clock.tick(60) screen.blit(board,(0,0)) myfont = pygame.font.Font(utils.dirlock("../data/Trajan-Bold.ttf"), 30) mx,my = pygame.mouse.get_pos() mouse_pos = (mx, my) pygame.draw.rect(screen, (100,40,80), (150,40, 336, 408)) for a in world: for b in a: pygame.draw.rect(screen, (0,0,0), (b.xpos, b.ypos, 84, 102)) if b.card: b.draw(b.card.image) screen.blit(b.image, (b.xpos, b.ypos)) for monster in cards: screen.blit(monster.image,(monster.xpos, monster.ypos)) if monster.selected == True: current_selected = myfont.render(monster.name + " is selected!", 1, (255,255,255)) screen.blit(current_selected, (100, 100)) for event in pygame.event.get(): if event.type == QUIT: running = False elif event.type == MOUSEBUTTONDOWN: cards, selection = events.watch(cards,selection,mouse_pos,world) pygame.display.update()
self.move_view(row_move,col_move) def cursor_tilenum(self): return self._cursor_tilenum if __name__ == "__main__": "UNIT TEST CODE" import time from random import randint from pyglet.window import key import worldgen gd = worldgen.gen_world() v = Viewport(gd._level,x_margin=5,y_margin=5,corner_row=80,corner_col=80,visible_rows=20,visible_cols=20) w = pyglet.window.Window() @w.event def on_draw(): w.clear() start = time.clock() v.render() v.draw() print(time.clock()-start) @w.event def on_key_press(symbol,modifiers): if symbol == key.NUM_8: print(v.move_view(3,0)) if symbol == key.NUM_2: print(v.move_view(-3,0))