def run(): # MENU if keyboard.key_pressed("esc"): store.dispatch("state", value=0) window.delay(150) # POWER UP if keyboard.key_pressed("p"): store.dispatch("state", value=2) window.delay(150) # GAME OVER if store.get("player").life <= 0: store.dispatch("state", value=3) window.delay(150) # CHANGE LEVEL if keyboard.key_pressed("y"): store.dispatch("enemy_mtx", value=[]) # DIE if keyboard.key_pressed("u"): store.get("player").life = -1 # SCORE if keyboard.key_pressed("t"): store.dispatch("score", lambda score: score + 200) background.draw() player.run() enemy.run() bullet.run() hud.run()
def run(): if keyboard.key_pressed("esc"): store.dispatch("game_started", value=False) if mouse.is_over_object(play_button): play_button.set_curr_frame(1) if mouse.is_button_pressed(1): store.dispatch("state", value=1) else: play_button.set_curr_frame(0) if mouse.is_over_object(rank_button): rank_button.set_curr_frame(1) if mouse.is_button_pressed(1): store.dispatch("state", value=4) else: rank_button.set_curr_frame(0) window.set_background_color((0, 0, 0)) title.update() title.draw() play_button.draw() rank_button.draw()
def run(): if keyboard.key_pressed("esc"): store.dispatch("state", value=0) window.delay(150) window.set_background_color((0, 0, 0)) data = Database().get_scores() data.insert(0, ["name:", "score:", "wave:"]) i = 0 for d in data: draw_name(d[0], 280, 300 + i) draw_score(d[1], 540, 300 + i) draw_wave(d[2], 810, 300 + i) i += 40 title.draw()
def run(): if keyboard.key_pressed("esc"): store.dispatch("state", value=1) window.delay(150) # POWER if mouse.is_over_object(power): power.set_curr_frame(1) if mouse.is_button_pressed(1) and store.get("score") > cost_strength(): aux_str = cost_strength() store.dispatch("score", lambda score: score - aux_str) store.get("player").strenght = update_strength() window.delay(150) else: power.set_curr_frame(0) # LIFE if mouse.is_over_object(life): life.set_curr_frame(1) if mouse.is_button_pressed(1) and store.get("score") > cost_life(): aux_life = cost_life() store.dispatch("score", lambda score: score - aux_life) store.get("player").max_life += update_life() window.delay(150) else: life.set_curr_frame(0) # HEAL if mouse.is_over_object(heal): heal.set_curr_frame(1) if mouse.is_button_pressed(1) and store.get("score") > cost_heal(): aux_heal = cost_heal() store.dispatch("score", lambda score: score - aux_heal) update_heal() store.get("player").life = store.get("player").max_life window.delay(150) else: heal.set_curr_frame(0) window.set_background_color((0, 0, 0)) # SCORE window.draw_text( "score: {}".format(store.get("score")), title.x + 30, title.y + title.height + 30, "./src/assets/fonts/pixel.ttf", size=24, color=(255, 255, 255), ) # PRICE AND OWNED POWER window.draw_text( "price: {}".format(cost_strength()), power.x + power.width + 25, power.y + 10, "./src/assets/fonts/pixel.ttf", size=16, color=(255, 255, 255), ) window.draw_text( "owned: {}".format(store.get("owned_strength")), power.x + power.width + 25, power.y + 50, "./src/assets/fonts/pixel.ttf", size=16, color=(255, 255, 255), ) # PRICE AND OWNED LIFE window.draw_text( "price: {}".format(cost_life()), life.x + life.width + 25, life.y + 10, "./src/assets/fonts/pixel.ttf", size=16, color=(255, 255, 255), ) window.draw_text( "owned: {}".format(store.get("owned_life")), life.x + life.width + 25, life.y + 50, "./src/assets/fonts/pixel.ttf", size=16, color=(255, 255, 255), ) # PRICE HEAL window.draw_text( "price: {}".format(cost_heal()), heal.x + heal.width + 25, heal.y + 10, "./src/assets/fonts/pixel.ttf", size=16, color=(255, 255, 255), ) title.draw() power.draw() life.draw() heal.draw()
def run(): global bullet_mtx global bullet_vel global player_can_shoot global bullet_cooldown # DEFAULT bullet_vel.update(0) # PLAYER SHOOT if player_can_shoot == False and bullet_cooldown >= 0: bullet_cooldown -= 5 if bullet_cooldown <= 0: player_can_shoot = True bullet_cooldown = config.BULLET_COOLDOWN if (keyboard.key_pressed("left") and keyboard.key_pressed("right") == False and player_can_shoot == True): bullet_vel.x = -1 if (keyboard.key_pressed("right") and keyboard.key_pressed("left") == False and player_can_shoot == True): bullet_vel.x = 1 if (keyboard.key_pressed("up") and keyboard.key_pressed("down") == False and player_can_shoot == True): bullet_vel.y = -1 if (keyboard.key_pressed("down") and keyboard.key_pressed("up") == False and player_can_shoot == True): bullet_vel.y = 1 if bullet_vel != math.Vector2(0): bullet_vel.normalize_ip() bullet_vel *= config.BULLET_VELOCITY bullet = store.get("player").shoot( "./src/assets/actors/bullet/bullet.png", 1, deepcopy(bullet_vel)) bullet_mtx.append(bullet) player_can_shoot = False # BULLET COLLISION for enemy in store.get("enemy_mtx"): for bullet in bullet_mtx: if bullet.collide(enemy): enemy.life -= store.get("player").strenght bullet_mtx.remove(bullet) if enemy.life <= 0: store.get("enemy_mtx").remove(enemy) if enemy.is_boss: store.dispatch("score", lambda score: score + 200) else: aux_score = get_score(store.get("wave")) store.dispatch("score", lambda score: score + aux_score) # DESTROY BULLET for bullet in bullet_mtx: if (bullet.animation.x >= config.WIDTH or bullet.animation.x <= 0 or bullet.animation.y >= config.HEIGHT or bullet.animation.y <= 48): bullet_mtx.remove(bullet) # DRAW if len(bullet_mtx) != 0: for bullet in bullet_mtx: bullet.update() bullet.render()
def run(): global vel_vector # DEFAULT player.set_state("idle") vel_vector.update(0, 0) # CHECKING COLLISION if player.animation.x <= 1: player.set_colliding(True, "left") player.set_position(player.animation.x + 1, player.animation.y) elif player.animation.x + player.animation.width >= window.width: player.set_colliding(True, "right") player.set_position(player.animation.x - 1, player.animation.y) if player.animation.y + (player.animation.height / 2) <= 96: player.set_colliding(True, "up") player.set_position(player.animation.x, player.animation.y + 1) elif player.animation.y + player.animation.height >= window.height: player.set_colliding(True, "down") player.set_position(player.animation.x, player.animation.y - 1) # RESET COLLISION if player.colliding["left"] == True and keyboard.key_pressed("d"): player.colliding["left"] = False if player.colliding["right"] == True and keyboard.key_pressed("a"): player.colliding["right"] = False if player.colliding["up"] == True and keyboard.key_pressed("s"): player.colliding["up"] = False if player.colliding["down"] == True and keyboard.key_pressed("w"): player.colliding["down"] = False # MOVING if (keyboard.key_pressed("d") == True and keyboard.key_pressed("a") == False and player.colliding["right"] == False): vel_vector.x = 1 player.set_direction("right") player.set_state("running") elif (keyboard.key_pressed("a") == True and keyboard.key_pressed("d") == False and player.colliding["left"] == False): vel_vector.x = -1 player.set_direction("left") player.set_state("running") if (keyboard.key_pressed("w") == True and keyboard.key_pressed("s") == False and player.colliding["up"] == False): vel_vector.y = -1 player.set_state("running") elif (keyboard.key_pressed("s") == True and keyboard.key_pressed("w") == False and player.colliding["down"] == False): vel_vector.y = 1 player.set_state("running") # COLLISION WITH ENEMY for enemy in store.get("enemy_mtx"): if player.collide(enemy) and player.staggered == False: player.damage(enemy.strenght) player.staggered = True # RESET COLLISION WITH ENEMY if player.staggered: player.damage_cooldown -= window.delta_time() * 1000 if player.damage_cooldown <= 0: player.damage_cooldown = config.DAMAGE_COOLDOWN player.staggered = False # ANIMATION if player.staggered: if player.state["idle"]: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/idle_right_staggered.png", 8) elif player.direction["left"]: player.set_animation( "./src/assets/actors/jorge/idle_left_staggered.png", 8) elif player.state["running"]: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/running_right_staggered.png", 8) elif player.direction["left"]: player.set_animation( "./src/assets/actors/jorge/running_left_staggered.png", 8) else: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/idle_right_staggered.png", 8) elif player.direction["left"]: player.set_animation( "./src/assets/actors/jorge/idle_left_staggered.png", 8) else: if player.state["idle"]: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/idle_right.png", 8) elif player.direction["left"]: player.set_animation("./src/assets/actors/jorge/idle_left.png", 8) elif player.state["running"]: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/running_right.png", 8) elif player.direction["left"]: player.set_animation( "./src/assets/actors/jorge/running_left.png", 8) else: if player.direction["right"]: player.set_animation( "./src/assets/actors/jorge/idle_right.png", 8) elif player.direction["left"]: player.set_animation("./src/assets/actors/jorge/idle_left.png", 8) if vel_vector != math.Vector2(0): vel_vector.normalize_ip() vel_vector *= config.VELOCITY_PLAYER player.move(vel_vector) player.update() player.render() store.dispatch("player", value=player)