def draw(self): #Draw all flags you are carrying i = -1.5 for f in self.flags: temp = flag.Flag(self.screen, self.row, self.col, f) temp.drawSmall(int(0.25 * i * tile_width), 0.5) i = i + 1 #Blink c = self.color if self.blink: c = black #Draw outline of ship. points = self.getCorners() pygame.draw.polygon(self.screen, c, points, int(scaling * 8)) #Draw current action offset_x, offset_y = self.getCenter() self.screen.blit(self.text, (offset_x, offset_y)) #Draw health bar r = pygame.Rect(offset_x - tile_width / 2.4, offset_y + tile_height * 0.3, tile_width * 0.8, tile_height * 0.1) pygame.draw.rect(self.screen, red, r) r = pygame.Rect(offset_x - tile_width / 2.4, offset_y + tile_height * 0.3, tile_width * 0.8 * (self.hp / self.max_hp), tile_height * 0.1) pygame.draw.rect(self.screen, green, r) #Draw laser beam if self.laser_end != None: x = self.laser_end[1] * tile_width + tile_width / 2 y = self.laser_end[0] * tile_height + tile_height / 2 start = (offset_x, offset_y) end = (x, y) pygame.draw.line(self.screen, red, start, end, 3) pygame.draw.line(self.screen, white, start, end, 1)
def __init__(inst, period=None, start=True): if period == None: period = inst.defMinsPerBeat inst.lock = threading.RLock() with inst.lock: inst.secsPerBeat = 60 * period # The following flags all share the same lock so that changes # to more than one of them at a time still happen atomically. inst.started = flag.Flag( lock=inst.lock) # Has the heart started beating yet? inst.beating = flag.Flag( lock=inst.lock) # Is the heart currently engaged in a beat? inst.pause = flag.Flag(lock=inst.lock) # Should the heart pause? inst.paused = flag.Flag(lock=inst.lock) # Is the heart paused? inst.dead = flag.Flag(lock=inst.lock) # Is the heart dead? # Number of beats since we've started. inst.nbeats = 0 # Do normal ThreadActor initialization. logmaster.ThreadActor.__init__(inst) if start: inst.start() # Start this new thread.
def __init__(inst, *args, **kargs): inst._lock = threading.RLock( ) # Reentrant mutex lock for thread-safe access to object data. with inst._lock: inst.defaultComponent = 'server' # Create flags for tracking various bits of state that we depend on. inst.ctu_ready = flag.Flag(lock=inst._lock, initiallyUp=False) inst.fedm_ready = flag.Flag(lock=inst._lock, initiallyUp=False) inst.good_time = flag.Flag(lock=inst._lock, initiallyUp=False) # Create our initial task: Start a run going as soon as we can. inst.initialTask = worklist.WorkItem(inst._queueStartupSequence) # Hand off control to the initializer for our parent class. worklist.Worker.__init__( inst, *args, **kargs) # This starts the Worker thread running.
def __init__(self, file_path): self.starting_blocks = [] self.starting_enemies = [] self.starting_coins = [] self.starting_powerups = [] self.starting_flag = [] self.starting_fires = [] self.blocks = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.coins = pygame.sprite.Group() self.powerups = pygame.sprite.Group() self.flag = pygame.sprite.Group() self.fires = pygame.sprite.Group() self.active_sprites = pygame.sprite.Group() self.inactive_sprites = pygame.sprite.Group() with open(file_path, 'r') as f: data = f.read() map_data = json.loads(data) self.width = map_data['width'] * game.GRID_SIZE self.height = map_data['height'] * game.GRID_SIZE self.start_x = map_data['start'][0] * game.GRID_SIZE self.start_y = map_data['start'][1] * game.GRID_SIZE for item in map_data['blocks']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE img = game.block_images[item[2]] self.starting_blocks.append(block.Block(x, y, img)) for item in map_data['fires']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_fires.append(fire.Fire(x, y, game.fire_img)) for item in map_data['bears']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append(bear.Bear(x, y, game.bear_images)) for item in map_data['monsters']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_enemies.append( monster.Monster(x, y, game.monster_images)) for item in map_data['coins']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_coins.append(coin.Coin(x, y, game.coin_img)) for item in map_data['oneups']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(oneUp.OneUp(x, y, game.oneup_img)) for item in map_data['hearts']: x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE self.starting_powerups.append(heart.Heart(x, y, game.heart_img)) for i, item in enumerate(map_data['flag']): x, y = item[0] * game.GRID_SIZE, item[1] * game.GRID_SIZE if i == 0: img = game.flag_img else: img = game.flagpole_img self.starting_flag.append(flag.Flag(x, y, img)) self.background_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.scenery_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.inactive_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.active_layer = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) if map_data['background-color'] != "": self.background_layer.fill(map_data['background-color']) if map_data['background-img'] != "": background_img = pygame.image.load( map_data['background-img']).convert_alpha() if map_data['background-fill-y']: h = background_img.get_height() w = int(background_img.get_width() * game.HEIGHT / h) background_img = pygame.transform.scale( background_img, (w, game.HEIGHT)) if "top" in map_data['background-position']: start_y = 0 elif "bottom" in map_data['background-position']: start_y = self.height - background_img.get_height() if map_data['background-repeat-x']: for x in range(0, self.width, background_img.get_width()): self.background_layer.blit(background_img, [x, start_y]) else: self.background_layer.blit(background_img, [0, start_y]) if map_data['scenery-img'] != "": scenery_img = pygame.image.load( map_data['scenery-img']).convert_alpha() if map_data['scenery-fill-y']: h = scenery_img.get_height() w = int(scenery_img.get_width() * game.HEIGHT / h) scenery_img = pygame.transform.scale(scenery_img, (w, game.HEIGHT)) if "top" in map_data['scenery-position']: start_y = 0 elif "bottom" in map_data['scenery-position']: start_y = self.height - scenery_img.get_height() if map_data['scenery-repeat-x']: for x in range(0, self.width, scenery_img.get_width()): self.scenery_layer.blit(scenery_img, [x, start_y]) else: self.scenery_layer.blit(scenery_img, [0, start_y]) pygame.mixer.music.load(map_data['music']) self.gravity = map_data['gravity'] self.terminal_velocity = map_data['terminal-velocity'] self.completed = False self.blocks.add(self.starting_blocks) self.enemies.add(self.starting_enemies) self.coins.add(self.starting_coins) self.powerups.add(self.starting_powerups) self.flag.add(self.starting_flag) self.fires.add(self.starting_fires) self.active_sprites.add(self.coins, self.enemies, self.powerups, self.fires) self.inactive_sprites.add(self.blocks, self.flag) # with this speed up blitting on slower computers? for s in self.active_sprites: s.image.convert() for s in self.inactive_sprites: s.image.convert() self.inactive_sprites.draw(self.inactive_layer) # is converting layers helpful at all? self.background_layer.convert() self.scenery_layer.convert() self.inactive_layer.convert() self.active_layer.convert()
surface = pygame.display.set_mode((map_width, map_height)) player1 = robot_wait.Waitbot(surface, white, 'Waiter') player2 = robot_ai1.AI1(surface, yellow, 'SmartBoi') player3 = robot_ai2.AI2(surface, blue, 'SimpleBoi') player4 = robot.Robot(surface, red, 'Rando') #Random bot player5 = robot_greedy.Greedybot(surface, black, 'Greedy') player_list = [player1, player2, player3, player4, player5] for i in range(len(player_list)): player_list[i].setStart(player_locations[i][0],player_locations[i][1]) flags = [] colors = [red, yellow, blue, green] for i in range(4): flags.append(flag.Flag(surface, flag_locations[i][0], flag_locations[i][1], colors[i])) #Use this list for ordering actions action_list = [] #List of winners winners = [] # Draw all images on the surface done = False while not done and len(player_list)>0 and round_count<round_limit: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE:
def __init__(this, initialContents: object = None, lock=None): """Instance initializer for objects of class WatchBox.""" if lock == None: lock = threading.RLock() this._lock = lock this._contents = initialContents this._updated = flag.Flag(lock=this._lock, initiallyUp=False)
def __init__(inst, initiallyPaused=False, period=None, socket=None, *args, **kargs): global theBroadcaster # We'll overwrite it later. # If the <period> argument is unspecified or None, then # use the class variable as its default value instead. if None == period: period = inst.defSecsBtwMsgs # Diagnostic output. logger.info( "__init__(): Begin broadcasting server address at %d-second intervals..." % period) # Copy this object to the module global. (We only expect # there will be one broadcaster in the whole application.) # (We could do error-checking here and complain if the # global's already been assigned a value other then "None".) theBroadcaster = inst # Create the re-entrant mutex lock which will guard # multithreaded access to this instance's state. inst.lock = threading.RLock() with inst.lock: # Initialize misc. instance variables. inst.secsBtwMsgs = period # Remember broadcast interval. inst.pauseAt = None # Initially, no preprogrammed pause time. # Create our control/status flags. inst.pause = flag.Flag( lock=inst.lock) # Should broadcasting pause? inst.paused = flag.Flag(lock=inst.lock) # Is broadcasting paused? inst.ended = flag.Flag( lock=inst.lock) # Has broadcaster terminated? # Create the network socket for sending broadcasts. # (Unless an existing socket to use is being passed in.) if socket == None: inst._openSocket() else: inst._sock = socket # Compose the message packet that we will send in each broadcast. inst._msg = bytes(_MSG_FMT_STR % sitedefs.MY_IP, 'ascii') # Complete ThreadActor initialization. ThreadActor.__init__(inst, *args, **kargs) # If we were asked to start the Broadcaster in the paused state, do so. if initiallyPaused: inst.pause.rise( ) # Can't use .suspend() method b/c thread not running yet. # Finally, start the new Broadcaster thread running. inst.start()
self.exitFlag = True host = "localhost" uid = "root" passw = "1123581321ElViNBV" schema = "pourtest" dbproxy.DBCommand.comList = { "ins_data" : "INSERT INTO data VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);", "ins_id" : "INSERT INTO flights(id,name) VALUES(%s,%s);" } exceptionOutput = queue.Queue(20) fileOutput = queue.Queue(20) flags = {p[0] : flag.Flag(False) for p in Processes.getAll() } queues = {q[0] : queue.Queue(50) for q in Queues.getAll()} #sID = "" #while not sID.isnumeric(): # sID = input("Input session id: ") sID = 8 sName = "" #sName = input("Input session name: ") ses = session.Session(sID,sName) expOut = fileio.FileIO("log.txt",fileOutput,flag.Flag()) expHandler = exceptionhandler.ExceptionHandler(exceptionOutput,fileOutput) processing.DataHandler.setErrorLog(exceptionOutput)