def __init__(self, charflag, unitdict): pygame.sprite.DirtySprite.__init__(self) for prop in ['id', 'stack_id', 'side']:#, 'environ_id']: setattr(self, prop, unitdict[prop]) if charflag is False: self.charflag = charflag self.name = unitdict["type"] for prop in ['mobile', 'environ_combat', 'space_combat', 'stack_id']: setattr(self, prop, unitdict[prop]) self.image, self.rect = load_image("DrJ.png") if charflag is True: properties = ('name', 'detected', 'wounds', 'active', 'stack_id', 'bonuses', 'title', 'race', 'combat', 'intelligence', 'leadership', 'diplomacy', 'navigation', 'homeworld', 'detected', 'captive') for prop in properties: setattr(self, prop, unitdict[prop]) self.image, self.rect = load_image(unitdict["img"]) self.loc_id = 2210 self.pos = None self.loc = None self.prev_image = self.image self.dirty = 2 self.stack_list = list() self.stack_list.append(self)
def __init__(self, charflag, unitdict): pygame.sprite.DirtySprite.__init__(self) self.charflag = charflag for prop in ['id', 'stack_id', 'side']: #, 'environ_id']: setattr(self, prop, unitdict[prop]) if charflag is False: #self.charflag = charflag self.name = unitdict["type"] for prop in [ 'mobile', 'environ_combat', 'space_combat', 'stack_id' ]: setattr(self, prop, unitdict[prop]) self.image, self.rect = load_image("DrJ.png") if charflag is True: properties = ('name', 'detected', 'wounds', 'active', 'stack_id', 'bonuses', 'title', 'race', 'combat', 'intelligence', 'leadership', 'diplomacy', 'navigation', 'homeworld', 'detected', 'captive') for prop in properties: setattr(self, prop, unitdict[prop]) self.image, self.rect = load_image(unitdict["img"]) #self.loc_id = 2210 self.pos = None self.loc = None self.prev_image = self.image self.dirty = 2 self.stack_list = list() self.stack_list.append(self)
def __init__(self, parent_system, planetdict, environlist, planet_orientation, image): #print planetdict self.parent = parent_system #self. self.location = planetdict["location"] self.planet_id = planetdict["id"] self.name = planetdict["name"] self.pdb_state = planetdict["pdb_state"] self.loyalty = planetdict["loyalty"] self.pdb_level = planetdict["pdb_level"] self.environ_count = planetdict["environ_count"] self.orient = planet_orientation self.prev_orient = None if self.orient is "left": self.pos = self.parent.screen.get_rect().midleft elif self.orient is "center": self.pos = self.parent.screen.get_rect().center elif self.orient is "right": self.pos = self.parent.screen.get_rect().midright pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image(image, -1) self.collide_rect = self.rect.inflate(-50, -50) #======================================================================= # Environment Population #======================================================================= self.environment = environments.EnvironBox(self, self.rect) for environ in environlist: #print environ if environ["planet_id"] == self.planet_id: self.environment.addEnviron(environ)
def __init__(self, parent_system, planetdict, environlist, planet_orientation, image): #print planetdict self.parent = parent_system #self. self.location = planetdict["location"] self.planet_id = planetdict["id"] self.name = planetdict["name"] self.pdb_state = planetdict["pdb_state"] self.loyalty = int(planetdict["loyalty"]) self.pdb_level = planetdict["pdb_level"] self.environ_count = planetdict["environ_count"] self.orient = planet_orientation self.prev_orient = None if self.orient is "left": self.pos = self.parent.screen.get_rect().midleft elif self.orient is "center": self.pos = self.parent.screen.get_rect().center elif self.orient is "right": self.pos = self.parent.screen.get_rect().midright pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image(image, -1) self.collide_rect = self.rect.inflate(-50, -50) #======================================================================= # Environment Population #======================================================================= self.environment = environments.EnvironBox(self, self.rect) for environ in environlist: #print environ if environ["planet_id"] == self.planet_id and environ["location"] != 0: self.environment.addEnviron(environ)
PlanetName = pygame.font.Font(None, 50) pdbtextrect = pygame.font.Font(None, 25) loyaltytextrectfont = pygame.font.Font(None, 20) planetname = planet1name pdbstatustext = "PDB Status" pdbstatustextrect = pygame.font.Font(None, 20) pdbfontsurface = pdbtextrect.render(pdbstatustext, 1, (255,255,255)) planetFontSurface = PlanetName.render(planetname, 1, planettextcolor) loayaltytextsurface = loyaltytextrectfont.render(loyaltytext, 1, loyaltytextcolor) pdbstatustexsurface = pdbstatustextrect.render(pdbstatustext, 1, (255,255,255)) pdbdownrect = pygame.Rect(pdbbox) pdb_image, pdbrect = load_image("pdbup.png", None) pdbrect.topleft = pdbboxpostion class MenuBar(): def __init__(self, planetname, loyaltystate, backgroundcolor, pdbup, position):#, PDBstatus=None): self.planetname = planetname #self.planetnametextcolor = planetnametextcolor self.loyaltystate = loyaltystate self.pdbup = pdbup self.pdbcontrol = "Rebel" self.backgroundcolor = backgroundcolor self.planetboxcolor = (255,200,200) self.buttoncolor = (50,102,255) self.position = position
def main(client, setupinfo=None): gameid = 'test1' #setupinfo["request"]["parameters"]["id"] height = 720 width = 1024 screensize = (width, height) screen = pygame.display.set_mode(screensize) clock = pygame.time.Clock() pygame.mouse.set_visible(0) animate = True running = True background, background_rect = load_image("stars.jpg") outer_menu = MenuBar(planet1name, 1, backgroundcolor, True, (90, 0)) menubar.pdb_image, menubar.pdbrect = load_image("pdbup.png", None) menubar.pdbrect.topleft = menubar.pdbboxpostion screen.blit(background, background_rect) mouse_ptr = MouseCursor("pointer2.png") mouse_sel = MouseCursor("selected2.png") mouse = pygame.sprite.RenderUpdates((mouse_ptr)) mouse.draw(screen) pygame.display.flip() #=========================================================================== # Object Initialization: #=========================================================================== characterlist = client.root.get_state( game_id=gameid, object_type="Character")["response"]["character"] planetlist = client.root.get_state( game_id=gameid, object_type="Planet")["response"]["planet"] environlist = client.root.get_state( game_id=gameid, object_type="Environ")["response"]["environ"] militarylist = client.root.get_state( game_id=gameid, object_type="Unit")["response"]["unit"] stacklist = client.root.get_state(game_id=gameid, object_type="Stack")["response"]["stack"] star_system = System(screen, background, animate, characterlist, planetlist, environlist, militarylist, stacklist) #print characterlist menu = Menu_Buttons.Menu(screen) selected_unit = None while running: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sysexit() elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sysexit() if not mouse_ptr.down: if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: if selected_unit: hover_unit = left_mouse_select_check( client, mouse_sel, star_system) if hover_unit != selected_unit: #mergeresponse = client.root.merge_stack(unit.stack_id, selected_unit.stack_id) #if mergeresponse["Success"]: selected_unit.add_unit(hover_unit) star_system.unit_list.remove(hover_unit) print "SPACE BAR" if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_ptr.pressed = mouse_sel.pressed = True mouse_ptr.released = mouse_sel.released = False selected_unit = left_mouse_select_check( client, mouse_ptr, star_system) # while the mouse button is down, change its cursor mouse.remove(mouse_ptr) mouse.add(mouse_sel) #Update Buttons and menu status menu.update_buttons(mouse_ptr.rect) elif event.button == 3: key_mod = pygame.key.get_mods() if key_mod == 4097 or key_mod == 1: hover_unit = star_system.unit_list.get_sprites_at( mouse_ptr.pos) print "STACK REMOVING FROM", hover_unit if hover_unit: if hover_unit[0].stack_list[-1].charflag: splitresponse = client.root.split_stack( stack_id=hover_unit[0].stack_id, character_id=hover_unit[0]. stack_list[-1].id) else: splitresponse = client.root.split_stack( stack_id=hover_unit[0].stack_id, unit_id=hover_unit[0].stack_list[-1].id ) print splitresponse if splitresponse["request"]["success"]: sprite = hover_unit[0].remove_unit() sprite.set_stack_id( splitresponse["response"]["unit"] ["stack_id"]) star_system.unit_list.add(sprite) print "SHIFT RIGHT CLICK" else: hover_unit = star_system.unit_list.get_sprites_at( mouse_ptr.pos) if hover_unit: hover_unit[0].cycle_unit() print "RIGHT CLICK" if event.type == pygame.MOUSEBUTTONUP: mouse_ptr.released = mouse_sel.released = True selected_unit = left_mouse_unselect_check( client, mouse, selected_unit, star_system) # while the mouse button is up, change its cursor mouse.remove(mouse_sel) mouse.add(mouse_ptr) screen.blit(background, background_rect) star_system.update() if selected_unit: selected_unit.update(True) mouse.update() star_system.draw() #Draw buttons and menus menu.draw_buttons(screen, height, width, selected_unit) for planet in star_system.planet_list: if planet.orient == 'center': current_planet = planet try: outer_menu.update(current_planet.name, current_planet.loyalty, current_planet.pdb_state, "Egrix", False, False) except: pass outer_menu.draw(background, screen, menubar_) mouse.draw(screen) pygame.display.flip()
def main(client, setupinfo=None): gameid = 'test1'#setupinfo["request"]["parameters"]["id"] height = 720 width = 1024 screensize = (width, height) screen = pygame.display.set_mode(screensize) clock = pygame.time.Clock() pygame.mouse.set_visible(0) animate = True running = True background, background_rect = load_image("stars.jpg") outer_menu = MenuBar(planet1name, 1, backgroundcolor, True, (90,0)) menubar.pdb_image, menubar.pdbrect = load_image("pdbup.png", None) menubar.pdbrect.topleft = menubar.pdbboxpostion screen.blit(background, background_rect) mouse_ptr = MouseCursor("pointer2.png") mouse_sel = MouseCursor("selected2.png") mouse = pygame.sprite.RenderUpdates((mouse_ptr)) mouse.draw(screen) pygame.display.flip() #=========================================================================== # Object Initialization: #=========================================================================== characterlist = client.root.get_state(game_id = gameid, object_type="Character")["response"]["character"] planetlist = client.root.get_state(game_id = gameid, object_type="Planet")["response"]["planet"] environlist = client.root.get_state(game_id = gameid, object_type="Environ")["response"]["environ"] militarylist = client.root.get_state(game_id = gameid, object_type="Unit")["response"]["unit"] stacklist = client.root.get_state(game_id = gameid, object_type="Stack")["response"]["stack"] star_system = System(screen, background, animate, characterlist, planetlist, environlist, militarylist, stacklist) #print characterlist menu = Menu_Buttons.Menu(screen) selected_unit = None while running: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sysexit() elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sysexit() if not mouse_ptr.down: if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: if selected_unit: hover_unit = left_mouse_select_check(client, mouse_sel, star_system) if hover_unit != selected_unit: #mergeresponse = client.root.merge_stack(unit.stack_id, selected_unit.stack_id) #if mergeresponse["Success"]: selected_unit.add_unit(hover_unit) star_system.unit_list.remove(hover_unit) print "SPACE BAR" if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_ptr.pressed = mouse_sel.pressed = True mouse_ptr.released = mouse_sel.released = False selected_unit = left_mouse_select_check(client, mouse_ptr, star_system) # while the mouse button is down, change its cursor mouse.remove(mouse_ptr) mouse.add(mouse_sel) #Update Buttons and menu status menu.update_buttons(mouse_ptr.rect) elif event.button == 3: key_mod = pygame.key.get_mods() if key_mod == 4097 or key_mod == 1: hover_unit = star_system.unit_list.get_sprites_at(mouse_ptr.pos) print "STACK REMOVING FROM", hover_unit if hover_unit: if hover_unit[0].stack_list[-1].charflag: splitresponse = client.root.split_stack(stack_id = hover_unit[0].stack_id, character_id =hover_unit[0].stack_list[-1].id) else: splitresponse = client.root.split_stack(stack_id = hover_unit[0].stack_id, unit_id =hover_unit[0].stack_list[-1].id) print splitresponse if splitresponse["request"]["success"]: sprite = hover_unit[0].remove_unit() sprite.set_stack_id(splitresponse["response"]["unit"]["stack_id"]) star_system.unit_list.add(sprite) print "SHIFT RIGHT CLICK" else: hover_unit = star_system.unit_list.get_sprites_at(mouse_ptr.pos) if hover_unit: hover_unit[0].cycle_unit() print "RIGHT CLICK" if event.type == pygame.MOUSEBUTTONUP: mouse_ptr.released = mouse_sel.released = True selected_unit = left_mouse_unselect_check(client, mouse, selected_unit, star_system) # while the mouse button is up, change its cursor mouse.remove(mouse_sel) mouse.add(mouse_ptr) screen.blit(background, background_rect) star_system.update() if selected_unit: selected_unit.update(True) mouse.update() star_system.draw() #Draw buttons and menus menu.draw_buttons(screen, height, width, selected_unit) for planet in star_system.planet_list: if planet.orient == 'center': current_planet = planet try: outer_menu.update(current_planet.name, current_planet.loyalty, current_planet.pdb_state, "Egrix", False, False) except: pass outer_menu.draw(background, screen, menubar_) mouse.draw(screen) pygame.display.flip()