class Weapon(Emitter, Inputable): def __init__(self, level, **kwargs): super().__init__(**kwargs) self._level = level self._part = None self._s = Surface((20, 10)) self._s.fill((255, 0, 0)) self._input = Input(inputStream=self.getInputStream()) self._input.set(pygame.KEYDOWN, self.createNew, pygame.K_f) def createNew(self): x, y = self._offsetFunc() self._part = Particle((self._anchor.x + x, self._anchor.y + y, 20, 10), (10, 0), self._s, self._level, Behaviors.killAt(150, 150), Behaviors.moveAt(self._anchor.getIntDir() * 10, 0), Behaviors.killOnCollision(exceptions=(self._anchor.getId(),)), Behaviors.cleanupCollision(), altname="bullet") if x < 0: self._part.x -= self._part.w self._part.move.setSpeed(x=self._part.move.getTopSpeed(x=True)) def _emit(self): if self._part: self._children.append(self._part) self._part = None def tick(self): self._input() super().tick()
def arc(self, surface, color, rect, start_angle, stop_angle, width=1): """ Draw arc shape, and returns bounding Rect. Argument include surface to draw, color, rect, start_angle, stop_angle. Optional width argument of outline. """ if hasattr(rect, 'width'): _rect = rect else: _rect = Rect(rect) if _rect.width == _rect.height: surface.beginPath() surface.arc(_rect.x + int(_rect.width / 2), _rect.y + int(_rect.height / 2), int(_rect.width / 2), -start_angle, -stop_angle, True) if width: surface.setLineWidth(width) if hasattr(color, 'a'): surface.setStrokeStyle(color) else: surface.setStrokeStyle(Color(color)) surface.stroke() else: surface.closePath() if hasattr(color, 'a'): surface.setFillStyle(color) else: surface.setFillStyle(Color(color)) surface.fill() else: if _rect.width < _rect.height: dim = _rect.height else: dim = _rect.width surf = Surface((dim, dim)) surf.beginPath() xdim = int(dim / 2) surf.arc(xdim, xdim, xdim, -start_angle, -stop_angle, True) if width: surf.setLineWidth(width) if hasattr(color, 'a'): surface.setStrokeStyle(color) else: surface.setStrokeStyle(Color(color)) surf.stroke() else: surface.closePath() if hasattr(color, 'a'): surface.setFillStyle(color) else: surface.setFillStyle(Color(color)) surf.fill() surface.drawImage(surf.canvas, 0, 0, dim, dim, _rect.x, _rect.y, _rect.width, _rect.height) #pyjs0.8 *.canvas if surface._display: return surface._display._surface_rect.clip(_rect) else: return surface.get_rect().clip(_rect)
def arc(self, surface, color, rect, start_angle, stop_angle, width=1): """ Draw arc shape, and returns bounding Rect. Argument include surface to draw, color, rect, start_angle, stop_angle. Optional width argument of outline. """ if hasattr(rect, 'width'): _rect = rect else: _rect = Rect(rect) if _rect.width == _rect.height: surface.beginPath() surface.arc(_rect.x+int(_rect.width/2), _rect.y+int(_rect.height/2), int(_rect.width/2), -start_angle, -stop_angle, True) if width: surface.setLineWidth(width) if hasattr(color, 'a'): surface.setStrokeStyle(color) else: surface.setStrokeStyle(Color(color)) surface.stroke() else: surface.closePath() if hasattr(color, 'a'): surface.setFillStyle(color) else: surface.setFillStyle(Color(color)) surface.fill() else: if _rect.width < _rect.height: dim = _rect.height else: dim = _rect.width surf = Surface((dim,dim)) surf.beginPath() xdim = int(dim/2) surf.arc(xdim, xdim, xdim, -start_angle, -stop_angle, True) if width: surf.setLineWidth(width) if hasattr(color, 'a'): surface.setStrokeStyle(color) else: surface.setStrokeStyle(Color(color)) surf.stroke() else: surface.closePath() if hasattr(color, 'a'): surface.setFillStyle(color) else: surface.setFillStyle(Color(color)) surf.fill() surface.drawImage(surf.canvas, 0, 0, dim, dim, _rect.x, _rect.y, _rect.width, _rect.height) #pyjs0.8 *.canvas if surface._display: return surface._display._surface_rect.clip(_rect) else: return surface.get_rect().clip(_rect)
def update(self): self._heartLen = self._parent.getBaseHealth() self.w, self.h = 10 * self._heartLen + 2 * ceil(self._heartLen / 2), 16 surf = Surface((self.w, self.h)) trans = self._heartFilled[0].get_at((0, 0)) surf.fill(trans) surf.set_colorkey(trans) self._display = Display(surface=surf, klass=self) for i in range(self._heartLen): self._hearts.append(surf.subsurface(Object(rect=(10 * i + 2 * (i // 2), 0, 10, 16)).asRect()))