├── .gitignore ├── .travis.yml ├── README.md ├── appveyor.yml ├── examples ├── 0_empty_kivy_app │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 10_particles_demo │ ├── LICENSE │ ├── assets │ │ ├── glsl │ │ │ ├── positionrotatecolorscale.glsl │ │ │ └── positionshader.glsl │ │ ├── stars-0.png │ │ └── stars.atlas │ ├── main.py │ └── yourappname.kv ├── 11_svg_demo │ ├── LICENSE │ ├── drawing.svg │ ├── lesson1-2.svg │ ├── main.py │ ├── music.svg │ ├── poscolorshader.glsl │ ├── ship.svg │ ├── sun.svg │ ├── tiger.svg │ └── yourappname.kv ├── 12_drawing_shapes │ ├── LICENSE │ ├── main.py │ ├── poscolorshader.glsl │ └── yourappname.kv ├── 13_tilemap │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 14_tmx_loader │ ├── LICENSE │ ├── main.py │ ├── poscolorshader.glsl │ └── yourappname.kv ├── 15_camera_rotate │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 16_svg_phys_objects │ ├── main.py │ ├── objects.svg │ ├── poscolorshader.glsl │ └── yourappname.kv ├── 17_joints │ ├── .vewpostactivate │ ├── LICENSE │ ├── circlewoffset.png │ ├── greencircle.png │ ├── main.py │ ├── redcircle.png │ ├── roundrect.png │ ├── yourappname.ini │ └── yourappname.kv ├── 1_empty_kivent_app │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 2_basic_app │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 3_creating_a_gamesystem │ ├── LICENSE │ ├── README.md │ ├── cythonvel.kv │ ├── main.py │ ├── main_with_cython.py │ ├── setup.py │ ├── velocity_module │ │ ├── __init__.py │ │ ├── velocity.pxd │ │ └── velocity.pyx │ └── yourappname.kv ├── 4_adding_physics_objects │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 5_interacting_with_physics │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 6_controlling_the_viewing_area │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 7_star_fade │ ├── LICENSE │ ├── assets │ │ ├── glsl │ │ │ └── positioncolor.glsl │ │ ├── star1.png │ │ ├── star2.png │ │ ├── star3.png │ │ ├── star_circle.png │ │ ├── star_square.png │ │ ├── stars-0.png │ │ └── stars.atlas │ ├── main.py │ └── yourappname.kv ├── 8_simple_animation │ ├── LICENSE │ ├── main.py │ └── yourappname.kv ├── 9_twinkling_stars │ ├── LICENSE │ ├── main.py │ └── yourappname.kv └── assets │ ├── animations.json │ ├── background_objects-0.png │ ├── background_objects.atlas │ ├── blue-tile.png │ ├── glsl │ ├── polyposcolorrotateshader.glsl │ ├── positioncolor.glsl │ ├── positioncolorrotatescaleshader.glsl │ ├── positioncolorrotateshader.glsl │ ├── positioncolorshader.glsl │ ├── positionrotateshader.glsl │ └── positionshader.glsl │ ├── green-tile.png │ ├── maps │ ├── basic_ground_tiles.png │ ├── hexagonal.tmx │ ├── isometric.tmx │ ├── isometric_staggered.tmx │ ├── orthogonal.tmx │ ├── spritesheet.png │ └── tileset_hexagonal.png │ ├── orange-tile.png │ ├── purple-tile.png │ ├── star1-blue.png │ ├── star1-red.png │ ├── star1.png │ ├── star2-blue.png │ ├── star2-red.png │ ├── star2.png │ ├── star3-blue.png │ ├── star3-red.png │ ├── star3.png │ ├── stars-0.png │ └── stars.atlas ├── modules ├── core │ ├── kivent_core │ │ ├── LICENSE │ │ ├── __init__.py │ │ ├── entity.pxd │ │ ├── entity.pyx │ │ ├── gameworld.pyx │ │ ├── managers │ │ │ ├── __init__.py │ │ │ ├── animation_manager.pxd │ │ │ ├── animation_manager.pyx │ │ │ ├── entity_manager.pxd │ │ │ ├── entity_manager.pyx │ │ │ ├── game_manager.pxd │ │ │ ├── game_manager.pyx │ │ │ ├── resource_managers.pxd │ │ │ ├── resource_managers.pyx │ │ │ ├── sound_manager.pxd │ │ │ ├── sound_manager.pyx │ │ │ ├── system_manager.pxd │ │ │ └── system_manager.pyx │ │ ├── memory_handlers │ │ │ ├── __init__.py │ │ │ ├── block.pxd │ │ │ ├── block.pyx │ │ │ ├── indexing.pxd │ │ │ ├── indexing.pyx │ │ │ ├── membuffer.pxd │ │ │ ├── membuffer.pyx │ │ │ ├── pool.pxd │ │ │ ├── pool.pyx │ │ │ ├── tests.pyx │ │ │ ├── utils.pxd │ │ │ ├── utils.pyx │ │ │ ├── zone.pxd │ │ │ ├── zone.pyx │ │ │ ├── zonedblock.pxd │ │ │ └── zonedblock.pyx │ │ ├── rendering │ │ │ ├── __init__.py │ │ │ ├── animation.pxd │ │ │ ├── animation.pyx │ │ │ ├── batching.pxd │ │ │ ├── batching.pyx │ │ │ ├── cmesh.pxd │ │ │ ├── cmesh.pyx │ │ │ ├── common.pxi │ │ │ ├── fixedvbo.pxd │ │ │ ├── fixedvbo.pyx │ │ │ ├── frame_objects.pxd │ │ │ ├── frame_objects.pyx │ │ │ ├── gl_debug.pxd │ │ │ ├── gl_debug.pyx │ │ │ ├── model.pxd │ │ │ ├── model.pyx │ │ │ ├── opcodes.pxi │ │ │ ├── svg_loader.pxd │ │ │ ├── svg_loader.pyx │ │ │ ├── vertex_format.pxd │ │ │ ├── vertex_format.pyx │ │ │ ├── vertex_formats.pxd │ │ │ └── vertex_formats.pyx │ │ ├── systems │ │ │ ├── __init__.py │ │ │ ├── animation_sys.pxd │ │ │ ├── animation_sys.pyx │ │ │ ├── color_systems.pxd │ │ │ ├── color_systems.pyx │ │ │ ├── gamemap.pxd │ │ │ ├── gamemap.pyx │ │ │ ├── gamesystem.pxd │ │ │ ├── gamesystem.pyx │ │ │ ├── gameview.pxd │ │ │ ├── gameview.pyx │ │ │ ├── lifespan.pxd │ │ │ ├── lifespan.pyx │ │ │ ├── position_systems.pxd │ │ │ ├── position_systems.pyx │ │ │ ├── renderers.pxd │ │ │ ├── renderers.pyx │ │ │ ├── rotate_systems.pxd │ │ │ ├── rotate_systems.pyx │ │ │ ├── scale_systems.pxd │ │ │ ├── scale_systems.pyx │ │ │ ├── staticmemgamesystem.pxd │ │ │ └── staticmemgamesystem.pyx │ │ └── uix │ │ │ ├── __init__.py │ │ │ ├── cwidget.pxd │ │ │ ├── cwidget.pyx │ │ │ └── gamescreens.pyx │ └── setup.py ├── cymunk │ ├── kivent_cymunk │ │ ├── LICENSE │ │ ├── __init__.py │ │ ├── interaction.pxd │ │ ├── interaction.pyx │ │ ├── physics.pxd │ │ └── physics.pyx │ └── setup.py ├── docs │ ├── Makefile │ ├── index.php │ └── source │ │ ├── conf.py │ │ ├── entity.rst │ │ ├── gamesystems.rst │ │ ├── gameworld.rst │ │ ├── index.rst │ │ ├── managers.rst │ │ ├── memory_handlers.rst │ │ ├── particles.rst │ │ ├── physics.rst │ │ ├── rendering.rst │ │ └── tiled.rst ├── maps │ ├── kivent_maps │ │ ├── __init__.py │ │ ├── map_data.pxd │ │ ├── map_data.pyx │ │ ├── map_manager.pxd │ │ ├── map_manager.pyx │ │ ├── map_system.pxd │ │ ├── map_system.pyx │ │ └── map_utils.py │ └── setup.py ├── particles │ ├── kivent_particles │ │ ├── __init__.py │ │ ├── emitter.pxd │ │ ├── emitter.pyx │ │ ├── particle.pxd │ │ ├── particle.pyx │ │ ├── particle_config.pxi │ │ ├── particle_formats.pxd │ │ ├── particle_formats.pyx │ │ ├── particle_math.pxi │ │ ├── particle_renderers.pxd │ │ └── particle_renderers.pyx │ └── setup.py ├── projectiles │ ├── kivent_projectiles │ │ ├── __init__.py │ │ ├── combatstats.pxd │ │ ├── combatstats.pyx │ │ ├── projectile_config.pxi │ │ ├── projectile_types.pxi │ │ ├── projectiles.pxd │ │ ├── projectiles.pyx │ │ ├── weapon_ai.pxd │ │ ├── weapon_ai.pyx │ │ ├── weapons.pxd │ │ └── weapons.pyx │ └── setup.py └── recipes │ ├── kivent_core │ └── recipe.sh │ ├── kivent_cymunk │ └── recipe.sh │ └── kivent_particles │ └── recipe.sh ├── requirements.txt ├── scripts ├── install_all.sh └── test_all.sh ├── tools └── appveyor │ ├── id_rsa.enc │ └── kivent-upload.sh └── website ├── images ├── bg_hr.png ├── bkg.png ├── blacktocat.png ├── icon_download.png ├── interaction.gif ├── kiventlogo.png ├── mallmap.gif ├── physics.gif ├── sprite_download.png ├── starfield.gif └── velocitymod.gif ├── index.html ├── javascripts └── main.js ├── params.json └── stylesheets ├── pygment_trac.css └── stylesheet.css /.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | *.o 3 | *.pyc 4 | .idea 5 | *.c 6 | *.pyd 7 | *.swp 8 | *.egg-info 9 | build 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 3.5 4 | - 3.6 5 | - 3.7 6 | sudo: required 7 | dist: xenial 8 | before_install: 9 | - sudo apt update 10 | - sudo apt install -y build-essential ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev 11 | - pip install -U pip 12 | - pip install Cython 13 | - pip install -r ./requirements.txt 14 | install: 15 | - scripts/install_all.sh 16 | script: 17 | - scripts/test_all.sh 18 | -------------------------------------------------------------------------------- /examples/0_empty_kivy_app/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/0_empty_kivy_app/main.py: -------------------------------------------------------------------------------- 1 | import kivy 2 | import kivent_core 3 | from kivy.app import App 4 | from kivy.uix.widget import Widget 5 | 6 | class TestGame(Widget): 7 | pass 8 | 9 | class YourAppNameApp(App): 10 | def build(self): 11 | pass 12 | 13 | if __name__ == '__main__': 14 | YourAppNameApp().run() 15 | -------------------------------------------------------------------------------- /examples/0_empty_kivy_app/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | 3 | TestGame: 4 | 5 | : 6 | -------------------------------------------------------------------------------- /examples/10_particles_demo/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/10_particles_demo/assets/glsl/positionrotatecolorscale.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec2 center; 14 | attribute vec2 scale; 15 | attribute vec4 v_color; 16 | attribute float rotate; 17 | 18 | /* uniform variables */ 19 | uniform mat4 modelview_mat; 20 | uniform mat4 projection_mat; 21 | uniform vec4 color; 22 | uniform float opacity; 23 | 24 | void main (void) { 25 | frag_color = v_color; 26 | tex_coord0 = uvs; 27 | float a_sin = sin(rotate); 28 | float a_cos = cos(rotate); 29 | mat4 rot_mat = mat4(a_cos, -a_sin, 0.0, 0.0, 30 | a_sin, a_cos, 0.0, 0.0, 31 | 0.0, 0.0, 1.0, 0.0, 32 | 0.0, 0.0, 0.0, 1.0 ); 33 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 34 | 0.0, 1.0, 0.0, center.y, 35 | 0.0, 0.0, 1.0, 0.0, 36 | 0.0, 0.0, 0.0, 1.0); 37 | vec4 t_pos = vec4(pos.xy*scale.xy, 0.0, 1.0); 38 | vec4 trans_pos = t_pos * rot_mat * trans_mat; 39 | gl_Position = projection_mat * modelview_mat * trans_pos; 40 | 41 | } 42 | 43 | 44 | ---FRAGMENT SHADER--- 45 | #ifdef GL_ES 46 | precision highp float; 47 | #endif 48 | 49 | /* Outputs from the vertex shader */ 50 | varying vec4 frag_color; 51 | varying vec2 tex_coord0; 52 | 53 | /* uniform texture samplers */ 54 | uniform sampler2D texture0; 55 | 56 | void main (void){ 57 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 58 | } 59 | -------------------------------------------------------------------------------- /examples/10_particles_demo/assets/glsl/positionshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = color * vec4(1.0, 1., 1.0, opacity); 22 | tex_coord0 = uvs; 23 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 24 | gl_Position = projection_mat * modelview_mat * new_pos; 25 | 26 | } 27 | 28 | 29 | ---FRAGMENT SHADER--- 30 | #ifdef GL_ES 31 | precision highp float; 32 | #endif 33 | 34 | /* Outputs from the vertex shader */ 35 | varying vec4 frag_color; 36 | varying vec2 tex_coord0; 37 | 38 | /* uniform texture samplers */ 39 | uniform sampler2D texture0; 40 | 41 | void main (void){ 42 | 43 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 44 | } 45 | -------------------------------------------------------------------------------- /examples/10_particles_demo/assets/stars-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/10_particles_demo/assets/stars-0.png -------------------------------------------------------------------------------- /examples/10_particles_demo/assets/stars.atlas: -------------------------------------------------------------------------------- 1 | {"stars-0.png": {"star_circle": [2, 60, 32, 32], "star_square": [36, 60, 32, 32], "star1": [2, 94, 32, 32], "star3": [70, 94, 32, 32], "star2": [36, 94, 32, 32]}} -------------------------------------------------------------------------------- /examples/10_particles_demo/main.py: -------------------------------------------------------------------------------- 1 | import kivy 2 | from kivy.app import App 3 | from kivy.uix.widget import Widget 4 | import kivent_core 5 | import kivent_particles 6 | from kivent_core.managers.resource_managers import texture_manager 7 | 8 | texture_manager.load_atlas('assets/stars.atlas') 9 | 10 | 11 | class TestGame(Widget): 12 | def on_kv_post(self, *args): 13 | self.gameworld.init_gameworld(['position', 'scale', 'rotate', 14 | 'color', 'particles', 'emitters', 'particle_renderer', 'renderer'], 15 | callback=self.init_game) 16 | 17 | def init_game(self): 18 | self.setup_states() 19 | self.set_state() 20 | self.load_emitter() 21 | 22 | def load_emitter(self): 23 | emitter_system = self.ids.emitter 24 | data = {'number_of_particles': 1000, 'texture': 'star3', 'paused': False, 25 | 'pos_variance': (150., 150.), 'life_span_variance': 2.0, 'speed_variance': 50.} 26 | eff_id = emitter_system.load_effect_from_data(data, 'effect_test') 27 | comp_args = { 28 | 'position': (200., 200.), 29 | 'rotate': 0., 30 | 'emitters': ['effect_test'], 31 | # 'renderer': {'texture': 'star2'}, 32 | } 33 | self.gameworld.init_entity(comp_args, ['position', 'rotate', 34 | 'emitters']) 35 | 36 | def setup_states(self): 37 | self.gameworld.add_state(state_name='main', 38 | systems_added=['particle_renderer', 'renderer'], 39 | systems_removed=[], systems_paused=[], 40 | systems_unpaused=['particle_renderer', 'renderer'], 41 | screenmanager_screen='main') 42 | 43 | def set_state(self): 44 | self.gameworld.state = 'main' 45 | 46 | 47 | class YourAppNameApp(App): 48 | def build(self): 49 | pass 50 | 51 | 52 | if __name__ == '__main__': 53 | YourAppNameApp().run() 54 | -------------------------------------------------------------------------------- /examples/10_particles_demo/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | 3 | TestGame: 4 | 5 | : 6 | gameworld: gameworld 7 | GameWorld: 8 | id: gameworld 9 | gamescreenmanager: gamescreenmanager 10 | size_of_gameworld: 100*1024 11 | size_of_entity_block: 128 12 | system_count: 12 13 | zones: {'general': 10000, 'particles': 10000} 14 | PositionSystem2D: 15 | system_id: 'position' 16 | gameworld: gameworld 17 | zones: ['general', 'particles'] 18 | size_of_component_block: 128 19 | RotateSystem2D: 20 | gameworld: gameworld 21 | zones: ['general', 'particles'] 22 | ScaleSystem2D: 23 | gameworld: gameworld 24 | zones: ['general', 'particles'] 25 | ColorSystem: 26 | gameworld: gameworld 27 | zones: ['general', 'particles'] 28 | ParticleSystem: 29 | id: particles 30 | gameworld: gameworld 31 | zones: ['particles'] 32 | particle_zone: 'particles' 33 | ParticleRenderer: 34 | gameworld: gameworld 35 | zones: ['particles'] 36 | shader_source: 'assets/glsl/positionrotatecolorscale.glsl' 37 | frame_count: 3 38 | updateable: True 39 | EmitterSystem: 40 | id: emitter 41 | gameworld: gameworld 42 | zones: ['general'] 43 | particle_system: particles.__self__ 44 | Renderer: 45 | zones: ['general'] 46 | gameworld: gameworld 47 | shader_source: 'assets/glsl/positionshader.glsl' 48 | frame_count: 3 49 | updateable: True 50 | GameScreenManager: 51 | id: gamescreenmanager 52 | size: root.size 53 | pos: root.pos 54 | gameworld: gameworld 55 | GameScreen: 56 | name: 'main' 57 | -------------------------------------------------------------------------------- /examples/11_svg_demo/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/11_svg_demo/drawing.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /examples/11_svg_demo/main.py: -------------------------------------------------------------------------------- 1 | import kivy 2 | from kivy.app import App 3 | from kivy.logger import Logger 4 | from kivy.uix.widget import Widget 5 | import kivent_core 6 | from kivent_core.rendering.svg_loader import SVG 7 | from kivy.properties import NumericProperty 8 | 9 | 10 | class TestGame(Widget): 11 | entity_id = NumericProperty(None) 12 | 13 | def on_kv_post(self, *args): 14 | self.uuids = {} 15 | self.gameworld.init_gameworld( 16 | ['position', 'poly_renderer'], 17 | callback=self.init_game) 18 | 19 | 20 | def init_game(self): 21 | self.setup_states() 22 | self.set_state() 23 | self.load_svg() 24 | 25 | def on_touch_move(self, touch): 26 | if self.entity_id is not None: 27 | entity = self.gameworld.entities[self.entity_id] 28 | position = entity.position 29 | position.x += touch.dx 30 | position.y += touch.dy 31 | 32 | 33 | def load_svg(self): 34 | model_manager = self.gameworld.model_manager 35 | data = model_manager.get_model_info_for_svg("tiger.svg") 36 | load_model_from_model_info = model_manager.load_model_from_model_info 37 | init_entity = self.gameworld.init_entity 38 | model_data = data['model_info'] 39 | svg_name = data['svg_name'] 40 | model_infos = [] 41 | entity_to_copy = None 42 | final_infos = model_manager.combine_model_infos(model_data) 43 | svg_bounds = model_manager.get_center_and_bbox_from_infos(final_infos) 44 | center = svg_bounds['center'] 45 | neg_center = [-center[0], -center[1]] 46 | for model_info in final_infos: 47 | model_name = load_model_from_model_info(model_info, svg_name) 48 | model = model_manager.models[model_name] 49 | Logger.info(model.vertex_count) 50 | model.add_all_vertex_attribute('pos', neg_center) 51 | create_dict = { 52 | 'position': (300, 300), 53 | 'poly_renderer': {'model_key': model_name}, 54 | } 55 | if entity_to_copy is not None: 56 | create_dict['position'] = entity_to_copy 57 | ent = init_entity(create_dict, ['position', 'poly_renderer']) 58 | if entity_to_copy is None: 59 | entity_to_copy = self.gameworld.entities[ent] 60 | self.entity_id = ent 61 | 62 | 63 | 64 | 65 | def setup_states(self): 66 | self.gameworld.add_state(state_name='main', 67 | systems_added=[], 68 | systems_removed=[], systems_paused=[], 69 | systems_unpaused=[], 70 | screenmanager_screen='main') 71 | 72 | def set_state(self): 73 | self.gameworld.state = 'main' 74 | 75 | 76 | class YourAppNameApp(App): 77 | def build(self): 78 | pass 79 | 80 | 81 | if __name__ == '__main__': 82 | YourAppNameApp().run() 83 | -------------------------------------------------------------------------------- /examples/11_svg_demo/poscolorshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | 9 | /* vertex attributes */ 10 | attribute vec2 pos; 11 | attribute vec4 v_color; 12 | 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = v_color*color; 22 | vec4 pos = vec4(pos.xy, 0.0, 1.0); 23 | gl_Position = projection_mat * modelview_mat * pos; 24 | 25 | } 26 | 27 | 28 | ---FRAGMENT SHADER--- 29 | #ifdef GL_ES 30 | precision highp float; 31 | #endif 32 | 33 | /* Outputs from the vertex shader */ 34 | varying vec4 frag_color; 35 | 36 | void main (void){ 37 | gl_FragColor = frag_color; 38 | } 39 | -------------------------------------------------------------------------------- /examples/11_svg_demo/sun.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/11_svg_demo/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | 3 | TestGame: 4 | 5 | : 6 | gameworld: gameworld 7 | canvas.before: 8 | Color: 9 | rgb: (1., 1., 1.) 10 | Rectangle: 11 | size: self.size 12 | pos: self.pos 13 | GameWorld: 14 | id: gameworld 15 | gamescreenmanager: gamescreenmanager 16 | size_of_gameworld: 2000*1024 17 | size_of_entity_block: 128 18 | system_count: 8 19 | zones: {'general': 1000000} 20 | model_format_allocations: {'vertex_format_2f4ub': (100000*1024, 100000*1024)} 21 | PositionSystem2D: 22 | system_id: 'position' 23 | gameworld: gameworld 24 | zones: ['general'] 25 | size_of_component_block: 512 26 | PolyRenderer: 27 | gameworld: gameworld 28 | zones: ['general'] 29 | frame_count: 2 30 | updateable: True 31 | size_of_batches: 786 32 | max_batches: 400 33 | size_of_component_block: 786 34 | shader_source: 'poscolorshader.glsl' 35 | GameScreenManager: 36 | GameScreenManager: 37 | id: gamescreenmanager 38 | size: root.size 39 | pos: root.pos 40 | gameworld: gameworld 41 | GameScreen: 42 | name: 'main' 43 | -------------------------------------------------------------------------------- /examples/12_drawing_shapes/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/12_drawing_shapes/poscolorshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | 9 | /* vertex attributes */ 10 | attribute vec2 pos; 11 | attribute vec4 v_color; 12 | 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = v_color*color; 22 | vec4 pos = vec4(pos.xy, 0.0, 1.0); 23 | gl_Position = projection_mat * modelview_mat * pos; 24 | 25 | } 26 | 27 | 28 | ---FRAGMENT SHADER--- 29 | #ifdef GL_ES 30 | precision highp float; 31 | #endif 32 | 33 | /* Outputs from the vertex shader */ 34 | varying vec4 frag_color; 35 | 36 | void main (void){ 37 | gl_FragColor = frag_color; 38 | } 39 | -------------------------------------------------------------------------------- /examples/12_drawing_shapes/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | 3 | TestGame: 4 | 5 | : 6 | gameworld: gameworld 7 | canvas.before: 8 | Color: 9 | rgb: (1., 1., 1.) 10 | Rectangle: 11 | size: self.size 12 | pos: self.pos 13 | GameWorld: 14 | id: gameworld 15 | gamescreenmanager: gamescreenmanager 16 | size_of_gameworld: 2000*1024 17 | size_of_entity_block: 128 18 | system_count: 8 19 | zones: {'general': 1000000} 20 | model_format_allocations: {'vertex_format_2f4ub': (100000*1024, 100000*1024)} 21 | PositionSystem2D: 22 | system_id: 'position' 23 | gameworld: gameworld 24 | zones: ['general'] 25 | size_of_component_block: 512 26 | PolyRenderer: 27 | gameworld: gameworld 28 | zones: ['general'] 29 | frame_count: 2 30 | updateable: True 31 | size_of_batches: 786 32 | max_batches: 400 33 | size_of_component_block: 786 34 | shader_source: 'poscolorshader.glsl' 35 | GameScreenManager: 36 | id: gamescreenmanager 37 | size: root.size 38 | pos: root.pos 39 | gameworld: gameworld 40 | GameScreen: 41 | name: 'main' 42 | BoxLayout: 43 | id: button_tray 44 | orientation: 'vertical' 45 | size_hint: (.15, .8) 46 | pos_hint: {'y': .1} 47 | ToggleButton: 48 | text: 'Layered Circle' 49 | on_state: root.draw_shape_callback('layered_circle_model') if self.state == 'down' else root.stop_drawing() 50 | group: 'shape_buttons' 51 | ToggleButton: 52 | text: 'Rectangle' 53 | on_state: root.draw_shape_callback('rectangle_model') if self.state == 'down' else root.stop_drawing() 54 | group: 'shape_buttons' 55 | ToggleButton: 56 | text: 'Triangle' 57 | on_state: root.draw_shape_callback('triangle_model') if self.state == 'down' else root.stop_drawing() 58 | group: 'shape_buttons' 59 | ToggleButton: 60 | text: 'Circle' 61 | on_state: root.draw_shape_callback('circle_model') if self.state == 'down' else root.stop_drawing() 62 | group: 'shape_buttons' 63 | Button: 64 | text: 'Clear' 65 | on_release: root.clear() 66 | -------------------------------------------------------------------------------- /examples/13_tilemap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/13_tilemap/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import get_asset_path __main__.get_asset_path 3 | 4 | TestGame: 5 | 6 | : 7 | gameworld: gameworld 8 | GameWorld: 9 | id: gameworld 10 | gamescreenmanager: gamescreenmanager 11 | size_of_gameworld: 100*1024 12 | system_count: 5 13 | zones: {'general': 100000} 14 | PositionSystem2D: 15 | system_id: 'position' 16 | gameworld: gameworld 17 | zones: ['general'] 18 | Renderer: 19 | id: map_layer0 20 | gameworld: gameworld 21 | system_id: 'map_layer0' 22 | system_names: ['map_layer0','position'] 23 | zones: ['general'] 24 | frame_count: 2 25 | gameview: 'camera1' 26 | shader_source: get_asset_path('positionshader.glsl', 'assets/glsl') 27 | AnimationSystem: 28 | id: map_layer0_animator 29 | gameworld: gameworld 30 | system_id: 'map_layer0_animator' 31 | system_names: ['map_layer0_animator','map_layer0'] 32 | updateable: True 33 | zones: ['general'] 34 | MapSystem: 35 | system_id: 'tile_map' 36 | id: tile_map 37 | gameworld: gameworld 38 | zones: ['general'] 39 | GameView: 40 | system_id: 'camera1' 41 | gameworld: gameworld 42 | size: root.size 43 | window_size: root.size 44 | pos: root.pos 45 | do_scroll_lock: False 46 | id: camera1 47 | updateable: True 48 | GameScreenManager: 49 | id: gamescreenmanager 50 | -------------------------------------------------------------------------------- /examples/14_tmx_loader/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Meet Udeshi 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/14_tmx_loader/poscolorshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | 9 | /* vertex attributes */ 10 | attribute vec2 pos; 11 | attribute vec4 v_color; 12 | 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = v_color*color; 22 | vec4 pos = vec4(pos.xy, 0.0, 1.0); 23 | gl_Position = projection_mat * modelview_mat * pos; 24 | 25 | } 26 | 27 | 28 | ---FRAGMENT SHADER--- 29 | #ifdef GL_ES 30 | precision highp float; 31 | #endif 32 | 33 | /* Outputs from the vertex shader */ 34 | varying vec4 frag_color; 35 | 36 | void main (void){ 37 | gl_FragColor = frag_color; 38 | } 39 | -------------------------------------------------------------------------------- /examples/14_tmx_loader/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import get_asset_path __main__.get_asset_path 3 | #:set map_layers ['map_layer%d' % i for i in range(4)] 4 | 5 | TestGame: 6 | on_touch_down: self.screen_touched(args[1]) 7 | 8 | : 9 | gameworld: gameworld 10 | camera1: camera1 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 250*1024 15 | system_count: 4 16 | zones: {'general': 100000} 17 | PositionSystem2D: 18 | system_id: 'position' 19 | gameworld: gameworld 20 | zones: ['general'] 21 | ColorSystem: 22 | system_id: 'color' 23 | gameworld: gameworld 24 | zones: ['general'] 25 | MapSystem: 26 | system_id: 'tile_map' 27 | id: tile_map 28 | gameworld: gameworld 29 | zones: ['general'] 30 | GameView: 31 | system_id: 'camera1' 32 | gameworld: gameworld 33 | size: root.size 34 | window_size: root.size 35 | pos: root.pos 36 | do_scroll_lock: False 37 | id: camera1 38 | updateable: True 39 | GameScreenManager: 40 | id: gamescreenmanager 41 | size: root.size 42 | pos: root.pos 43 | gameworld: gameworld 44 | 45 | : 46 | MainScreen: 47 | id: main_screen 48 | 49 | : 50 | name: 'main' 51 | 52 | FloatLayout: 53 | DebugPanel: 54 | size_hint: (.2, .1) 55 | pos_hint: {'x': .225, 'y': .025} 56 | 57 | 58 | : 59 | Label: 60 | pos: root.pos 61 | size: root.size 62 | font_size: root.size[1]*.5 63 | halign: 'center' 64 | valign: 'middle' 65 | color: (1,1,1,1) 66 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 67 | -------------------------------------------------------------------------------- /examples/15_camera_rotate/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/15_camera_rotate/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 10000, 'touch': 100} 16 | PositionSystem2D: 17 | system_id: 'position' 18 | gameworld: gameworld 19 | zones: ['general', 'touch'] 20 | RotateSystem2D: 21 | system_id: 'rotate' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | RotateRenderer: 25 | gameworld: gameworld 26 | zones: ['general'] 27 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionrotateshader.glsl') 28 | gameview: 'camera1' 29 | CymunkPhysics: 30 | gameworld: root.gameworld 31 | zones: ['general'] 32 | CymunkTouchSystem: 33 | gameworld: root.gameworld 34 | zones: ['touch'] 35 | zone_to_use: 'touch' 36 | physics_system: 'cymunk_physics' 37 | touch_radius: 30 38 | gameview: 'camera1' 39 | GameView: 40 | system_id: 'camera1' 41 | gameworld: gameworld 42 | size: root.size 43 | pos: root.pos 44 | do_scroll_lock: False 45 | window_size: root.size 46 | updateable: True 47 | GameScreenManager: 48 | id: gamescreenmanager 49 | size: root.size 50 | pos: root.pos 51 | gameworld: gameworld 52 | 53 | : 54 | MainScreen: 55 | id: main_screen 56 | 57 | : 58 | name: 'main' 59 | FloatLayout: 60 | Button: 61 | text: 'Draw Some Stuff' 62 | size_hint: (.2, .1) 63 | pos_hint: {'x': .025, 'y': .025} 64 | on_release: app.root.draw_some_stuff() 65 | DebugPanel: 66 | size_hint: (.2, .1) 67 | pos_hint: {'x': .225, 'y': .025} 68 | Label: 69 | text: str(app.count) 70 | size_hint: (.2, .1) 71 | font_size: 24 72 | pos_hint: {'x': .425, 'y': .025} 73 | 74 | : 75 | Label: 76 | pos: root.pos 77 | size: root.size 78 | font_size: root.size[1]*.5 79 | halign: 'center' 80 | valign: 'middle' 81 | color: (1,1,1,1) 82 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 83 | -------------------------------------------------------------------------------- /examples/16_svg_phys_objects/poscolorshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | 9 | /* vertex attributes */ 10 | attribute vec2 pos; 11 | attribute vec4 v_color; 12 | 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = v_color*color; 22 | vec4 pos = vec4(pos.xy, 0.0, 1.0); 23 | gl_Position = projection_mat * modelview_mat * pos; 24 | 25 | } 26 | 27 | 28 | ---FRAGMENT SHADER--- 29 | #ifdef GL_ES 30 | precision highp float; 31 | #endif 32 | 33 | /* Outputs from the vertex shader */ 34 | varying vec4 frag_color; 35 | 36 | void main (void){ 37 | gl_FragColor = frag_color; 38 | } 39 | -------------------------------------------------------------------------------- /examples/16_svg_phys_objects/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 20000, 'touch': 100} 16 | model_format_allocations: {'vertex_format_2f4ub': (150*1024, 150*1024),'vertex_format_4f': (150*1024, 150*1024) } 17 | PositionSystem2D: 18 | system_id: 'position' 19 | gameworld: gameworld 20 | zones: ['general', 'touch'] 21 | 22 | RotateSystem2D: 23 | system_id: 'rotate' 24 | gameworld: gameworld 25 | zones: ['general'] 26 | 27 | PolyRenderer: 28 | id: 'poly_renderer' 29 | system_id: 'poly_renderer' 30 | gameworld: gameworld 31 | zones: ['general'] 32 | frame_count: 2 33 | updateable: True 34 | shader_source: 'poscolorshader.glsl' 35 | 36 | CymunkPhysics: 37 | gameworld: root.gameworld 38 | zones: ['general'] 39 | 40 | CymunkTouchSystem: 41 | gameworld: root.gameworld 42 | zones: ['touch'] 43 | zone_to_use: 'touch' 44 | physics_system: 'cymunk_physics' 45 | touch_radius: 30 46 | 47 | GameScreenManager: 48 | id: gamescreenmanager 49 | size: root.size 50 | pos: root.pos 51 | gameworld: gameworld 52 | 53 | : 54 | MainScreen: 55 | id: main_screen 56 | 57 | : 58 | name: 'main' 59 | FloatLayout: 60 | Button: 61 | text: 'Draw Some Stuff' 62 | size_hint: (.2, .1) 63 | pos_hint: {'x': .025, 'y': .025} 64 | on_release: app.root.draw_some_stuff() 65 | DebugPanel: 66 | size_hint: (.2, .1) 67 | pos_hint: {'x': .225, 'y': .025} 68 | Label: 69 | text: str(app.count) 70 | size_hint: (.2, .1) 71 | font_size: 24 72 | pos_hint: {'x': .425, 'y': .025} 73 | 74 | : 75 | Label: 76 | pos: root.pos 77 | size: root.size 78 | font_size: root.size[1]*.5 79 | halign: 'center' 80 | valign: 'middle' 81 | color: (1,1,1,1) 82 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 83 | -------------------------------------------------------------------------------- /examples/17_joints/.vewpostactivate: -------------------------------------------------------------------------------- 1 | kh3 2 | -------------------------------------------------------------------------------- /examples/17_joints/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2017 Łukasz Mach, Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/17_joints/circlewoffset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/17_joints/circlewoffset.png -------------------------------------------------------------------------------- /examples/17_joints/greencircle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/17_joints/greencircle.png -------------------------------------------------------------------------------- /examples/17_joints/redcircle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/17_joints/redcircle.png -------------------------------------------------------------------------------- /examples/17_joints/roundrect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/17_joints/roundrect.png -------------------------------------------------------------------------------- /examples/17_joints/yourappname.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/17_joints/yourappname.ini -------------------------------------------------------------------------------- /examples/17_joints/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 20000, 'touch': 100} 16 | physics: physics 17 | PositionSystem2D: 18 | system_id: 'position' 19 | gameworld: gameworld 20 | zones: ['general', 'touch'] 21 | RotateSystem2D: 22 | system_id: 'rotate' 23 | gameworld: gameworld 24 | zones: ['general'] 25 | RotateRenderer: 26 | gameworld: gameworld 27 | zones: ['general'] 28 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionrotateshader.glsl') 29 | CymunkPhysics: 30 | id: physics 31 | gameworld: root.gameworld 32 | zones: ['general'] 33 | gravity: 0, -100.0 34 | CymunkTouchSystem: 35 | gameworld: root.gameworld 36 | zones: ['touch'] 37 | zone_to_use: 'touch' 38 | physics_system: 'cymunk_physics' 39 | touch_radius: 30 40 | GameScreenManager: 41 | id: gamescreenmanager 42 | size: root.size 43 | pos: root.pos 44 | gameworld: gameworld 45 | 46 | : 47 | MainScreen: 48 | id: main_screen 49 | 50 | : 51 | name: 'main' 52 | FloatLayout: 53 | Button: 54 | text: 'Draw Some Stuff' 55 | size_hint: (.2, .1) 56 | pos_hint: {'x': .025, 'y': .025} 57 | on_release: app.root.draw_some_stuff() 58 | DebugPanel: 59 | size_hint: (.2, .1) 60 | pos_hint: {'x': .225, 'y': .025} 61 | Label: 62 | text: str(app.count) 63 | size_hint: (.2, .1) 64 | font_size: 24 65 | pos_hint: {'x': .425, 'y': .025} 66 | 67 | : 68 | Label: 69 | pos: root.pos 70 | size: root.size 71 | font_size: root.size[1]*.5 72 | halign: 'center' 73 | valign: 'middle' 74 | color: (1,1,1,1) 75 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 76 | -------------------------------------------------------------------------------- /examples/1_empty_kivent_app/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/1_empty_kivent_app/main.py: -------------------------------------------------------------------------------- 1 | import kivy 2 | from kivy.app import App 3 | from kivy.uix.widget import Widget 4 | import kivent_core 5 | 6 | class TestGame(Widget): 7 | def on_kv_post(self, *args): 8 | self.gameworld.init_gameworld([], callback=self.init_game) 9 | 10 | def init_game(self): 11 | self.setup_states() 12 | self.set_state() 13 | 14 | def setup_states(self): 15 | self.gameworld.add_state(state_name='main', 16 | systems_added=[], 17 | systems_removed=[], systems_paused=[], 18 | systems_unpaused=[], 19 | screenmanager_screen='main') 20 | 21 | def set_state(self): 22 | self.gameworld.state = 'main' 23 | 24 | class YourAppNameApp(App): 25 | def build(self): 26 | pass 27 | 28 | if __name__ == '__main__': 29 | YourAppNameApp().run() 30 | -------------------------------------------------------------------------------- /examples/1_empty_kivent_app/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | 3 | TestGame: 4 | 5 | : 6 | gameworld: gameworld 7 | GameWorld: 8 | id: gameworld 9 | gamescreenmanager: gamescreenmanager 10 | size_of_gameworld: 100*1024 11 | size_of_entity_block: 128 12 | system_count: 2 13 | zones: {'general': 10000} 14 | GameScreenManager: 15 | id: gamescreenmanager 16 | size: root.size 17 | pos: root.pos 18 | gameworld: gameworld 19 | GameScreen: 20 | name: 'main' 21 | -------------------------------------------------------------------------------- /examples/2_basic_app/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/2_basic_app/main.py: -------------------------------------------------------------------------------- 1 | import kivy 2 | 3 | from kivy.app import App 4 | from kivy.uix.widget import Widget 5 | from kivy.clock import Clock 6 | from kivy.core.window import Window 7 | from random import randint, choice 8 | import kivent_core 9 | from kivent_core.gameworld import GameWorld 10 | from kivent_core.systems.position_systems import PositionSystem2D 11 | from kivent_core.systems.renderers import Renderer 12 | from kivent_core.managers.resource_managers import texture_manager 13 | from kivy.properties import StringProperty 14 | from os.path import dirname, join, abspath 15 | 16 | texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets', 17 | 'background_objects.atlas')) 18 | 19 | 20 | class TestGame(Widget): 21 | def on_kv_post(self, *args): 22 | self.gameworld.init_gameworld( 23 | ['renderer', 'position'], 24 | callback=self.init_game) 25 | 26 | def init_game(self): 27 | self.setup_states() 28 | self.set_state() 29 | self.load_models() 30 | self.draw_some_stuff() 31 | 32 | def load_models(self): 33 | model_manager = self.gameworld.model_manager 34 | model_manager.load_textured_rectangle('vertex_format_4f', 7., 7., 35 | 'star1', 'star1-4') 36 | model_manager.load_textured_rectangle('vertex_format_4f', 10., 10., 37 | 'star1', 'star1-4-2') 38 | 39 | def draw_some_stuff(self): 40 | init_entity = self.gameworld.init_entity 41 | for x in range(2000): 42 | pos = randint(0, Window.width), randint(0, Window.height) 43 | model_key = choice(['star1-4', 'star1-4-2']) 44 | create_dict = { 45 | 'position': pos, 46 | 'renderer': {'texture': 'star1', 47 | 'model_key': model_key}, 48 | } 49 | ent = init_entity(create_dict, ['position', 'renderer']) 50 | #If you do not set Renderer.force_update to True, call update_trigger 51 | #self.ids.renderer.update_trigger() 52 | 53 | def setup_states(self): 54 | self.gameworld.add_state(state_name='main', 55 | systems_added=['renderer'], 56 | systems_removed=[], systems_paused=[], 57 | systems_unpaused=['renderer'], 58 | screenmanager_screen='main') 59 | 60 | def set_state(self): 61 | self.gameworld.state = 'main' 62 | 63 | class DebugPanel(Widget): 64 | fps = StringProperty(None) 65 | 66 | def __init__(self, **kwargs): 67 | super(DebugPanel, self).__init__(**kwargs) 68 | Clock.schedule_once(self.update_fps) 69 | 70 | def update_fps(self,dt): 71 | self.fps = str(int(Clock.get_fps())) 72 | Clock.schedule_once(self.update_fps, .05) 73 | 74 | class YourAppNameApp(App): 75 | def build(self): 76 | Window.clearcolor = (0, 0, 0, 1.) 77 | 78 | if __name__ == '__main__': 79 | YourAppNameApp().run() 80 | -------------------------------------------------------------------------------- /examples/2_basic_app/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | GameWorld: 11 | id: gameworld 12 | gamescreenmanager: gamescreenmanager 13 | size_of_gameworld: 100*1024 14 | size_of_entity_block: 128 15 | system_count: 2 16 | zones: {'general': 10000} 17 | PositionSystem2D: 18 | system_id: 'position' 19 | gameworld: gameworld 20 | zones: ['general'] 21 | size_of_component_block: 128 22 | Renderer: 23 | gameworld: gameworld 24 | system_id: 'renderer' 25 | zones: ['general'] 26 | frame_count: 1 27 | updateable: False 28 | force_update: True 29 | size_of_batches: 512 30 | size_of_component_block: 128 31 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionshader.glsl') 32 | GameScreenManager: 33 | id: gamescreenmanager 34 | size: root.size 35 | pos: root.pos 36 | gameworld: gameworld 37 | 38 | : 39 | MainScreen: 40 | id: main_screen 41 | 42 | : 43 | name: 'main' 44 | FloatLayout: 45 | DebugPanel: 46 | size_hint: (.2, .1) 47 | pos_hint: {'x': .225, 'y': .025} 48 | 49 | : 50 | Label: 51 | pos: root.pos 52 | size: root.size 53 | font_size: root.size[1]*.5 54 | halign: 'center' 55 | valign: 'middle' 56 | color: (1,1,1,1) 57 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 58 | 59 | -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/README.md: -------------------------------------------------------------------------------- 1 | # Creating a GameSystem 2 | 3 | This example shows how to create a KivEnt gamesystem. 4 | 5 | To run the main_with_cython.py example, first cythonize the velocity module: 6 | 7 | ``` 8 | $ cythonize -a -i ./velocity_module/velocity.pyx 9 | ``` 10 | 11 | This will create shared object files alongside the cython source, which python 12 | can import directly. Then run the example as usual: 13 | 14 | ``` 15 | $ python ./main_with_cython.py 16 | ``` 17 | 18 | -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/cythonvel.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | test: 'test' 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | size_of_entity_block: 128 16 | system_count: 4 17 | zones: {'general': 10000} 18 | PositionSystem2D: 19 | system_id: 'position' 20 | gameworld: gameworld 21 | zones: ['general'] 22 | size_of_component_block: 128 23 | VelocitySystem2D: 24 | system_id: 'velocity' 25 | gameworld: gameworld 26 | zones: ['general'] 27 | updateable: True 28 | Renderer: 29 | gameworld: gameworld 30 | system_id: 'renderer' 31 | zones: ['general'] 32 | frame_count: 2 33 | updateable: True 34 | size_of_batches: 1024 35 | size_of_component_block: 128 36 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionshader.glsl') 37 | GameScreenManager: 38 | id: gamescreenmanager 39 | size: root.size 40 | pos: root.pos 41 | gameworld: gameworld 42 | 43 | : 44 | MainScreen: 45 | id: main_screen 46 | 47 | : 48 | name: 'main' 49 | FloatLayout: 50 | DebugPanel: 51 | size_hint: (.2, .1) 52 | pos_hint: {'x': .225, 'y': .025} 53 | 54 | 55 | : 56 | Label: 57 | pos: root.pos 58 | size: root.size 59 | font_size: root.size[1]*.5 60 | halign: 'center' 61 | valign: 'middle' 62 | color: (1,1,1,1) 63 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 64 | 65 | -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/main_with_cython.py: -------------------------------------------------------------------------------- 1 | from kivy.app import App 2 | from kivy.uix.widget import Widget 3 | from kivy.clock import Clock 4 | from kivy.core.window import Window 5 | from random import randint, choice 6 | import kivent_core 7 | from kivent_core.gameworld import GameWorld 8 | from kivent_core.systems.position_systems import PositionSystem2D 9 | from kivent_core.systems.renderers import Renderer 10 | from kivent_core.systems.gamesystem import GameSystem 11 | from kivent_core.managers.resource_managers import texture_manager 12 | from kivy.properties import StringProperty 13 | from kivy.factory import Factory 14 | from velocity_module.velocity import VelocitySystem2D 15 | from os.path import dirname, join, abspath 16 | 17 | texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets', 18 | 'background_objects.atlas')) 19 | 20 | class TestGame(Widget): 21 | def on_kv_post(self, *args): 22 | self.gameworld.init_gameworld( 23 | ['renderer', 'position', 'velocity'], 24 | callback=self.init_game) 25 | 26 | def init_game(self): 27 | self.setup_states() 28 | self.load_models() 29 | self.set_state() 30 | self.draw_some_stuff() 31 | 32 | def load_models(self): 33 | model_manager = self.gameworld.model_manager 34 | model_manager.load_textured_rectangle('vertex_format_4f', 7., 7., 35 | 'star1', 'star1-4') 36 | model_manager.load_textured_rectangle('vertex_format_4f', 10., 10., 37 | 'star1', 'star1-4-2') 38 | 39 | def draw_some_stuff(self): 40 | init_entity = self.gameworld.init_entity 41 | for x in range(10000): 42 | pos = randint(0, Window.width), randint(0, Window.height) 43 | model_key = choice(['star1-4', 'star1-4-2']) 44 | create_dict = { 45 | 'position': pos, 46 | 'velocity': (randint(-75, 75), randint(-75, 75)), 47 | 'renderer': {'texture': 'star1', 48 | 'model_key': model_key}, 49 | } 50 | ent = init_entity(create_dict, ['position', 'velocity', 51 | 'renderer']) 52 | 53 | 54 | def setup_states(self): 55 | self.gameworld.add_state(state_name='main', 56 | systems_added=['renderer'], 57 | systems_removed=[], systems_paused=[], 58 | systems_unpaused=['renderer', 'velocity'], 59 | screenmanager_screen='main') 60 | 61 | def set_state(self): 62 | self.gameworld.state = 'main' 63 | 64 | 65 | class DebugPanel(Widget): 66 | fps = StringProperty(None) 67 | 68 | def __init__(self, **kwargs): 69 | super(DebugPanel, self).__init__(**kwargs) 70 | Clock.schedule_once(self.update_fps) 71 | 72 | def update_fps(self,dt): 73 | self.fps = str(int(Clock.get_fps())) 74 | Clock.schedule_once(self.update_fps, .05) 75 | 76 | 77 | class CythonVelApp(App): 78 | def build(self): 79 | Window.clearcolor = (0, 0, 0, 1.) 80 | 81 | 82 | if __name__ == '__main__': 83 | CythonVelApp().run() 84 | -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/setup.py: -------------------------------------------------------------------------------- 1 | from os import environ, remove 2 | from os.path import dirname, join, isfile 3 | from distutils.core import setup 4 | from distutils.extension import Extension 5 | try: 6 | from Cython.Build import cythonize 7 | from Cython.Distutils import build_ext 8 | have_cython = True 9 | except ImportError: 10 | have_cython = False 11 | import sys 12 | 13 | platform = sys.platform 14 | if platform == 'win32': 15 | cstdarg = '-std=gnu99' 16 | else: 17 | cstdarg = '-std=c99' 18 | 19 | do_clear_existing = True 20 | 21 | 22 | 23 | velocity_modules = { 24 | 'velocity_module.velocity': ['velocity_module/velocity.pyx',], 25 | } 26 | 27 | velocity_modules_c = { 28 | 'velocity_module.velocity': ['velocity_module/velocity.c',], 29 | } 30 | 31 | check_for_removal = ['velocity_module/velocity.c',] 32 | 33 | def build_ext(ext_name, files, include_dirs=[]): 34 | return Extension(ext_name, files, include_dirs, 35 | extra_compile_args=[cstdarg, '-ffast-math',]) 36 | 37 | extensions = [] 38 | velocity_extensions = [] 39 | cmdclass = {} 40 | 41 | def build_extensions_for_modules_cython(ext_list, modules): 42 | ext_a = ext_list.append 43 | for module_name in modules: 44 | ext = build_ext(module_name, modules[module_name]) 45 | if environ.get('READTHEDOCS', None) == 'True': 46 | ext.pyrex_directives = {'embedsignature': True} 47 | ext_a(ext) 48 | return cythonize(ext_list) 49 | 50 | def build_extensions_for_modules(ext_list, modules): 51 | ext_a = ext_list.append 52 | for module_name in modules: 53 | ext = build_ext(module_name, modules[module_name]) 54 | if environ.get('READTHEDOCS', None) == 'True': 55 | ext.pyrex_directives = {'embedsignature': True} 56 | ext_a(ext) 57 | return ext_list 58 | 59 | if have_cython: 60 | if do_clear_existing: 61 | for file_name in check_for_removal: 62 | if isfile(file_name): 63 | remove(file_name) 64 | velocity_extensions = build_extensions_for_modules_cython( 65 | velocity_extensions, velocity_modules) 66 | else: 67 | velocity_extensions = build_extensions_for_modules(velocity_extensions, 68 | velocity_modules_c) 69 | 70 | 71 | setup( 72 | name='KivEnt Velocity Module', 73 | description='''A game engine for the Kivy Framework. 74 | https://github.com/Kovak/KivEnt for more info.''', 75 | author='Jacob Kovac', 76 | author_email='kovac1066@gmail.com', 77 | ext_modules=velocity_extensions, 78 | cmdclass=cmdclass, 79 | packages=[ 80 | 'velocity_module', 81 | ], 82 | package_dir={'velocity_module': 'velocity_module'}) -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/velocity_module/__init__.py: -------------------------------------------------------------------------------- 1 | from velocity_module import velocity -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/velocity_module/velocity.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | 4 | 5 | ctypedef struct VelocityStruct2D: 6 | unsigned int entity_id 7 | float vx 8 | float vy 9 | 10 | 11 | cdef class VelocityComponent2D(MemComponent): 12 | pass 13 | 14 | 15 | cdef class VelocitySystem2D(StaticMemGameSystem): 16 | pass -------------------------------------------------------------------------------- /examples/3_creating_a_gamesystem/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | GameWorld: 11 | id: gameworld 12 | gamescreenmanager: gamescreenmanager 13 | size_of_gameworld: 100*1024 14 | size_of_entity_block: 128 15 | system_count: 4 16 | zones: {'general': 10000} 17 | PositionSystem2D: 18 | system_id: 'position' 19 | gameworld: gameworld 20 | zones: ['general'] 21 | size_of_component_block: 128 22 | VelocitySystem2D: 23 | system_id: 'velocity' 24 | gameworld: gameworld 25 | updateable: True 26 | Renderer: 27 | gameworld: gameworld 28 | system_id: 'renderer' 29 | zones: ['general'] 30 | frame_count: 2 31 | updateable: True 32 | size_of_batches: 512 33 | size_of_component_block: 128 34 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionshader.glsl') 35 | GameScreenManager: 36 | id: gamescreenmanager 37 | size: root.size 38 | pos: root.pos 39 | gameworld: gameworld 40 | 41 | : 42 | MainScreen: 43 | id: main_screen 44 | 45 | : 46 | name: 'main' 47 | FloatLayout: 48 | DebugPanel: 49 | size_hint: (.2, .1) 50 | pos_hint: {'x': .225, 'y': .025} 51 | 52 | : 53 | Label: 54 | pos: root.pos 55 | size: root.size 56 | font_size: root.size[1]*.5 57 | halign: 'center' 58 | valign: 'middle' 59 | color: (1,1,1,1) 60 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 61 | 62 | -------------------------------------------------------------------------------- /examples/4_adding_physics_objects/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/4_adding_physics_objects/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 20000} 16 | PositionSystem2D: 17 | system_id: 'position' 18 | gameworld: gameworld 19 | zones: ['general'] 20 | RotateSystem2D: 21 | system_id: 'rotate' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | RotateRenderer: 25 | gameworld: gameworld 26 | zones: ['general'] 27 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionrotateshader.glsl') 28 | CymunkPhysics: 29 | gameworld: root.gameworld 30 | zones: ['general'] 31 | GameScreenManager: 32 | id: gamescreenmanager 33 | size: root.size 34 | pos: root.pos 35 | gameworld: gameworld 36 | 37 | : 38 | MainScreen: 39 | id: main_screen 40 | 41 | : 42 | name: 'main' 43 | FloatLayout: 44 | Button: 45 | text: 'Draw Some Stuff' 46 | size_hint: (.2, .1) 47 | pos_hint: {'x': .025, 'y': .025} 48 | on_release: app.root.draw_some_stuff() 49 | DebugPanel: 50 | size_hint: (.2, .1) 51 | pos_hint: {'x': .225, 'y': .025} 52 | Label: 53 | text: str(app.count) 54 | size_hint: (.2, .1) 55 | font_size: 24 56 | pos_hint: {'x': .425, 'y': .025} 57 | 58 | : 59 | Label: 60 | pos: root.pos 61 | size: root.size 62 | font_size: root.size[1]*.5 63 | halign: 'center' 64 | valign: 'middle' 65 | color: (1,1,1,1) 66 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' -------------------------------------------------------------------------------- /examples/5_interacting_with_physics/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/5_interacting_with_physics/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 20000, 'touch': 100} 16 | PositionSystem2D: 17 | system_id: 'position' 18 | gameworld: gameworld 19 | zones: ['general', 'touch'] 20 | RotateSystem2D: 21 | system_id: 'rotate' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | RotateRenderer: 25 | gameworld: gameworld 26 | zones: ['general'] 27 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionrotateshader.glsl') 28 | CymunkPhysics: 29 | gameworld: root.gameworld 30 | zones: ['general'] 31 | CymunkTouchSystem: 32 | gameworld: root.gameworld 33 | zones: ['touch'] 34 | zone_to_use: 'touch' 35 | physics_system: 'cymunk_physics' 36 | touch_radius: 30 37 | GameScreenManager: 38 | id: gamescreenmanager 39 | size: root.size 40 | pos: root.pos 41 | gameworld: gameworld 42 | 43 | : 44 | MainScreen: 45 | id: main_screen 46 | 47 | : 48 | name: 'main' 49 | FloatLayout: 50 | Button: 51 | text: 'Draw Some Stuff' 52 | size_hint: (.2, .1) 53 | pos_hint: {'x': .025, 'y': .025} 54 | on_release: app.root.draw_some_stuff() 55 | DebugPanel: 56 | size_hint: (.2, .1) 57 | pos_hint: {'x': .225, 'y': .025} 58 | Label: 59 | text: str(app.count) 60 | size_hint: (.2, .1) 61 | font_size: 24 62 | pos_hint: {'x': .425, 'y': .025} 63 | 64 | : 65 | Label: 66 | pos: root.pos 67 | size: root.size 68 | font_size: root.size[1]*.5 69 | halign: 'center' 70 | valign: 'middle' 71 | color: (1,1,1,1) 72 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' -------------------------------------------------------------------------------- /examples/6_controlling_the_viewing_area/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/6_controlling_the_viewing_area/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | app: app 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | zones: {'general': 10000, 'touch': 100} 16 | PositionSystem2D: 17 | system_id: 'position' 18 | gameworld: gameworld 19 | zones: ['general', 'touch'] 20 | RotateSystem2D: 21 | system_id: 'rotate' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | RotateRenderer: 25 | gameworld: gameworld 26 | zones: ['general'] 27 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionrotateshader.glsl') 28 | gameview: 'camera1' 29 | CymunkPhysics: 30 | gameworld: root.gameworld 31 | zones: ['general'] 32 | CymunkTouchSystem: 33 | gameworld: root.gameworld 34 | zones: ['touch'] 35 | zone_to_use: 'touch' 36 | physics_system: 'cymunk_physics' 37 | touch_radius: 30 38 | gameview: 'camera1' 39 | GameView: 40 | system_id: 'camera1' 41 | gameworld: gameworld 42 | size: root.size 43 | window_size: root.size 44 | pos: root.pos 45 | do_scroll_lock: False 46 | updateable: True 47 | GameScreenManager: 48 | id: gamescreenmanager 49 | size: root.size 50 | pos: root.pos 51 | gameworld: gameworld 52 | 53 | : 54 | MainScreen: 55 | id: main_screen 56 | 57 | : 58 | name: 'main' 59 | FloatLayout: 60 | Button: 61 | text: 'Draw Some Stuff' 62 | size_hint: (.2, .1) 63 | pos_hint: {'x': .025, 'y': .025} 64 | on_release: app.root.draw_some_stuff() 65 | DebugPanel: 66 | size_hint: (.2, .1) 67 | pos_hint: {'x': .225, 'y': .025} 68 | Label: 69 | text: str(app.count) 70 | size_hint: (.2, .1) 71 | font_size: 24 72 | pos_hint: {'x': .425, 'y': .025} 73 | 74 | : 75 | Label: 76 | pos: root.pos 77 | size: root.size 78 | font_size: root.size[1]*.5 79 | halign: 'center' 80 | valign: 'middle' 81 | color: (1,1,1,1) 82 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 83 | -------------------------------------------------------------------------------- /examples/7_star_fade/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/7_star_fade/assets/glsl/positioncolor.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec4 vColor; 14 | 15 | /* uniform variables */ 16 | uniform mat4 modelview_mat; 17 | uniform mat4 projection_mat; 18 | uniform vec4 color; 19 | uniform float opacity; 20 | 21 | void main (void) { 22 | frag_color = vColor * color * vec4(1.0, 1., 1.0, opacity); 23 | tex_coord0 = uvs; 24 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 25 | gl_Position = projection_mat * modelview_mat * new_pos; 26 | 27 | } 28 | 29 | 30 | ---FRAGMENT SHADER--- 31 | #ifdef GL_ES 32 | precision highp float; 33 | #endif 34 | 35 | /* Outputs from the vertex shader */ 36 | varying vec4 frag_color; 37 | varying vec2 tex_coord0; 38 | 39 | /* uniform texture samplers */ 40 | uniform sampler2D texture0; 41 | 42 | void main (void){ 43 | 44 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 45 | } 46 | -------------------------------------------------------------------------------- /examples/7_star_fade/assets/star1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/star1.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/star2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/star2.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/star3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/star3.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/star_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/star_circle.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/star_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/star_square.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/stars-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/7_star_fade/assets/stars-0.png -------------------------------------------------------------------------------- /examples/7_star_fade/assets/stars.atlas: -------------------------------------------------------------------------------- 1 | {"stars-0.png": {"star_circle": [2, 60, 32, 32], "star_square": [36, 60, 32, 32], "star1": [2, 94, 32, 32], "star3": [70, 94, 32, 32], "star2": [36, 94, 32, 32]}} -------------------------------------------------------------------------------- /examples/7_star_fade/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | GameWorld: 11 | id: gameworld 12 | gamescreenmanager: gamescreenmanager 13 | size_of_gameworld: 100*1024 14 | size_of_entity_block: 128 15 | system_count: 4 16 | size: root.size 17 | pos: root.pos 18 | zones: {'general': 10000} 19 | PositionSystem2D: 20 | system_id: 'position' 21 | gameworld: gameworld 22 | zones: ['general'] 23 | size_of_component_block: 128 24 | ColorSystem: 25 | system_id: 'color' 26 | gameworld: gameworld 27 | zones: ['general'] 28 | ColorRenderer: 29 | gameworld: gameworld 30 | system_id: 'renderer' 31 | zones: ['general'] 32 | frame_count: 3 33 | updateable: True 34 | system_names: ['renderer', 'position','color'] 35 | size_of_batches: 256 36 | size_of_component_block: 128 37 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positioncolor.glsl') 38 | FadingSystem: 39 | gameworld: gameworld 40 | system_id: 'fade' 41 | updateable: True 42 | make_entity: root.draw_a_star 43 | update_time: 1./24. 44 | GameScreenManager: 45 | id: gamescreenmanager 46 | size: root.size 47 | pos: root.pos 48 | gameworld: gameworld 49 | 50 | 51 | : 52 | MainScreen: 53 | id: main_screen 54 | 55 | 56 | : 57 | name: 'main' 58 | FloatLayout: 59 | DebugPanel: 60 | size_hint: (.2, .1) 61 | pos_hint: {'x': .225, 'y': .025} 62 | 63 | 64 | : 65 | Label: 66 | pos: root.pos 67 | size: root.size 68 | font_size: root.size[1]*.5 69 | halign: 'center' 70 | valign: 'middle' 71 | color: (1,1,1,1) 72 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 73 | -------------------------------------------------------------------------------- /examples/8_simple_animation/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/8_simple_animation/main.py: -------------------------------------------------------------------------------- 1 | from kivy.app import App 2 | from kivy.uix.widget import Widget 3 | from kivy.clock import Clock 4 | from kivy.core.window import Window 5 | from random import randint, choice, randrange 6 | import kivent_core 7 | from kivent_core.gameworld import GameWorld 8 | from kivent_core.systems.position_systems import PositionSystem2D 9 | from kivent_core.systems.renderers import Renderer 10 | from kivent_core.systems.gamesystem import GameSystem 11 | from kivent_core.managers.resource_managers import texture_manager 12 | from kivy.properties import StringProperty, ObjectProperty 13 | from kivy.factory import Factory 14 | from os.path import dirname, join, abspath 15 | 16 | texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets', 17 | 'star1.png')) 18 | texture_manager.load_image(join(dirname(dirname(abspath(__file__))), 'assets', 19 | 'star2.png')) 20 | 21 | 22 | class MyAnimationSystem(GameSystem): 23 | 24 | def update(self, dt): 25 | entities = self.gameworld.entities 26 | for component in self.components: 27 | if component is not None: 28 | entity_id = component.entity_id 29 | entity = entities[entity_id] 30 | render_comp = entity.renderer 31 | if render_comp.texture_key == 'star1': 32 | render_comp.texture_key = 'star2' 33 | else: 34 | render_comp.texture_key = 'star1' 35 | 36 | Factory.register('MyAnimationSystem', cls=MyAnimationSystem) 37 | 38 | class TestGame(Widget): 39 | def on_kv_post(self, *args): 40 | self.gameworld.init_gameworld( 41 | ['color', 'position', 'renderer'], 42 | callback=self.init_game) 43 | self.entities = [] 44 | 45 | def init_game(self): 46 | self.setup_states() 47 | self.set_state() 48 | self.draw_some_stuff() 49 | 50 | def draw_some_stuff(self): 51 | init_entity = self.gameworld.init_entity 52 | for x in range(100): 53 | self.draw_a_star() 54 | 55 | def draw_a_star(self): 56 | pos = randint(0, Window.width), randint(0, Window.height) 57 | create_dict = { 58 | 'position': pos, 59 | 'animation': {}, 60 | 'renderer': {'texture': 'star1', 'size': (50., 50.)}, 61 | } 62 | ent = self.gameworld.init_entity(create_dict, ['position', 'renderer', 63 | 'animation']) 64 | self.entities.append(ent) 65 | 66 | 67 | def setup_states(self): 68 | self.gameworld.add_state(state_name='main', 69 | systems_added=['renderer'], 70 | systems_removed=[], systems_paused=[], 71 | systems_unpaused=['renderer'], 72 | screenmanager_screen='main') 73 | 74 | def set_state(self): 75 | self.gameworld.state = 'main' 76 | 77 | class DebugPanel(Widget): 78 | fps = StringProperty(None) 79 | 80 | def __init__(self, **kwargs): 81 | super(DebugPanel, self).__init__(**kwargs) 82 | Clock.schedule_once(self.update_fps) 83 | 84 | def update_fps(self,dt): 85 | self.fps = str(int(Clock.get_fps())) 86 | Clock.schedule_once(self.update_fps, .05) 87 | 88 | 89 | class YourAppNameApp(App): 90 | def build(self): 91 | Window.clearcolor = (0, 0, 0, 1.) 92 | 93 | 94 | if __name__ == '__main__': 95 | YourAppNameApp().run() 96 | -------------------------------------------------------------------------------- /examples/8_simple_animation/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | 9 | : 10 | gameworld: gameworld 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | size_of_entity_block: 128 16 | system_count: 4 17 | size: root.size 18 | pos: root.pos 19 | zones: {'general': 10000,} 20 | PositionSystem2D: 21 | system_id: 'position' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | size_of_component_block: 128 25 | ColorSystem: 26 | system_id: 'color' 27 | gameworld: gameworld 28 | zones: ['general'] 29 | MyAnimationSystem: 30 | system_id: 'animation' 31 | gameworld: gameworld 32 | update_time: 1.0 33 | updateable: True 34 | Renderer: 35 | gameworld: gameworld 36 | system_id: 'renderer' 37 | zones: ['general'] 38 | frame_count: 3 39 | updateable: True 40 | system_names: ['renderer', 'position'] 41 | size_of_batches: 256 42 | size_of_component_block: 128 43 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionshader.glsl') 44 | GameScreenManager: 45 | id: gamescreenmanager 46 | size: root.size 47 | pos: root.pos 48 | gameworld: gameworld 49 | 50 | 51 | : 52 | MainScreen: 53 | id: main_screen 54 | 55 | 56 | : 57 | name: 'main' 58 | FloatLayout: 59 | DebugPanel: 60 | size_hint: (.2, .1) 61 | pos_hint: {'x': .225, 'y': .025} 62 | 63 | 64 | : 65 | Label: 66 | pos: root.pos 67 | size: root.size 68 | font_size: root.size[1]*.5 69 | halign: 'center' 70 | valign: 'middle' 71 | color: (1,1,1,1) 72 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 73 | -------------------------------------------------------------------------------- /examples/9_twinkling_stars/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/9_twinkling_stars/yourappname.kv: -------------------------------------------------------------------------------- 1 | #:kivy 1.11.0 2 | #:import path os.path 3 | #:import dirname os.path.dirname 4 | #:import main __main__ 5 | 6 | TestGame: 7 | 8 | : 9 | gameworld: gameworld 10 | test: 'test' 11 | GameWorld: 12 | id: gameworld 13 | gamescreenmanager: gamescreenmanager 14 | size_of_gameworld: 100*1024 15 | size_of_entity_block: 128 16 | system_count: 3 17 | camera_size: root.size 18 | pos: root.pos 19 | zones: {'general': 10000} 20 | PositionSystem2D: 21 | system_id: 'position' 22 | gameworld: gameworld 23 | zones: ['general'] 24 | size_of_component_block: 128 25 | Renderer: 26 | id: renderer 27 | gameworld: gameworld 28 | system_id: 'renderer' 29 | zones: ['general'] 30 | frame_count: 2 31 | updateable: True 32 | force_update: True 33 | size_of_batches: 128 34 | size_of_component_block: 128 35 | shader_source: path.join(dirname(dirname(path.abspath(main.__file__))), 'assets', 'glsl', 'positionshader.glsl') 36 | gameview: 'camera1' 37 | AnimationSystem: 38 | id: animation 39 | gameworld: gameworld 40 | system_id: 'animation' 41 | zones: ['general'] 42 | GameView: 43 | system_id: 'camera1' 44 | gameworld: gameworld 45 | size: root.size 46 | pos: root.pos 47 | camera_pos: (0, 0) 48 | do_scroll_lock: False 49 | updateable: True 50 | GameScreenManager: 51 | id: gamescreenmanager 52 | size: root.size 53 | pos: root.pos 54 | gameworld: gameworld 55 | 56 | : 57 | MainScreen: 58 | id: main_screen 59 | 60 | : 61 | name: 'main' 62 | FloatLayout: 63 | DebugPanel: 64 | size_hint: (.2, .1) 65 | pos_hint: {'x': .225, 'y': .025} 66 | 67 | 68 | : 69 | Label: 70 | pos: root.pos 71 | size: root.size 72 | font_size: root.size[1]*.5 73 | halign: 'center' 74 | valign: 'middle' 75 | color: (1,1,1,1) 76 | text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' 77 | -------------------------------------------------------------------------------- /examples/assets/animations.json: -------------------------------------------------------------------------------- 1 | { 2 | "star-animation-50" : [ 3 | {"texture": "star1", 4 | "model" : "star1-4", 5 | "duration" : 300 }, 6 | {"texture": "star2", 7 | "model" : "star2-4", 8 | "duration" : 300 }, 9 | {"texture": "star3", 10 | "model" : "star3-4", 11 | "duration" : 300 }], 12 | "star-animation-51" : [ 13 | {"texture": "star1", 14 | "model" : "star1-4", 15 | "duration" : 400 }, 16 | {"texture": "star2", 17 | "model" : "star2-4", 18 | "duration" : 400 }, 19 | {"texture": "star3", 20 | "model" : "star3-4", 21 | "duration" : 400 }] 22 | } 23 | -------------------------------------------------------------------------------- /examples/assets/background_objects-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/background_objects-0.png -------------------------------------------------------------------------------- /examples/assets/background_objects.atlas: -------------------------------------------------------------------------------- 1 | {"background_objects-0.png": {"asteroid1": [94, 190, 64, 64], "asteroid2": [2, 164, 90, 90], "star5": [160, 196, 28, 28], "star4": [220, 226, 28, 28], "star7": [226, 208, 16, 16], "star6": [208, 208, 16, 16], "star1": [160, 226, 28, 28], "star3": [190, 226, 28, 28], "star2": [190, 208, 16, 16], "star8": [94, 172, 16, 16]}} -------------------------------------------------------------------------------- /examples/assets/blue-tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/blue-tile.png -------------------------------------------------------------------------------- /examples/assets/glsl/polyposcolorrotateshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | 9 | /* vertex attributes */ 10 | attribute vec2 pos; 11 | attribute float rot; 12 | attribute vec2 center; 13 | attribute vec4 v_color; 14 | 15 | 16 | /* uniform variables */ 17 | uniform mat4 modelview_mat; 18 | uniform mat4 projection_mat; 19 | uniform vec4 color; 20 | uniform float opacity; 21 | 22 | void main (void) { 23 | frag_color = v_color * color * vec4(1.0, 1.0, 1.0, opacity); 24 | float a_sin = sin(rot); 25 | float a_cos = cos(rot); 26 | mat4 rot_mat = mat4(a_cos, -a_sin, 0.0, 0.0, 27 | a_sin, a_cos, 0.0, 0.0, 28 | 0.0, 0.0, 1.0, 0.0, 29 | 0.0, 0.0, 0.0, 1.0 ); 30 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 31 | 0.0, 1.0, 0.0, center.y, 32 | 0.0, 0.0, 1.0, 0.0, 33 | 0.0, 0.0, 0.0, 1.0); 34 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 35 | vec4 trans_pos = new_pos * rot_mat * trans_mat; 36 | gl_Position = projection_mat * modelview_mat * trans_pos; 37 | } 38 | 39 | 40 | ---FRAGMENT SHADER--- 41 | #ifdef GL_ES 42 | precision highp float; 43 | #endif 44 | 45 | /* Outputs from the vertex shader */ 46 | varying vec4 frag_color; 47 | 48 | void main (void){ 49 | gl_FragColor = frag_color; 50 | } -------------------------------------------------------------------------------- /examples/assets/glsl/positioncolor.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec4 v_color; 14 | 15 | /* uniform variables */ 16 | uniform mat4 modelview_mat; 17 | uniform mat4 projection_mat; 18 | uniform vec4 color; 19 | uniform float opacity; 20 | 21 | void main (void) { 22 | frag_color = v_color * color * vec4(1.0, 1., 1.0, opacity); 23 | tex_coord0 = uvs; 24 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 25 | gl_Position = projection_mat * modelview_mat * new_pos; 26 | 27 | } 28 | 29 | 30 | ---FRAGMENT SHADER--- 31 | #ifdef GL_ES 32 | precision highp float; 33 | #endif 34 | 35 | /* Outputs from the vertex shader */ 36 | varying vec4 frag_color; 37 | varying vec2 tex_coord0; 38 | 39 | /* uniform texture samplers */ 40 | uniform sampler2D texture0; 41 | 42 | void main (void){ 43 | 44 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 45 | } 46 | -------------------------------------------------------------------------------- /examples/assets/glsl/positioncolorrotatescaleshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec2 center; 14 | attribute float rot; 15 | attribute vec4 v_color; 16 | attribute float scale; 17 | 18 | /* uniform variables */ 19 | uniform mat4 modelview_mat; 20 | uniform mat4 projection_mat; 21 | uniform vec4 color; 22 | uniform float opacity; 23 | 24 | void main (void) { 25 | frag_color = v_color * color * vec4(1.0, 1.0, 1.0, opacity); 26 | tex_coord0 = uvs; 27 | float a_sin = sin(rot); 28 | float a_cos = cos(rot); 29 | mat4 rot_mat = mat4(a_cos, -a_sin, 0.0, 0.0, 30 | a_sin, a_cos, 0.0, 0.0, 31 | 0.0, 0.0, 1.0, 0.0, 32 | 0.0, 0.0, 0.0, 1.0 ); 33 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 34 | 0.0, 1.0, 0.0, center.y, 35 | 0.0, 0.0, 1.0, 0.0, 36 | 0.0, 0.0, 0.0, 1.0); 37 | vec4 new_pos = vec4(pos.xy*scale, 0.0, 1.0); 38 | vec4 trans_pos = new_pos * rot_mat * trans_mat; 39 | gl_Position = projection_mat * modelview_mat * trans_pos; 40 | 41 | } 42 | 43 | 44 | ---FRAGMENT SHADER--- 45 | #ifdef GL_ES 46 | precision highp float; 47 | #endif 48 | 49 | /* Outputs from the vertex shader */ 50 | varying vec4 frag_color; 51 | varying vec2 tex_coord0; 52 | 53 | /* uniform texture samplers */ 54 | uniform sampler2D texture0; 55 | 56 | void main (void){ 57 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 58 | } 59 | -------------------------------------------------------------------------------- /examples/assets/glsl/positioncolorrotateshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec2 center; 14 | attribute float rot; 15 | attribute vec4 v_color; 16 | 17 | /* uniform variables */ 18 | uniform mat4 modelview_mat; 19 | uniform mat4 projection_mat; 20 | uniform vec4 color; 21 | uniform float opacity; 22 | 23 | void main (void) { 24 | frag_color = v_color * color * vec4(1.0, 1.0, 1.0, opacity); 25 | tex_coord0 = uvs; 26 | float a_sin = sin(rot); 27 | float a_cos = cos(rot); 28 | mat4 rot_mat = mat4(a_cos, -a_sin, 0.0, 0.0, 29 | a_sin, a_cos, 0.0, 0.0, 30 | 0.0, 0.0, 1.0, 0.0, 31 | 0.0, 0.0, 0.0, 1.0 ); 32 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 33 | 0.0, 1.0, 0.0, center.y, 34 | 0.0, 0.0, 1.0, 0.0, 35 | 0.0, 0.0, 0.0, 1.0); 36 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 37 | vec4 trans_pos = new_pos * rot_mat * trans_mat; 38 | gl_Position = projection_mat * modelview_mat * trans_pos; 39 | 40 | } 41 | 42 | 43 | ---FRAGMENT SHADER--- 44 | #ifdef GL_ES 45 | precision highp float; 46 | #endif 47 | 48 | /* Outputs from the vertex shader */ 49 | varying vec4 frag_color; 50 | varying vec2 tex_coord0; 51 | 52 | /* uniform texture samplers */ 53 | uniform sampler2D texture0; 54 | 55 | void main (void){ 56 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 57 | } 58 | -------------------------------------------------------------------------------- /examples/assets/glsl/positioncolorshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute vec2 center; 14 | attribute vec4 v_color; 15 | 16 | /* uniform variables */ 17 | uniform mat4 modelview_mat; 18 | uniform mat4 projection_mat; 19 | uniform vec4 color; 20 | uniform float opacity; 21 | 22 | void main (void) { 23 | frag_color = v_color * color * vec4(1.0, 1.0, 1.0, opacity); 24 | tex_coord0 = uvs; 25 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 26 | 0.0, 1.0, 0.0, center.y, 27 | 0.0, 0.0, 1.0, 0.0, 28 | 0.0, 0.0, 0.0, 1.0); 29 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 30 | vec4 trans_pos = new_pos * trans_mat; 31 | gl_Position = projection_mat * modelview_mat * trans_pos; 32 | 33 | } 34 | 35 | 36 | ---FRAGMENT SHADER--- 37 | #ifdef GL_ES 38 | precision highp float; 39 | #endif 40 | 41 | /* Outputs from the vertex shader */ 42 | varying vec4 frag_color; 43 | varying vec2 tex_coord0; 44 | 45 | /* uniform texture samplers */ 46 | uniform sampler2D texture0; 47 | 48 | void main (void){ 49 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 50 | } 51 | -------------------------------------------------------------------------------- /examples/assets/glsl/positionrotateshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | attribute float rot; 14 | attribute vec2 center; 15 | 16 | /* uniform variables */ 17 | uniform mat4 modelview_mat; 18 | uniform mat4 projection_mat; 19 | uniform vec4 color; 20 | uniform float opacity; 21 | 22 | void main (void) { 23 | frag_color = color * vec4(1.0, 1., 1.0, opacity); 24 | tex_coord0 = uvs; 25 | float a_sin = sin(rot); 26 | float a_cos = cos(rot); 27 | mat4 rot_mat = mat4(a_cos, -a_sin, 0.0, 0.0, 28 | a_sin, a_cos, 0.0, 0.0, 29 | 0.0, 0.0, 1.0, 0.0, 30 | 0.0, 0.0, 0.0, 1.0 ); 31 | mat4 trans_mat = mat4(1.0, 0.0, 0.0, center.x, 32 | 0.0, 1.0, 0.0, center.y, 33 | 0.0, 0.0, 1.0, 0.0, 34 | 0.0, 0.0, 0.0, 1.0); 35 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 36 | vec4 trans_pos = new_pos * rot_mat * trans_mat; 37 | gl_Position = projection_mat * modelview_mat * trans_pos; 38 | 39 | } 40 | 41 | 42 | ---FRAGMENT SHADER--- 43 | #ifdef GL_ES 44 | precision highp float; 45 | #endif 46 | 47 | /* Outputs from the vertex shader */ 48 | varying vec4 frag_color; 49 | varying vec2 tex_coord0; 50 | 51 | /* uniform texture samplers */ 52 | uniform sampler2D texture0; 53 | 54 | void main (void){ 55 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 56 | } 57 | -------------------------------------------------------------------------------- /examples/assets/glsl/positionshader.glsl: -------------------------------------------------------------------------------- 1 | ---VERTEX SHADER--- 2 | #ifdef GL_ES 3 | precision highp float; 4 | #endif 5 | 6 | /* Outputs to the fragment shader */ 7 | varying vec4 frag_color; 8 | varying vec2 tex_coord0; 9 | 10 | /* vertex attributes */ 11 | attribute vec2 pos; 12 | attribute vec2 uvs; 13 | 14 | /* uniform variables */ 15 | uniform mat4 modelview_mat; 16 | uniform mat4 projection_mat; 17 | uniform vec4 color; 18 | uniform float opacity; 19 | 20 | void main (void) { 21 | frag_color = color * vec4(1.0, 1., 1.0, opacity); 22 | tex_coord0 = uvs; 23 | vec4 new_pos = vec4(pos.xy, 0.0, 1.0); 24 | gl_Position = projection_mat * modelview_mat * new_pos; 25 | 26 | } 27 | 28 | 29 | ---FRAGMENT SHADER--- 30 | #ifdef GL_ES 31 | precision highp float; 32 | #endif 33 | 34 | /* Outputs from the vertex shader */ 35 | varying vec4 frag_color; 36 | varying vec2 tex_coord0; 37 | 38 | /* uniform texture samplers */ 39 | uniform sampler2D texture0; 40 | 41 | void main (void){ 42 | 43 | gl_FragColor = frag_color * texture2D(texture0, tex_coord0); 44 | } 45 | -------------------------------------------------------------------------------- /examples/assets/green-tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/green-tile.png -------------------------------------------------------------------------------- /examples/assets/maps/basic_ground_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/maps/basic_ground_tiles.png -------------------------------------------------------------------------------- /examples/assets/maps/spritesheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/maps/spritesheet.png -------------------------------------------------------------------------------- /examples/assets/maps/tileset_hexagonal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/maps/tileset_hexagonal.png -------------------------------------------------------------------------------- /examples/assets/orange-tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/orange-tile.png -------------------------------------------------------------------------------- /examples/assets/purple-tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/purple-tile.png -------------------------------------------------------------------------------- /examples/assets/star1-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star1-blue.png -------------------------------------------------------------------------------- /examples/assets/star1-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star1-red.png -------------------------------------------------------------------------------- /examples/assets/star1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star1.png -------------------------------------------------------------------------------- /examples/assets/star2-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star2-blue.png -------------------------------------------------------------------------------- /examples/assets/star2-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star2-red.png -------------------------------------------------------------------------------- /examples/assets/star2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star2.png -------------------------------------------------------------------------------- /examples/assets/star3-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star3-blue.png -------------------------------------------------------------------------------- /examples/assets/star3-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star3-red.png -------------------------------------------------------------------------------- /examples/assets/star3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/star3.png -------------------------------------------------------------------------------- /examples/assets/stars-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/examples/assets/stars-0.png -------------------------------------------------------------------------------- /examples/assets/stars.atlas: -------------------------------------------------------------------------------- 1 | {"stars-0.png": {"star_circle": [2, 60, 32, 32], "star_square": [36, 60, 32, 32], "star1": [2, 94, 32, 32], "star3": [70, 94, 32, 32], "star2": [36, 94, 32, 32]}} -------------------------------------------------------------------------------- /modules/core/kivent_core/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /modules/core/kivent_core/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __VERSION__ = '2.1.0' 4 | 5 | if 'KIVENT_PREVENT_INIT' not in os.environ: 6 | from kivy.core.window import Window 7 | from kivent_core import memory_handlers 8 | from kivent_core import rendering 9 | from kivent_core import managers 10 | from kivent_core import entity 11 | from kivent_core import gameworld 12 | from kivent_core import systems 13 | -------------------------------------------------------------------------------- /modules/core/kivent_core/entity.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport MemComponent 2 | from kivent_core.managers.system_manager cimport SystemManager 3 | 4 | cdef class Entity(MemComponent): 5 | cdef list _load_order 6 | cdef SystemManager system_manager 7 | cdef void set_component(self, unsigned int component_id, 8 | unsigned int system_id) 9 | cpdef unsigned int get_component_index(self, str name) 10 | -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/__init__.py: -------------------------------------------------------------------------------- 1 | from kivent_core.managers import resource_managers 2 | from kivent_core.managers import entity_manager 3 | from kivent_core.managers import system_manager 4 | from kivent_core.managers import sound_manager 5 | from kivent_core.managers import game_manager 6 | -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/animation_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.resource_managers cimport ModelManager 2 | from kivent_core.memory_handlers.block cimport MemoryBlock 3 | from kivent_core.managers.resource_managers cimport ModelManager 4 | from kivent_core.managers.game_manager cimport GameManager 5 | 6 | 7 | cdef class AnimationManager(GameManager): 8 | cdef MemoryBlock memory_block 9 | cdef ModelManager model_manager 10 | cdef unsigned int allocation_size 11 | cdef dict _animations 12 | -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/entity_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone 2 | from kivent_core.managers.game_manager cimport GameManager 3 | 4 | cdef class EntityManager(GameManager): 5 | cdef IndexedMemoryZone memory_index 6 | cdef unsigned int system_count 7 | 8 | cdef void clear_entity(self, unsigned int entity_id) 9 | cdef void set_component(self, unsigned int entity_id, 10 | unsigned int component_id, unsigned int system_id) 11 | cdef unsigned int generate_entity(self, str zone) except -1 12 | cdef void remove_entity(self, unsigned int entity_id) 13 | cdef void set_entity_active(self, unsigned int entity_id) 14 | cdef unsigned int get_size(self) 15 | cpdef unsigned int get_active_entity_count(self) 16 | cpdef unsigned int get_active_entity_count_in_zone(self, str zone) except -1 -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/game_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivy._event cimport EventDispatcher 2 | 3 | cdef class GameManager(EventDispatcher): 4 | pass -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/game_manager.pyx: -------------------------------------------------------------------------------- 1 | from kivy._event cimport EventDispatcher 2 | 3 | cdef class GameManager(EventDispatcher): 4 | 5 | def allocate(self, master_buffer, gameworld): 6 | """ 7 | The GameManager should override and implement this function if it 8 | needs to allocate memory. This function will be called by 9 | GameWorld.allocate. 10 | 11 | Args: 12 | master_buffer (Buffer): The buffer from which the space for the 13 | entity IndexedMemoryZone will be allocated. 14 | 15 | gameworld (GameWorld): The GameWorld instance. 16 | 17 | Return: 18 | int: The amount of memory allocated by the system. 19 | 20 | """ 21 | return 0 22 | 23 | def deallocate(self, master_buffer, gameworld): 24 | """ 25 | The GameManager should override and implement this function to 26 | free previouslly allocated resources. 27 | """ 28 | pass 29 | -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/resource_managers.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.game_manager cimport GameManager 2 | 3 | cdef class TextureManager(GameManager): 4 | cdef dict _textures 5 | cdef dict _keys 6 | cdef dict _sizes 7 | cdef dict _uvs 8 | cdef dict _groups 9 | cdef dict _key_index 10 | cdef dict _texkey_index 11 | cdef int _key_count 12 | 13 | cdef class ModelManager(GameManager): 14 | cdef dict memory_blocks 15 | cdef unsigned int allocation_size 16 | cdef dict _models 17 | cdef dict _key_counts 18 | cdef dict _model_register 19 | cdef dict _svg_index 20 | cdef dict _models_by_format 21 | -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/sound_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.game_manager cimport GameManager 2 | 3 | cdef class SoundManager(GameManager): 4 | cdef dict sound_dict 5 | cdef dict sound_keys 6 | cdef int sound_count 7 | cdef dict music_dict 8 | cpdef play_direct(self, int sound_index, float volume) 9 | cpdef play_direct_loop(self, int sound_index, float volume) 10 | cpdef stop_direct(self, int sound_index) -------------------------------------------------------------------------------- /modules/core/kivent_core/managers/system_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.game_manager cimport GameManager 2 | cdef unsigned int DEFAULT_SYSTEM_COUNT 3 | cdef unsigned int DEFAULT_COUNT 4 | 5 | cdef class ZoneConfig: 6 | cdef str zone_name 7 | cdef list systems 8 | cdef unsigned int count 9 | 10 | 11 | cdef class SystemConfig: 12 | cdef dict zone_configs 13 | 14 | 15 | cdef class SystemManager(GameManager): 16 | cdef list systems 17 | cdef dict zones 18 | cdef dict system_index 19 | cdef list _update_order 20 | cdef bint initialized 21 | cdef list free_indices 22 | cdef list free_non_component_indices 23 | cdef unsigned int first_non_component_index 24 | cdef unsigned int system_count 25 | cdef unsigned int current_count 26 | cdef SystemConfig system_config 27 | 28 | cdef unsigned int get_system_index(self, str system_name) 29 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/__init__.py: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers import block 2 | from kivent_core.memory_handlers import membuffer 3 | from kivent_core.memory_handlers import utils 4 | from kivent_core.memory_handlers import indexing 5 | from kivent_core.memory_handlers import pool 6 | from kivent_core.memory_handlers import zone 7 | from kivent_core.memory_handlers import tests 8 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/block.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.membuffer cimport Buffer 2 | 3 | cdef class MemoryBlock(Buffer): 4 | cdef Buffer master_buffer 5 | cdef unsigned int master_index 6 | 7 | cdef void* allocate_memory_with_buffer(self, 8 | Buffer master_buffer) except NULL 9 | cdef void remove_from_buffer(self) 10 | cdef void deallocate_memory(self) 11 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/block.pyx: -------------------------------------------------------------------------------- 1 | # cython: profile=True 2 | # cython: embedsignature=True 3 | from kivent_core.memory_handlers.membuffer cimport Buffer 4 | 5 | cdef class MemoryBlock(Buffer): 6 | '''The MemoryBlock is like the Buffer, except instead of allocating its 7 | memory using malloc, it gets it from either a Buffer or another MemoryBlock. 8 | It is suitable for nesting, for instance during rendering KivEnt will 9 | allocate one large MemoryBlock to represent the maximum number of frames to 10 | be rendered something like 20*512*1024 bytes: 11 | 12 | .. code-block:: python 13 | 14 | #allocate the initial space 15 | buffer = Buffer(100*1024*1024, 1, 1) 16 | buffer.allocate_memory() 17 | #allocate our first MemoryBlock, in units of bytes 18 | mem_block = MemoryBlock(20*512*1024, 512*1024, 1) 19 | mem_block.allocate_memory_with_buffer(buffer) 20 | #allocate a block with the mem_block, units in 512 kib blocks 21 | #will allocate 1 block of mem_block.type_size and split it into 22 | #mem_block.type_size // other_type_size blocks. 23 | mem_block2 = MemoryBlock(1, other_type_size, 512*1024) 24 | mem_block2.allocate_memory_with_buffer(mem_block) 25 | 26 | 27 | You must allocate with the function **allocate_memory_with_buffer** instead 28 | of **allocate_memory**. Deallocation is handled with **remove_from_buffer**. 29 | 30 | **Attributes: (Cython Access Only)** 31 | **master_buffer** (Buffer): The Buffer from which memory has been 32 | allocated. Defaults to None, will be set after 33 | **allocate_memory_with_buffer** has been called. 34 | 35 | **master_index** (unsigned int): The location the data has been 36 | allocated at in the master_buffer. Defaults to 0, will be set after 37 | **allocate_memory_with_buffer** has been called. 38 | ''' 39 | 40 | def __cinit__(self, unsigned int size_in_blocks, unsigned int type_size, 41 | unsigned int master_block_size): 42 | self.master_index = 0 43 | self.master_buffer = None 44 | 45 | cdef void* allocate_memory_with_buffer(self, 46 | Buffer master_buffer) except NULL: 47 | '''Replaces **allocate_memory**, uses master_buffer.add_data to allocate 48 | with another Buffer or MemoryBlock. 49 | Args: 50 | master_buffer (Buffer): The buffer to allocate from. 51 | ''' 52 | self.master_buffer = master_buffer 53 | cdef unsigned int index = master_buffer.add_data(self.size_in_blocks) 54 | self.master_index = index 55 | self.data = master_buffer.get_pointer(index) 56 | return self.data 57 | 58 | cdef void remove_from_buffer(self): 59 | '''Replaces **deallocate_memory** used to free the memory previously 60 | acquired from **master_buffer**.''' 61 | self.master_buffer.remove_data(self.master_index, self.size_in_blocks) 62 | self.master_index = 0 63 | self.master_buffer = None 64 | 65 | cdef void deallocate_memory(self): 66 | '''Overridden to do nothing as we no longer need to free''' 67 | pass 68 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/indexing.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.zone cimport MemoryZone 2 | 3 | 4 | cdef class BlockIndex: 5 | cdef list block_objects 6 | 7 | 8 | cdef class PoolIndex: 9 | cdef list _block_indices 10 | 11 | 12 | cdef class ZoneIndex: 13 | cdef dict _pool_indices 14 | cdef MemoryZone memory_zone 15 | 16 | 17 | cdef class IndexedMemoryZone: 18 | cdef MemoryZone memory_zone 19 | cdef ZoneIndex zone_index 20 | 21 | cdef void* get_pointer(self, unsigned int index) except NULL 22 | cdef unsigned int get_size(self) 23 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/membuffer.pxd: -------------------------------------------------------------------------------- 1 | from cpython cimport bool 2 | 3 | cdef class Buffer: 4 | cdef unsigned int size 5 | cdef void* data 6 | cdef unsigned int used_count 7 | cdef list free_blocks 8 | cdef unsigned int free_block_count 9 | cdef unsigned int type_size 10 | cdef unsigned int data_in_free 11 | cdef unsigned int real_size 12 | cdef unsigned int size_in_blocks 13 | 14 | cdef unsigned int add_data(self, unsigned int block_count) except -1 15 | cdef void remove_data(self, unsigned int block_index, 16 | unsigned int block_count) 17 | cdef unsigned int get_largest_free_block(self) 18 | cdef unsigned int get_first_free_block_that_fits(self, 19 | unsigned int block_count) 20 | cdef unsigned int get_blocks_on_tail(self) 21 | cdef bool can_fit_data(self, unsigned int block_count) 22 | cdef void clear(self) 23 | cdef void* get_pointer(self, unsigned int block_index) except NULL 24 | cdef void deallocate_memory(self) 25 | cdef void* allocate_memory(self) except NULL 26 | cdef bool check_empty(self) 27 | cdef unsigned int get_offset(self, unsigned int block_index) 28 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/pool.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.membuffer cimport Buffer 2 | from kivent_core.memory_handlers.block cimport MemoryBlock 3 | 4 | cdef class MemoryPool: 5 | cdef unsigned int count 6 | cdef list memory_blocks 7 | cdef list blocks_with_free_space 8 | cdef unsigned int used 9 | cdef unsigned int free_count 10 | cdef Buffer master_buffer 11 | cdef unsigned int type_size 12 | cdef MemoryBlock master_block 13 | cdef unsigned int block_count 14 | cdef unsigned int slots_per_block 15 | 16 | cdef unsigned int get_block_from_index(self, unsigned int index) 17 | cdef unsigned int get_slot_index_from_index(self, unsigned int index) 18 | cdef MemoryBlock get_memory_block_from_index(self, unsigned int index) 19 | cdef unsigned int get_index_from_slot_index_and_block(self, 20 | unsigned int slot_index, unsigned int block_index) 21 | cdef void* get_pointer(self, unsigned int index) except NULL 22 | cdef unsigned int get_free_slot(self) except -1 23 | cdef void free_slot(self, unsigned int index) 24 | cdef void clear(self) 25 | cdef unsigned int get_size(self) 26 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/utils.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone 2 | 3 | cdef class memrange_iter: 4 | cdef IndexedMemoryZone memory_index 5 | cdef unsigned int current 6 | cdef unsigned int end 7 | 8 | cdef class memrange: 9 | cdef IndexedMemoryZone memory_index 10 | cdef unsigned int start 11 | cdef unsigned int end 12 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/utils.pyx: -------------------------------------------------------------------------------- 1 | # cython: embedsignature=True 2 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone, ZoneIndex 3 | from kivent_core.memory_handlers.zone cimport MemoryZone 4 | 5 | cdef class memrange: 6 | ''' 7 | Use memrange to iterate a IndexedMemoryZone object and return the active 8 | game entities' python objects , an active memory object is one that 9 | currently does not have the first attribute of its struct set to 10 | -1. Typically KivEnt store the entity_id for the component 11 | in this position. Memory objects that have never been allocated are 12 | skipped. 13 | 14 | Args: 15 | 16 | memory_index (IndexedMemoryZone): The IndexedMemoryZone to iterate. 17 | 18 | start (int): The start of iteration. Defaults 0. 19 | 20 | end (int): The end of iteration. Defaults None. If no end is specified 21 | we will iterate all memory. 22 | 23 | zone (str): The zone to iterate. Defaults None. If no zone is 24 | specified we will iterate through all zones. 25 | 26 | You must reference an IndexedMemoryZone, by default we will iterate 27 | through all the memory. The area of memory iterated can be controlled 28 | with options *start* and *end*, or you can provide the name of one of 29 | the reserved zones to iterate that specific memory area. 30 | ''' 31 | 32 | def __init__(self, IndexedMemoryZone memory_index, start=0, 33 | end=None, zone=None): 34 | cdef MemoryZone memory_zone = memory_index.memory_zone 35 | cdef unsigned int zone_count = memory_zone.count 36 | self.memory_index = memory_index 37 | if zone is not None: 38 | start, end = memory_zone.get_pool_range( 39 | memory_zone.get_pool_index_from_name(zone)) 40 | elif end is None or end > zone_count: 41 | end = zone_count 42 | self.start = start 43 | self.end = end 44 | 45 | def __iter__(self): 46 | return memrange_iter(self.memory_index, self.start, self.end) 47 | 48 | cdef class memrange_iter: 49 | 50 | def __init__(self, IndexedMemoryZone memory_index, int start, 51 | int end): 52 | self.memory_index = memory_index 53 | self.current = start 54 | self.end = end 55 | 56 | def __iter__(self): 57 | return self 58 | 59 | def __next__(self): 60 | 61 | cdef IndexedMemoryZone memory_index = self.memory_index 62 | cdef MemoryZone memory_zone = memory_index.memory_zone 63 | cdef ZoneIndex zone_index = memory_index.zone_index 64 | cdef unsigned int current = self.current 65 | cdef unsigned int pool_index, used 66 | cdef void* pointer 67 | if current >= self.end: 68 | raise StopIteration 69 | else: 70 | pool_index = memory_zone.get_pool_index_from_index(current) 71 | used = memory_zone.get_pool_end_from_pool_index(pool_index) 72 | if current >= used: 73 | self.current = memory_zone.get_pool_range(pool_index)[1] + 1 74 | return next(self) 75 | else: 76 | pointer = memory_zone.get_pointer(current) 77 | self.current += 1 78 | if pointer == -1: 79 | return next(self) 80 | return zone_index.get_component_from_index(current) 81 | -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/zone.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.membuffer cimport Buffer 2 | from kivent_core.memory_handlers.pool cimport MemoryPool 3 | from kivent_core.memory_handlers.block cimport MemoryBlock 4 | 5 | cdef class MemoryZone: 6 | cdef unsigned int block_size_in_kb 7 | cdef dict memory_pools 8 | cdef list reserved_ranges 9 | cdef unsigned int count 10 | cdef list reserved_names 11 | cdef unsigned int reserved_count 12 | cdef Buffer master_buffer 13 | 14 | cdef unsigned int get_pool_index_from_index(self, unsigned int index) 15 | cdef unsigned int remove_pool_offset(self, unsigned int index, 16 | unsigned int pool_index) 17 | cdef unsigned int add_pool_offset(self, unsigned int index, 18 | unsigned int pool_index) 19 | cdef MemoryPool get_pool_from_pool_index(self, unsigned int pool_index) 20 | cdef unsigned int get_block_from_index(self, unsigned int index) 21 | cdef unsigned int get_slot_index_from_index(self, unsigned int index) 22 | cdef MemoryBlock get_memory_block_from_index(self, unsigned int index) 23 | cdef unsigned int get_index_from_slot_block_pool_index(self, 24 | unsigned int slot_index, unsigned int block_index, 25 | unsigned int pool_index) 26 | cdef tuple get_pool_block_slot_indices(self, unsigned int index) 27 | cdef unsigned int get_free_slot(self, str reserved_hint) except -1 28 | cdef int free_slot(self, unsigned int index) except -1 29 | cdef void* get_pointer(self, unsigned int index) except NULL 30 | cdef unsigned int get_pool_end_from_pool_index(self, unsigned int index) 31 | cdef tuple get_pool_range(self, unsigned int pool_index) 32 | cdef unsigned int get_pool_index_from_name(self, str zone_name) except -1 33 | cdef unsigned int get_pool_offset(self, unsigned int pool_index) 34 | cdef unsigned int get_size(self) 35 | cdef unsigned int get_active_slot_count(self) 36 | cdef unsigned int get_active_slot_count_in_pool(self, unsigned int pool_index) except -1 -------------------------------------------------------------------------------- /modules/core/kivent_core/memory_handlers/zonedblock.pxd: -------------------------------------------------------------------------------- 1 | from cpython cimport bool 2 | from kivent_core.memory_handlers.membuffer cimport Buffer 3 | 4 | 5 | cdef class BlockZone: 6 | cdef unsigned int used_count 7 | cdef unsigned int total 8 | cdef unsigned int start 9 | cdef unsigned int data_in_free 10 | cdef list free_blocks 11 | cdef str name 12 | 13 | cdef unsigned int add_data(self, unsigned int block_count) except -1 14 | cdef void remove_data(self, unsigned int block_index, 15 | unsigned int block_count) 16 | cdef unsigned int get_largest_free_block(self) 17 | cdef unsigned int get_first_free_block_that_fits(self, 18 | unsigned int block_count) 19 | cdef unsigned int get_blocks_on_tail(self) 20 | cdef bool can_fit_data(self, unsigned int block_count) 21 | cdef void clear(self) 22 | 23 | 24 | cdef class ZonedBlock: 25 | cdef dict zones 26 | cdef Buffer master_buffer 27 | cdef unsigned int master_index 28 | cdef unsigned int size 29 | cdef unsigned int type_size 30 | cdef unsigned int count 31 | cdef void* data 32 | 33 | cdef bool check_empty(self) 34 | cdef void* allocate_memory_with_buffer(self, 35 | Buffer master_buffer) except NULL 36 | cdef void remove_from_buffer(self) 37 | cdef unsigned int add_data(self, unsigned int block_count, 38 | str zone) except -1 39 | cdef void remove_data(self, unsigned int block_index, 40 | unsigned int block_count) 41 | cdef BlockZone get_zone_from_index(self, unsigned int block_index) 42 | cdef void* get_pointer(self, unsigned int block_index) except NULL 43 | cdef void clear(self) 44 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/__init__.py: -------------------------------------------------------------------------------- 1 | from kivent_core.rendering import vertex_format 2 | from kivent_core.rendering import frame_objects 3 | from kivent_core.rendering import cmesh 4 | from kivent_core.rendering import batching 5 | from kivent_core.rendering import vertex_formats 6 | from kivent_core.rendering import fixedvbo 7 | from kivent_core.rendering import model 8 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/animation.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.resource_managers cimport ModelManager 2 | from kivent_core.memory_handlers.membuffer cimport Buffer 3 | from kivent_core.memory_handlers.block cimport MemoryBlock 4 | 5 | 6 | ctypedef struct FrameStruct: 7 | unsigned int texkey 8 | void* model 9 | float duration 10 | 11 | 12 | cdef class Frame: 13 | cdef FrameStruct* frame_pointer 14 | cdef ModelManager model_manager 15 | 16 | 17 | cdef class FrameList: 18 | cdef MemoryBlock frames_block 19 | cdef ModelManager model_manager 20 | cdef str name 21 | cdef unsigned int frame_count 22 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/batching.pxd: -------------------------------------------------------------------------------- 1 | from kivy.graphics.cgl cimport GLuint 2 | from kivent_core.memory_handlers.block cimport MemoryBlock 3 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone 4 | from kivent_core.memory_handlers.membuffer cimport Buffer 5 | from kivent_core.rendering.vertex_format cimport KEVertexFormat 6 | from cpython cimport bool 7 | from kivent_core.rendering.frame_objects cimport FixedFrameData 8 | from kivent_core.systems.staticmemgamesystem cimport ComponentPointerAggregator 9 | from kivent_core.managers.resource_managers import texture_manager 10 | 11 | 12 | cdef class IndexedBatch: 13 | cdef list frame_data 14 | cdef unsigned int current_frame 15 | cdef unsigned int frame_count 16 | cdef unsigned int tex_key 17 | cdef unsigned int batch_id 18 | cdef GLuint mode 19 | cdef object mesh_instruction 20 | cdef ComponentPointerAggregator entity_components 21 | 22 | cdef tuple add_entity(self, unsigned int entity_id, unsigned int num_verts, 23 | unsigned int num_indices) 24 | cdef void remove_entity(self, unsigned int entity_id, 25 | unsigned int num_verts, unsigned int vert_index, 26 | unsigned int num_indices, unsigned int ind_index) 27 | cdef bool check_empty(self) 28 | cdef bool can_fit_data(self, unsigned int num_verts, 29 | unsigned int num_indices) 30 | cdef void* get_vbo_frame_to_draw(self) 31 | cdef FixedFrameData get_current_vbo(self) 32 | cdef FixedFrameData get_next_vbo(self) 33 | cdef void* get_indices_frame_to_draw(self) 34 | cdef void set_index_count_for_frame(self, 35 | unsigned int index_count) 36 | cdef void draw_frame(self) 37 | cdef void clear_frames(self) 38 | 39 | cdef class BatchManager: 40 | cdef MemoryBlock batch_block 41 | cdef MemoryBlock indices_block 42 | cdef list batches 43 | cdef list free_batches 44 | cdef dict batch_groups 45 | cdef object gameworld 46 | cdef unsigned int batch_count 47 | cdef unsigned int max_batches 48 | cdef unsigned int frame_count 49 | cdef unsigned int slots_per_block 50 | cdef unsigned int index_slots_per_block 51 | cdef unsigned int vbo_size_in_kb 52 | cdef str mode_str 53 | cdef GLuint mode 54 | cdef KEVertexFormat vertex_format 55 | cdef object canvas 56 | cdef list system_names 57 | cdef Buffer master_buffer 58 | cdef unsigned int ent_per_batch 59 | 60 | cdef void set_mode(self, str mode) 61 | cdef str get_mode(self) 62 | cdef unsigned int get_size(self) 63 | cdef unsigned int get_size_of_component_pointers(self) 64 | cdef unsigned int create_batch(self, unsigned int tex_key) except -1 65 | cdef int remove_batch(self, unsigned int batch_id) except 0 66 | cdef IndexedBatch get_batch_with_space(self, unsigned int tex_key, 67 | unsigned int num_verts, unsigned int num_indices) 68 | cdef tuple batch_entity(self, unsigned int entity_id, unsigned int tex_key, 69 | unsigned int num_verts, unsigned int num_indices) 70 | cdef bint unbatch_entity(self, unsigned int entity_id, 71 | unsigned int batch_id, unsigned int num_verts, 72 | unsigned int num_indices, unsigned int vert_index, 73 | unsigned int ind_index) except 0 74 | cdef list get_vbos(self) 75 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/cmesh.pxd: -------------------------------------------------------------------------------- 1 | from kivy.graphics.instructions cimport VertexInstruction 2 | from kivent_core.rendering.batching cimport IndexedBatch 3 | 4 | cdef class CMesh(VertexInstruction): 5 | cdef IndexedBatch _batch 6 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/cmesh.pyx: -------------------------------------------------------------------------------- 1 | # cython: profile=True 2 | # cython: embedsignature=True 3 | from kivy.graphics.instructions cimport VertexInstruction 4 | from kivent_core.rendering.batching cimport IndexedBatch 5 | include "opcodes.pxi" 6 | include "common.pxi" 7 | 8 | 9 | cdef class CMesh(VertexInstruction): 10 | 11 | def __init__(self, **kwargs): 12 | VertexInstruction.__init__(self, **kwargs) 13 | cdef IndexedBatch batch = kwargs.get('batch') 14 | self._batch = batch 15 | 16 | 17 | def __dealloc__(self): 18 | self._batch.clear_frames() 19 | 20 | cdef int apply(self) except -1: 21 | if self.flags & GI_NEEDS_UPDATE: 22 | self._batch.current_frame += 1 23 | self.flag_update_done() 24 | self._batch.draw_frame() 25 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/common.pxi: -------------------------------------------------------------------------------- 1 | # 2 | # Common definition 3 | # 4 | 5 | DEF PI2 = 1.5707963267948966 6 | DEF PI = 3.1415926535897931 7 | 8 | cdef extern from *: 9 | ctypedef char* const_char_ptr "const char*" 10 | 11 | cdef double pi = PI 12 | cdef extern from "math.h": 13 | double cos(double) nogil 14 | double sin(double) nogil 15 | double sqrt(double) nogil 16 | double pow(double x, double y) nogil 17 | double atan2(double y, double x) nogil 18 | double tan(double) nogil 19 | 20 | cdef extern from "stdlib.h": 21 | ctypedef unsigned long size_t 22 | void free(void *ptr) nogil 23 | void *realloc(void *ptr, size_t size) nogil 24 | void *malloc(size_t size) nogil 25 | void *calloc(size_t nmemb, size_t size) nogil 26 | 27 | cdef extern from "string.h": 28 | void *memcpy(void *dest, void *src, size_t n) 29 | void *memset(void *dest, int c, size_t len) 30 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/fixedvbo.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.block cimport MemoryBlock 2 | from kivent_core.rendering.vertex_format cimport KEVertexFormat 3 | from kivy.graphics.cgl cimport GLuint 4 | 5 | cdef class FixedVBO: 6 | cdef MemoryBlock memory_block 7 | cdef int usage 8 | cdef GLuint id 9 | cdef short flags 10 | cdef int target 11 | cdef unsigned int size_last_frame 12 | cdef unsigned int data_size 13 | cdef KEVertexFormat vertex_format 14 | 15 | cdef int have_id(self) 16 | cdef void generate_buffer(self) 17 | cdef void update_buffer(self) 18 | cdef void bind(self) 19 | cdef void unbind(self) 20 | cdef void return_memory(self) 21 | cdef void reload(self) 22 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/frame_objects.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.rendering.fixedvbo cimport FixedVBO 2 | 3 | cdef class FixedFrameData: 4 | cdef FixedVBO index_vbo 5 | cdef FixedVBO vertex_vbo 6 | 7 | cdef void return_memory(self) 8 | cdef void clear(self) 9 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/frame_objects.pyx: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.block cimport MemoryBlock 2 | from kivent_core.rendering.vertex_format cimport KEVertexFormat 3 | from kivent_core.rendering.fixedvbo cimport FixedVBO 4 | 5 | cdef class FixedFrameData: 6 | '''The FixedFrameData manages 2 FixedVBO, suitable for rendering using the 7 | GL_TRIANGLES mode. One FixedVBO will hold the indices data and the other 8 | the actual vertex data. 9 | 10 | **Attributes: (Cython Access Only)** 11 | **index_vbo** (FixedVBO): The FixedVBO holding indices data. Will 12 | have the target: GL_ELEMENTS_ARRAY_BUFFER. 13 | 14 | **vertex_vbo** (FixedVBO): The FixedVBO holding vertex data. Will 15 | have the target: GL_ARRAY_BUFFER. 16 | ''' 17 | 18 | def __cinit__(self, MemoryBlock index_block, MemoryBlock vertex_block, 19 | KEVertexFormat vertex_format): 20 | '''When initializing a FixedFrameData we must pass in the MemoryBlock 21 | that will be used to store the data, and the KEVertexFormat specifying 22 | the format of the data. 23 | 24 | Args: 25 | index_block (MemoryBlock): Container for holding the indices data. 26 | 27 | vertex_block (MemoryBlock): Container for holding the vertex data. 28 | 29 | vertex_format (KEVertexFormat): Format of the vertex data. 30 | ''' 31 | self.index_vbo = FixedVBO( 32 | vertex_format, index_block, 'stream', 'elements') 33 | self.vertex_vbo = FixedVBO( 34 | vertex_format, vertex_block, 'stream', 'array') 35 | 36 | cdef void return_memory(self): 37 | '''Returns the memory held by **index_vbo** and **vertex_vbo** by 38 | calling their respective return_memory functions''' 39 | self.index_vbo.return_memory() 40 | self.vertex_vbo.return_memory() 41 | 42 | cdef void clear(self): 43 | self.index_vbo.reload() 44 | self.vertex_vbo.reload() 45 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/gl_debug.pxd: -------------------------------------------------------------------------------- 1 | cdef void gl_log_debug_message(str name, object data=*) 2 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/gl_debug.pyx: -------------------------------------------------------------------------------- 1 | from kivy.graphics.cgl cimport GLenum, cgl 2 | from kivy.logger import Logger 3 | 4 | cdef void gl_log_debug_message(str name, object data=None): 5 | cdef GLenum ret = cgl.glGetError() 6 | if ret: 7 | Logger.error( 8 | "OpenGL Error (%s) %d / %x for %s" % (name, ret, ret, data) 9 | ) 10 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/model.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.membuffer cimport Buffer 2 | from kivent_core.memory_handlers.block cimport MemoryBlock 3 | from kivent_core.rendering.vertex_formats cimport FormatConfig 4 | 5 | 6 | cdef class Vertex: 7 | cdef dict vertex_format 8 | cdef void* vertex_pointer 9 | 10 | 11 | cdef class VertexModel: 12 | cdef MemoryBlock vertices_block 13 | cdef MemoryBlock indices_block 14 | cdef FormatConfig _format_config 15 | cdef unsigned int _vertex_count 16 | cdef unsigned int _index_count 17 | cdef Buffer index_buffer 18 | cdef Buffer vertex_buffer 19 | cdef str _name 20 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/opcodes.pxi: -------------------------------------------------------------------------------- 1 | cdef int GI_NOOP = 1 << 0 2 | cdef int GI_IGNORE = 1 << 1 3 | cdef int GI_NEEDS_UPDATE = 1 << 2 4 | cdef int GI_GROUP = 1 << 3 5 | cdef int GI_CONTEXT_MOD = 1 << 4 6 | cdef int GI_VERTEX_DATA = 1 << 5 7 | cdef int GI_COMPILER = 1 << 6 8 | cdef int GI_NO_APPLY_ONCE = 1 << 7 9 | cdef int GI_NO_REMOVE = 1 << 8 10 | 11 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/svg_loader.pxd: -------------------------------------------------------------------------------- 1 | from cython cimport view 2 | from kivy.graphics.instructions cimport RenderContext 3 | from kivy.graphics.texture cimport Texture 4 | from kivy.graphics.vertex cimport VertexFormat 5 | from kivy.graphics.vertex_instructions cimport StripMesh 6 | from cpython cimport array 7 | from array import array 8 | from libc.math cimport acos, fabs 9 | 10 | cdef set COMMANDS 11 | cdef set UPPERCASE 12 | cdef object RE_LIST 13 | cdef object RE_COMMAND 14 | cdef object RE_FLOAT 15 | cdef object RE_POLYLINE 16 | cdef object RE_TRANSFORM 17 | cdef VertexFormat VERTEX_FORMAT 18 | ctypedef double matrix_t[6] 19 | cdef list kv_color_to_int_color(color) 20 | cdef float parse_float(txt) 21 | cdef list parse_list(string) 22 | cdef dict parse_style(string) 23 | cdef parse_color(c, current_color=?) 24 | 25 | cdef class SVGModelInfo: 26 | cdef public list path_vertices 27 | cdef list indices 28 | cdef dict vertices 29 | cdef int vertex_count 30 | cdef int index_count 31 | cdef str title 32 | cdef str description 33 | cdef str element_id 34 | cdef dict custom_data 35 | 36 | cdef class Matrix: 37 | cdef matrix_t mat 38 | cdef void transform(self, float ox, float oy, float *x, float *y) 39 | cpdef Matrix inverse(self) 40 | 41 | cdef class SVG: 42 | cdef public double width 43 | cdef public double height 44 | cdef float line_width 45 | cdef list paths 46 | cdef object transform 47 | cdef object fill 48 | cdef object tree 49 | cdef public object current_color 50 | cdef dict custom_data 51 | cdef object stroke 52 | cdef float opacity 53 | cdef float x 54 | cdef float y 55 | cdef str element_id 56 | cdef str title 57 | cdef str description 58 | cdef public str metadata_description 59 | cdef str label 60 | cdef list custom_fields 61 | cdef bint fill_was_none 62 | cdef object el_id 63 | cdef int close_index 64 | cdef list path 65 | cdef array.array loop 66 | cdef int bezier_points 67 | cdef int circle_points 68 | cdef public object gradients 69 | cdef view.array bezier_coefficients 70 | cdef float anchor_x 71 | cdef float anchor_y 72 | cdef double last_cx 73 | cdef double last_cy 74 | cdef Texture line_texture 75 | cdef StripMesh last_mesh 76 | 77 | cdef parse_tree(self, tree) 78 | cdef parse_element(seld, e) 79 | cdef list parse_transform(self, transform_def) 80 | cdef parse_path(self, pathdef) 81 | cdef void new_path(self) 82 | cdef void close_path(self) 83 | cdef void set_line_width(self, float width) 84 | cdef void set_position(self, float x, float y, int absolute=*) 85 | cdef arc_to(self, float rx, float ry, float phi, float large_arc, 86 | float sweep, float x, float y) 87 | cdef void curve_to(self, float x1, float y1, float x2, float y2, 88 | float x, float y) 89 | cdef void end_path(self) 90 | cdef SVGModelInfo push_mesh(self, float[:] path, fill, Matrix transform, 91 | mode) 92 | cdef SVGModelInfo get_model_info(self, float *vertices, int vindex, 93 | int count, int mode=*) 94 | cdef SVGModelInfo push_line_mesh(self, float[:] path, fill, 95 | Matrix transform, 96 | float line_width, bint fill_was_none) 97 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/vertex_format.pxd: -------------------------------------------------------------------------------- 1 | from cython cimport Py_ssize_t 2 | from kivy.graphics.vertex cimport VertexFormat 3 | 4 | cdef class KEVertexFormat(VertexFormat): 5 | cdef Py_ssize_t* attr_offsets 6 | cdef int* attr_normalize 7 | cdef object fmt 8 | 9 | cdef void bind(self) 10 | -------------------------------------------------------------------------------- /modules/core/kivent_core/rendering/vertex_formats.pxd: -------------------------------------------------------------------------------- 1 | from kivy.graphics.cgl cimport GLfloat, GLubyte 2 | 3 | ctypedef struct VertexFormat4F: 4 | GLfloat[2] pos 5 | GLfloat[2] uvs 6 | 7 | ctypedef struct VertexFormat7F: 8 | GLfloat[2] pos 9 | GLfloat[2] uvs 10 | GLfloat rot 11 | GLfloat[2] center 12 | 13 | ctypedef struct VertexFormat4F4UB: 14 | GLfloat[2] pos 15 | GLfloat[2] uvs 16 | GLubyte[4] v_color #we don't want to clash with Kivy's 'color' uniform 17 | 18 | ctypedef struct VertexFormat2F4UB: 19 | GLfloat[2] pos 20 | GLubyte[4] v_color 21 | 22 | ctypedef struct VertexFormat5F4UB: 23 | GLfloat[2] pos 24 | GLfloat rot 25 | GLfloat[2] center 26 | GLubyte[4] v_color 27 | 28 | ctypedef struct VertexFormat7F4UB: 29 | GLfloat[2] pos 30 | GLfloat[2] uvs 31 | GLfloat rot 32 | GLfloat[2] center 33 | GLubyte[4] v_color 34 | 35 | 36 | cdef class FormatConfig: 37 | cdef unsigned int _size 38 | cdef list _format 39 | cdef str _name 40 | cdef dict _format_dict 41 | 42 | cdef class VertexFormatRegister: 43 | cdef dict _vertex_formats 44 | 45 | cdef VertexFormatRegister format_registrar 46 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/__init__.py: -------------------------------------------------------------------------------- 1 | from kivent_core.systems import gamesystem 2 | from kivent_core.systems import staticmemgamesystem 3 | from kivent_core.systems import scale_systems 4 | from kivent_core.systems import gameview 5 | from kivent_core.systems import rotate_systems 6 | from kivent_core.systems import color_systems 7 | from kivent_core.systems import position_systems 8 | from kivent_core.systems import gamemap 9 | from kivent_core.systems import renderers 10 | from kivent_core.systems import lifespan 11 | from kivent_core.systems import animation_sys 12 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/animation_sys.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | from kivent_core.rendering.animation cimport FrameList, Frame, FrameStruct 3 | 4 | 5 | ctypedef struct AnimationStruct: 6 | unsigned int entity_id 7 | void* frames 8 | void* manager 9 | unsigned int current_frame_index 10 | float current_duration 11 | bint loop 12 | bint dirty 13 | 14 | cdef class AnimationComponent(MemComponent): 15 | pass 16 | 17 | cdef class AnimationSystem(StaticMemGameSystem): 18 | pass 19 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/color_systems.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | 3 | 4 | ctypedef struct ColorStruct: 5 | unsigned int entity_id 6 | unsigned char[4] color 7 | 8 | cdef class ColorComponent(MemComponent): 9 | pass 10 | 11 | 12 | cdef class ColorSystem(StaticMemGameSystem): 13 | pass 14 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/gamemap.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.gamesystem cimport GameSystem 2 | 3 | cdef class GameMap(GameSystem): 4 | pass 5 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/gamemap.pyx: -------------------------------------------------------------------------------- 1 | # cython: embedsignature=True 2 | from kivent_core.systems.gamesystem cimport GameSystem 3 | from kivy.core.window import Window 4 | from kivy.properties import (StringProperty, ListProperty, BooleanProperty) 5 | from kivy.factory import Factory 6 | 7 | cdef class GameMap(GameSystem): 8 | ''' 9 | GameMap is a basic implementation of a map size for your GameWorld that 10 | limits the scrolling of GameView typically a GameMap does not actually 11 | have any entities, it simply holds some data and logic for use by 12 | other GameSystems 13 | 14 | **Attributes:** 15 | **map_size** (ListProperty): Sets the size of this map, used to 16 | determine scrolling bounds. If the map size is smaller than the 17 | window it will be centered inside the window. 18 | 19 | **margins** (ListProperty): The amount of scrolling beyond the size of 20 | the map in x, y directions to be allowed. If the map is smaller than 21 | the window. This value is calculated automatically. 22 | 23 | **default_margins** (ListProperty): The amount of margin if the map is 24 | larger than the window, defaults to (0, 0) which means no scrolling 25 | beyond edge of GameMap. 26 | 27 | ''' 28 | system_id = StringProperty('default_map') 29 | map_size = ListProperty((2000., 2000.)) 30 | window_size = ListProperty((0., 0.)) 31 | margins = ListProperty((0., 0.)) 32 | map_color = ListProperty((1., 1., 1., 1.)) 33 | do_components = BooleanProperty(False) 34 | default_margins = ListProperty((0., 0.)) 35 | 36 | def on_map_size(self, instance, value): 37 | self.check_margins() 38 | 39 | def on_size(self, instance, value): 40 | self.check_margins() 41 | 42 | def check_margins(self): 43 | map_size = self.map_size 44 | window_size = Window.size 45 | window_larger_x = False 46 | window_larger_y = False 47 | if window_size[0] > map_size[0]: 48 | margin_x = (window_size[0] - map_size[0])/2. 49 | window_larger_x = True 50 | if window_size[1] > map_size[1]: 51 | margin_y = (window_size[1] - map_size[1])/2. 52 | window_larger_y = True 53 | if window_larger_x: 54 | self.margins[0] = margin_x 55 | if window_larger_y: 56 | self.margins[1] = margin_y 57 | if not window_larger_x and not window_larger_y: 58 | self.margins = self.default_margins 59 | 60 | 61 | Factory.register('GameMap', cls=GameMap) 62 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/gamesystem.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.uix.cwidget cimport CWidget 2 | 3 | cdef class GameSystem(CWidget): 4 | cdef float _frame_time 5 | cdef list py_components 6 | cdef unsigned int component_count 7 | cdef object free_indices 8 | cdef dict copied_components 9 | cpdef unsigned int get_active_component_count(self) except -1 10 | cpdef unsigned int get_active_component_count_in_zone(self, str zone) except -1 11 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/gameview.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.gamesystem cimport GameSystem 2 | from kivy.graphics.transformation cimport Matrix 3 | 4 | 5 | cdef class GameView(GameSystem): 6 | cdef Matrix matrix 7 | cdef list _touches 8 | cdef int _touch_count 9 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/lifespan.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | 4 | ctypedef struct LifespanStruct: 5 | unsigned int entity_id 6 | float lifespan 7 | float current_time 8 | bint paused 9 | 10 | 11 | cdef class LifespanComponent(MemComponent): 12 | pass 13 | 14 | cdef class LifespanSystem(StaticMemGameSystem): 15 | pass -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/position_systems.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | 3 | 4 | ctypedef struct PositionStruct2D: 5 | unsigned int entity_id 6 | float x 7 | float y 8 | 9 | 10 | cdef class PositionComponent2D(MemComponent): 11 | pass 12 | 13 | 14 | cdef class PositionSystem2D(StaticMemGameSystem): 15 | pass 16 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/renderers.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.rendering.cmesh cimport CMesh 2 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 3 | from kivent_core.rendering.batching cimport BatchManager 4 | from kivent_core.rendering.vertex_format cimport KEVertexFormat 5 | from kivent_core.memory_handlers.membuffer cimport Buffer 6 | from kivent_core.rendering.model cimport VertexModel 7 | from cpython cimport bool 8 | 9 | 10 | ctypedef struct RenderStruct: 11 | unsigned int entity_id 12 | unsigned int texkey 13 | unsigned int batch_id 14 | void* model 15 | void* renderer 16 | int vert_index 17 | int ind_index 18 | bint render 19 | 20 | 21 | cdef class RenderComponent(MemComponent): 22 | pass 23 | 24 | 25 | cdef class Renderer(StaticMemGameSystem): 26 | cdef BatchManager batch_manager 27 | cdef object update_trigger 28 | cdef bint do_texture 29 | 30 | cdef void* _batch_entity(self, unsigned int entity_id, 31 | RenderStruct* component_data) except NULL 32 | cdef void* _unbatch_entity(self, unsigned int entity_id, 33 | RenderStruct* component_data) except NULL 34 | cdef void* _init_component(self, unsigned int component_index, 35 | unsigned int entity_id, bool render, VertexModel model, 36 | unsigned int texkey) except NULL 37 | cdef void* setup_batch_manager(self, Buffer master_buffer) except NULL 38 | 39 | 40 | cdef class RotateRenderer(Renderer): 41 | pass 42 | 43 | cdef class RotateScaleRenderer(RotateRenderer): 44 | pass 45 | 46 | cdef class RotateColorRenderer(Renderer): 47 | pass 48 | 49 | cdef class RotateColorScaleRenderer(RotateColorRenderer): 50 | pass 51 | 52 | cdef class ColorRenderer(Renderer): 53 | pass 54 | 55 | cdef class PolyRenderer(Renderer): 56 | pass 57 | 58 | cdef class RotatePolyRenderer(Renderer): 59 | pass 60 | 61 | cdef class RotateColorScalePolyRenderer(RotatePolyRenderer): 62 | pass 63 | 64 | cdef class ColorPolyRenderer(Renderer): 65 | pass 66 | 67 | cdef class ScaledRenderer(Renderer): 68 | pass 69 | 70 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/rotate_systems.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | 3 | 4 | ctypedef struct RotateStruct2D: 5 | unsigned int entity_id 6 | float r 7 | 8 | 9 | cdef class RotateComponent2D(MemComponent): 10 | pass 11 | 12 | 13 | cdef class RotateSystem2D(StaticMemGameSystem): 14 | pass 15 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/rotate_systems.pyx: -------------------------------------------------------------------------------- 1 | # cython: embedsignature=True 2 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 3 | from kivent_core.memory_handlers.zone cimport MemoryZone 4 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone 5 | from kivent_core.memory_handlers.membuffer cimport Buffer 6 | from kivy.factory import Factory 7 | from kivy.properties import ObjectProperty, NumericProperty, StringProperty 8 | 9 | cdef class RotateComponent2D(MemComponent): 10 | '''The component associated with RotateSystem2D. 11 | 12 | **Attributes:** 13 | **entity_id** (unsigned int): The entity_id this component is currently 14 | associated with. Will be -1 if the component is 15 | unattached. 16 | 17 | **r** (float): The rotation around center of the entity. 18 | ''' 19 | 20 | property entity_id: 21 | def __get__(self): 22 | cdef RotateStruct2D* data = self.pointer 23 | return data.entity_id 24 | 25 | property r: 26 | def __get__(self): 27 | cdef RotateStruct2D* data = self.pointer 28 | return data.r 29 | def __set__(self, float value): 30 | cdef RotateStruct2D* data = self.pointer 31 | data.r = value 32 | 33 | 34 | cdef class RotateSystem2D(StaticMemGameSystem): 35 | ''' 36 | RotateSystem2D abstracts 2 dimensional rotation data out into its own 37 | system so that all other GameSystem can interact with the rotation of an 38 | Entity without having to know specifically about dependent systems such as 39 | the CymunkPhysics system or any other method of determining the actual 40 | rotation. This GameSystem does no processing of its own, just holding data. 41 | 42 | Typically other GameSystems will interpret this rotation as being a 43 | rotation around the center of the entity. 44 | ''' 45 | type_size = NumericProperty(sizeof(RotateStruct2D)) 46 | component_type = ObjectProperty(RotateComponent2D) 47 | system_id = StringProperty('rotate') 48 | 49 | def init_component(self, unsigned int component_index, 50 | unsigned int entity_id, str zone, float r): 51 | '''A RotateComponent2D is always initialized with a single float 52 | representing a rotation in degrees. 53 | ''' 54 | cdef MemoryZone memory_zone = self.imz_components.memory_zone 55 | cdef RotateStruct2D* component = ( 56 | memory_zone.get_pointer(component_index)) 57 | component.entity_id = entity_id 58 | component.r = r 59 | 60 | def clear_component(self, unsigned int component_index): 61 | cdef MemoryZone memory_zone = self.imz_components.memory_zone 62 | cdef RotateStruct2D* pointer = ( 63 | memory_zone.get_pointer(component_index)) 64 | pointer.entity_id = -1 65 | pointer.r = 0. 66 | 67 | 68 | Factory.register('RotateSystem2D', cls=RotateSystem2D) 69 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/scale_systems.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | 3 | 4 | ctypedef struct ScaleStruct2D: 5 | unsigned int entity_id 6 | float sx 7 | float sy 8 | 9 | 10 | cdef class ScaleComponent2D(MemComponent): 11 | pass 12 | 13 | 14 | cdef class ScaleSystem2D(StaticMemGameSystem): 15 | pass 16 | -------------------------------------------------------------------------------- /modules/core/kivent_core/systems/staticmemgamesystem.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.memory_handlers.indexing cimport IndexedMemoryZone 2 | from kivent_core.systems.gamesystem cimport GameSystem 3 | from kivent_core.memory_handlers.block cimport MemoryBlock 4 | from kivent_core.memory_handlers.zonedblock cimport ZonedBlock 5 | from cpython cimport bool 6 | 7 | 8 | cdef class MemComponent: 9 | cdef void* pointer 10 | cdef unsigned int _id 11 | 12 | 13 | cdef class StaticMemGameSystem(GameSystem): 14 | cdef IndexedMemoryZone imz_components 15 | cdef ZonedAggregator entity_components 16 | 17 | 18 | cdef class ZonedAggregator: 19 | cdef ZonedBlock memory_block 20 | cdef unsigned int count 21 | cdef unsigned int total 22 | cdef dict entity_block_index 23 | cdef object gameworld 24 | cdef list system_names 25 | 26 | cdef bool check_empty(self) 27 | cdef void free(self) 28 | cdef unsigned int get_size(self) 29 | cdef void clear(self) 30 | cdef int remove_entity(self, unsigned int entity_id) except 0 31 | cdef unsigned int add_entity(self, unsigned int entity_id, 32 | str zone_name) except -1 33 | 34 | 35 | cdef class ComponentPointerAggregator: 36 | cdef MemoryBlock memory_block 37 | cdef object gameworld 38 | cdef unsigned int count 39 | cdef unsigned int total 40 | cdef list system_names 41 | cdef dict entity_block_index 42 | 43 | cdef bool check_empty(self) 44 | cdef unsigned int get_size(self) 45 | cdef void free(self) 46 | cdef void clear(self) 47 | cdef int remove_entity(self, unsigned int entity_id) except 0 48 | cdef unsigned int add_entity(self, unsigned int entity_id) except -1 49 | -------------------------------------------------------------------------------- /modules/core/kivent_core/uix/__init__.py: -------------------------------------------------------------------------------- 1 | from . import cwidget 2 | from . import gamescreens 3 | -------------------------------------------------------------------------------- /modules/core/kivent_core/uix/cwidget.pxd: -------------------------------------------------------------------------------- 1 | from kivy._event cimport EventDispatcher 2 | 3 | cdef class CWidget(EventDispatcher): 4 | cdef object _context 5 | cdef object canvas 6 | cdef object _disabled_value 7 | cdef object _disabled_count 8 | -------------------------------------------------------------------------------- /modules/core/kivent_core/uix/gamescreens.pyx: -------------------------------------------------------------------------------- 1 | from kivy.properties import StringProperty 2 | from kivy.uix.screenmanager import ScreenManager, Screen 3 | 4 | 5 | class GameScreenManager(ScreenManager): 6 | state = StringProperty('initial') 7 | 8 | def __init__(self, **kwargs): 9 | super(GameScreenManager, self).__init__(**kwargs) 10 | self.states = {} 11 | 12 | def on_state(self, instance, value): 13 | state_name = self.states[value] 14 | if state_name is not None: 15 | self.current = state_name 16 | 17 | 18 | class GameScreen(Screen): 19 | name = StringProperty('default_screen_id') 20 | -------------------------------------------------------------------------------- /modules/cymunk/kivent_cymunk/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Jacob Kovac 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /modules/cymunk/kivent_cymunk/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __VERSION__ = '1.0.0' 4 | 5 | if 'KIVENT_PREVENT_INIT' not in os.environ: 6 | from kivent_cymunk import physics 7 | from kivent_cymunk import interaction 8 | -------------------------------------------------------------------------------- /modules/cymunk/kivent_cymunk/interaction.pxd: -------------------------------------------------------------------------------- 1 | from cymunk.cymunk cimport (Body, PivotJoint, GearJoint, cpBody, cpPivotJoint, 2 | cpGearJoint, cpVect) 3 | from cpython cimport bool 4 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 5 | MemComponent) 6 | from kivent_cymunk.physics cimport PhysicsStruct 7 | 8 | ctypedef struct CymunkTouchStruct: 9 | unsigned int entity_id 10 | cpBody* touch_body 11 | cpPivotJoint* pivot 12 | 13 | cdef class CymunkTouchComponent(MemComponent): 14 | cdef Body _touch_body 15 | cdef PivotJoint _pivot 16 | 17 | cdef class CymunkTouchSystem(StaticMemGameSystem): 18 | pass 19 | 20 | ctypedef struct SteeringStruct: 21 | unsigned int entity_id 22 | cpBody* steering_body 23 | cpPivotJoint* pivot 24 | cpGearJoint* gear 25 | float[2] target 26 | float speed 27 | float arrived_radius 28 | bint active 29 | bint do_movement 30 | 31 | cdef class SteeringComponent(MemComponent): 32 | cdef Body _steering_body 33 | cdef PivotJoint _pivot 34 | cdef GearJoint _gear 35 | 36 | cdef class SteeringSystem(StaticMemGameSystem): 37 | pass 38 | 39 | ctypedef struct SteeringAIStruct: 40 | unsigned int entity_id 41 | unsigned int target_id 42 | float desired_angle 43 | float desired_distance 44 | float angle_variance 45 | float distance_variance 46 | float base_distance 47 | float base_angle 48 | float current_time 49 | float recalculate_time 50 | float query_radius 51 | 52 | cdef class SteeringAIComponent(MemComponent): 53 | pass 54 | 55 | cdef class SteeringAISystem(StaticMemGameSystem): 56 | cdef cpVect calculate_avoid_vector(self, list obstacles, 57 | PhysicsStruct* entity_physics, SteeringAIStruct* entity_ai) 58 | -------------------------------------------------------------------------------- /modules/cymunk/kivent_cymunk/physics.pxd: -------------------------------------------------------------------------------- 1 | from cymunk.cymunk cimport Body, cpBody, Space 2 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 3 | MemComponent) 4 | 5 | 6 | cdef class PhysicsComponent(MemComponent): 7 | cdef Body _body 8 | cdef list _shapes 9 | cdef str _shape_type 10 | 11 | ctypedef struct PhysicsStruct: 12 | unsigned int entity_id 13 | cpBody* body 14 | 15 | 16 | cdef class CymunkPhysics(StaticMemGameSystem): 17 | cdef Space space 18 | cdef list bb_query_result 19 | cdef list on_screen_result 20 | cdef list segment_query_result 21 | cdef int collision_type_count 22 | cdef dict collision_type_index 23 | 24 | cdef unsigned int _init_component(self, unsigned int component_index, 25 | unsigned int entity_id, cpBody* body, str zone_name) except -1 26 | cdef int _clear_component(self, unsigned int component_index) except 0 27 | -------------------------------------------------------------------------------- /modules/docs/index.php: -------------------------------------------------------------------------------- 1 | `_. 10 | 11 | KivEnt is a framework for building performant, dynamic real-time scenes in Kivy. While not as powerful as something like the Unreal engine or Unity3d, KivEnt is capable of creating games that handle several thousands to tens of thousands of entities, depending on what type of processing we are doing on them. You can easily have a hundreds thousand static sprites rendered in the background if they do not have any dynamic processing. At the same time, almost the entire API is accessible through Python, with a more performant cythonic API for those looking to get closer to the metal. Even without creating any cython gamesystems, you ought to be able to create games that feature up to several thousand game objects at once. 12 | 13 | The only dependency for the kivent_core module is `Kivy `_ itself. Additional modules may have other requirements, such as kivent_cymunk module being based on `Chipmunk2d `_ and its `cymunk wrapper `_. 14 | 15 | An entity-component architecture is used to control game object state and the logic of processing the game objects. This means that your game objects will be made up of collections of independent components that stricly hold data; each component corresponds to a GameSystem that will perform all data processing on the components, in the update loop each frame, and as a result of user interaction or other programmaticaly generated events. All memory for 16 | the built-in components is allocated statically: if you would like learn more 17 | about memory management, `read here `_. 18 | 19 | KivEnt is built with a modular architecture and designed to have both a python api and a c-level cython api that allows more performant access to your game data. This makes it suitable for quickly prototyping a mechanic completely in python, and relatively trivial to then deeply cythonize that GameSystem if you find it to be performance sensitive. This process has already been done for the built-in components meaning they are ready for you to build new, performant game systems on top of them. 20 | 21 | The entire framework is made available to you with an MIT license so that you have the freedom to build whatever you want on top of it and monetize it however you like. 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | 26 | gameworld 27 | entity 28 | gamesystems 29 | managers 30 | physics 31 | particles 32 | rendering 33 | memory_handlers 34 | tiled 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /modules/docs/source/managers.rst: -------------------------------------------------------------------------------- 1 | Managers 2 | ******** 3 | **Most of these Classes have cdefed functions that cannot be read by 4 | Sphinx. Read the source if you want to find out more about using them.** 5 | 6 | 7 | .. autoclass:: kivent_core.managers.entity_manager.EntityManager 8 | :members: 9 | 10 | .. autoclass:: kivent_core.managers.game_manager.GameManager 11 | 12 | System Management 13 | ================= 14 | .. automodule:: kivent_core.managers.system_manager 15 | .. autoclass:: kivent_core.managers.system_manager.ZoneConfig 16 | :members: 17 | .. autoclass:: kivent_core.managers.system_manager.SystemConfig 18 | :members: 19 | .. autoclass:: kivent_core.managers.system_manager.SystemManager 20 | :members: 21 | 22 | Resource Managers 23 | ================= 24 | Resource handling is not quite done yet so consider these sections 25 | slightly experimental and know they will probably change in the future. As of 26 | 2.1 a new ModelManager has been introduced with slightly different functionality. 27 | 28 | .. autoclass:: kivent_core.managers.resource_managers.ModelManager 29 | :members: 30 | .. autoclass:: kivent_core.managers.resource_managers.TextureManager 31 | :members: 32 | .. autoclass:: kivent_core.managers.sound_manager.SoundManager 33 | :members: 34 | .. autoclass:: kivent_core.managers.animation_manager.AnimationManager 35 | :members: 36 | -------------------------------------------------------------------------------- /modules/docs/source/memory_handlers.rst: -------------------------------------------------------------------------------- 1 | Memory Handlers 2 | *************** 3 | **Most of these Classes have cdefed functions that cannot be read by 4 | Sphinx. Read the source if you want to find out more about using them.** 5 | 6 | .. automodule:: kivent_core.memory_handlers.indexing 7 | 8 | Buffer 9 | ====== 10 | .. autoclass:: kivent_core.memory_handlers.membuffer.Buffer 11 | :members: 12 | 13 | MemoryBlock 14 | =========== 15 | .. autoclass:: kivent_core.memory_handlers.block.MemoryBlock 16 | :members: 17 | 18 | MemoryPool 19 | ========== 20 | .. autoclass:: kivent_core.memory_handlers.pool.MemoryPool 21 | :members: 22 | 23 | MemoryZone 24 | ========== 25 | .. autoclass:: kivent_core.memory_handlers.zone.MemoryZone 26 | :members: 27 | 28 | BlockZone 29 | ========= 30 | .. autoclass:: kivent_core.memory_handlers.zonedblock.BlockZone 31 | :members: 32 | 33 | ZonedBlock 34 | ========== 35 | .. autoclass:: kivent_core.memory_handlers.zonedblock.ZonedBlock 36 | :members: 37 | 38 | BlockIndex 39 | ========== 40 | .. autoclass:: kivent_core.memory_handlers.indexing.BlockIndex 41 | :members: 42 | 43 | PoolIndex 44 | ========= 45 | .. autoclass:: kivent_core.memory_handlers.indexing.PoolIndex 46 | :members: 47 | 48 | ZoneIndex 49 | ========= 50 | .. autoclass:: kivent_core.memory_handlers.indexing.ZoneIndex 51 | :members: 52 | 53 | IndexedMemoryZone 54 | ================= 55 | .. autoclass:: kivent_core.memory_handlers.indexing.IndexedMemoryZone 56 | :members: 57 | 58 | memrange 59 | ============= 60 | .. autoclass:: kivent_core.memory_handlers.utils.memrange 61 | :members: -------------------------------------------------------------------------------- /modules/docs/source/particles.rst: -------------------------------------------------------------------------------- 1 | Particles 2 | ********* 3 | The particles module can be used to easily add particle effects to your app. 4 | You will be most concerned with using the EmitterSystem module directly, 5 | but be sure you have an EmitterSystem, ParticleSystem, and ParticleRenderer. 6 | You can use the Particle Panda 2 application to produce your own effects 7 | using a graphical editor. 8 | 9 | Emitters 10 | ======== 11 | 12 | .. autoclass:: kivent_particles.emitter.EmitterSystem 13 | :members: 14 | 15 | .. autoclass:: kivent_particles.emitter.EmitterComponent 16 | :members: 17 | 18 | .. autoclass:: kivent_particles.emitter.ParticleEmitter 19 | :members: 20 | 21 | Particles 22 | ========= 23 | 24 | .. autoclass:: kivent_particles.particle.ParticleSystem 25 | :members: 26 | 27 | .. autoclass:: kivent_particles.particle.ParticleComponent 28 | :members: 29 | 30 | Renderers 31 | ========= 32 | 33 | .. autoclass:: kivent_particles.particle_renderers.ParticleRenderer 34 | :members: 35 | -------------------------------------------------------------------------------- /modules/docs/source/physics.rst: -------------------------------------------------------------------------------- 1 | The Cymunk Module 2 | ***************** 3 | **These classes have cdefed functions that cannot be read by 4 | Sphinx. Read the source if you want to find out more about using them.** 5 | 6 | This module extends the base functionality of KivEnt by integrating it with 7 | the Chipmunk2d Physics engine. This will allow you to perform complex 8 | collision detection and real-time 2d physics calculations on large numbers of 9 | entities simultaneously. 10 | 11 | Physics 12 | ======= 13 | .. autoclass:: kivent_cymunk.physics.PhysicsComponent 14 | :members: 15 | 16 | .. autoclass:: kivent_cymunk.physics.CymunkPhysics 17 | :members: 18 | 19 | 20 | Interaction 21 | =========== 22 | 23 | .. autoclass:: kivent_cymunk.interaction.CymunkTouchComponent 24 | :members: 25 | 26 | .. autoclass:: kivent_cymunk.interaction.CymunkTouchSystem 27 | :members: -------------------------------------------------------------------------------- /modules/docs/source/rendering.rst: -------------------------------------------------------------------------------- 1 | Rendering 2 | ********* 3 | **Most of these Classes have cdefed functions that cannot be read by 4 | Sphinx. Read the source if you want to find out more about using them.** 5 | 6 | 7 | VBOs 8 | ==== 9 | .. autoclass:: kivent_core.rendering.fixedvbo.FixedVBO 10 | :members: 11 | 12 | Instructions 13 | ============ 14 | .. autoclass:: kivent_core.rendering.cmesh.CMesh 15 | :members: 16 | 17 | Models 18 | ====== 19 | .. autoclass:: kivent_core.rendering.model.VertexModel 20 | :members: 21 | 22 | .. autoclass:: kivent_core.rendering.model.Vertex 23 | :members: 24 | 25 | Vertex Formats 26 | ============== 27 | .. autoclass:: kivent_core.rendering.vertex_format.KEVertexFormat 28 | :members: 29 | 30 | Frame Objects 31 | ============== 32 | .. autoclass:: kivent_core.rendering.frame_objects.FixedFrameData 33 | :members: 34 | 35 | Batching 36 | ============ 37 | .. autoclass:: kivent_core.rendering.batching.IndexedBatch 38 | :members: 39 | .. autoclass:: kivent_core.rendering.batching.BatchManager 40 | :members: -------------------------------------------------------------------------------- /modules/docs/source/tiled.rst: -------------------------------------------------------------------------------- 1 | The Maps Module 2 | *************** 3 | **These classes have cdefed functions that cannot be read by 4 | Sphinx. Read the source if you want to find out more about using them.** 5 | 6 | This module extends the base functionality of KivEnt by integrating it with 7 | the Tiled map editor. See example 14_tmx_loader for a practical demonstration 8 | of using these systems. 9 | 10 | Tiled Managers 11 | ============== 12 | If you are using the kivent_maps module, an additional manager will be 13 | available to aid in the use of Tiled's map format. 14 | 15 | .. autoclass:: kivent_maps.map_manager.MapManager 16 | :members: 17 | 18 | Systems 19 | ======= 20 | .. autoclass:: kivent_maps.map_system.MapSystem 21 | :members: 22 | 23 | .. autoclass:: kivent_maps.map_system.MapComponent 24 | :members: 25 | 26 | Utils 27 | ===== 28 | 29 | .. automodule:: kivent_maps.map_utils 30 | :members: 31 | 32 | Map Data 33 | ======== 34 | .. automodule:: kivent_maps.map_data 35 | :members: -------------------------------------------------------------------------------- /modules/maps/kivent_maps/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __VERSION__ = '1.0.0' 4 | 5 | if 'KIVENT_PREVENT_INIT' not in os.environ: 6 | pass 7 | -------------------------------------------------------------------------------- /modules/maps/kivent_maps/map_data.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.resource_managers cimport ModelManager 2 | from kivent_core.managers.animation_manager cimport AnimationManager 3 | from kivent_core.memory_handlers.block cimport MemoryBlock 4 | 5 | 6 | ctypedef struct TileStruct: 7 | void* model 8 | unsigned int texkey 9 | void* animation 10 | 11 | ctypedef struct ObjStruct: 12 | void* model 13 | unsigned int texkey 14 | unsigned int x 15 | unsigned int y 16 | 17 | cdef class LayerTile: 18 | cdef TileStruct* tile_pointer 19 | cdef ModelManager model_manager 20 | cdef AnimationManager animation_manager 21 | cdef unsigned int layer 22 | 23 | cdef class LayerObject: 24 | cdef ObjStruct* obj_pointer 25 | cdef ModelManager model_manager 26 | cdef unsigned int layer 27 | 28 | cdef class Tile: 29 | cdef TileStruct* _layers 30 | cdef ModelManager model_manager 31 | cdef AnimationManager animation_manager 32 | cdef unsigned int layer_count 33 | 34 | cdef class TileMap: 35 | cdef MemoryBlock tiles_block 36 | cdef MemoryBlock objects_block 37 | cdef ModelManager model_manager 38 | cdef AnimationManager animation_manager 39 | cdef str name 40 | cdef unsigned int size_x 41 | cdef unsigned int size_y 42 | cdef unsigned int tile_size_x 43 | cdef unsigned int tile_size_y 44 | cdef unsigned int tile_layer_count 45 | cdef unsigned int obj_layer_count 46 | cdef unsigned int object_count 47 | cdef list _z_index_map 48 | cdef list _obj_layers_index 49 | 50 | cdef class StaggeredTileMap(TileMap): 51 | cdef bint _stagger_index # True for Even, False for Odd 52 | cdef bint _stagger_axis # True for X, False for Y 53 | 54 | cdef class HexagonalTileMap(StaggeredTileMap): 55 | cdef unsigned int hex_side_length 56 | 57 | cdef class IsometricTileMap(TileMap): 58 | pass 59 | 60 | -------------------------------------------------------------------------------- /modules/maps/kivent_maps/map_manager.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.managers.resource_managers cimport ModelManager 2 | from kivent_core.managers.animation_manager cimport AnimationManager 3 | from kivent_core.managers.game_manager cimport GameManager 4 | from kivent_core.memory_handlers.block cimport MemoryBlock 5 | 6 | 7 | cdef class MapManager(GameManager): 8 | cdef MemoryBlock maps_block 9 | cdef ModelManager model_manager 10 | cdef AnimationManager animation_manager 11 | cdef unsigned int allocation_size 12 | cdef dict _maps 13 | -------------------------------------------------------------------------------- /modules/maps/kivent_maps/map_system.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | 3 | 4 | ctypedef struct MapStruct: 5 | unsigned int entity_id 6 | void* tile_map 7 | unsigned int pos_x 8 | unsigned int pos_y 9 | 10 | cdef class MapComponent(MemComponent): 11 | pass 12 | 13 | cdef class MapSystem(StaticMemGameSystem): 14 | pass 15 | -------------------------------------------------------------------------------- /modules/maps/kivent_maps/map_system.pyx: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport StaticMemGameSystem, MemComponent 2 | from kivent_core.memory_handlers.zone cimport MemoryZone 3 | from kivent_core.gameworld import GameWorld 4 | from kivy.properties import (StringProperty, ObjectProperty, NumericProperty, 5 | BooleanProperty, ListProperty) 6 | from kivy.factory import Factory 7 | from kivent_maps.map_data cimport TileMap 8 | from kivent_maps.map_manager cimport MapManager 9 | 10 | 11 | cdef class MapComponent(MemComponent): 12 | ''' 13 | The component associated with MapSystem. 14 | 15 | **Attributes:** 16 | **entity_id** (unsigned int): The entity_id this component is currently 17 | associated with. Will be -1 if the component is 18 | unattached. 19 | 20 | **pos** (tuple): The coordinate position for this tile on the map. 21 | 22 | ''' 23 | property entity_id: 24 | def __get__(self): 25 | cdef MapStruct* data = self.pointer 26 | return data.entity_id 27 | 28 | property pos: 29 | def __get__(self): 30 | cdef MapStruct* data = self.pointer 31 | return (data.pos_x, data.pos_y) 32 | 33 | def __set__(self, value): 34 | cdef MapStruct* data = self.pointer 35 | data.pos_x = value[0] 36 | data.pos_y = value[1] 37 | 38 | cdef class MapSystem(StaticMemGameSystem): 39 | ''' 40 | The MapSystem manages a dynamic set of renderers used to display the 41 | various labels of the provided tilemap. It will register a new MapManager 42 | with **Gameworld.reigster_manager** that will be used to manage the various 43 | data loaded from .tmx files. Each component represents a coordinate 44 | for a tile. 45 | ''' 46 | 47 | system_id = StringProperty('tile_map') 48 | processor = BooleanProperty(True) 49 | updataeble = BooleanProperty(False) 50 | type_size = NumericProperty(sizeof(MapStruct)) 51 | component_type = ObjectProperty(MapComponent) 52 | system_names = ListProperty(['tile_map','renderer']) 53 | gameworld = ObjectProperty(None) 54 | memory_required = NumericProperty(500*1024) 55 | 56 | def on_gameworld(self, instance, value): 57 | model_manager = self.gameworld.managers["model_manager"] 58 | animation_manager = self.gameworld.managers["animation_manager"] 59 | map_manager = MapManager(model_manager, animation_manager, 60 | self.memory_required) 61 | self.gameworld.register_manager("map_manager", map_manager) 62 | 63 | def init_component(self, unsigned int component_index, 64 | unsigned int entity_id, str zone, args): 65 | model_manager = self.gameworld.managers["model_manager"] 66 | map_manager = self.gameworld.managers["map_manager"] 67 | 68 | cdef MemoryZone memory_zone = self.imz_components.memory_zone 69 | cdef MapStruct* component = ( 70 | memory_zone.get_pointer(component_index)) 71 | cdef TileMap tile_map = map_manager.maps[args['name']] 72 | 73 | component.entity_id = entity_id 74 | component.tile_map = tile_map 75 | component.pos_x = args['pos'][0] 76 | component.pos_y = args['pos'][1] 77 | 78 | 79 | Factory.register('MapSystem', cls=MapSystem) 80 | -------------------------------------------------------------------------------- /modules/particles/kivent_particles/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __VERSION__ = '1.0.0' 4 | 5 | if 'KIVENT_PREVENT_INIT' not in os.environ: 6 | from kivent_particles import particle 7 | from kivent_particles import emitter 8 | from kivent_particles import particle_renderers 9 | from kivent_particles import particle_formats 10 | -------------------------------------------------------------------------------- /modules/particles/kivent_particles/emitter.pxd: -------------------------------------------------------------------------------- 1 | from cython cimport bint 2 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 3 | MemComponent) 4 | 5 | include "particle_config.pxi" 6 | 7 | 8 | cdef class ParticleEmitter: 9 | cdef str _effect_name 10 | cdef str _texture 11 | cdef float _emit_angle_offset 12 | cdef float _emit_angle 13 | cdef float[2] _pos 14 | cdef float[2] _pos_offset 15 | cdef float _life_span 16 | cdef bint _paused 17 | cdef set active_particles 18 | cdef int _emitter_type 19 | cdef int _number_of_particles 20 | cdef int _current_particles 21 | cdef float _frame_time 22 | cdef float[2] _gravity 23 | cdef float[2] _pos_variance 24 | cdef float _start_scale 25 | cdef float _emission_rate 26 | cdef float _start_scale_variance 27 | cdef float _end_scale 28 | cdef float _end_scale_variance 29 | cdef float _emit_angle_variance 30 | cdef float _start_rotation 31 | cdef float _start_rotation_variance 32 | cdef float _end_rotation 33 | cdef float _end_rotation_variance 34 | cdef float _life_span_variance 35 | cdef float _speed 36 | cdef float _speed_variance 37 | cdef float _radial_acceleration 38 | cdef float _radial_acceleration_variance 39 | cdef float _tangential_acceleration 40 | cdef float _tangential_acceleration_variance 41 | cdef float _max_radius 42 | cdef float _max_radius_variance 43 | cdef float _min_radius 44 | cdef float _rotate_per_second 45 | cdef float _rotate_per_second_variance 46 | cdef unsigned char[4] _start_color 47 | cdef unsigned char[4] _start_color_variance 48 | cdef unsigned char[4] _end_color 49 | cdef unsigned char[4] _end_color_variance 50 | 51 | 52 | ctypedef struct EmitterStruct: 53 | unsigned int entity_id 54 | void* emitters[MAX_EMITTERS] 55 | 56 | 57 | cdef class EmitterComponent(MemComponent): 58 | cdef list _emitters 59 | 60 | 61 | cdef class EmitterSystem(StaticMemGameSystem): 62 | cdef dict _emitter_prototypes 63 | cdef list attributes_to_save 64 | cdef dict editor_fields 65 | cdef str subobject_field 66 | cdef str editor_type 67 | cdef str subobject_name_field 68 | cdef dict panels 69 | 70 | cdef int insert_effect_into_component(self, ParticleEmitter effect, 71 | EmitterComponent py_component) except -1 72 | cdef void copy_effect(self, ParticleEmitter from_emitter, 73 | ParticleEmitter to_emitter) 74 | -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | from kivent_particles.emitter cimport ParticleEmitter 4 | 5 | ctypedef struct ParticleStruct: 6 | unsigned int entity_id 7 | float current_time 8 | float total_time 9 | float[2] start_pos 10 | float[2] velocity 11 | float radial_acceleration 12 | float tangential_acceleration 13 | float emit_radius 14 | float emit_radius_delta 15 | float emit_rotation 16 | float emit_rotation_delta 17 | float rotation_delta 18 | float scale_delta 19 | void* emitter 20 | float[4] color_delta 21 | float[4] color 22 | 23 | 24 | cdef class ParticleComponent(MemComponent): 25 | pass 26 | 27 | 28 | cdef class ParticleSystem(StaticMemGameSystem): 29 | cdef list _system_names 30 | cdef unsigned int create_particle(self, ParticleEmitter emitter) except -1 -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle_config.pxi: -------------------------------------------------------------------------------- 1 | DEF MAX_EMITTERS = 8 2 | DEF EMITTER_TYPE_GRAVITY = 0 3 | DEF EMITTER_TYPE_RADIAL = 1 4 | DEF MIN_PARTICLE_SIZE = .1 -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle_formats.pxd: -------------------------------------------------------------------------------- 1 | from kivy.graphics.cgl cimport GLfloat, GLubyte 2 | 3 | 4 | ctypedef struct VertexFormat9F4UB: 5 | GLfloat[2] pos 6 | GLfloat[2] uvs 7 | GLfloat[2] center 8 | GLfloat[2] scale 9 | GLubyte[4] v_color 10 | GLfloat rotate -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle_formats.pyx: -------------------------------------------------------------------------------- 1 | from cython cimport Py_ssize_t 2 | cdef extern from "Python.h": 3 | ctypedef int Py_intptr_t 4 | from kivent_core.rendering.vertex_formats cimport format_registrar 5 | 6 | cdef VertexFormat9F4UB* tmp1 = NULL 7 | pos_offset = ((tmp1.pos) - (tmp1)) 8 | uvs_offset = ((tmp1.uvs) - (tmp1)) 9 | center_offset = ((tmp1.center) - (tmp1)) 10 | rotate_offset = ((&tmp1.rotate) - (tmp1)) 11 | scale_offset = ((tmp1.scale) - (tmp1)) 12 | color_offset = ((tmp1.v_color) - (tmp1)) 13 | 14 | vertex_format_9f4ub = [ 15 | (b'pos', 2, b'float', pos_offset, False), 16 | (b'uvs', 2, b'float', uvs_offset, False), 17 | (b'center', 2, b'float', center_offset, False), 18 | (b'rotate', 1, b'float', rotate_offset, False), 19 | (b'scale', 2, b'float', scale_offset, False), 20 | (b'v_color', 4, b'ubyte', color_offset, True), 21 | ] 22 | 23 | format_registrar.register_vertex_format('vertex_format_9f4ub', 24 | vertex_format_9f4ub, sizeof(VertexFormat9F4UB)) -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle_math.pxi: -------------------------------------------------------------------------------- 1 | from libc.math cimport fmax, fmin, sqrt 2 | from libc.stdlib cimport rand, RAND_MAX 3 | from libc.math cimport sin, cos, pow 4 | 5 | DEF PI = 3.14159265358979323846 6 | 7 | cdef inline float cy_random(): 8 | return rand()/RAND_MAX 9 | 10 | 11 | cdef inline float cy_radians(float degrees): 12 | return degrees*(PI/180.0) 13 | 14 | cdef inline float cy_degrees(float radians): 15 | return radians*(180./PI) 16 | 17 | 18 | cdef inline void rotate_offset(float* offset, float angle_radians, 19 | float* output): 20 | cdef float cs = cos(angle_radians) 21 | cdef float sn = sin(angle_radians) 22 | output[0] = offset[0] * cs - offset[1] * sn 23 | output[1] = offset[0] * sn + offset[1] * cs 24 | 25 | 26 | cdef inline unsigned char char_lerp(unsigned char v0, unsigned char v1, 27 | float t): 28 | return ((1-t)*v0 + t * v1) 29 | 30 | 31 | cdef inline float random_variance(float base, float variance): 32 | return base + variance * (cy_random() * 2.0 - 1.0) 33 | 34 | 35 | cdef inline void color_delta(unsigned char* color1, unsigned char* color2, 36 | float* output, float dt): 37 | cdef int i 38 | for i in range(4): 39 | output[i] = ((color2[i] - color1[i]) / dt) 40 | 41 | 42 | cdef inline void color_variance(unsigned char* base, unsigned char* variance, 43 | unsigned char* output): 44 | cdef int i 45 | for i in range(4): 46 | output[i] = fmin(fmax(0., random_variance(base[i], 47 | variance[i])), 255.) 48 | 49 | 50 | cdef inline void color_integrate(float* current, float* delta, 51 | float* output, float dt): 52 | cdef int i 53 | for i in range(4): 54 | output[i] = fmin(fmax(0., current[i] + delta[i]*dt), 255.) 55 | 56 | 57 | cdef inline void color_copy(float* from_color, unsigned char* destination): 58 | cdef int i 59 | for i in range(4): 60 | destination[i] = from_color[i] 61 | 62 | 63 | cdef inline float calc_distance(float point_1_x, float point_1_y, 64 | float point_2_x, float point_2_y): 65 | cdef double x_dist2 = point_2_x - point_1_x 66 | cdef double y_dist2 = point_2_y - point_1_y 67 | x_dist2 *= x_dist2 68 | y_dist2 *= y_dist2 69 | return sqrt(x_dist2 + y_dist2) -------------------------------------------------------------------------------- /modules/particles/kivent_particles/particle_renderers.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.renderers cimport Renderer 2 | 3 | 4 | cdef class ParticleRenderer(Renderer): 5 | pass -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/__init__.py: -------------------------------------------------------------------------------- 1 | ''' 2 | The KivEnt Projectiles module is an experimental module that demonstrates 3 | how many of the various kivent submodules could be brought together to 4 | produce a complex system. In this case handling the basics of projectiles, 5 | collision logic, and damage. The module is sparsely documented at the moment, 6 | but demonstrates how to bring the projectiles, cymunk, and core modules 7 | together to produce another cython module that makes use of C level features 8 | in all 3 modules. 9 | ''' 10 | import os 11 | 12 | __VERSION__ = '0.0.1' 13 | 14 | if 'KIVENT_PREVENT_INIT' not in os.environ: 15 | from kivent_projectiles import projectiles 16 | from kivent_projectiles import weapons 17 | from kivent_projectiles import combatstats 18 | from kivent_projectiles import weapon_ai 19 | -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/combatstats.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | 4 | ctypedef struct CombatStatsStruct: 5 | unsigned int entity_id 6 | float health 7 | float armor 8 | float max_health 9 | 10 | 11 | cdef class CombatStatsComponent(MemComponent): 12 | cdef object _destruction_callback 13 | cdef object _on_hit_callback 14 | 15 | 16 | cdef class CombatStatsSystem(StaticMemGameSystem): 17 | pass 18 | -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/projectile_config.pxi: -------------------------------------------------------------------------------- 1 | DEF NO_WEAPON = 0 2 | DEF SINGLESHOT = 1 3 | DEF MISSLE = 2 4 | DEF MULTISHOT = 3 5 | DEF CHARGE = 4 6 | 7 | DEF MAX_BARRELS = 6 8 | DEF MAX_WEAPONS = 2 -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/projectile_types.pxi: -------------------------------------------------------------------------------- 1 | DEF NO_WEAPON = 0 2 | DEF BULLET = 1 3 | DEF MISSLE = 2 4 | 5 | DEF MAX_BARRELS = 6 6 | DEF MAX_WEAPONS = 2 -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/projectiles.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | 4 | 5 | cdef class ProjectileTemplate: 6 | cdef str texture 7 | cdef str model 8 | cdef str tail_effect 9 | cdef str main_effect 10 | cdef float damage 11 | cdef float armor_pierce 12 | cdef float width 13 | cdef float height 14 | cdef float mass 15 | cdef int projectile_type 16 | cdef int collision_type 17 | cdef float speed 18 | cdef float rot_speed 19 | cdef float lifespan 20 | cdef int hit_sound 21 | cdef object destruction_callback 22 | 23 | 24 | ctypedef struct ProjectileStruct: 25 | unsigned int entity_id 26 | float damage 27 | float armor_pierce 28 | int projectile_type 29 | int main_effect 30 | int tail_effect 31 | int hit_sound 32 | unsigned int origin_entity 33 | 34 | 35 | cdef class ProjectileComponent(MemComponent): 36 | pass 37 | 38 | 39 | cdef class ProjectileSystem(StaticMemGameSystem): 40 | cdef dict projectile_templates 41 | cdef dict projectile_keys 42 | cdef dict collision_type_index 43 | cdef int projectile_count 44 | cdef unsigned int create_projectile(self, int ammo_type, tuple position, 45 | float rotation, unsigned int firing_entity) 46 | 47 | -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/weapon_ai.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | 4 | ctypedef struct WeaponAIStruct: 5 | unsigned int entity_id 6 | float line_of_sight 7 | int team 8 | bint active 9 | unsigned int target_id 10 | float cone_size 11 | 12 | cdef class WeaponAISystem(StaticMemGameSystem): 13 | pass 14 | 15 | cdef class WeaponAIComponent(MemComponent): 16 | pass -------------------------------------------------------------------------------- /modules/projectiles/kivent_projectiles/weapons.pxd: -------------------------------------------------------------------------------- 1 | from kivent_core.systems.staticmemgamesystem cimport (StaticMemGameSystem, 2 | MemComponent) 3 | from libc.stdlib cimport rand, RAND_MAX 4 | from kivent_projectiles.projectiles cimport ProjectileSystem 5 | from kivent_core.managers.sound_manager cimport SoundManager 6 | from kivent_cymunk.physics cimport PhysicsStruct 7 | include "projectile_config.pxi" 8 | 9 | 10 | ctypedef struct ProjectileWeapon: 11 | float reload_time 12 | int projectile_type 13 | int ammo_count 14 | int shot_count 15 | float spread 16 | int current_shot 17 | float shot_timer 18 | float time_between_shots 19 | float rate_of_fire 20 | int in_clip 21 | int clip_size 22 | float[MAX_BARRELS*2] barrel_offsets 23 | float projectile_width 24 | float projectile_height 25 | int barrel_count 26 | int ammo_type 27 | float accel 28 | int reload_begin_sound 29 | int reload_end_sound 30 | int fire_sound 31 | int display_name_id 32 | 33 | 34 | cdef class Weapon: 35 | cdef ProjectileWeapon *weapon_pointer 36 | 37 | 38 | cdef class WeaponTemplate: 39 | cdef ProjectileWeapon weapon_data 40 | cdef Weapon weapon 41 | 42 | 43 | ctypedef struct ProjectileWeaponStruct: 44 | unsigned int entity_id 45 | int current_weapon 46 | bint firing 47 | bint reloading 48 | float cooldown 49 | ProjectileWeapon[MAX_WEAPONS] weapons 50 | 51 | 52 | cdef class ProjectileWeaponComponent(MemComponent): 53 | pass 54 | 55 | cdef class ProjectileWeaponSystem(StaticMemGameSystem): 56 | cdef dict weapon_templates 57 | cdef list weapon_display_names 58 | cdef int weapon_count 59 | cdef void copy_template_to_weapon(self, str template_name, 60 | ProjectileWeapon *weapon) 61 | cdef void fire_projectile(self, unsigned int entity_id, float accel) 62 | cdef void handle_multi_shot(self, ProjectileWeaponStruct* system_comp, 63 | ProjectileWeapon* weapon, PhysicsStruct* physics_comp, 64 | SoundManager sound_manager, ProjectileSystem projectile_system, 65 | float dt) 66 | cdef void handle_single_shot(self, ProjectileWeaponStruct* system_comp, 67 | ProjectileWeapon* weapon, PhysicsStruct* physics_comp, 68 | SoundManager sound_manager, ProjectileSystem projectile_system, 69 | float dt) 70 | cdef void handle_missle(self, ProjectileWeaponStruct* system_comp, 71 | ProjectileWeapon* weapon, PhysicsStruct* physics_comp, 72 | SoundManager sound_manager, ProjectileSystem projectile_system, 73 | float dt) 74 | cdef void fire_missle(self, unsigned int entity_id, float accel) 75 | 76 | 77 | cdef inline float cy_random(): 78 | return rand()/RAND_MAX 79 | 80 | cdef inline float random_variance(float base, float variance): 81 | return base + variance * (cy_random() * 2.0 - 1.0) -------------------------------------------------------------------------------- /modules/recipes/kivent_core/recipe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION_kivent_core=2.1.0 4 | URL_kivent_core=https://github.com/kivy/KivEnt/archive/master.zip 5 | MD5_kivent_core= 6 | DEPS_kivent_core=(python kivy) 7 | BUILD_kivent_core=$BUILD_PATH/kivent_core/master/modules/core 8 | RECIPE_kivent_core=$RECIPES_PATH/kivent_core 9 | 10 | function prebuild_kivent_core() { 11 | true 12 | } 13 | 14 | function build_kivent_core() { 15 | cd $BUILD_kivent_core 16 | 17 | push_arm 18 | 19 | export LDSHARED="$LIBLINK" 20 | export PYTHONPATH=$BUILD_kivy/:$PYTHONPATH 21 | try find . -iname '*.pyx' -exec $CYTHON {} \; 22 | try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v 23 | try find build/lib.* -name "*.o" -exec $STRIP {} \; 24 | 25 | export PYTHONPATH=$BUILD_PATH/python-install/lib/python2.7/site-packages:$PYTHONPATH 26 | try $BUILD_hostpython/hostpython setup.py install -O2 --root=$BUILD_PATH/python-install --install-lib=lib/python2.7/site-packages 27 | 28 | unset LDSHARED 29 | pop_arm 30 | } 31 | 32 | function postbuild_kivent_core() { 33 | true 34 | } 35 | -------------------------------------------------------------------------------- /modules/recipes/kivent_cymunk/recipe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION_kivent_cymunk=1.0.0 4 | URL_kivent_cymunk=https://github.com/kivy/KivEnt/archive/master.zip 5 | MD5_kivent_cymunk= 6 | DEPS_kivent_cymunk=(python cymunk kivy kivent_core) 7 | BUILD_kivent_cymunk=$BUILD_PATH/kivent_cymunk/master/modules/cymunk 8 | RECIPE_kivent_cymunk=$RECIPES_PATH/kivent_cymunk 9 | 10 | function prebuild_kivent_cymunk() { 11 | true 12 | } 13 | 14 | function build_kivent_cymunk() { 15 | cd $BUILD_kivent_cymunk 16 | 17 | push_arm 18 | 19 | export LDSHARED="$LIBLINK" 20 | export PYTHONPATH=$BUILD_kivy/:$PYTHONPATH 21 | export PYTHONPATH=$BUILD_cymunk/:$PYTHONPATH 22 | export PYTHONPATH=$BUILD_kivent_core/:$PYTHONPATH 23 | try find . -iname 'physics.pyx' -exec $CYTHON {} \; 24 | try find . -iname 'interaction.pyx' -exec $CYTHON {} \; 25 | try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v 26 | try find build/lib.* -name "*.o" -exec $STRIP {} \; 27 | 28 | export PYTHONPATH=$BUILD_PATH/python-install/lib/python2.7/site-packages:$PYTHONPATH 29 | try $BUILD_hostpython/hostpython setup.py install -O2 --root=$BUILD_PATH/python-install --install-lib=lib/python2.7/site-packages 30 | 31 | unset LDSHARED 32 | pop_arm 33 | } 34 | 35 | function postbuild_kivent_cymunk() { 36 | true 37 | } 38 | -------------------------------------------------------------------------------- /modules/recipes/kivent_particles/recipe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION_kivent_particles=1.0.0 4 | URL_kivent_particles=https://github.com/kivy/KivEnt/archive/master.zip 5 | MD5_kivent_particles= 6 | DEPS_kivent_particles=(python kivy) 7 | BUILD_kivent_particles=$BUILD_PATH/kivent_particles/master/modules/particles 8 | RECIPE_kivent_particles=$RECIPES_PATH/kivent_particles 9 | 10 | function prebuild_kivent_particles() { 11 | true 12 | } 13 | 14 | function build_kivent_particles() { 15 | cd $BUILD_kivent_particles 16 | 17 | push_arm 18 | 19 | export LDSHARED="$LIBLINK" 20 | export PYTHONPATH=$BUILD_kivy/:$PYTHONPATH 21 | export PYTHONPATH=$BUILD_kivent_core/:$PYTHONPATH 22 | try find . -iname '*.pyx' -exec $CYTHON {} \; 23 | try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v 24 | try find build/lib.* -name "*.o" -exec $STRIP {} \; 25 | 26 | export PYTHONPATH=$BUILD_PATH/python-install/lib/python2.7/site-packages:$PYTHONPATH 27 | try $BUILD_hostpython/hostpython setup.py install -O2 --root=$BUILD_PATH/python-install --install-lib=lib/python2.7/site-packages 28 | 29 | unset LDSHARED 30 | pop_arm 31 | } 32 | 33 | function postbuild_kivent_particles() { 34 | true 35 | } 36 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Cython>=0.29.10 2 | Kivy>=1.11.1 3 | git+git://github.com/tito/cymunk 4 | -------------------------------------------------------------------------------- /scripts/install_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_CMD="python setup.py build_ext --inplace --force" 4 | INSTALL_CMD="python setup.py install" 5 | ROOT=$(pwd) 6 | 7 | function safe_cmd { 8 | "$@" 9 | if [ $? != 0 ]; then 10 | exit $? 11 | fi 12 | } 13 | 14 | function build_and_install { 15 | cd "$ROOT/$1" 16 | safe_cmd ${BUILD_CMD} 17 | safe_cmd ${INSTALL_CMD} 18 | } 19 | 20 | build_and_install modules/core 21 | build_and_install modules/cymunk 22 | build_and_install modules/particles 23 | build_and_install modules/projectiles 24 | -------------------------------------------------------------------------------- /scripts/test_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "No tests yet..." 4 | -------------------------------------------------------------------------------- /tools/appveyor/id_rsa.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/tools/appveyor/id_rsa.enc -------------------------------------------------------------------------------- /tools/appveyor/kivent-upload.sh: -------------------------------------------------------------------------------- 1 | pacman -S --noconfirm git rsync 2 | if [ ! -d "/home/appveyor/.ssh" ]; then 3 | mkdir "/home/appveyor/.ssh" 4 | fi 5 | echo -e "Host 159.203.106.198\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config 6 | cp $(cygpath -u "C:\projects\kivent\tools\appveyor\id_rsa") ~/.ssh/id_rsa 7 | rsync -avh -e "ssh -p 2458" "/c/kivent_wheels/" root@159.203.106.198:/web/downloads/appveyor/kivent 8 | -------------------------------------------------------------------------------- /website/images/bg_hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/bg_hr.png -------------------------------------------------------------------------------- /website/images/bkg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/bkg.png -------------------------------------------------------------------------------- /website/images/blacktocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/blacktocat.png -------------------------------------------------------------------------------- /website/images/icon_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/icon_download.png -------------------------------------------------------------------------------- /website/images/interaction.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/interaction.gif -------------------------------------------------------------------------------- /website/images/kiventlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/kiventlogo.png -------------------------------------------------------------------------------- /website/images/mallmap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/mallmap.gif -------------------------------------------------------------------------------- /website/images/physics.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/physics.gif -------------------------------------------------------------------------------- /website/images/sprite_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/sprite_download.png -------------------------------------------------------------------------------- /website/images/starfield.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/starfield.gif -------------------------------------------------------------------------------- /website/images/velocitymod.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kivy/kivent/e89a5b0aef9309a65b5a14132000b2bcae773416/website/images/velocitymod.gif -------------------------------------------------------------------------------- /website/javascripts/main.js: -------------------------------------------------------------------------------- 1 | console.log('This would be the main JS file.'); 2 | -------------------------------------------------------------------------------- /website/params.json: -------------------------------------------------------------------------------- 1 | {"name":"KivEnt","tagline":"Game Engine for the Kivy Framework","body":"### Welcome to GitHub Pages.\r\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:\r\n\r\n```\r\n$ cd your_repo_root/repo_name\r\n$ git fetch origin\r\n$ git checkout gh-pages\r\n```\r\n\r\nIf you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.\r\n\r\n### Designer Templates\r\nWe've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.\r\n\r\n### Rather Drive Stick?\r\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\r\n\r\n### Authors and Contributors\r\nYou can @mention a GitHub username to generate a link to their profile. The resulting `` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} --------------------------------------------------------------------------------