Пример #1
0
    def update_enemies(self):
        #pewpew
        #print self.enemy_list
        for enemy_index in range(len(self.enemy_list)):
            self.enemy_list[enemy_index].update_bar()
            for projectile_index in range(len(self.projectile_list)):
                if helper.check_collision(self.projectile_list[projectile_index], self.enemy_list[enemy_index]):
                    if self.enemy_list[enemy_index].sign.id[0] != "GHOST":
                        self.score += 100
                        self.enemy_list[enemy_index].get_hit_by(self.projectile_list[projectile_index])
                        del self.projectile_list[projectile_index]
                    break

        #cleanup kills
        for enemy_index in range(len(self.enemy_list)):
            if not self.enemy_list[enemy_index].alive:
                if self.master.ask_if_drop(self.hero.stats.current_hp/self.hero.stats.hp):
                    drop_signature = ["PICKUP", [self.master.determine_drop(self.hpp())]]
                    self.pickup_list.append(self.enemy_list[enemy_index].drop(drop_signature))
                self.hero.stats.attack += 1
                self.killcount += 1
                del self.enemy_list[enemy_index]
                break

        #cleanup offscreen
        for enemy_index in range(len(self.enemy_list)):
            if self.enemy_list[enemy_index].right <= 0:
                self.enemy_list.pop(enemy_index)
                break

        # For the laser detection
        for enemy_index in range(len(self.enemy_list)):
            if self.hero.is_firing_laser:
                if helper.check_collision(self.enemy_list[enemy_index], self.hero.laser):
                    self.killcount += 1
                    if self.master.ask_if_drop(self.hero.stats.current_hp/self.hero.stats.hp):
                        drop_signature = ["PICKUP", [self.master.determine_drop(self.hpp())]]
                        self.pickup_list.append(self.enemy_list[enemy_index].drop(drop_signature))
                    self.score += 300
                    del self.enemy_list[enemy_index]
                    self.hero.stats.attack += 1
                    break

        #needs to be made into a long and complex function
        for enemy in self.enemy_list:
            enemy.move()
            engines.siny(enemy, enemy.stats)
            #engines.cosxx(enemy, enemy.stats)

        #panic
        if len(self.enemy_list) < 2:
            print "Less than two enemies left"
            self.next_wave()
Пример #2
0
    def cb_start_simulation(self):
        if len(self.starting_objs_list) == 0:
            self.starting_objs_list = deepcopy(self.objs_list)

        if self.start_simulation_button['text'] == 'Pause':
            self.start_simulation_button.config(text='Start')
            return
        else:
            self.start_simulation_button.config(text='Pause')

        gravity_params = ph.GravityParameters(self.objs_list)

        try:
            while self.start_simulation_button['text'] == 'Pause':
                clear_canvas(self.canvas)
                ph.update_objects_positions(gravity_params, APPROXIMATION_TIME)
                ph.check_collision(gravity_params, COLLISION_RADIUS)

                display_all_gravity_objects(gravity_params.objects,
                                            self.canvas)

                if self.is_checked_objects_paths.get():
                    for obj in gravity_params.objects:
                        display_object_path(obj.previous_positions,
                                            self.canvas)

                    for list_of_prev in gravity_params.prev_positions_of_deleted_obj:
                        display_object_path(list_of_prev, self.canvas)

                if self.is_checked_mass_center.get():
                    display_mass_center(gravity_params, self.canvas)

                if self.is_checked_geom_center.get():
                    display_geometrical_center(gravity_params, self.canvas)

                update_window(self.root)
                sleep_value = self.max_sleep - round(
                    self.speed_scale_bar.get(), 3)
                sleep(sleep_value)

            self.start_simulation_button.config(text='Start')

        except tk.TclError as e:
            print("You have left during a simulation. Error occured: ")
            print(e)
Пример #3
0
    def on_draw(self):
        """
        Overrides the Pyglet on_draw method,
        to update our triangles. This is called
        every frame and propagates the triangles
        through space.
        :return:
        """
        # clear the graphics buffer
        pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
        pyglet.gl.glClear(pyglet.gl.GL_DEPTH_BUFFER_BIT)

        pyglet.gl.glEnable(pyglet.graphics.GL_DEPTH_TEST)
        pyglet.gl.glDepthFunc(pyglet.gl.GL_LESS)

        pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
        pyglet.gl.glEnable(pyglet.graphics.GL_ALPHA_TEST)
        pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA,
                              pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)

        self.draw_set(self.walls)
        self.draw_set(self.sprites)

        a = (pyglet.gl.GLfloat * 16)()
        mvm = pyglet.gl.glGetFloatv(pyglet.gl.GL_MODELVIEW_MATRIX, a)
        forward_vector = np.array([list(a)[2], list(a)[6], -list(a)[10]])
        forward_vector = forward_vector / np.sqrt(
            np.dot(forward_vector, forward_vector))
        if self.mouse_frames:
            pyglet.gl.glColor3d(1, 0.875, 0)
            pyglet.gl.glLineWidth(10.0)
            pyglet.graphics.draw(2, pyglet.gl.GL_LINES,
                                 ("v3f",
                                  (0, -50.0, 0.0, -forward_vector[0] * 10, 0.0,
                                   forward_vector[2] * 10.0)))
            self.mouse_frames -= 1
        physics.check_collision(walls=self.walls, sprites=self.sprites)
Пример #4
0
def game_logic(log):
    """
    Handles all game logic,
    such as collisions, damage calculation, movement,etc.
    """
    #Hero
    location = helper.locate_in_boundary(game_state.hero, environment.BOUNDARY)
    helper.movement_manager(game_state.hero, location)
    game_state.hero.update_pos()
    game_state.hero.recharge()

    if game_state.hero.vulnerable:
        for enemy in game_state.enemy_list:
            if helper.check_collision(enemy, game_state.hero):
                game_state.hitcount += 1
                game_state.hero.get_hit_by_enemy(enemy)
                game_state.hero.knockback()
                game_state.hero.give_immunity()
                game_state.update_hero_bar()
                if game_state.hero.isdead():
                    game_state.game_over = True
                    print "GAME_OVER"  # GAME OVER - TODO
    else:
        if (time.clock() - game_state.hero.vulnerability_time) > 1.5:
            game_state.hero.take_immunity()

    # Hero - Laser
    if game_state.hero.is_firing_laser:
        if time.clock() - game_state.hero.fire_time < 6:
            game_state.hero.fire_laser()
        else:
            game_state.hero.stop_firing_laser()

    # Pews
    game_state.update_pews()
    
    # Rupees
    game_state.update_pickups()

    # Enemies and Waves
    game_state.update_enemies()

    hp_100 = game_state.hero.stats.current_hp / game_state.hero.stats.hp
    game_state.master.update(hp_100)

    log.add_row(game_state)
Пример #5
0
    def update_pickups(self):
        for i in range(0, len(self.pickup_list)):
            collision = helper.check_collision(self.hero, self.pickup_list[i])
            self.pickup_list[i].move()
            if collision:
                dj.play_beep()
                pickup_type = self.pickup_list[i].sign.id[0]
                self.score += score_manager.calculate_score(pickup_type)  # Increment Score

                if pickup_type == "DEFENSE":
                    self.hero.stats.defense += 1

                if pickup_type == "HP":
                    if self.hpp() < 0.8:
                        self.hero.stats.current_hp += 20
                    else:
                        self.hero.stats.current_hp = 100
                    self.update_hero_bar()

                if pickup_type == "LASER":
                    self.hero.equip_laser()

                del self.pickup_list[i]
                break
Пример #6
0
for platform in platforms:
    st.objs.append(platform)

enemy = entities.Enemy(st.en_image, st.en_rect, st.ens_map_rect, st.en_speed,
                       st.en_jump_speed)
st.objs.append(enemy)

ct = time.time()
tt = 0
while True:
    pt = ct  # Past Time
    ct = time.time()  # Current Time
    dt = ct - pt  # Delta Time
    tt += dt  # Total Time

    events.keyboard_events(st, mc)

    # Updating objects and background position/velocity
    physics.velocity_restrictions([mc])
    events.update_movement([mc, enemy])
    hit_objects, collision = physics.check_collision(mc, [*platforms, enemy])
    #    events.update_all(st, dt, hit_objects, collision, [mc])
    physics.update_all(st, dt, [mc])
    events.update_background(st, mc)

    st.screen.blit(st.main_map_image, [-i for i in st.main_map_pos])
    events.draw_objects(st.screen, st.main_map_pos, [mc, enemy, *platforms])
    pg.display.flip()

    time.sleep(0.016)
a