def draw(self, surface, flags): bp = intpos(self._worldobj.body.position) if flags["DEBUG"]: # position text surface.blit(debugfont().render(repr((bp[0], bp[1])), False, (192, 192, 192)), (bp[0]-30, bp[1]-self._dist-30)) # id text surface.blit(debugfont().render("#"+str(self._worldobj.id), False, (192, 192, 192)), (bp[0]-4, bp[1]+self._dist+4)) # collision circle if self._worldobj.__dict__.has_key("points"): #Polygon self.draw_poly(surface, (192, 192, 192), bp, self._worldobj.shape.get_points(), 2) else: wrapcircle(surface, (192, 192, 192), bp, self._dist, self._world.size, 2) if self._worldobj.in_nebula != None: wrapcircle(surface, (255, 64, 64), bp, self._dist, self._world.size, 4) # velocity vector pygame.draw.line(surface, (255, 0, 0), bp, self._worldobj.body.velocity + bp) # Velocity if flags["STATS"] and self._worldobj.health.maximum > 0: # Health Bar Background pygame.draw.rect(surface, (64, 0, 0), pygame.Rect(bp[0]-16, bp[1] - 25, 32, 8)) if flags["DEBUG"]: surface.blit(debugfont().render(repr(int(100 * self._worldobj.health.percent)), False, (255, 255, 255)), (bp[0]+18, bp[1] - 26)) # Health Bar surface.blit(GUIEntity._healthbar, (bp[0]-15, bp[1] - 24), pygame.Rect(0, 0, 30 * self._worldobj.health.percent, 6)) if flags["STATS"] and self._worldobj.energy.maximum > 0: # Energy Bar pygame.draw.rect(surface, (0, 64, 0), pygame.Rect(bp[0]-16, bp[1] + 26, 32, 5)) if flags["DEBUG"]: surface.blit(debugfont().render(repr(int(100 * self._worldobj.energy.percent)), False, (255, 255, 255)), (bp[0]+18, bp[1] + 24)) surface.blit(GUIEntity._energybar, (bp[0]-15, bp[1] + 27), pygame.Rect(0, 0, 30 * self._worldobj.energy.percent, 3))
def draw(self, surface, flags): super(DragonGUI, self).draw(surface, flags) # Draw Dragon attack area if flags["DEBUG"] and isinstance( self._worldobj, Dragon) and self._worldobj.influence_range > 0: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range + self._worldobj.attack_speed))) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position - (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position - (self._worldobj.influence_range + self._worldobj.attack_speed, 0))) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position + (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position + (self._worldobj.influence_range + self._worldobj.attack_speed, 0))) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range + self._worldobj.attack_speed))) # radius surface.blit( debugfont().render(repr(self._worldobj.influence_range), False, (255, 255, 192)), intpos((bp[0], bp[1] - self._worldobj.influence_range - 16))) # speed surface.blit( debugfont().render( repr(int(self._worldobj.body.velocity.length)), False, (255, 255, 255)), (bp[0] + 20, bp[1])) if self._worldobj.target != None: # highlight wrapcircle(surface, (64, 64, 192), intpos(self._worldobj.target[1].body.position), 32, self._world.size, 2)
def draw(self, surface, flags): # Check if Thrusting or Braking #surface.blit(self.surface, intpos((self._worldobj.body.position[0] - 8, self._worldobj.body.position[1] - 8))) bp = intpos(self._worldobj.body.position) wrapcircle(surface, (0, 255, 255), bp, int(self._worldobj.size), self._world.size, 1) # Radar if flags["GAME"]: text = namefont().render("Points: %.1f" % (self._worldobj.size - self._worldobj.basesize), False, (0, 255, 255)) surface.blit(text, (bp[0]-text.get_width()/2, bp[1]-44)) if self._worldobj.pname != None: text = namefont().render("From %s" % self._worldobj.pname, False, (0, 255, 255)) surface.blit(text, (bp[0]-text.get_width()/2, bp[1]+44)) super(BubbleWrapper, self).draw(surface, flags)
def gui_draw_game_world_info(self, surface, flags, trackplayer): for player in self.game_get_current_player_list(): obj = player.object if obj != None: bp = intpos(obj.body.position) wrapcircle(surface, (0, 255, 255), bp, self.scanrange, self.world.size, 1) # Scan Range text = debugfont().render("%s [%s]" % (repr(player.mission), player.failed), False, (0, 255, 255)) surface.blit(text, (bp[0]-text.get_width()/2, bp[1] - 6)) if trackplayer != None: curs = [] curf = [] obj = trackplayer.object if obj != None: for cmd in obj.commandQueue: if isinstance(cmd, ScanCommand): if cmd.success: curs.append(cmd.target) else: curf.append(cmd.target) for obj in self.world: if trackplayer in obj.scanned_by: wrapcircle(surface, (0, 255, 255), intpos(obj.body.position), obj.radius + 4, self.world.size, 4) if obj.id in curs: wrapcircle(surface, (255, 255, 0), intpos(obj.body.position), obj.radius + 5, self.world.size, 2) elif obj.id in curf: wrapcircle(surface, (255, 0, 0), intpos(obj.body.position), obj.radius + 5, self.world.size, 2)
def gui_draw_game_world_info(self, surface, flags, trackplayer): for player in self.game_get_current_player_list(): obj = player.object if obj != None: bp = intpos(obj.body.position) wrapcircle(surface, (0, 255, 255), bp, self.scanrange, self.world.size, 1) # Scan Range if self.usemissions: text = debugfont().render("%s [%s]" % (repr(player.mission), player.failed), False, (0, 255, 255)) surface.blit(text, (bp[0]-text.get_width()/2, bp[1] - 6)) if trackplayer != None: curs = [] curf = [] obj = trackplayer.object if obj != None: # Draw Success/Failure Circles around Current Scan Targets for cmd in obj.commandQueue: if isinstance(cmd, ScanCommand): if cmd.success: obj = self.world[cmd.target] wrapcircle(surface, (255, 255, 0), intpos(obj.body.position), obj.radius + 6, self.world.size, 2) else: obj = self.world[cmd.target] wrapcircle(surface, (255, 0, 0), intpos(obj.body.position), obj.radius + 6, self.world.size, 2) # Draw Circles around scanned entities for id, scantime in trackplayer.scantimes.iteritems(): obj = self.world[id] #if trackplayer in obj.scanned_by: if self.scanduration > 0: c = 160 * (scantime / self.scanduration) else: c = 0 wrapcircle(surface, (0, 255 - c, 255 - c), intpos(obj.body.position), obj.radius + 4, self.world.size, 4)
def draw(self, surface, flags): self.anicount += 1 if self.anicount == self.anispeed: self.anicount = 0 self.anirot += self.anidirection if self.anirot >= 360: self.anirot = 0 elif self.anirot <= 0: self.anirot = 360 rotimg = Cache().getRotatedImage(self._imageName, self.anirot) w, h = rotimg.get_rect().size # TODO: convert world to graphics coordinates surface.blit(rotimg, (self._worldobj.body.position[0] - w / 2, self._worldobj.body.position[1] - h / 2)) if flags["DEBUG"]: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.gravityFieldLength, self._world.size, 3) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position - (0, self._worldobj.gravityFieldLength)), intpos(self._worldobj.body.position - (0, self._worldobj.gravityFieldLength - self._worldobj.pull)), ) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position - (self._worldobj.gravityFieldLength, 0)), intpos(self._worldobj.body.position - (self._worldobj.gravityFieldLength - self._worldobj.pull, 0)), ) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position + (self._worldobj.gravityFieldLength, 0)), intpos(self._worldobj.body.position + (self._worldobj.gravityFieldLength - self._worldobj.pull, 0)), ) pygame.draw.line( surface, (64, 128, 255), intpos(self._worldobj.body.position + (0, self._worldobj.gravityFieldLength)), intpos(self._worldobj.body.position + (0, self._worldobj.gravityFieldLength - self._worldobj.pull)), ) # radius surface.blit( debugfont().render(repr(self._worldobj.gravityFieldLength), False, (255, 255, 192)), intpos((bp[0], bp[1] - self._worldobj.gravityFieldLength - 16)), ) super(PlanetGUI, self).draw(surface, flags)
def draw(self, surface, flags): bp = intpos(self._worldobj.body.position) surface.blit(SpaceMineGUI._mine_surface.subsurface(pygame.Rect(16 * (self._worldobj.active + (self._worldobj.target != None)), 0, 16, 16)), (bp[0] - 8, bp[1] - 8)) if flags["DEBUG"]: # position text if self._worldobj.mode == 3: # Homing wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) if self._worldobj.target != None: surface.blit(debugfont().render(repr(intpos(self._worldobj.target)), False, (192, 192, 192)), (bp[0]-30, bp[1]-self._worldobj.radius-10)) elif self._worldobj.mode == 2: # Autonomnous distance = self._worldobj.speed * 10 dest = (math.cos(math.radians(-self._worldobj.direction)) * distance, math.sin(math.radians(-self._worldobj.direction)) * distance) pygame.draw.line(surface, (64, 64, 255), bp, (bp[0] + dest[0], bp[1] + dest[1])) # Preview of where Mine is heading # id text surface.blit(debugfont().render("#"+str(self._worldobj.id)+" T"+repr(self._worldobj.mode), False, (192, 192, 192)), (bp[0]-20, bp[1]+self._worldobj.radius+4))
def draw(self, surface, flags): ang = 45 - self._worldobj.body.velocity.angle_degrees rang = math.radians(self._worldobj.body.velocity.angle_degrees) #rotimg = pygame.transform.rotate(self.surface, ang) rotimg = Cache().getRotatedImage(self._imageName, ang) w, h = rotimg.get_rect().size #TODO: convert world to graphics coordinates surface.blit(rotimg, (self._worldobj.body.position[0] - w / 2 - self.__extra * math.cos(rang), self._worldobj.body.position[1] - h / 2 - self.__extra * math.sin(rang))) # Draw Dragon attack area if flags["DEBUG"] and isinstance(self._worldobj, Dragon) and self._worldobj.influence_range > 0: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range + self._worldobj.attack_speed))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position - (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position - (self._worldobj.influence_range + self._worldobj.attack_speed, 0))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position + (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position + (self._worldobj.influence_range + self._worldobj.attack_speed, 0))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range + self._worldobj.attack_speed))) # radius surface.blit(debugfont().render(repr(self._worldobj.influence_range), False, (255, 255, 192)), intpos((bp[0], bp[1] - self._worldobj.influence_range - 16))) super(AsteroidGUI, self).draw(surface, flags)
def draw(self, surface, flags): bp = intpos(self._worldobj.body.position) rotimg = Cache().getRotatedImage(self._imageName, math.degrees(-self._worldobj.body.angle)) w, h = rotimg.get_rect().size #TODO: convert world to graphics coordinates surface.blit(rotimg, (bp[0] -w/2, bp[1] -h/2)) #if flags["DEBUG"]: #pygame.draw.line(surface, (64, 128, 255), bp, intpos(self._worldobj.body.position - (self._worldobj.pull / 50, 0))) if flags["DEBUG"]: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) if self._worldobj.type == WormHole.RANDOM: # make 'X' for Random pygame.draw.line(surface, (64, 64, 255), intpos(self._worldobj.body.position - (self._worldobj.influence_range, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (self._worldobj.influence_range, self._worldobj.influence_range)), 5) pygame.draw.line(surface, (64, 64, 255), intpos(self._worldobj.body.position - (-self._worldobj.influence_range, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (-self._worldobj.influence_range, self._worldobj.influence_range)), 5) elif self._worldobj.type == WormHole.FIXED_POINT: pygame.draw.line(surface, (64, 64, 255), bp, intpos(self._worldobj.exit)) wrapcircle(surface, (64, 64, 255), intpos(self._worldobj.exit), self._worldobj.radius / 2, self._world.size, 2) # 'target' elif self._worldobj.type == WormHole.OTHER_CELESTIALBODY: c = (64, 64, 255) if isinstance(self._worldobj.exit, WormHole) and isinstance(self._worldobj.exit.exit, WormHole) and self._worldobj.exit.exit == self._worldobj: c = (128, 192, 255) # check if linked in both directions - make brighter if two-way wormhole pygame.draw.line(surface, c, bp, intpos(self._worldobj.exit.body.position)) wrapcircle(surface, c, intpos(self._worldobj.exit.body.position), self._worldobj.radius / 2, self._world.size, 2) # 'target' super(WormHoleGUI, self).draw(surface, flags)
def draw(self, surface, flags): self.anicount += 1 if self.anicount == self.anispeed: self.anicount = 0 self.anirot += self.anidirection if self.anirot >= 360: self.anirot = 0 elif self.anirot <= 0: self.anirot = 360 rotimg = Cache().getRotatedImage(self._imageName, self.anirot) w, h = rotimg.get_rect().size #TODO: convert world to graphics coordinates surface.blit(rotimg, (self._worldobj.body.position[0] -w/2, self._worldobj.body.position[1] -h/2)) if flags["DEBUG"] and isinstance(self._worldobj, Influential) and self._worldobj.influence_range > 0: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position - (0, self._worldobj.influence_range - self._worldobj.pull))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position - (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position - (self._worldobj.influence_range - self._worldobj.pull, 0))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position + (self._worldobj.influence_range, 0)), intpos(self._worldobj.body.position + (self._worldobj.influence_range - self._worldobj.pull, 0))) pygame.draw.line(surface, (64, 128, 255), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (0, self._worldobj.influence_range - self._worldobj.pull))) # radius surface.blit(debugfont().render(repr(self._worldobj.influence_range), False, (255, 255, 192)), intpos((bp[0], bp[1] - self._worldobj.influence_range - 16))) super(PlanetGUI, self).draw(surface, flags)
def draw(self, surface, flags): bp = intpos(self._worldobj.body.position) rotimg = Cache().getRotatedImage( self._imageName, math.degrees(-self._worldobj.body.angle)) w, h = rotimg.get_rect().size #TODO: convert world to graphics coordinates surface.blit(rotimg, (bp[0] - w / 2, bp[1] - h / 2)) #if flags["DEBUG"]: #pygame.draw.line(surface, (64, 128, 255), bp, intpos(self._worldobj.body.position - (self._worldobj.pull / 50, 0))) if flags["DEBUG"]: bp = intpos(self._worldobj.body.position) wrapcircle(surface, (64, 64, 255), bp, self._worldobj.influence_range, self._world.size, 3) if self._worldobj.type == WormHole.RANDOM: # make 'X' for Random pygame.draw.line( surface, (64, 64, 255), intpos(self._worldobj.body.position - (self._worldobj.influence_range, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (self._worldobj.influence_range, self._worldobj.influence_range)), 5) pygame.draw.line( surface, (64, 64, 255), intpos(self._worldobj.body.position - (-self._worldobj.influence_range, self._worldobj.influence_range)), intpos(self._worldobj.body.position + (-self._worldobj.influence_range, self._worldobj.influence_range)), 5) elif self._worldobj.type == WormHole.FIXED_POINT: pygame.draw.line(surface, (64, 64, 255), bp, intpos(self._worldobj.exit)) wrapcircle(surface, (64, 64, 255), intpos(self._worldobj.exit), self._worldobj.radius / 2, self._world.size, 2) # 'target' elif self._worldobj.type == WormHole.OTHER_CELESTIALBODY: c = (64, 64, 255) if isinstance(self._worldobj.exit, WormHole) and isinstance( self._worldobj.exit.exit, WormHole ) and self._worldobj.exit.exit == self._worldobj: c = ( 128, 192, 255 ) # check if linked in both directions - make brighter if two-way wormhole pygame.draw.line(surface, c, bp, intpos(self._worldobj.exit.body.position)) wrapcircle(surface, c, intpos(self._worldobj.exit.body.position), self._worldobj.radius / 2, self._world.size, 2) # 'target' super(WormHoleGUI, self).draw(surface, flags)
def gui_draw_game_world_info(self, surface, flags, trackplayer): for player in self.game_get_current_player_list(): obj = player.object if obj != None: bp = intpos(obj.body.position) wrapcircle(surface, (0, 255, 255), bp, self.scanrange, self.world.size, 1) # Scan Range if self.usemissions: text = debugfont().render( "%s [%s]" % (repr(player.mission), player.failed), False, (0, 255, 255)) surface.blit(text, (bp[0] - text.get_width() / 2, bp[1] - 6)) if trackplayer != None: curs = [] curf = [] obj = trackplayer.object if obj != None: # Draw Success/Failure Circles around Current Scan Targets for cmd in obj.commandQueue: if isinstance(cmd, ScanCommand): if cmd.success: obj = self.world[cmd.target] wrapcircle(surface, (255, 255, 0), intpos(obj.body.position), obj.radius + 6, self.world.size, 2) else: obj = self.world[cmd.target] wrapcircle(surface, (255, 0, 0), intpos(obj.body.position), obj.radius + 6, self.world.size, 2) # Draw Circles around scanned entities for id, scantime in trackplayer.scantimes.iteritems(): obj = self.world[id] #if trackplayer in obj.scanned_by: if self.scanduration > 0: c = 160 * (scantime / self.scanduration) else: c = 0 wrapcircle(surface, (0, 255 - c, 255 - c), intpos(obj.body.position), obj.radius + 4, self.world.size, 4)
def draw(self, surface, flags, sp=None): if sp == None: sp = self._worldobj.body.position # Check if Thrusting or Braking state = 0 # TODO: Notify Ship of Start/End of Commands...? yoff = 0 if self._worldobj.commandQueue.containstype(CloakCommand): yoff = 64 if self._worldobj.commandQueue.containstype(WarpCommand): state = 6 elif self._worldobj.commandQueue.containstype(BrakeCommand): state = 5 else: cmd = self._worldobj.commandQueue.containstype(ThrustCommand) # HACK? TODO - One loop if cmd != None: #pygame.draw.circle(surface, (255, 255, 0), intpos(pos + cmd.getForceVector(self._worldobj.thrusterForce, self._worldobj.rotationAngle, 0.02)), 5) state = 1 + ['L','F','R','B'].index(cmd.direction) #eif #eif # Rotate to Current Direction rotimg = pygame.transform.rotate(self.surface.subsurface(pygame.Rect(64 * state, yoff, 64, 64)), self._worldobj.rotationAngle - 90) w, h = rotimg.get_rect().size bp = intpos(sp) pos = intpos(sp - (w/2, h/2)) if len(self._worldobj.lasernodes) > 0 and sp == self._worldobj.body.position: for i in range(0, len(self._worldobj.lasernodes)+1, 2): if i < len(self._worldobj.lasernodes)-1: pygame.draw.line(surface, self._worldobj.player.color, self._worldobj.lasernodes[i], self._worldobj.lasernodes[i+1], 3) elif i < len(self._worldobj.lasernodes): pygame.draw.line(surface, self._worldobj.player.color, self._worldobj.lasernodes[i], intpos(self._worldobj.body.position), 3) #eif # Draw surface.blit(rotimg, pos) gp = (sp[0] - 32, sp[1] - 32) #adjusted fixed graphic size # Draw shield if self._worldobj.commandQueue.containstype(RaiseShieldsCommand) and self._worldobj.shield.value > 0: surface.blit(ShipGUI._shieldsurface, gp) # Draw explosion if self.dying: surface.blit(ShipGUI._exsurface.subsurface(pygame.Rect(64 * self.dyframe, 0, 64, 64)), gp) self.dyframe += 1 if self.dyframe == 16: self.dead = True self.dying = False if flags["NAMES"]: # HACK TODO: Ship name should be from team text = namefont().render(self._worldobj.player.name, False, self._worldobj.player.color) surface.blit(text, (bp[0]-text.get_width()/2, bp[1]-44)) if flags["DEBUG"]: #wrapcircle(surface, (0, 255, 0), bp, 4, self._world.size) # Position wrapcircle(surface, (255, 255, 0), bp, self._worldobj.radarRange, self._world.size, 1) # Radar if flags["STATS"] and self._worldobj.shield.maximum > 0: # Shield Bar pygame.draw.rect(surface, (0, 0, 96), pygame.Rect(bp[0]-16, bp[1] + 21, 32, 5)) if flags["DEBUG"]: surface.blit(debugfont().render(repr(int(100 * self._worldobj.shield.percent)), False, (255, 255, 255)), (bp[0]+18, bp[1] + 16)) surface.blit(ShipGUI._shieldhudsurface, (bp[0]-15, bp[1] + 22), pygame.Rect(0, 0, 30 * self._worldobj.shield.percent, 3)) if flags["GAME"] and self._worldobj.player.score > 0: surface.blit(infofont().render(("%.1f" % self._worldobj.player.score) + " Pts", False, (0, 255, 255)), (bp[0]-24, bp[1] + 32)) super(ShipGUI, self).draw(surface, flags, sp)
def draw(self, surface, flags, sp=None): if sp == None: sp = self._worldobj.body.position # Check if Thrusting or Braking state = 0 # TODO: Notify Ship of Start/End of Commands...? yoff = 0 steer = self._worldobj.commandQueue.containstype(SteerCommand) if steer and steer.orgdeg != 0: if steer.orgdeg > 0: steer = -math.sin(steer.percent() * math.pi) else: steer = math.sin(steer.percent() * math.pi) # TODO: Figure out best way to determine when ship facing opposite direction and should 'bank' other way #if abs(self._worldobj.rotationAngle - self._worldobj.body.velocity.angle_degrees) % 360 > 180: # steer = -steer else: steer = 0 if self._worldobj.commandQueue.containstype(CloakCommand): yoff = 64 if self._worldobj.commandQueue.containstype(WarpCommand): state = 6 elif self._worldobj.commandQueue.containstype(BrakeCommand): state = 5 else: cmd = self._worldobj.commandQueue.containstype( ThrustCommand) # HACK? TODO - One loop if cmd != None: #pygame.draw.circle(surface, (255, 255, 0), intpos(pos + cmd.getForceVector(self._worldobj.thrusterForce, self._worldobj.rotationAngle, 0.02)), 5) state = 1 + ['L', 'F', 'R', 'B'].index(cmd.direction) #eif #eif # Rotate to Current Direction scaled = self.surface.subsurface(pygame.Rect(64 * state, yoff, 64, 64)) if steer != 0: newimg = pygame.Surface((64, 64), pygame.SRCALPHA) if steer > 0: newimg.blit( pygame.transform.scale(scaled, (64 - int(16 * abs(steer)), 64)), (int(steer * 16), 0)) else: newimg.blit( pygame.transform.scale(scaled, (64 - int(16 * abs(steer)), 64)), (0, 0)) scaled = newimg rotimg = pygame.transform.rotate(scaled, self._worldobj.rotationAngle - 90) w, h = rotimg.get_rect().size bp = intpos(sp) pos = intpos(sp - (w / 2, h / 2)) if len(self._worldobj.lasernodes ) > 0 and sp == self._worldobj.body.position: for i in range(0, len(self._worldobj.lasernodes) + 1, 2): if i < len(self._worldobj.lasernodes) - 1: pygame.draw.line(surface, self._worldobj.player.color, self._worldobj.lasernodes[i], self._worldobj.lasernodes[i + 1], 3) elif i < len(self._worldobj.lasernodes): pygame.draw.line(surface, self._worldobj.player.color, self._worldobj.lasernodes[i], intpos(self._worldobj.body.position), 3) #eif # Draw surface.blit(rotimg, pos) gp = (sp[0] - 32, sp[1] - 32) #adjusted fixed graphic size # Draw shield if self._worldobj.commandQueue.containstype( RaiseShieldsCommand) and self._worldobj.shield.value > 0: surface.blit(ShipGUI._shieldsurface, gp) # Draw explosion if self.dying: surface.blit( ShipGUI._exsurface.subsurface( pygame.Rect(64 * self.dyframe, 0, 64, 64)), gp) self.dyframe += 1 if self.dyframe == 16: self.dead = True self.dying = False if flags["NAMES"]: # HACK TODO: Ship name should be from team text = namefont().render(self._worldobj.player.name, False, self._worldobj.player.color) surface.blit(text, (bp[0] - text.get_width() / 2, bp[1] - 44)) if flags["DEBUG"]: #wrapcircle(surface, (0, 255, 0), bp, 4, self._world.size) # Position wrapcircle(surface, (255, 255, 0), bp, self._worldobj.radarRange, self._world.size, 1) # Radar if flags["STATS"] and self._worldobj.shield.maximum > 0: # Shield Bar pygame.draw.rect(surface, (0, 0, 96), pygame.Rect(bp[0] - 16, bp[1] + 21, 32, 5)) if flags["DEBUG"]: surface.blit( debugfont().render( repr(int(100 * self._worldobj.shield.percent)), False, (255, 255, 255)), (bp[0] + 18, bp[1] + 16)) surface.blit( ShipGUI._shieldhudsurface, (bp[0] - 15, bp[1] + 22), pygame.Rect(0, 0, 30 * self._worldobj.shield.percent, 3)) if flags["GAME"] and self._worldobj.player.score > 0: surface.blit( infofont().render( ("%.1f" % self._worldobj.player.score) + " Pts", False, (0, 255, 255)), (bp[0] - 24, bp[1] + 32)) super(ShipGUI, self).draw(surface, flags, sp)
def draw(self, surface, flags, sp=None): if sp == None: bp = intpos(self._worldobj.body.position) if self._points != None and bp != self._lp: self._lp = bp self._points = self._worldobj.shape.get_points() else: bp = intpos(sp) if flags["DEBUG"]: # position text surface.blit( debugfont().render(repr((bp[0], bp[1])), False, (192, 192, 192)), (bp[0] - 30, bp[1] - self._dist - 30)) # id text surface.blit( debugfont().render("#" + str(self._worldobj.id), False, (192, 192, 192)), (bp[0] - 4, bp[1] + self._dist + 4)) # collision circle if self._worldobj.__dict__.has_key("points"): #Polygon self.draw_poly(surface, (192, 192, 192), bp, self._points, 2) else: wrapcircle(surface, (192, 192, 192), bp, self._dist, self._world.size, 2) if len(self._worldobj.in_celestialbody) > 0: wrapcircle(surface, (255, 64, 64), bp, self._dist, self._world.size, 4) # velocity vector pygame.draw.line(surface, (255, 0, 0), bp, self._worldobj.body.velocity + bp) # Velocity if flags["STATS"] and self._worldobj.health.maximum > 0: # Health Bar Background pygame.draw.rect(surface, (64, 0, 0), pygame.Rect(bp[0] - 16, bp[1] - 25, 32, 8)) if flags["DEBUG"]: surface.blit( debugfont().render( repr(int(100 * self._worldobj.health.percent)), False, (255, 255, 255)), (bp[0] + 18, bp[1] - 26)) # Health Bar surface.blit( GUIEntity._healthbar, (bp[0] - 15, bp[1] - 24), pygame.Rect(0, 0, 30 * self._worldobj.health.percent, 6)) if flags["STATS"] and self._worldobj.energy.maximum > 0: # Energy Bar pygame.draw.rect(surface, (0, 64, 0), pygame.Rect(bp[0] - 16, bp[1] + 26, 32, 5)) if flags["DEBUG"]: surface.blit( debugfont().render( repr(int(100 * self._worldobj.energy.percent)), False, (255, 255, 255)), (bp[0] + 18, bp[1] + 24)) surface.blit( GUIEntity._energybar, (bp[0] - 15, bp[1] + 27), pygame.Rect(0, 0, 30 * self._worldobj.energy.percent, 3))