def place(self): ''' Place the tag according to the angle and radius properties. Return True if the tag is entirely on radar, False otherwise. ''' cx, cy = self.plane.trail[0] rad = radians(self.angle) ox = U.rint(cos(rad) * self.radius) oy = -U.rint(sin(rad) * self.radius) #minus because of screen coordinates x, y = cx + ox, cy + oy self.rect = U.get_rect_at_centered_pos(self.image, (x, y)) return self.radar_rect.contains(self.rect)
def update(self, *args): status = self.data_source.sprite_index heading = self.data_source.heading if status != self.last_status or heading != self.last_heading: img = self.sprites[status] # The following line needs a bit of explanation: # 1. plane heading in the simulation is defined as CW degrees from # North, but on screen (and for pygame) they are CCW from East # 2. screen Y axis has reversed polarity from simulation one (it # decreases going UP!! # The CCW vs CW is compensated by sign reversal. The 90 degrees # offset is compensated by the orientation of the original sprite # (North rather than East). heading *= -1 self.image = self.rotoscale(img, heading, S.SPRITE_SCALING, S.MIN_PLANE_ICON_SIZE) self.rect = \ U.get_rect_at_centered_pos(self.image, self.data_source.trail[0])
def update(self): STEP = U.rint(S.PING_PERIOD / 1000.0 + 1) #arbitrary: ping in sec + 1 self.image.fill(S.BLACK) delta = U.rint(self.gamelogic.score) - self.score if abs(delta) < STEP: colour = S.WHITE variation = delta elif delta > 0: colour = S.OK_COLOUR variation = STEP else: colour = S.KO_COLOUR variation = -STEP self.score += variation score = str(self.score).zfill(6) score_img = self.fontobj.render(score, True, colour) score_img.subsurface(score_img.get_bounding_rect()).copy() pos = U.get_rect_at_centered_pos(score_img, self.rect.center) self.image.blit(score_img, pos)
def update(self, *args): status = self.data_source.sprite_index if status != self.last_status: self.image = self.sprites[self.time_shift][status] rect = self.data_source.trail[self.time_shift] self.rect = U.get_rect_at_centered_pos(self.image, rect)