def __init__(self): super().__init__() # set graphics self.setPixmap(QPixmap('./res/imgs/knight.png')) self.setTransformOriginPoint(16, 16) # initialize health bar h = Bar(self) h.set_max_val(45) h.set_current_val(45) self.set_health(h) # set specs self.set_speed(3) self.set_attack(2) self.set_range(25) # set destination self.destination_timer = QTimer() self.destination_timer.timeout.connect(self.set_dest_to_closest) self.destination_timer.start(1000 / 30) # connect timer to move forward self.move_timer = QTimer() self.move_timer.timeout.connect(self.move_forward) self.move_timer.start(1000 / 30) # timer to damage self.damage_timer = QTimer() self.damage_timer.timeout.connect(self.damage_if_colliding) self.damage_timer.start(1000)
def __init__(self): super().__init__() # initialize attack range (area) self.attack_area = QGraphicsPolygonItem() self.attack_dest = QPointF(0, 0) self.has_target = False # set the graphics self.setPixmap( QPixmap('./res/imgs/lol_tower.png').scaled(80, 80, Qt.KeepAspectRatio)) # initializes health h = Bar(self) h.set_max_val(250) h.set_current_val(250) self.set_health(h) self.attack = 30 # create points vector points = [ QPointF(1, 0), QPointF(2, 0), QPointF(3, 1), QPointF(3, 2), QPointF(2, 3), QPointF(1, 3), QPointF(0, 2), QPointF(0, 1) ] # scale points SCALE_FACTOR = 100 points = [p * SCALE_FACTOR for p in points] self.range = SCALE_FACTOR # create polygon self.polygon = QPolygonF(points) # create QGraphicsPolygonItem self.attack_area = QGraphicsPolygonItem(self.polygon, self) self.attack_area.setPen(QPen(Qt.DotLine)) # move the polygon poly_center = QPointF(1.5 * SCALE_FACTOR, 1.5 * SCALE_FACTOR) poly_center = self.mapToScene(poly_center) tower_center = QPointF(self.x() + 40, self.y() + 40) ln = QLineF(poly_center, tower_center) self.attack_area.setPos(self.x() + ln.dx(), self.y() + ln.dy()) # connect a timer to acquire target self.damage_timer = QTimer() self.damage_timer.timeout.connect(self.acquire_target) self.damage_timer.start(1000) # allow responding to hover events self.setAcceptHoverEvents(True)
def __init__(self): super().__init__() # graphics self.set_sprite_image(QPixmap('./res/imgs/ogrillion-move.png')) # set specs h = Bar(self) h.set_max_val(700) h.set_current_val(700) self.set_health(h) self.set_speed(5) self.set_attack(5) self.set_range(100) self.set_cooldown(10000)
def __init__(self): super().__init__() # graphics self.set_sprite_image(QPixmap('./res/imgs/troll-move.png')) # set specs h = Bar(self) h.set_max_val(666) h.set_current_val(666) self.set_health(h) self.set_speed(3) self.set_attack(5) self.set_range(40) self.set_cooldown(40000)
def __init__(self): super().__init__() # graphics self.set_sprite_image(QPixmap('./res/imgs/player-move.png')) # set specs h = Bar(self) h.set_max_val(500) h.set_current_val(500) self.set_health(h) self.set_speed(5) self.set_attack(5) self.set_range(100) self.set_cooldown(30000) self.items_freezed = []
def __init__(self, powered_up=False): super().__init__() # set graphics if not powered_up: self.setPixmap( QPixmap('./res/imgs/wizard.png').scaled( 40, 40, Qt.KeepAspectRatio)) self.setTransformOriginPoint(20, 20) h = Bar(self) h.set_max_val(60) h.set_current_val(60) self.set_health(h) self.set_attack(4) else: self.setPixmap( QPixmap('./res/imgs/wizard.png').scaled( 60, 60, Qt.KeepAspectRatio)) self.setTransformOriginPoint(30, 30) h = Bar(self) h.set_max_val(120) h.set_current_val(120) self.set_health(h) self.set_attack(10) # set specs self.set_speed(2) # set attack area self.set_range(100) # connect a timer to acquire target self.damage_timer = QTimer() self.damage_timer.timeout.connect(self.acquire_target) self.damage_timer.start(1000) # timer to move forward, but if has target, then it does not move self.move_timer = QTimer() self.move_timer.timeout.connect(self.move_forward) self.move_timer.start(1000 / 30) # set destination self.destination_timer = QTimer() self.destination_timer.timeout.connect(self.set_dest_to_closest) self.destination_timer.start(1000 / 30)
def __init__(self): super().__init__() # set the graphics self.setPixmap( QPixmap('./res/imgs/lol_inhibitor_2.png').scaled( 50, 50, Qt.KeepAspectRatio)) # initializes health h = Bar(self) h.set_max_val(600) h.set_current_val(600) self.set_health(h) # initializes signal (when it dies) self.s = InhibitorSignal() # allow responding to hover events self.setAcceptHoverEvents(True)
def __init__(self, ): super().__init__() # set the graphics self.setPixmap( QPixmap('./res/imgs/lol_nexus_1.png').scaled( 80, 80, Qt.KeepAspectRatio)) # initializes health h = Bar(self) h.set_max_val(1200) h.set_current_val(1200) self.set_health(h) # set signal self.s = NexusSignal() # set not damageable self.set_damageable(False) # allow responding to hover events self.setAcceptHoverEvents(True)
class Enemy(QGraphicsPixmapItem): def __init__(self, points_to_follow): super().__init__() # initialize keys dictionary self.keys = { Qt.Key_W: False, Qt.Key_A: False, Qt.Key_D: False, Qt.Key_S: False } self.points = points_to_follow self.dest = QPointF() self.point_index = 0 self.team = 1 # set graphics self.setPixmap( QPixmap('./res/imgs/enemy_3.png').scaled(50, 50, Qt.KeepAspectRatio)) self.setTransformOriginPoint(25, 25) self.point_index = 0 self.dest = self.points[self.point_index] self.rotate_to_point(self.dest) # connect timer to move forward # self.timer = QTimer() # self.timer.timeout.connect(self.move_forward) # self.timer.start(150) # WASD timer self.move_timer = QTimer() self.move_timer.timeout.connect(self.timer_event) self.move_timer.start(1000 / 60) # set animations self.current_frame = 0 self.sprite_image = QPixmap('./res/imgs/player-move.png') # initialize health bar self.health = 100 self.max_health = 100 self.health_bar = Bar(self) self.health_bar.set_max_val(100) self.health_bar.set_current_val(100) # create a timer to change the frame self.sprite_timer = QTimer() self.sprite_timer.timeout.connect(self.nextFrame) def is_damageable(self): return True def nextFrame(self): self.current_frame += 64 if self.current_frame >= 512: self.current_frame = 0 self.update(-10, -10, 64, 64) def boundingRect(self): return QRectF(-10, -10, 64, 64) def paint(self, painter, option, widget): # draw one of the frames of the player painter.drawPixmap(-10, -10, self.sprite_image, self.current_frame, 0, 64, 64) def move_forward(self): # if close to dest, rotate to next dest ln = QLineF(self.pos(), self.dest) if ln.length() < 5: if self.point_index + 1 >= len(self.points): self.timer.stop() self.timer.disconnect() else: self.point_index += 1 self.dest = self.points[self.point_index] self.rotate_to_point(self.dest) STEP_SIZE = 5 theta = self.rotation() # degrees theta = theta * pi / 180 # radians dx = STEP_SIZE * cos(theta) dy = STEP_SIZE * sin(theta) # move enemy forward at current alnge self.setPos(self.x() + dx, self.y() + dy) def rotate_to_point(self, point): '''point: QPointF''' ln = QLineF(self.pos(), point) # that 90 is because sprite sheet is pointing north self.setRotation(-1 * ln.angle() + 90) def keyPressEvent(self, event): if event.key() in self.keys: self.keys[event.key()] = True self.sprite_timer.start(25) super().keyPressEvent(event) def keyReleaseEvent(self, event): self.keys[event.key()] = False if self.sprite_timer.isActive(): self.sprite_timer.stop() super().keyReleaseEvent(event) def timer_event(self): # move in the direction of the rotation # had to change the angles because sprite sheet is pointing north if self.keys[Qt.Key_W]: theta = self.rotation() + 270 # degrees elif self.keys[Qt.Key_A]: theta = self.rotation() + 180 elif self.keys[Qt.Key_D]: theta = self.rotation() elif self.keys[Qt.Key_S]: theta = self.rotation() + 90 else: return STEP_SIZE = 5 theta = theta * pi / 180 # radians dx = STEP_SIZE * cos(theta) dy = STEP_SIZE * sin(theta) # move enemy forward at current alnge self.setPos(self.x() + dx, self.y() + dy)