Example #1
0
 def setup_unexplored_icon(self):
     texture_name = texture_manager.load_image(
         get_asset_path('assets', 'ui_elements', 'unexplored-icon.png'))
     model_manager = self.gameworld.model_manager
     self.unexplored_icon = model_manager.load_textured_rectangle(
         'vertex_format_4f',
         64,
         64,
         'unexplored-icon',
         '4f_unexplored-icon',
     )
     model = model_manager.models[self.unexplored_icon]
     vt1 = model[0]
     vt2 = model[1]
     vt3 = model[2]
     vt4 = model[3]
     u1, v1 = vt1.uvs
     u2, v2 = vt2.uvs
     u3, v3 = vt3.uvs
     u4, v4 = vt4.uvs
     vt1.uvs = (u1, v3)
     vt2.uvs = (u2, v4)
     vt3.uvs = (u3, v1)
     vt4.uvs = (u4, v2)
     self.unexplored_texture = 'unexplored-icon'
Example #2
0
 def setup_unexplored_icon(self):
     texture_name = texture_manager.load_image(
         get_asset_path('assets', 'ui_elements', 'unexplored-icon.png')
         )
     model_manager = self.gameworld.model_manager
     self.unexplored_icon = model_manager.load_textured_rectangle(
         'vertex_format_4f', 64, 64, 'unexplored-icon',
         '4f_unexplored-icon',
         )
     model = model_manager.models[self.unexplored_icon]
     vt1 = model[0]
     vt2 = model[1]
     vt3 = model[2]
     vt4 = model[3]
     u1, v1 = vt1.uvs
     u2, v2 = vt2.uvs
     u3, v3 = vt3.uvs
     u4, v4 = vt4.uvs
     vt1.uvs = (u1, v3)
     vt2.uvs = (u2, v4)
     vt3.uvs = (u3, v1)
     vt4.uvs = (u4, v2)
     self.unexplored_texture = 'unexplored-icon'
Example #3
0
import kivent_core
import kivent_cymunk
from kivent_core.gameworld import GameWorld
from kivent_core.managers.resource_managers import texture_manager
from kivent_core.systems.renderers import RotateRenderer
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.rotate_systems import RotateSystem2D
from kivent_cymunk.interaction import CymunkTouchSystem
from kivy.properties import StringProperty, NumericProperty


def get_asset_path(asset, asset_loc):
    return join(dirname(dirname(abspath(__file__))), asset_loc, asset)


texture_manager.load_image('redcircle.png')
texture_manager.load_image('greencircle.png')
texture_manager.load_image('circlewoffset.png')
texture_manager.load_image('roundrect.png')
texture_manager.load_image(get_asset_path('blue-tile.png', 'assets'))


class TestGame(Widget):
    def __init__(self, **kwargs):
        super(TestGame, self).__init__(**kwargs)
        self.gameworld.init_gameworld([
            'cymunk_physics', 'rotate_renderer', 'rotate', 'position',
            'cymunk_touch'
        ],
                                      callback=self.init_game)
Example #4
0
File: main.py Project: kivy/kivent
from kivy.clock import Clock
from kivy.core.window import Window
import kivent_core
import kivent_cymunk
from kivent_core.gameworld import GameWorld
from kivent_core.managers.resource_managers import texture_manager
from kivent_core.systems.renderers import RotateRenderer
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.rotate_systems import RotateSystem2D
from kivent_cymunk.interaction import CymunkTouchSystem
from kivy.properties import StringProperty, NumericProperty

def get_asset_path(asset, asset_loc):
    return join(dirname(dirname(abspath(__file__))), asset_loc, asset)

texture_manager.load_image('redcircle.png')
texture_manager.load_image('greencircle.png')
texture_manager.load_image('circlewoffset.png')
texture_manager.load_image('roundrect.png')
texture_manager.load_image(get_asset_path('blue-tile.png', 'assets'))



class TestGame(Widget):
    def __init__(self, **kwargs):
        super(TestGame, self).__init__(**kwargs)
        self.gameworld.init_gameworld(
            ['cymunk_physics', 'rotate_renderer', 'rotate', 'position',
            'cymunk_touch'],
            callback=self.init_game)
Example #5
0
File: main.py Project: kivy/kivent
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.core.window import Window
from random import randint, choice, randrange
import kivent_core
from kivent_core.gameworld import GameWorld
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.renderers import Renderer
from kivent_core.systems.gamesystem import GameSystem
from kivent_core.managers.resource_managers import texture_manager
from kivy.properties import StringProperty, ObjectProperty
from kivy.factory import Factory
from os.path import dirname, join, abspath

texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets', 
    'star1.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets', 
    'star2.png'))


class MyAnimationSystem(GameSystem):

    def update(self, dt):
        entities = self.gameworld.entities
        for component in self.components:
            if component is not None:
                entity_id = component.entity_id
                entity = entities[entity_id]
                render_comp = entity.renderer
                if render_comp.texture_key == 'star1':
                    render_comp.texture_key = 'star2'
Example #6
0
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.core.window import Window
from random import randint, choice
import kivent_core
from kivent_core.gameworld import GameWorld
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.renderers import Renderer
from kivent_core.systems.animation_sys import AnimationSystem
from kivent_core.managers.resource_managers import texture_manager
from kivy.properties import StringProperty
from os.path import dirname, join, abspath

texture_manager.load_atlas(
    join(dirname(dirname(abspath(__file__))), 'assets', 'stars.atlas'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star1-blue.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star2-blue.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star3-blue.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star1-red.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star2-red.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star3-red.png'))


class TestGame(Widget):
    def on_kv_post(self, *args):
        self.gameworld.init_gameworld(['renderer', 'position', 'animation'],
Example #7
0
 def load_textures(self):
     texture_manager.load_image(get_asset_path('orange-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('purple-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('green-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('blue-tile.png', 'assets'))
Example #8
0

def get_all_files(dir_name, extension):
    output = []
    output_a = output.append
    for root, dirs, files in walk(dir_name):
        for fl in files:
            if fl.endswith(extension): 
                output_a(join(root,fl))
    return output

images_to_load = get_all_files(
    join(dirname(__file__), 'assets', 'particle_graphics', 'image'), '.png')

for im_add in images_to_load:
    texture_manager.load_image(im_add)


class EditorPanel(FloatLayout):
    pass


class EditorScreen(Screen):
    pass


class SliderWithValues(BoxLayout):
    minimum = NumericProperty(0.)
    maximum = NumericProperty(100.)
    step = NumericProperty(1.)
    current_value = NumericProperty(0.)
Example #9
0
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.core.window import Window
from random import randint, choice
import kivent_core
from kivent_core.gameworld import GameWorld
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.renderers import Renderer
from kivent_core.systems.animation import AnimationSystem
from kivent_core.managers.resource_managers import texture_manager
from kivy.properties import StringProperty
from os.path import dirname, join, abspath

texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets',
    'stars.atlas'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star1-blue.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star2-blue.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star3-blue.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star1-red.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star2-red.png'))
texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets',
    'star3-red.png'))


class TestGame(Widget):
    def __init__(self, **kwargs):
        super(TestGame, self).__init__(**kwargs)
Example #10
0
File: main.py Project: kivy/kivent
 def load_textures(self):
     texture_manager.load_image(get_asset_path('orange-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('purple-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('green-tile.png', 'assets'))
     texture_manager.load_image(get_asset_path('blue-tile.png', 'assets'))
Example #11
0
    def load_assets(self):
        model_manager = self.gameworld.model_manager
        emitter_system = self.ids.emitter
        projectile_system = self.ids.projectiles
        weapon_system = self.ids.weapons
        sound_manager = self.gameworld.sound_manager
        asteroid_system = self.ids.asteroids
        physics_system = self.ids.physics
        shield_system = self.ids.shields
        explosion_system = self.ids.explosions
        texture_manager.load_atlas(
            get_asset_path('assets', 'particles', 'particles.atlas'))
        texture_manager.load_image(
            get_asset_path('assets', 'objects', 'asteroid1.png'))
        texture_manager.load_image(
            get_asset_path('assets', 'objects', 'asteroid1-radar.png'))
        texture_manager.load_image(
            get_asset_path('assets', 'particles', 'particle3.png'))

        asteroid_model = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            64,
            64,
            'asteroid1',
            '4f_asteroid1',
        )
        asteroid_radar_model = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            64,
            64,
            'asteroid1-radar',
            '4f_asteroid1_radar',
        )
        asteroid_collision_type = physics_system.register_collision_type(
            'asteroids')
        ship_collision_type = physics_system.register_collision_type('ships')
        projectile_system.add_origin_collision_type(asteroid_collision_type)
        projectile_system.add_origin_collision_type(ship_collision_type)
        self.load_weapons()

        ship_hit_asteroid = sound_manager.load_sound('ship_hit_asteroid',
                                                     get_asset_path(
                                                         'assets', 'soundfx',
                                                         'shiphit.wav'),
                                                     track_count=2)
        asteroid_hit_asteroid = sound_manager.load_sound(
            'asteroid_hit_asteroid',
            get_asset_path('assets', 'soundfx', 'asteroidhitasteroid.wav'),
            track_count=2)
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'asteroidexplosion.kep'))
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'shipexplosion.kep'))
        explosion_system.register_template('ship_explosion', 'shipexplosion',
                                           3.0, 1.5)
        asteroid_system.register_template(
            'asteroid1',
            asteroid_collision_type,
            mass=125.,
            radius=30.,
            texture='asteroid1',
            model_key=asteroid_model,
            health=15.,
            armor=4.,
            ship_collision_sound=ship_hit_asteroid,
            asteroid_collision_sound=asteroid_hit_asteroid,
            radar_model=asteroid_radar_model,
            radar_texture='asteroid1-radar')

        explosion_system.register_template('asteroid_explosion',
                                           'asteroidexplosion', 1.5, 1.0)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            ship_collision_type,
            begin_func=asteroid_system.on_collision_begin_asteroid_ship)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            asteroid_collision_type,
            begin_func=asteroid_system.on_collision_begin_asteroid_asteroid)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_asteroid_shield)
        physics_system.add_collision_handler(
            shield_system.shield_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_shield_shield)
        physics_system.add_collision_handler(
            ship_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_ship_shield)
        projectile_system.add_custom_collision_type(
            shield_system.shield_collision_type,
            shield_system.on_collision_begin_bullet_shield)
        self.load_ships(ship_collision_type)
Example #12
0
    def load_weapons(self):
        emitter_system = self.ids.emitter
        projectile_system = self.ids.projectiles
        sound_manager = self.gameworld.sound_manager
        weapon_system = self.ids.weapons
        model_manager = self.gameworld.model_manager
        explosion_system = self.ids.explosions
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'blaster_projectile.kep'))
        blaster_hit_sound = sound_manager.load_sound('blaster_hit',
                                                     get_asset_path(
                                                         'assets', 'soundfx',
                                                         'blaster', 'hit.wav'),
                                                     track_count=2)
        blaster_bullet_type = projectile_system.register_projectile_template(
            'blaster_projectile',
            10.,
            1.,
            1,
            None,
            None,
            12,
            12,
            1.,
            550.,
            50.,
            main_effect="blaster_projectile",
            hit_sound=blaster_hit_sound,
            destruction_callback=self.spawn_explosion_for_blaster)
        blaster_begin = sound_manager.load_sound(
            'blaster-reload-begin',
            get_asset_path('assets', 'soundfx', 'blaster', 'reload-laser.wav'),
            track_count=2)
        blaster_end = sound_manager.load_sound(
            'blaster-reload-end',
            get_asset_path('assets', 'soundfx', 'blaster', 'reload-end.wav'),
            track_count=2)
        blaster_fire_sound = sound_manager.load_sound(
            'blaster-shoot',
            get_asset_path('assets', 'soundfx', 'blaster', 'shoot.wav'),
            track_count=2)
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'orb_explosion.kep'))
        explosion_system.register_template('orb_explosion', 'orb_explosion',
                                           .3, .6)

        weapon_system.register_weapon_template(
            'ship1_blaster',
            'Blaster',
            reload_time=3.5,
            projectile_type=1,
            ammo_count=100,
            rate_of_fire=.4,
            clip_size=14,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=blaster_bullet_type,
            projectile_width=12.,
            projectile_height=12.,
            accel=500,
            reload_begin_sound=blaster_begin,
            reload_end_sound=blaster_end,
            fire_sound=blaster_fire_sound,
            spread=radians(0.),
            shot_count=1,
            time_between_shots=0.35,
        )
        rifle_hit_sound = sound_manager.load_sound('blaster_hit',
                                                   get_asset_path(
                                                       'assets', 'soundfx',
                                                       'rifle', 'hit.wav'),
                                                   track_count=2)

        bullet_tex = texture_manager.load_image(
            get_asset_path('assets', 'projectiles', 'bullet-14px.png'))
        bullet_model = model_manager.load_textured_rectangle(
            'vertex_format_4f', 28., 14., 'bullet-14px', '4f_bullet-14px')
        rifle_bullet_type = projectile_system.register_projectile_template(
            'rifle_projectile',
            12.,
            1.,
            1,
            'bullet-14px',
            bullet_model,
            14.,
            14.,
            10,
            750.,
            50.,
            hit_sound=rifle_hit_sound)

        rifle_begin = sound_manager.load_sound(
            'rifle-reload-begin',
            get_asset_path('assets', 'soundfx', 'rifle', 'reload-begin.wav'),
            track_count=2)
        rifle_end = sound_manager.load_sound('rifle-reload-end',
                                             get_asset_path(
                                                 'assets', 'soundfx', 'rifle',
                                                 'reload-end.wav'),
                                             track_count=2)
        rifle_fire_sound = sound_manager.load_sound('rifle-shoot',
                                                    get_asset_path(
                                                        'assets', 'soundfx',
                                                        'rifle', 'shoot.wav'),
                                                    track_count=2)
        weapon_system.register_weapon_template(
            'ship1_rifle',
            'Rifle',
            reload_time=5.0,
            projectile_type=3,
            ammo_count=100,
            rate_of_fire=.5,
            clip_size=8,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=rifle_bullet_type,
            projectile_width=12.,
            projectile_height=12.,
            accel=10000.,
            reload_begin_sound=rifle_begin,
            reload_end_sound=rifle_end,
            fire_sound=rifle_fire_sound,
            spread=radians(0.),
            shot_count=2,
            time_between_shots=.1,
        )

        shotgun_begin = sound_manager.load_sound(
            'shotgun-reload-begin',
            get_asset_path('assets', 'soundfx', 'shotgun', 'reload-begin.wav'))
        shotgun_end = sound_manager.load_sound(
            'shotgun-reload-end',
            get_asset_path('assets', 'soundfx', 'shotgun', 'reload-end.wav'))
        shotgun_fire_sound = sound_manager.load_sound(
            'shotgun-shoot',
            get_asset_path('assets', 'soundfx', 'shotgun', 'shoot.wav'))

        shotgun_bullet_tex = texture_manager.load_image(
            get_asset_path('assets', 'projectiles', 'bullet-6px.png'))
        shotgun_bullet_model = model_manager.load_textured_rectangle(
            'vertex_format_4f', 6., 6., 'bullet-6px', '4f_bullet-6px')
        shotgun_bullet_type = projectile_system.register_projectile_template(
            'shotgun_projectile',
            7.,
            1.,
            1,
            'bullet-6px',
            shotgun_bullet_model,
            4.5,
            4.5,
            2.5,
            750.,
            50.,
            lifespan=2.0,
            hit_sound=rifle_hit_sound)
        weapon_system.register_weapon_template(
            'ship1_shotgun',
            'Shotgun',
            reload_time=2.5,
            projectile_type=1,
            ammo_count=100,
            rate_of_fire=.70,
            clip_size=8,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=shotgun_bullet_type,
            projectile_width=4.,
            projectile_height=4.,
            accel=3000,
            reload_begin_sound=shotgun_begin,
            reload_end_sound=shotgun_end,
            fire_sound=shotgun_fire_sound,
            spread=radians(15.),
            shot_count=5,
            time_between_shots=0.,
        )
Example #13
0
    def load_ships(self, ship_collision_type):
        ship_system = self.ids.ship_system
        emitter_system = self.ids.emitter
        physics_system = self.ids.physics
        model_manager = self.gameworld.model_manager
        sound_manager = self.gameworld.sound_manager
        player_system = self.ids.player
        radar_texture = texture_manager.load_image(
            get_asset_path('assets', 'ships', 'ship1-radar.png'))
        texture_name = texture_manager.load_image(
            get_asset_path('assets', 'ships', 'ship1.png'))
        radar_model_name = model_manager.load_textured_rectangle(
            'vertex_format_4f', 104, 128, 'ship1-radar', '4f_ship1_radar')
        model_name = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            104,
            128,
            'ship1',
            '4f_ship1',
        )
        effect_name = emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'engine1.kep'))
        shield_model_data = generate_shield_model(85., 10.)
        shield_model = model_manager.load_model(
            'vertex_format_2f4ub',
            shield_model_data['vert_count'],
            shield_model_data['ind_count'],
            'shield_model',
            indices=shield_model_data['indices'],
            vertices=shield_model_data['vertices'],
            do_copy=False)

        explosion_sound = sound_manager.load_sound(
            'explosion_sound',
            get_asset_path('assets', 'soundfx', 'explosion.wav'))
        ship_system.register_template('ship1',
                                      'Bulldog',
                                      model_name,
                                      'ship1',
                                      ship_collision_type,
                                      health=100.,
                                      mass=250.,
                                      max_speed=200.,
                                      max_turn_speed=200.,
                                      accel=15000.,
                                      angular_accel=45.,
                                      boost_force=25000.,
                                      boost_drain=25.,
                                      max_boost_speed=300.,
                                      armor=5.,
                                      boost_reserve=50.,
                                      boost_regen=10.,
                                      width=96.,
                                      height=108.,
                                      weapons=['ship1_shotgun'],
                                      emitters=[effect_name],
                                      emitter_speed_base=90.,
                                      scale_base=2.2,
                                      emitter_scaling_factor=150.,
                                      explosion_sound=explosion_sound,
                                      has_shield=True,
                                      shield_model=shield_model,
                                      shield_health=100.,
                                      shield_radius=90.,
                                      shield_timeout=1.25,
                                      shield_recharge=20.,
                                      radar_model_name=radar_model_name,
                                      radar_texture='ship1-radar')
        ship_engine_rumble = sound_manager.load_sound(
            'engine_rumble',
            get_asset_path('assets', 'soundfx', 'shipengine.wav'),
        )
Example #14
0
from random import randint, choice
import kivent_core
from kivent_core.gameworld import GameWorld
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.renderers import Renderer  # RotateRenderer
from kivent_core.managers.resource_managers import texture_manager
from kivy.properties import StringProperty
from os.path import dirname, join, abspath
from kivent_core.systems.rotate_systems import RotateSystem2D
#from kivent_core.systems.scale_systems import ScaleSystem2D
""" Load custom Sfx renderer """
from spaceguppy_sfx.sfx import SfxComponent, SfxSystem
from spaceguppy_sfx.sfx_renderer import SfxRenderer

test_image = abspath(join('..', 'res', 'img', 'aster1.png'))
texture_manager.load_image(test_image)


class TestGame(Widget):
    def __init__(self, **kwargs):
        super(TestGame, self).__init__(**kwargs)
        self.gameworld.init_gameworld(
            ['position', 'rotate', 'sfx', 'sfx_renderer'],
            callback=self.init_game)

    def init_game(self):
        self.setup_states()
        self.set_state()
        self.load_models()
        self.draw_some_stuff()
Example #15
0
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.core.window import Window
from random import randint, choice, randrange
import kivent_core
from kivent_core.gameworld import GameWorld
from kivent_core.systems.position_systems import PositionSystem2D
from kivent_core.systems.renderers import Renderer
from kivent_core.systems.gamesystem import GameSystem
from kivent_core.managers.resource_managers import texture_manager
from kivy.properties import StringProperty, ObjectProperty
from kivy.factory import Factory
from os.path import dirname, join, abspath

texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star1.png'))
texture_manager.load_image(
    join(dirname(dirname(abspath(__file__))), 'assets', 'star2.png'))


class MyAnimationSystem(GameSystem):
    def update(self, dt):
        entities = self.gameworld.entities
        for component in self.components:
            if component is not None:
                entity_id = component.entity_id
                entity = entities[entity_id]
                render_comp = entity.renderer
                if render_comp.texture_key == 'star1':
                    render_comp.texture_key = 'star2'
                else: