├── .gitignore ├── LICENSE ├── README.md ├── defrs ├── assets │ └── textures │ │ ├── auras │ │ ├── aura_blue.png │ │ └── auras.atlas │ │ └── misc │ │ ├── misc.atlas │ │ └── pearl.png ├── fonts │ ├── materials │ │ ├── pixel_font.fp │ │ ├── pixel_font.material │ │ ├── pixel_font.vp │ │ ├── pixel_font_bmfnt.fp │ │ ├── pixel_font_bmfnt.material │ │ ├── pixel_font_bmfnt.vp │ │ ├── pixel_font_toptile.fp │ │ ├── pixel_font_toptile.material │ │ └── pixel_font_toptile.vp │ └── nes_chimera │ │ ├── nes_chimera.font │ │ ├── nes_chimera.ttf │ │ ├── nes_chimera_bmfont.bmfc │ │ ├── nes_chimera_bmfont.fnt │ │ ├── nes_chimera_bmfont_0.png │ │ └── nes_chimera_bmfont_0.psd ├── gui │ ├── screen_size.go │ └── screen_size.gui ├── materials │ ├── sprite_normal.fp │ ├── sprite_normal.material │ ├── sprite_normal.vp │ ├── sprite_pixelart.fp │ ├── sprite_pixelart.material │ ├── sprite_pixelart.vp │ ├── sprite_pixelart_buffer.fp │ ├── sprite_pixelart_buffer.material │ ├── sprite_pixelart_buffer.vp │ ├── tile_map_pixelart.fp │ ├── tile_map_pixelart.material │ └── tile_map_pixelart.vp ├── particle_fx │ └── motes.particlefx ├── scripts │ ├── go_set_scale.script │ ├── handle_alt_f4.script │ └── sprite_set_tint_color.script ├── toys │ ├── idioms.lua │ ├── learn_lua.lua │ ├── rpg_hp.lua │ └── rpg_xp.lua └── utils │ ├── all_top_sorts.lua │ ├── animations.lua │ ├── api_ext.lua │ ├── astar.lua │ ├── colors.json │ ├── colors.lua │ ├── colors_extra.lua │ ├── constants.lua │ ├── deep_copy.lua │ ├── easing_equations.lua │ ├── format_time.lua │ ├── fsm.lua │ ├── heap.lua │ ├── inspect.lua │ ├── json.lua │ ├── lume.lua │ ├── mersennetwister.lua │ ├── mini_profiler.lua │ ├── mouse_helper.lua │ ├── perlin.lua │ ├── prettify.lua │ ├── random.lua │ ├── rgb_hex.lua │ ├── rng.lua │ ├── stringbuffer.lua │ ├── superstrict.lua │ ├── tables.lua │ ├── timer.lua │ ├── types.lua │ ├── uuid.lua │ └── vec2d.lua ├── examples ├── _render │ ├── custom │ │ ├── custom.render │ │ └── custom.render_script │ ├── default.display_profiles │ ├── default.render │ ├── default.render_script │ └── readme.txt ├── effects │ └── spinning_aura │ │ ├── particles.script │ │ ├── spinning_aura.collection │ │ └── spinning_aura.script ├── input │ ├── 4dir_move │ │ ├── 4dir_move.collection │ │ └── 4dir_move.script │ ├── alt_f4 │ │ └── alt_f4.collection │ ├── multitouch │ │ ├── multitouch.collection │ │ ├── multitouch.script │ │ ├── particlefx_set_tint_color.script │ │ ├── poof_1.particlefx │ │ ├── poof_2.particlefx │ │ ├── poof_3.particlefx │ │ ├── poof_4.particlefx │ │ └── poof_5.particlefx │ └── text_typing │ │ ├── text_typing.collection │ │ └── text_typing.script ├── tools │ ├── api_ext │ │ ├── api_ext.collection │ │ └── api_ext.script │ ├── colors │ │ ├── colors.collection │ │ └── colors.script │ ├── curves │ │ ├── dot.go │ │ ├── pearl.go │ │ └── pearl.script │ ├── easing_equations │ │ ├── easing_equations.collection │ │ └── easing_equations.script │ ├── html_run_code │ │ ├── html_run_code.collection │ │ ├── html_run_code.script │ │ └── index.html │ ├── ms_rng │ │ ├── ms_rng.collection │ │ └── ms_rng.script │ └── texture_dynamic_buffer │ │ ├── buffer_controller.script │ │ ├── buffer_sprite_1.atlas │ │ ├── buffer_sprite_2.atlas │ │ ├── texture_64.atlas │ │ ├── texture_64_2.png │ │ └── texture_dynamic_buffer.collection └── toys │ ├── arc_swing │ ├── arc_swing.collection │ ├── bouncer_ball.go │ ├── spacer.go │ └── swing.script │ ├── bouncer │ ├── ball.script │ ├── big_wall.collection │ ├── ground.collection │ ├── ground_gen.script │ ├── images │ │ └── logo.png │ ├── logo.atlas │ └── main_bouncer.collection │ ├── identicons │ ├── identicon_manager.script │ ├── identicon_prefab.go │ ├── identicons.collection │ ├── identicons.script │ ├── identicons.tilemap │ └── identicons.tilesource │ ├── konami_code │ ├── konami_code.collection │ ├── konami_code.script │ ├── sawsquarenoise_-_01_-_Interstellar.ogg │ ├── sawsquarenoise_-_01_-_Interstellar_LICENSE.txt │ └── victory.particlefx │ ├── minesweeper │ ├── minesweeper.collection │ ├── minesweeper.script │ ├── minesweeper_borders.tilesource │ ├── minesweeper_cells.tilemap │ ├── minesweeper_cells.tilesource │ ├── minesweeper_character.tilesource │ ├── minesweeper_numbers.tilemap │ └── minesweeper_numbers.tilesource │ ├── orbit │ ├── crosshair.script │ ├── crosshairs.png │ ├── crosshairs.pyxel │ ├── crosshairs.tilesource │ ├── exhaust.particlefx │ ├── manager.script │ ├── orb.go │ ├── orbit.collection │ ├── pixel_ship.script │ ├── pixel_ship_freemove.script │ ├── pixel_ships.png │ ├── pixel_ships.pyxel │ ├── pixel_ships.tilesource │ └── ship.script │ ├── random_level │ ├── random_level.collection │ ├── random_level.script │ └── random_level.tilemap │ ├── rpg_movement │ ├── critter_land.tilemap │ ├── critters.tilesource │ ├── player.script │ └── rpg_movement.collection │ └── shooter │ ├── level_1.tilemap │ ├── mouse_checker.script │ ├── shooter.collection │ ├── shooter_sprites.tilesource │ ├── shooter_tiles.tilesource │ └── tile_manager.script ├── game.project ├── input └── game.input_binding ├── liveupdate.settings ├── psds ├── auras.psd ├── defold.psd ├── defold2.psd └── pearl.psd ├── pyxels ├── buffer_sprite_1.png ├── buffer_sprite_1.pyxel ├── buffer_sprite_2.png ├── buffer_sprite_2.pyxel ├── critters.png ├── critters.pyxel ├── critters2.png ├── minesweeper.png ├── minesweeper.pyxel ├── pastel_tile_colors.png ├── pastel_tile_colors.pyxel ├── shooter_sprites.png ├── shooter_sprites.pyxel ├── shooter_tiles.png └── shooter_tiles.pyxel ├── target_resources ├── android │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ ├── mipmap-ldpi │ │ └── ic_launcher.png │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ └── playstore-icon.png ├── html5 │ ├── index.html │ └── todo.txt ├── ios │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-57x57@1x.png │ │ ├── Icon-App-57x57@2x.png │ │ ├── Icon-App-60x60@1x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-72x72@1x.png │ │ ├── Icon-App-72x72@2x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ ├── Icon-App-76x76@3x.png │ │ ├── Icon-App-83.5x83.5@2x.png │ │ ├── Icon-Small-50x50@1x.png │ │ └── Icon-Small-50x50@2x.png │ ├── iTunesArtwork@1x.png │ ├── iTunesArtwork@2x.png │ └── iTunesArtwork@3x.png ├── linux │ └── defold.png ├── macos │ └── defold2.icns └── windows │ └── defold.ico └── text ├── english_words_long.lua ├── english_words_medium.lua └── english_words_short.lua /.gitignore: -------------------------------------------------------------------------------- 1 | .externalToolBuilders 2 | .DS_Store 3 | .lock-wscript 4 | build 5 | *.pyc 6 | .project 7 | .cproject 8 | builtins 9 | .internal 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DefRS 2 | A collection of useful general resources made ready to be used with the Defold game engine 3 | 4 | The purpose of this resource collection is to help speed up workflows for new projects, and help new users to learn useful techniques. 5 | 6 | The license for the files included are [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) unless otherwise noted. 7 | 8 | ## Installation 9 | You can use DefRS in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add: 10 | 11 | https://github.com/subsoap/defrs/archive/master.zip 12 | 13 | Once installed, you can use the resources you wish to use from their associated folders much like you would builtin resources. When you make builds Defold will only package the files you actually use so do not worry about the extra files included. Check your build folder to see for yourself. 14 | 15 | Check the source files and examples for full usage. 16 | 17 | ## Toys 18 | * Swing of an arc (arc_swing) 19 | * Random and seed based generation of identicons 20 | * Space movement showing moving by vectors (orbit) 21 | * Classic RPG style tile movement 22 | 23 | ## Utils 24 | * Set of easy to use colors 25 | * Mersenne Twister PRNG 26 | 27 | ## Input 28 | 29 | * Handling Alt+F4 to close game on Windows 30 | * Multitouch with unique ID for each finger 31 | * Detecting the konami code or other cheat codes 32 | 33 | ## Effects 34 | 35 | * How to make a spinning spell aura in orthographic view 36 | 37 | ## Particle FX 38 | 39 | ## Helper Scripts 40 | * Set scale of GO based on properties 41 | * Set color tint of Sprite based on properties 42 | 43 | 44 | ## Templates 45 | -------------------------------------------------------------------------------- /defrs/assets/textures/auras/aura_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/assets/textures/auras/aura_blue.png -------------------------------------------------------------------------------- /defrs/assets/textures/auras/auras.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/defrs/assets/textures/auras/aura_blue.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /defrs/assets/textures/misc/misc.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/defrs/assets/textures/misc/pearl.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /defrs/assets/textures/misc/pearl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/assets/textures/misc/pearl.png -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | varying lowp vec4 var_face_color; 3 | varying lowp vec4 var_outline_color; 4 | varying lowp vec4 var_shadow_color; 5 | 6 | uniform lowp vec4 texture_size_recip; 7 | uniform lowp sampler2D texture; 8 | 9 | void main() 10 | { 11 | // Outline 12 | lowp vec2 t = texture2D(texture, var_texcoord0.xy).xy; 13 | gl_FragColor = vec4(var_face_color.xyz, 1.0) * t.x * var_face_color.w + vec4(var_outline_color.xyz * t.y * var_outline_color.w, t.y * var_outline_color.w) * (1.0 - t.x); 14 | } 15 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font.material: -------------------------------------------------------------------------------- 1 | name: "pixel_font" 2 | tags: "tile" 3 | vertex_program: "/defrs/fonts/materials/pixel_font.vp" 4 | fragment_program: "/defrs/fonts/materials/pixel_font.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | samplers { 10 | name: "texture" 11 | wrap_u: WRAP_MODE_REPEAT 12 | wrap_v: WRAP_MODE_REPEAT 13 | filter_min: FILTER_MODE_MIN_NEAREST 14 | filter_mag: FILTER_MODE_MAG_NEAREST 15 | } 16 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | varying mediump vec2 var_texcoord0; 4 | varying lowp vec4 var_face_color; 5 | varying lowp vec4 var_outline_color; 6 | 7 | // positions are in world space 8 | attribute mediump vec4 position; 9 | attribute mediump vec2 texcoord0; 10 | attribute lowp vec4 face_color; 11 | attribute lowp vec4 outline_color; 12 | attribute lowp vec4 shadow_color; 13 | 14 | void main() 15 | { 16 | var_texcoord0 = texcoord0; 17 | var_face_color = face_color; 18 | var_outline_color = outline_color; 19 | gl_Position = view_proj * vec4(position.x, position.y, position.z, 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_bmfnt.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | varying lowp vec4 var_face_color; 3 | 4 | uniform lowp vec4 texture_size_recip; 5 | uniform lowp sampler2D texture; 6 | 7 | void main() 8 | { 9 | gl_FragColor = texture2D(texture, var_texcoord0.xy) * var_face_color * var_face_color.a; 10 | } 11 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_bmfnt.material: -------------------------------------------------------------------------------- 1 | name: "font" 2 | tags: "gui" 3 | vertex_program: "/defrs/fonts/materials/pixel_font_bmfnt.vp" 4 | fragment_program: "/defrs/fonts/materials/pixel_font_bmfnt.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | samplers { 10 | name: "texture" 11 | wrap_u: WRAP_MODE_REPEAT 12 | wrap_v: WRAP_MODE_REPEAT 13 | filter_min: FILTER_MODE_MIN_NEAREST 14 | filter_mag: FILTER_MODE_MAG_NEAREST 15 | } 16 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_bmfnt.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | varying mediump vec2 var_texcoord0; 4 | varying lowp vec4 var_face_color; 5 | varying lowp vec4 var_outline_color; 6 | 7 | // positions are in world space 8 | attribute mediump vec4 position; 9 | attribute mediump vec2 texcoord0; 10 | attribute lowp vec4 face_color; 11 | attribute lowp vec4 outline_color; 12 | attribute lowp vec4 shadow_color; 13 | 14 | void main() 15 | { 16 | var_texcoord0 = texcoord0; 17 | var_face_color = face_color; 18 | gl_Position = view_proj * vec4(position.x, position.y, position.z, 1.0); 19 | } 20 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_toptile.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | varying lowp vec4 var_face_color; 3 | varying lowp vec4 var_outline_color; 4 | varying lowp vec4 var_shadow_color; 5 | 6 | uniform lowp vec4 texture_size_recip; 7 | uniform lowp sampler2D texture; 8 | 9 | void main() 10 | { 11 | // Outline 12 | lowp vec2 t = texture2D(texture, var_texcoord0.xy).xy; 13 | gl_FragColor = vec4(var_face_color.xyz, 1.0) * t.x * var_face_color.w + vec4(var_outline_color.xyz * t.y * var_outline_color.w, t.y * var_outline_color.w) * (1.0 - t.x); 14 | } 15 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_toptile.material: -------------------------------------------------------------------------------- 1 | name: "pixel_font" 2 | tags: "toptile" 3 | vertex_program: "/defrs/fonts/materials/pixel_font_toptile.vp" 4 | fragment_program: "/defrs/fonts/materials/pixel_font_toptile.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | samplers { 10 | name: "texture" 11 | wrap_u: WRAP_MODE_REPEAT 12 | wrap_v: WRAP_MODE_REPEAT 13 | filter_min: FILTER_MODE_MIN_NEAREST 14 | filter_mag: FILTER_MODE_MAG_NEAREST 15 | } 16 | -------------------------------------------------------------------------------- /defrs/fonts/materials/pixel_font_toptile.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | varying mediump vec2 var_texcoord0; 4 | varying lowp vec4 var_face_color; 5 | varying lowp vec4 var_outline_color; 6 | 7 | // positions are in world space 8 | attribute mediump vec4 position; 9 | attribute mediump vec2 texcoord0; 10 | attribute lowp vec4 face_color; 11 | attribute lowp vec4 outline_color; 12 | attribute lowp vec4 shadow_color; 13 | 14 | void main() 15 | { 16 | var_texcoord0 = texcoord0; 17 | var_face_color = face_color; 18 | var_outline_color = outline_color; 19 | gl_Position = view_proj * vec4(position.x, position.y, position.z, 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /defrs/fonts/nes_chimera/nes_chimera.font: -------------------------------------------------------------------------------- 1 | font: "/defrs/fonts/nes_chimera/nes_chimera.ttf" 2 | material: "/builtins/fonts/font.material" 3 | size: 16 4 | all_chars: true 5 | -------------------------------------------------------------------------------- /defrs/fonts/nes_chimera/nes_chimera.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/fonts/nes_chimera/nes_chimera.ttf -------------------------------------------------------------------------------- /defrs/fonts/nes_chimera/nes_chimera_bmfont.bmfc: -------------------------------------------------------------------------------- 1 | # AngelCode Bitmap Font Generator configuration file 2 | fileVersion=1 3 | 4 | # font settings 5 | fontName=NES Chimera 6 | fontFile= 7 | charSet=0 8 | fontSize=16 9 | aa=1 10 | scaleH=100 11 | useSmoothing=0 12 | isBold=0 13 | isItalic=0 14 | useUnicode=1 15 | disableBoxChars=1 16 | outputInvalidCharGlyph=0 17 | dontIncludeKerningPairs=0 18 | useHinting=1 19 | renderFromOutline=0 20 | useClearType=1 21 | 22 | # character alignment 23 | paddingDown=0 24 | paddingUp=0 25 | paddingRight=0 26 | paddingLeft=0 27 | spacingHoriz=1 28 | spacingVert=1 29 | useFixedHeight=1 30 | forceZero=0 31 | 32 | # output file 33 | outWidth=256 34 | outHeight=256 35 | outBitDepth=32 36 | fontDescFormat=0 37 | fourChnlPacked=0 38 | textureFormat=png 39 | textureCompression=0 40 | alphaChnl=0 41 | redChnl=4 42 | greenChnl=4 43 | blueChnl=4 44 | invA=0 45 | invR=0 46 | invG=0 47 | invB=0 48 | 49 | # outline 50 | outlineThickness=0 51 | 52 | # selected chars 53 | chars=32-126,161-167,169,171,176-177,183-189,191,215,247 54 | 55 | # imported icon images 56 | -------------------------------------------------------------------------------- /defrs/fonts/nes_chimera/nes_chimera_bmfont_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/fonts/nes_chimera/nes_chimera_bmfont_0.png -------------------------------------------------------------------------------- /defrs/fonts/nes_chimera/nes_chimera_bmfont_0.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/fonts/nes_chimera/nes_chimera_bmfont_0.psd -------------------------------------------------------------------------------- /defrs/gui/screen_size.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "gui" 3 | component: "/defrs/gui/screen_size.gui" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /defrs/gui/screen_size.gui: -------------------------------------------------------------------------------- 1 | script: "" 2 | background_color { 3 | x: 0.0 4 | y: 0.0 5 | z: 0.0 6 | w: 0.0 7 | } 8 | material: "/builtins/materials/gui.material" 9 | adjust_reference: ADJUST_REFERENCE_LEGACY 10 | max_nodes: 512 11 | -------------------------------------------------------------------------------- /defrs/materials/sprite_normal.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | 3 | uniform lowp sampler2D DIFFUSE_TEXTURE; 4 | uniform lowp vec4 tint; 5 | 6 | void main() 7 | { 8 | // Pre-multiply alpha since all runtime textures already are 9 | lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); 10 | gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm; 11 | } 12 | -------------------------------------------------------------------------------- /defrs/materials/sprite_normal.material: -------------------------------------------------------------------------------- 1 | name: "sprite" 2 | tags: "tile" 3 | vertex_program: "/defrs/materials/sprite_normal.vp" 4 | fragment_program: "/defrs/materials/sprite_normal.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | fragment_constants { 10 | name: "tint" 11 | type: CONSTANT_TYPE_USER 12 | value { 13 | x: 1.0 14 | y: 1.0 15 | z: 1.0 16 | w: 1.0 17 | } 18 | } 19 | samplers { 20 | name: "DIFFUSE_TEXTURE" 21 | wrap_u: WRAP_MODE_REPEAT 22 | wrap_v: WRAP_MODE_REPEAT 23 | filter_min: FILTER_MODE_MIN_LINEAR_MIPMAP_LINEAR 24 | filter_mag: FILTER_MODE_MAG_LINEAR 25 | } 26 | -------------------------------------------------------------------------------- /defrs/materials/sprite_normal.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | // positions are in world space 4 | attribute mediump vec4 position; 5 | attribute mediump vec2 texcoord0; 6 | 7 | varying mediump vec2 var_texcoord0; 8 | 9 | void main() 10 | { 11 | gl_Position = view_proj * vec4(position.xyz, 1.0); 12 | var_texcoord0 = texcoord0; 13 | } 14 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | 3 | uniform lowp sampler2D DIFFUSE_TEXTURE; 4 | uniform lowp vec4 tint; 5 | 6 | void main() 7 | { 8 | // Pre-multiply alpha since all runtime textures already are 9 | lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); 10 | gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm; 11 | } 12 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart.material: -------------------------------------------------------------------------------- 1 | name: "sprite" 2 | tags: "tile" 3 | vertex_program: "/defrs/materials/sprite_pixelart.vp" 4 | fragment_program: "/defrs/materials/sprite_pixelart.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | fragment_constants { 10 | name: "tint" 11 | type: CONSTANT_TYPE_USER 12 | value { 13 | x: 1.0 14 | y: 1.0 15 | z: 1.0 16 | w: 1.0 17 | } 18 | } 19 | samplers { 20 | name: "DIFFUSE_TEXTURE" 21 | wrap_u: WRAP_MODE_REPEAT 22 | wrap_v: WRAP_MODE_REPEAT 23 | filter_min: FILTER_MODE_MIN_LINEAR_MIPMAP_NEAREST 24 | filter_mag: FILTER_MODE_MAG_NEAREST 25 | } 26 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | // positions are in world space 4 | attribute mediump vec4 position; 5 | attribute mediump vec2 texcoord0; 6 | 7 | varying mediump vec2 var_texcoord0; 8 | 9 | void main() 10 | { 11 | gl_Position = view_proj * vec4(position.xyz, 1.0); 12 | var_texcoord0 = texcoord0; 13 | } 14 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart_buffer.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | 3 | uniform lowp sampler2D DIFFUSE_TEXTURE; 4 | uniform lowp vec4 tint; 5 | 6 | void main() 7 | { 8 | // Pre-multiply alpha since all runtime textures already are 9 | lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); 10 | gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm; 11 | } 12 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart_buffer.material: -------------------------------------------------------------------------------- 1 | name: "sprite" 2 | tags: "tile" 3 | vertex_program: "/defrs/materials/sprite_pixelart_buffer.vp" 4 | fragment_program: "/defrs/materials/sprite_pixelart_buffer.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | fragment_constants { 10 | name: "tint" 11 | type: CONSTANT_TYPE_USER 12 | value { 13 | x: 1.0 14 | y: 1.0 15 | z: 1.0 16 | w: 1.0 17 | } 18 | } 19 | samplers { 20 | name: "DIFFUSE_TEXTURE" 21 | wrap_u: WRAP_MODE_REPEAT 22 | wrap_v: WRAP_MODE_REPEAT 23 | filter_min: FILTER_MODE_MIN_NEAREST 24 | filter_mag: FILTER_MODE_MAG_NEAREST 25 | } 26 | -------------------------------------------------------------------------------- /defrs/materials/sprite_pixelart_buffer.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | 3 | // positions are in world space 4 | attribute mediump vec4 position; 5 | attribute mediump vec2 texcoord0; 6 | 7 | varying mediump vec2 var_texcoord0; 8 | 9 | void main() 10 | { 11 | gl_Position = view_proj * vec4(position.xyz, 1.0); 12 | var_texcoord0 = texcoord0; 13 | } 14 | -------------------------------------------------------------------------------- /defrs/materials/tile_map_pixelart.fp: -------------------------------------------------------------------------------- 1 | varying mediump vec2 var_texcoord0; 2 | 3 | uniform lowp sampler2D DIFFUSE_TEXTURE; 4 | uniform lowp vec4 tint; 5 | 6 | void main() 7 | { 8 | // Pre-multiply alpha since all runtime textures already are 9 | lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w); 10 | gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm; 11 | } 12 | -------------------------------------------------------------------------------- /defrs/materials/tile_map_pixelart.material: -------------------------------------------------------------------------------- 1 | name: "tile_map" 2 | tags: "tile" 3 | vertex_program: "/defrs/materials/tile_map_pixelart.vp" 4 | fragment_program: "/defrs/materials/tile_map_pixelart.fp" 5 | vertex_constants { 6 | name: "view_proj" 7 | type: CONSTANT_TYPE_VIEWPROJ 8 | } 9 | vertex_constants { 10 | name: "world" 11 | type: CONSTANT_TYPE_WORLD 12 | } 13 | fragment_constants { 14 | name: "tint" 15 | type: CONSTANT_TYPE_USER 16 | value { 17 | x: 1.0 18 | y: 1.0 19 | z: 1.0 20 | w: 1.0 21 | } 22 | } 23 | samplers { 24 | name: "DIFFUSE_TEXTURE" 25 | wrap_u: WRAP_MODE_REPEAT 26 | wrap_v: WRAP_MODE_REPEAT 27 | filter_min: FILTER_MODE_MIN_NEAREST 28 | filter_mag: FILTER_MODE_MAG_NEAREST 29 | } 30 | -------------------------------------------------------------------------------- /defrs/materials/tile_map_pixelart.vp: -------------------------------------------------------------------------------- 1 | uniform mediump mat4 view_proj; 2 | uniform mediump mat4 world; 3 | 4 | attribute mediump vec4 position; 5 | attribute mediump vec2 texcoord0; 6 | 7 | varying mediump vec2 var_texcoord0; 8 | 9 | void main() 10 | { 11 | mediump mat4 mvp = view_proj * world; 12 | gl_Position = mvp * vec4(position.xyz, 1.0); 13 | var_texcoord0 = texcoord0; 14 | } 15 | -------------------------------------------------------------------------------- /defrs/scripts/go_set_scale.script: -------------------------------------------------------------------------------- 1 | -- Add this script as a GO with a #sprite component to be able to change that 2 | -- sprite's tint shader constant from the script properties 3 | -- using a sprite other than #sprite requires a custom version of this script 4 | 5 | go.property("scale",vmath.vector3(1.0, 1.0, 1.0)) 6 | 7 | function init(self) 8 | go.set(".", "scale", self.scale) 9 | end -------------------------------------------------------------------------------- /defrs/scripts/handle_alt_f4.script: -------------------------------------------------------------------------------- 1 | -- This shows you how to detect a user pressing Alt+F4, which is a common way to force close a program on Windows 2 | -- General behavior for Alt+F4 is to be instant close without waiting for action.pressed on F4 3 | -- You may wish to instead show a dialog and let user confirm closing, but instant close is best 4 | -- Make sure you save user data properly before closing if so you'll want to make a copy of this script to customize 5 | -- If you are publishing on Windows then you want to include this as an option 6 | -- You can also detect Alt+Enter in a similar way - it is a common way to toggle fullscreen mode in Windows programs 7 | -- You can toggle between window mode and fullscreen with DefOS 8 | -- Your game.input_binding must have alt and f4 9 | --[[ 10 | key_trigger { 11 | input: KEY_LALT 12 | action: "alt" 13 | } 14 | key_trigger { 15 | input: KEY_RALT 16 | action: "alt" 17 | } 18 | key_trigger { 19 | input: KEY_F4 20 | action: "f4" 21 | } 22 | --]] 23 | 24 | 25 | function init(self) 26 | msg.post(".", "acquire_input_focus") 27 | self.alt_held_down = false 28 | self.sysinfo = sys.get_sys_info() 29 | end 30 | 31 | function on_input(self, action_id, action) 32 | if self.sysinfo.system_name == "Windows" then 33 | if action_id == hash("alt") then 34 | self.alt_held_down = true 35 | end 36 | if action_id == hash("alt") and action.released then 37 | self.alt_held_down = false 38 | end 39 | if action_id == hash("f4") and self.alt_held_down then 40 | msg.post("@system:", "exit", {code = 0}) 41 | end 42 | end 43 | end 44 | 45 | 46 | --[[ 47 | function on_input(self, action_id, action) 48 | sysinfo.system_name == "Windows" then 49 | if action_id == hash("alt") then 50 | self.alt_held_down = true 51 | print("alt held down") 52 | end 53 | if action_id == hash("alt") and action.released then 54 | self.alt_held_down = false 55 | print("releaseing alt") 56 | end 57 | if action_id == hash("f4") and self.alt_held_down then 58 | print("show confirm dialog to close game") 59 | end 60 | if action_id == hash("f4") and action.pressed then 61 | print("f4") 62 | end 63 | end 64 | end 65 | --]] -------------------------------------------------------------------------------- /defrs/scripts/sprite_set_tint_color.script: -------------------------------------------------------------------------------- 1 | -- Add this script as a GO with a #sprite component to be able to change that 2 | -- sprite's tint shader constant from the script properties 3 | -- using a sprite other than #sprite requires a custom version of this script 4 | 5 | go.property("tint",vmath.vector4(1.0, 1.0, 1.0, 1.0)) 6 | 7 | function init(self) 8 | sprite.set_constant("#sprite", "tint", self.tint) 9 | end -------------------------------------------------------------------------------- /defrs/toys/rpg_hp.lua: -------------------------------------------------------------------------------- 1 | --- apply damage randomly 2 | -- use something like Mersenne Twister for good random numbers! 3 | health = health or 100 -- total health 4 | attack = attack or {min = 0, max = 10} -- range of possible attack 5 | attack_damage = attack_damage or 0 -- init 6 | total_attacks = total_attacks or 0 -- counter 7 | _ = math.random(attack.min, attack.max) -- dispose of bad RNG 8 | -- comment out the above and see what happens! 9 | -- math.randomseed(os.time()) -- only uncomment after testing above 10 | while health >= 1 do 11 | print("Current HP: " .. health) 12 | attack_damage = math.random(attack.min, attack.max) 13 | health = health - attack_damage 14 | total_attacks = total_attacks + 1 15 | print("Attack #: " .. total_attacks) 16 | if health <= 0 then 17 | print("Dead!") 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /defrs/toys/rpg_xp.lua: -------------------------------------------------------------------------------- 1 | --- level up while gaining XP 2 | -- this for example is very similar to the way Overwatch does XP 3 | -- minus xp gain, but that's explained below 4 | player_level = 1 5 | xp_needed = 2000 6 | current_xp = 0 7 | total_xp = 0 8 | xp_gained = 0 9 | level_xp_amounts = { 10 | 2000, 3500, 5000, 6500, 7500, 8500, 9500, 10500, 11500, 12500, 11 | 13500, 14500, 15000, 16000, 16500, 17000, 17500, 18000, 18500, 12 | 19000, 20000} 13 | -- 1 to 10 -- 11 to 20 -- 21 to 22 -- all next levels = 20k too 14 | -- 22+ XP stays same to keep grind from getting out of hand 15 | -- you could use a formula to calculate XP required on the fly too 16 | -- instead of using a lookup table, which just makes it easy to tune 17 | -- some games such as Pokemon use different formulas for different Pokemon 18 | -- and different formulas for different level ranges 19 | -- http://bulbapedia.bulbagarden.net/wiki/Experience 20 | -- you should look up XP formulas for your favorites RPGS 21 | -- for example, Demon's Souls http://demonssouls.wikidot.com/stat-slvl 22 | -- also used in Dark Souls, Bloodborne, and Dark Souls 3 (Dark Souls 2 was b-team) 23 | -- xp_required = 0.02 * level^3 + 3.06 * level^2 + 105.6 * level - 895 24 | -- above formula is used for levels 12 and up, the rest are hand coded 25 | -- (test it out to see why) 26 | xp_gain_range = {min = 250, max = 500} 27 | -- just a random range for testing 28 | -- Overwatch gives 250XP per completed round + 500XP for winning 29 | -- and an extra 3.4 XP per second while in a match 30 | -- and other bonus XP for getting medals in game 31 | -- 50 XP for bronze, 100 XP for silver, 150 XP for gold 32 | -- only gives you highest medal earned in a match not for each 33 | -- consecutive match bonus 200 XP 34 | -- first win of the day bonus 1500 XP -- good excuse to play every day 35 | -- joining game in progress and finishing it 400 XP 36 | -- playing with a group +20% bonus 37 | -- Overwatch levels loops back to level 1 once player reaches level 101 38 | -- with an extra star next to name -- getting early levels fast is fun! 39 | -- learn from other games and make good progrssion systems for your project! 40 | while player_level < 100 do 41 | xp_gained = math.random(xp_gain_range.min, xp_gain_range.max) 42 | total_xp = total_xp + xp_gained 43 | current_xp = current_xp + xp_gained 44 | if current_xp >= xp_needed then 45 | current_xp = current_xp - xp_needed 46 | player_level = player_level + 1 47 | if player_level > 21 then 48 | xp_needed = 20000 49 | else 50 | xp_needed = level_xp_amounts[player_level] 51 | end 52 | end 53 | print("Current level: " .. player_level .. ", Current XP: " .. current_xp .. ", Total XP: " .. total_xp .. ", XP Needed: " .. xp_needed) 54 | end 55 | -------------------------------------------------------------------------------- /defrs/utils/all_top_sorts.lua: -------------------------------------------------------------------------------- 1 | -- all_top_sorts.lua 2 | -- public domain 3 | -- 4 | -- Generate all permutations - aka topological sorts - of 5 | -- the set [1, 2, ..., n] such that the permutation has 6 | -- certain pairs in a given order. This can also be thought 7 | -- of as listing all linear orders consistent with a given 8 | -- partial order. 9 | -- 10 | -- This code is based on chapter 3 of 11 | -- Donald Knuth's book Literate Programming. 12 | -- 13 | 14 | -- Print out all topological sorts of [1, 2, ..., n] 15 | -- consistent with a given list of ordered pairs. 16 | -- The ordered pairs are given as an array of 2-element 17 | -- arrays, each of which is a pair that will remain 18 | -- in the given order. For example: 19 | -- all_top_sorts(5, {{1, 3}, {2, 4}, {3, 2}}) 20 | function all_top_sorts(n, ordered_pairs) 21 | local larger = {} 22 | local D = {min = 1, max = 0} -- This is an empty deque. 23 | local count = {} 24 | for i = 1, n do count[i], larger[i] = 0, {} end 25 | for _, p in ipairs(ordered_pairs) do 26 | -- Add p to larger. 27 | local bigger = larger[p[1]] 28 | bigger[#bigger + 1] = p[2] 29 | larger[p[1]] = bigger 30 | 31 | -- Add p to count. 32 | count[p[2]] = count[p[2]] + 1 33 | end 34 | 35 | -- Add all maximal (nothing-smaller-than-them) elements to D. 36 | for i = 1, n do 37 | if count[i] == 0 then push_back(D, i) end 38 | end 39 | 40 | local k = 0 41 | sub_top_sorts(n, k, larger, count, D, '') 42 | end 43 | 44 | -- Functions for working with a deque. 45 | -- A deque is a table with string keys min and max such that the 46 | -- sequence is D[D.min] .. D[D.max]; making pushing and 47 | -- popping from either side easy. 48 | 49 | function push_back(D, item) 50 | D.max = D.max + 1 51 | D[D.max] = item 52 | end 53 | 54 | function pop_back(D) 55 | local val = D[D.max] 56 | D[D.max] = nil 57 | D.max = D.max - 1 58 | return val 59 | end 60 | 61 | function push_front(D, item) 62 | D.min = D.min - 1 63 | D[D.min] = item 64 | end 65 | 66 | -- sub_top_sorts is the recursive function used by 67 | -- all_top_sorts to do most of the work. 68 | -- 69 | -- These are the parameters: 70 | -- * n = Defines the set of integers being considered, [1..n]. 71 | -- * k = The number of items already printed as a prefix of 72 | -- the about-to-be-printed subset of all_top_sorts. 73 | -- * larger = A table so that larger[i] = array of items that 74 | -- will be > i. That is, i < j for each j in larger[i]. 75 | -- * count = A table so that count[i] is the number of not-yet- 76 | -- printed items that will be smaller than i. 77 | -- * D = A table containing not-yet-printed items which are not 78 | -- larger than anything else not-yet-printed. They can be 79 | -- printed at any time. D is a deque (see above). 80 | -- * indent = A string of all spaces that's useful for indenting 81 | -- subsequent suffixes for easy printing & reading. 82 | function sub_top_sorts(n, k, larger, count, D, indent) 83 | if k == n then return end 84 | local base = D[D.max] 85 | repeat 86 | 87 | local q = pop_back(D) 88 | local saved_larger_q = larger[q] 89 | for _, j in ipairs(larger[q]) do 90 | count[j] = count[j] - 1 91 | if count[j] == 0 then push_back(D, j) end 92 | end 93 | larger[q] = {} 94 | if q ~= base then io.write(indent) end 95 | io.write(q .. ' ') 96 | if k == n - 1 then io.write('\n') end 97 | sub_top_sorts(n, k + 1, larger, count, D, indent .. ' ') 98 | larger[q] = saved_larger_q 99 | for _, j in ipairs(larger[q]) do 100 | count[j] = count[j] + 1 101 | if count[j] == 1 then pop_back(D) end 102 | end 103 | push_front(D, q) 104 | until D[D.max] == base 105 | end 106 | 107 | -- Try out an example. 108 | all_top_sorts(5, {{1, 3}, {2, 1}, {2, 4}, {4, 3}, {4, 5}}) 109 | -------------------------------------------------------------------------------- /defrs/utils/api_ext.lua: -------------------------------------------------------------------------------- 1 | -- Simply require this file 2 | -- require("defrs.utils.api_ext") 3 | 4 | function sprite.play_animation(url, animation) 5 | msg.post(url, "play_animation", {id = hash(animation)}) 6 | end -------------------------------------------------------------------------------- /defrs/utils/astar.lua: -------------------------------------------------------------------------------- 1 | -- Implements the A* algorithm. 2 | -- First base of inspiration from http://www.redblobgames.com/pathfinding/a-star/implementation.html#orgheadline18 3 | 4 | local heap = require("defrs/utils/heap") 5 | 6 | local M = {} 7 | 8 | function M.manhattan_distance(x1, y1, x2, y2) 9 | local dist = math.abs(x1 - x2) + math.abs(y1 - y2) 10 | return dist 11 | end 12 | 13 | --- Finds the shortest path between the start and goal indices, given a grid and the costs for that grid 14 | -- @param grid_size A 2-tuple which is the size of the grid 15 | -- @param costs The costs for the individual tiles in the grid (where 0 is the lowest). An array which is grid_size[0]*grid_size[1] large 16 | -- @param start The start of the search. An index into the costs array 17 | -- @param goal The goal of the search. An index into the costs array 18 | -- @return A 2-tuple (came_from, cost_so_far) 19 | function M.astar_grid(grid_size, 20 | costs, 21 | start, 22 | goal) 23 | 24 | local frontier = heap() 25 | frontier:add(0, start) 26 | 27 | local came_from = {} 28 | came_from[start] = start 29 | local cost_so_far = {} 30 | cost_so_far[start] = 0 31 | 32 | local grid_width = grid_size[1] 33 | local grid_height = grid_size[2] 34 | local gx = math.floor((goal-1) % grid_width) 35 | local gy = math.floor((goal-1) / grid_width) 36 | 37 | while not frontier:empty() do 38 | prio, current = frontier:pop() 39 | 40 | if current == goal then 41 | break 42 | end 43 | 44 | -- make the coords 0 based 45 | local x = math.floor((current-1) % grid_width) 46 | local y = math.floor((current-1) / grid_width) 47 | -- step down, left, right, up 48 | local next_coords = { {x, y-1}, {x-1, y}, {x+1, y}, {x, y+1} } 49 | for i = 1, 4 do 50 | local nx = next_coords[i][1] 51 | local ny = next_coords[i][2] 52 | local next = ny * grid_width + nx 53 | 54 | if nx >= 0 and nx < grid_width and ny >= 0 and ny < grid_height then 55 | local next = ny * grid_width + nx + 1 56 | local current_cost = cost_so_far[current] 57 | local new_cost = current_cost + costs[next] 58 | local next_cost = cost_so_far[next] 59 | 60 | if next_cost == nil or new_cost < next_cost then 61 | cost_so_far[next] = new_cost 62 | local priority = new_cost + M.manhattan_distance(nx, ny, gx, gy) 63 | frontier:add(priority, next) 64 | came_from[next] = current 65 | end 66 | end 67 | end 68 | end 69 | 70 | return came_from, cost_so_far 71 | end 72 | 73 | return M 74 | -------------------------------------------------------------------------------- /defrs/utils/colors.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/defrs/utils/colors.json -------------------------------------------------------------------------------- /defrs/utils/constants.lua: -------------------------------------------------------------------------------- 1 | local superstrict = require "defrs/utils/superstrict" 2 | 3 | local M = {} 4 | 5 | -- Built-in system messages. 6 | M.EXIT = hash("exit") 7 | M.REBOOT = hash("reboot") 8 | M.SET_UPDATE_FREQUENCY = hash("set_update_frequency") 9 | M.START_RECORD = hash("start_record") 10 | M.STOP_RECORD = hash("stop_record") 11 | M.TOGGLE_PROFILE = hash("toggle_profile") 12 | 13 | -- Built-in game object messages. 14 | M.ACQUIRE_INPUT_FOCUS = hash("acquire_input_focus") 15 | M.DISABLE = hash("disable") 16 | M.ENABLE = hash("enable") 17 | M.RELEASE_INPUT_FOCUS = hash("release_input_focus") 18 | M.SET_PARENT = hash("set_parent") 19 | 20 | -- Built-in render messages. 21 | M.CLEAR_COLOR = hash("clear_color") 22 | M.DRAW_LINE = hash("draw_line") 23 | M.DRAW_TEXT = hash("draw_text") 24 | M.WINDOW_RESIZED = hash("window_resized") 25 | 26 | -- Built-in sprite messages. 27 | M.ANIMATION_DONE = hash("animation_done") 28 | M.PLAY_ANIMATION = hash("play_animation") 29 | 30 | -- Built-in sound messages. 31 | M.PLAY_SOUND = hash("play_sound") 32 | M.SET_GAIN = hash("set_gain") 33 | M.STOP_SOUND = hash("stop_sound") 34 | 35 | -- Built-in spine messages. 36 | M.SPINE_ANIMATION_DONE = hash("spine_animation_done") 37 | M.SPINE_EVENT = hash("spine_event") 38 | 39 | -- Built-in collision messages. 40 | M.APPLY_FORCE = hash("apply_force") 41 | M.COLLISION_RESPONSE = hash("collision_response") 42 | M.CONTACT_POINT_RESPONSE = hash("contact_point_response") 43 | M.RAY_CAST_RESPONSE = hash("ray_cast_response") 44 | M.TRIGGER_RESPONSE = hash("trigger_response") 45 | 46 | -- Built-in collection proxy messages. 47 | M.ASYNC_LOAD = hash("async_load") 48 | M.DISABLE = hash("disable") 49 | M.ENABLE = hash("enable") 50 | M.FINAL = hash("final") 51 | M.INIT = hash("init") 52 | M.LOAD = hash("load") 53 | M.PROXY_LOADED = hash("proxy_loaded") 54 | M.PROXY_UNLOADED = hash("proxy_unloaded") 55 | M.SET_TIME_STEP = hash("set_time_step") 56 | M.UNLOAD = hash("unload") 57 | 58 | -- Built-in camera messages. 59 | M.ACQUIRE_CAMERA_FOCUS = hash("acquire_camera_focus") 60 | M.RELEASE_CAMERA_FOCUS = hash("release_camera_focus") 61 | M.SET_CAMERA = hash("set_camera") 62 | 63 | -- Custom messages. 64 | 65 | 66 | -- IDs. 67 | 68 | 69 | -- Input. 70 | M.TOUCH = hash("touch") 71 | 72 | 73 | -- Config. 74 | 75 | 76 | -- Misc. 77 | M.LEFT_UNIT = vmath.vector3(-1, 0, 0) 78 | M.RIGHT_UNIT = vmath.vector3(1, 0, 0) 79 | M.SCREEN_WIDTH = tonumber(sys.get_config("display.width")) 80 | M.SCREEN_HEIGHT = tonumber(sys.get_config("display.height")) 81 | M.SCREEN_CENTER = vmath.vector3(M.SCREEN_WIDTH / 2, M.SCREEN_HEIGHT / 2, 0) 82 | 83 | -- Lock all the things. 84 | local locked = { 85 | M, 86 | sys, 87 | go, 88 | gui, 89 | render, 90 | crash, 91 | sprite, 92 | sound, 93 | tilemap, 94 | spine, 95 | particlefx, 96 | physics, 97 | factory, 98 | collectionfactory, 99 | iac, 100 | msg, 101 | vmath, 102 | http, 103 | image, 104 | json, 105 | zlib, 106 | iap, 107 | push, 108 | facebook 109 | } 110 | for _, t in ipairs(locked) do 111 | superstrict.lock(t) 112 | end 113 | 114 | return M 115 | -------------------------------------------------------------------------------- /defrs/utils/deep_copy.lua: -------------------------------------------------------------------------------- 1 | --- Makes a proper copy of a table 2 | -- supports meta tables and recursive structures 3 | -- why: normally variables do not hold table values but table references 4 | -- may require modification for your needs, see refs 5 | -- http://www.lua.org/pil/2.5.html 6 | -- http://lua-users.org/wiki/CopyTable 7 | -- http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value 8 | 9 | local M = {} 10 | 11 | function M.deep_copy(obj, seen) 12 | if type(obj) ~= 'table' then return obj end 13 | if seen and seen[obj] then return seen[obj] end 14 | local s = seen or {} 15 | local res = setmetatable({}, getmetatable(obj)) 16 | s[obj] = res 17 | for k, v in pairs(obj) do res[copy3(k, s)] = copy3(v, s) end 18 | return res 19 | end 20 | 21 | return M 22 | -------------------------------------------------------------------------------- /defrs/utils/format_time.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | function M.seconds_to_string(seconds) 4 | 5 | if seconds < 60 * 60 then -- MM:SS 6 | return string.format("%02d:%02d", math.floor(seconds / 60), seconds % 60 ) 7 | elseif seconds < 60 * 60 * 24 then -- HH:MM:SS 8 | return string.format("%02d:%02d:%02d", math.floor(seconds / 3600), math.floor(seconds / 60) % 60, seconds % 60) 9 | else -- DD:HH:MM:SS 10 | return string.format("%02d:%02d:%02d:%02d", math.floor(seconds / (3600 * 24)), math.floor(seconds / 3600) % 24, math.floor(seconds / 60) % 60, seconds % 60) 11 | end 12 | 13 | end 14 | 15 | return M -------------------------------------------------------------------------------- /defrs/utils/mersennetwister.lua: -------------------------------------------------------------------------------- 1 | -- Based on: 2 | -- MT19937: 32-bit Mersenne Twister by Matsumoto and Nishimura, 1998 3 | -- http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf 4 | -- https://en.wikipedia.org/wiki/Mersenne_Twister 5 | -- This work is licensed under the Creative Commons Attribution 4.0 International License. 6 | -- To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/. 7 | -- Author: Mr Doomah - with slight modifications 8 | 9 | local M = {} 10 | 11 | 12 | local w, n, m, r = 32, 624, 397, 31 13 | local a = 0x9908B0DF 14 | local u = 11 15 | local s, b = 7, 0x9D2C5680 16 | local t, c = 15, 0xEFC60000 17 | local l = 18 18 | local f = 1812433253 19 | 20 | -- Assign functions 21 | local bnot = bit.bnot 22 | local bxor = bit.bxor 23 | local band = bit.band 24 | local bor = bit.bor 25 | local rshift = bit.rshift 26 | local lshift = bit.lshift 27 | local function int32(int) -- 32 bits 28 | return band(int, 0xFFFFFFFF) 29 | end 30 | 31 | -- Create an array to store the state of the generator 32 | local MT = {} 33 | local index = n+1 34 | local lower_mask = lshift(1, r) -1 35 | local upper_mask = int32(bnot(lower_mask)) 36 | 37 | -- Initialize the generator from a seed 38 | function M.seed_mt(seed) 39 | index = n 40 | if not seed then seed = os.time() end 41 | MT[0] = int32(seed) 42 | for i = 1, n-1 do 43 | MT[i] = int32(f * bxor(MT[i-1], rshift(MT[i-1], w-2) + i)) 44 | end 45 | end 46 | 47 | -- Extract a tempered value based on MT[index] 48 | -- calling M.twist() every n numbers 49 | function M.extract_number() 50 | if index >= n then 51 | if index > n then 52 | M.seed_mt() 53 | end 54 | M.twist() 55 | end 56 | 57 | local y = MT[index] 58 | y = bxor(y, rshift(y, u)) 59 | y = bxor(y, band(lshift(y, s), b)) 60 | y = bxor(y, band(lshift(y, t), c)) 61 | y = bxor(y, rshift(y, l)) 62 | 63 | index = index+1 64 | return int32(y) 65 | end 66 | 67 | -- Generate the next n values from the series x_i 68 | function M.twist() 69 | for i = 0, n-1 do 70 | local x = bor(band(MT[i], upper_mask), band(MT[(i+1) % n], lower_mask)) 71 | local xA = rshift(x, 1) 72 | if x % 2 ~= 0 then 73 | xA = bxor(xA, a) 74 | end 75 | MT[i] = int32(bxor(MT[(i + m) % n], xA)) 76 | end 77 | index = 0 78 | end 79 | 80 | -- Function to call to get a random number 81 | function M.random(p, q) 82 | if p then 83 | if q then 84 | return p + M.extract_number() % (q - p + 1) 85 | else 86 | return 1 + M.extract_number() % p 87 | end 88 | else 89 | return M.extract_number() / 0xFFFFFFFF 90 | end 91 | end 92 | 93 | return M -------------------------------------------------------------------------------- /defrs/utils/mini_profiler.lua: -------------------------------------------------------------------------------- 1 | --- measure the speed of a section of Lua code 2 | -- call mark1, mark2, and mark3 in order. The intended use case is to either 3 | -- isolate a bottleneck - decided between the first or second interval measured 4 | -- or to get an absolute measure of the average run time of the code 5 | -- between mark1 and mark3. 6 | -- public domain 7 | 8 | local t_sum = 0 9 | local t_num = 0 10 | local t1, t2, t3 11 | local do_time = true 12 | 13 | local function mark1() 14 | if not do_time then return end 15 | t1 = os.clock() 16 | end 17 | 18 | local function mark2() 19 | if not do_time then return end 20 | t2 = os.clock() 21 | end 22 | 23 | local function mark3() 24 | if not do_time then return end 25 | t3 = os.clock() 26 | 27 | print('---') 28 | print(string.format('t1-t3 took %gs', t3 - t1)) 29 | print(string.format('t1-t2 took %gs', t2 - t1)) 30 | print(string.format('t2-t3 took %gs', t3 - t2)) 31 | 32 | t_sum = t_sum + t3 - t1 33 | t_num = t_num + 1 34 | print(string.format('avg t1-t3 is now %gs', t_sum / t_num)) 35 | end 36 | -------------------------------------------------------------------------------- /defrs/utils/mouse_helper.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.mouse_x = 0.0 4 | M.mouse_y = 0.0 5 | 6 | return M -------------------------------------------------------------------------------- /defrs/utils/perlin.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | function M.noise( x, y, z) 4 | local X = math.floor(x % 255) 5 | local Y = math.floor(y % 255) 6 | local Z = math.floor(z % 255) 7 | x = x - math.floor(x) 8 | y = y - math.floor(y) 9 | z = z - math.floor(z) 10 | local u = M.fade(x) 11 | local v = M.fade(y) 12 | local w = M.fade(z) 13 | 14 | A = p[X ]+Y 15 | AA = p[A]+Z 16 | AB = p[A+1]+Z 17 | B = p[X+1]+Y 18 | BA = p[B]+Z 19 | BB = p[B+1]+Z 20 | return M.lerp(w, M.lerp(v, M.lerp(u, M.grad(p[AA ], x , y , z ), 21 | M.grad(p[BA ], x-1, y , z )), 22 | M.lerp(u, M.grad(p[AB ], x , y-1, z ), 23 | M.grad(p[BB ], x-1, y-1, z ))), 24 | M.lerp(v, M.lerp(u, M.grad(p[AA+1], x , y , z-1 ), 25 | M.grad(p[BA+1], x-1, y , z-1 )), 26 | M.lerp(u, M.grad(p[AB+1], x , y-1, z-1 ), 27 | M.grad(p[BB+1], x-1, y-1, z-1 ))) 28 | ) 29 | end 30 | 31 | 32 | function M.fade (t) 33 | return t * t * t * (t * (t * 6 - 15) + 10) 34 | end 35 | 36 | 37 | function M.lerp(t,a,b) 38 | return a + t * (b - a) 39 | end 40 | 41 | 42 | function M.grad(hash,x,y,z) 43 | local h = hash % 16 44 | local u 45 | local v 46 | 47 | if (h<8) then u = x else u = y end 48 | if (h<4) then v = y elseif (h==12 or h==14) then v=x else v=z end 49 | local r 50 | 51 | if ((h%2) == 0) then r=u else r=-u end 52 | if ((h%4) == 0) then r=r+v else r=r-v end 53 | return r 54 | end 55 | 56 | 57 | M.p = {} 58 | local permutation = { 151,160,137,91,90,15, 59 | 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 60 | 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 61 | 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 62 | 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 63 | 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 64 | 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 65 | 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 66 | 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 67 | 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 68 | 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 69 | 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 70 | 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 71 | } 72 | 73 | for i=0,255 do 74 | M.p[i] = permutation[i+1] 75 | M.p[256+i] = permutation[i+1] 76 | end 77 | 78 | return M -------------------------------------------------------------------------------- /defrs/utils/prettify.lua: -------------------------------------------------------------------------------- 1 | --- Module to prettify/format structured data in a way that makes it easier to 2 | -- read for a human. 3 | -- The module can currently prettify Lua tables. 4 | -- @usage 5 | -- require "prettify" 6 | -- local foo = { some = "data" } 7 | -- print(prettify(foo)) 8 | 9 | local M = {} 10 | 11 | M.indentation = " " 12 | 13 | --- Prettify a table 14 | -- @param data 15 | -- @return Prettified table 16 | function M.prettify_table(data) 17 | local encountered_tables = {} 18 | local indentation = M.indentation 19 | local current_indentation = "" 20 | local result = "" 21 | 22 | local function indent_more() 23 | current_indentation = current_indentation .. indentation 24 | end 25 | 26 | local function indent_less() 27 | current_indentation = current_indentation:sub(1, #current_indentation - #indentation) 28 | end 29 | 30 | local function add_line(line) 31 | result = result .. current_indentation .. line .. "\n" 32 | end 33 | 34 | local function format_table(value) 35 | add_line("{") 36 | indent_more() 37 | for name,data in pairs(value) do 38 | if type(name) == "string" then 39 | name = '"'..name..'"' 40 | else 41 | name = tostring(name) 42 | end 43 | local dt = type(data) 44 | if dt == "table" then 45 | if not encountered_tables[data] then 46 | encountered_tables[data] = true 47 | add_line(name .. " = [".. tostring(data) .. "]") 48 | format_table(data) 49 | else 50 | add_line(name .. " = [".. tostring(data) .. "] (Circular reference)") 51 | end 52 | elseif dt == "string" then 53 | add_line(name .. ' = "' .. tostring(data) .. '"') 54 | else 55 | add_line(name .. " = " .. tostring(data)) 56 | end 57 | end 58 | indent_less() 59 | add_line("}") 60 | end 61 | 62 | if type(data) == "table" then 63 | format_table(data) 64 | else 65 | result = tostring(data) 66 | end 67 | return result 68 | end 69 | 70 | 71 | return setmetatable(M, { 72 | __call = function(self, ...) 73 | return M.prettify_table(...) 74 | end, 75 | }) 76 | -------------------------------------------------------------------------------- /defrs/utils/random.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | -- Improve seeding on OSX and FreeBSD by throwing away the high part of time, 4 | -- then reversing the digits so the least significant part makes the biggest 5 | -- change. 6 | math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) 7 | 8 | function M.boolean() 9 | return math.random(0, 1) == 1 10 | end 11 | 12 | function M.angle(range) 13 | return (math.random() * range * 2) - range 14 | end 15 | 16 | function M.direction(direction, range) 17 | local angle = M.angle(range) 18 | return vmath.rotate(vmath.quat_rotation_z(angle), direction) 19 | end 20 | 21 | return M 22 | -------------------------------------------------------------------------------- /defrs/utils/rgb_hex.lua: -------------------------------------------------------------------------------- 1 | --- Convert between RGB colors and hex triplet colors 2 | -- hex value needs to be a string and should have a leading # 3 | -- RGB value can be either a string or a table 4 | -- #FFFFFF <-> 255,255,255 5 | 6 | local M = {} 7 | 8 | function M.hex_to_rgb(hex) 9 | hex = hex:gsub("#", "") -- remove the leading # symbol if there 10 | local rgb = {} 11 | rgb.r = tonumber("0x" .. hex:sub(1,2)) 12 | rgb.g = tonumber("0x" .. hex:sub(3,4)) 13 | rgb.b = tonumber("0x" .. hex:sub(5,6)) 14 | return rgb 15 | end 16 | 17 | function M.rgb_to_hex(rgb) 18 | local hex = "#" 19 | if type(rgb) == "string" then 20 | for color in rgb:gmatch("%d+") do 21 | hex = hex .. ("%X"):format(tostring(color)) 22 | end 23 | elseif type(rgb) == "table" then 24 | for _, color in pairs(rgb) do 25 | hex = hex .. ("%X"):format(tostring(color)) 26 | end 27 | end 28 | return hex 29 | end 30 | 31 | print(M.rgb_to_hex({255,255,255})) 32 | print(M.rgb_to_hex("255,255,255")) 33 | --newrgb = M.hex_to_rgb("#FFFFFF") 34 | --print(newrgb.r, newrgb.g, newrgb.b) 35 | 36 | return M 37 | -------------------------------------------------------------------------------- /defrs/utils/rng.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | -- Require this once to setup your math.rng so that it's random based on OS time 4 | -- you do not need to call M.setup_rng() yourself and generally shouldn't 5 | 6 | 7 | 8 | function M.setup_rng() 9 | math.randomseed(os.time() + math.random()) 10 | math.random(); math.random(); math.random() -- clear bad rng 11 | end 12 | 13 | function M.random(first, second) 14 | if first == nil then 15 | return math.random() 16 | elseif second == nil then 17 | return math.random(first) 18 | else 19 | return math.random(first, second) 20 | end 21 | end 22 | 23 | function M.randomseed(seed) 24 | math.randomseed(seed) 25 | end 26 | 27 | M.setup_rng() 28 | 29 | return M -------------------------------------------------------------------------------- /defrs/utils/stringbuffer.lua: -------------------------------------------------------------------------------- 1 | -- Module for efficiently building up a string. 2 | -- More efficient than repeated '..', according to PiL? 3 | -- It has probably been implemented many times, but I put this together 4 | -- from scratch because I wasn't about to go searching for extant libs. 5 | -- 6 | -- Author: J. 'KwirkyJ' Smith 7 | -- Date: 2016 8 | -- Version: 1.0.0-0 9 | -- License: MIT License 10 | 11 | 12 | 13 | local stringbuffer = {_VERSION = "1.0.0-0"} 14 | 15 | local bufferobj = {} 16 | 17 | 18 | 19 | ---(StringBuffer):add(...) 20 | -- Add strings to the end of the buffer; can be either: 21 | -- (1) one or more strings, or 22 | -- (2) a list with an optional delimiter key; 23 | -- first non-string element in the sequence terminates addition; 24 | -- if provided table has a suffix, then its suffix is add after each element 25 | -- added from that list; 26 | -- if the StringBuffer object has a suffix set that is not '', then 27 | -- its suffix is appended at the end of all additions made by the call. 28 | -- @param ... One or more {Strings} 29 | -- or a {Table} indexed (1..n) with optional ['suffix']. 30 | stringbuffer.add = function(bufferobj, ...) 31 | local list, suffix, len 32 | list = {...} 33 | if type(list[1]) == 'table' then 34 | list = list[1] 35 | end 36 | suffix = list['suffix'] 37 | len = #bufferobj[1] 38 | for i=1, #list do 39 | if type(list[i]) ~= 'string' then break end 40 | len = len+1 41 | bufferobj[1][len] = list[i] 42 | if suffix then 43 | len = len+1 44 | bufferobj[1][len] = suffix 45 | end 46 | end 47 | --if suffix then 48 | -- bufferobj[1][#bufferobj[1]] = nil 49 | --end 50 | if bufferobj[2] and bufferobj[2] ~= '' then 51 | bufferobj[1][#bufferobj[1]+1] = bufferobj[2] 52 | end 53 | end 54 | 55 | ---(StringBuffer):getString() 56 | -- Convert the buffer to a string literal. 57 | -- @return {String} 58 | stringbuffer.getString = function(bufferobj) 59 | return table.concat(bufferobj[1]) 60 | end 61 | 62 | ---(StringBuffer):setSuffix(s) 63 | -- Set a string to be appended at end of each add() call. 64 | -- @param s {String} (default '') 65 | -- @error Raised iff provided suffix is not a string. 66 | stringbuffer.setSuffix = function(bufferobj, s) 67 | s = s or '' 68 | assert(type(s) == 'string', 'suffix must be string but was '.. type(string)) 69 | bufferobj[2] = s 70 | end 71 | 72 | 73 | 74 | ---StringBuffer.new([suffix]) 75 | -- Get a new StringBuffer table/object. 76 | -- @param suffix {String} Optional string to add at the end of each add() call. 77 | -- @error Raised if suffix is not a string or nil. 78 | -- @return {StringBuffer} 79 | stringbuffer.new = function(suffix) 80 | suffix = suffix or '' 81 | assert(type(suffix) == 'string', 'suffix must be string but was '.. type(suffix)) 82 | 83 | return {[1] = {}, 84 | [2] = suffix, 85 | add = stringbuffer.add, 86 | getString = stringbuffer.getString, 87 | setSuffix = stringbuffer.setSuffix, 88 | } 89 | end 90 | 91 | 92 | 93 | return stringbuffer 94 | -------------------------------------------------------------------------------- /defrs/utils/superstrict.lua: -------------------------------------------------------------------------------- 1 | -- Protect error function from modification. 2 | local _error = error 3 | 4 | local M = {} 5 | 6 | local function lock_newindex(t, n) 7 | _error("attempting to write value to '" .. n .. "' in locked table [" .. tostring(t) .. "]", 2) 8 | end 9 | 10 | local function lock_index(t, n) 11 | _error("attempting to read undefined value '" .. n .. "' in locked table [" .. tostring(t) .. "]", 2) 12 | end 13 | 14 | function M.lock(t) 15 | assert(t, "missing table to lock") 16 | local mt = getmetatable(t) or {} 17 | mt.__newindex = lock_newindex 18 | mt.__index = lock_index 19 | setmetatable(t, mt) 20 | end 21 | 22 | function M.unlock(t) 23 | assert(t, "missing table to unlock") 24 | local mt = getmetatable(t) or {} 25 | mt.__newindex = rawset 26 | mt.__index = rawget 27 | setmetatable(t, mt) 28 | end 29 | 30 | return M -------------------------------------------------------------------------------- /defrs/utils/timer.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | local timers = {} 4 | 5 | function M.frames(frames, callback) 6 | if frames == 0 then 7 | callback() 8 | else 9 | table.insert(timers, {frames = frames, callback = callback}) 10 | end 11 | end 12 | 13 | function M.seconds(seconds, callback) 14 | table.insert(timers, {seconds = seconds, callback = callback}) 15 | end 16 | 17 | function M.cancel_all() 18 | timers = {} 19 | end 20 | 21 | function M.update(dt) 22 | for k, timer in pairs(timers) do 23 | if timer.frames then 24 | timer.frames = timer.frames - 1 25 | if timer.frames <= 0 then 26 | timers[k] = nil 27 | timer.callback() 28 | end 29 | elseif timer.seconds then 30 | timer.seconds = timer.seconds - dt 31 | if timer.seconds <= 0 then 32 | timers[k] = nil 33 | timer.callback() 34 | end 35 | end 36 | end 37 | end 38 | 39 | return M 40 | -------------------------------------------------------------------------------- /defrs/utils/types.lua: -------------------------------------------------------------------------------- 1 | local function gen_is_type(thetype) 2 | return function(k, v) return type(v or k) == thetype end 3 | end 4 | 5 | local is_nil = gen_is_type('nil') 6 | local is_function = gen_is_type('function') 7 | local is_number = gen_is_type('number' ) 8 | local is_string = gen_is_type('string' ) 9 | local is_boolean = gen_is_type('boolean' ) 10 | local is_table = gen_is_type('table' ) 11 | local is_userdata = gen_is_type('userdata') 12 | local is_thread = gen_is_type('thread' ) 13 | 14 | local function is_callable(f) 15 | if is_function(f) then return true end 16 | local mt = getmetatable(f) 17 | return mt and is_callable(mt.__call) 18 | end 19 | 20 | local function is_integer(n) 21 | return is_number(n) and math.floor(n) == n 22 | end 23 | 24 | local function is_positive(n) 25 | return is_number(n) and n >= 0 26 | end 27 | 28 | local function is_negative(n) 29 | return is_number(n) and n < 0 30 | end 31 | 32 | local function is_fundamental(v) 33 | return is_number(v) or is_boolean(v) or is_nil(v) or is_string(v) 34 | end 35 | 36 | local function is_object(o) 37 | return is_table(o) or is_userdata(o) 38 | end 39 | 40 | local function is_array(t) 41 | if not is_table(t) then return false end 42 | local i = 0 43 | for _,_ in pairs(t) do i = i + 1 end 44 | return i == #t 45 | end 46 | 47 | local function is_path(s) 48 | if not is_string(s) then return false end 49 | local path = s:match('(.-)([^\\/]-%.?([^%.\\/]*))$') 50 | return path ~= '' 51 | end 52 | 53 | local function is_relative_path(s) 54 | return #s > 1 and s:sub(1, 1) ~= '/' 55 | end 56 | 57 | local function file_exist(path) 58 | if not is_string(path) then return false end 59 | 60 | local f=io.open(path ,"r") 61 | if f~=nil then 62 | io.close(f) 63 | return true 64 | else 65 | return false 66 | end 67 | end 68 | 69 | local function is_dir(path) 70 | if not is_string(path) then return false end 71 | 72 | path = string.gsub(path, "^(.-)[\\/]?$", "%1") 73 | local f, _, code = io.open(path, "rb") 74 | 75 | if f then 76 | _, _, code = f:read("*a") 77 | f:close() 78 | if code == 21 then 79 | return true 80 | end 81 | elseif code == 13 then 82 | return true 83 | end 84 | 85 | return false 86 | end 87 | 88 | local exports = { 89 | is_nil = is_nil , 90 | is_function = is_function, 91 | is_number = is_number , 92 | is_string = is_string , 93 | is_boolean = is_boolean , 94 | is_table = is_table , 95 | is_userdata = is_userdata, 96 | is_object = is_object , 97 | is_array = is_array , 98 | is_thread = is_thread , 99 | is_callable = is_callable, 100 | is_integer = is_integer , 101 | is_positive = is_positive, 102 | is_negative = is_negative, 103 | is_fundamental = is_fundamental, 104 | 105 | is_relative_path = is_relative_path, 106 | } 107 | 108 | return exports 109 | -------------------------------------------------------------------------------- /defrs/utils/uuid.lua: -------------------------------------------------------------------------------- 1 | --- Generates UUIDs in version 4 format (randomly) only right now 2 | -- random seed is set once on module init 3 | 4 | M = {} 5 | 6 | function M.randomseed(seed) 7 | local bitsize = 32 8 | local lua_version = tonumber(_VERSION:match("%d%.*%d*")) 9 | seed = math.floor(math.abs(seed)) 10 | if seed >= (2^bitsize) then 11 | -- avoid overflow causing 1 or 0 as seed = repeated seeds 12 | seed = seed - math.floor(seed / 2^bitsize) * (2^bitsize) 13 | end 14 | if lua_version < 5.2 then 15 | -- 5.1 (incorrect) signed int 16 | math.randomseed(seed - 2^(bitsize-1)) 17 | else 18 | -- 5.2 (correct) unsigned int 19 | math.randomseed(seed) 20 | end 21 | return seed 22 | end 23 | 24 | function M.set_random_seed() 25 | M.randomseed(os.time()*10000) 26 | end 27 | 28 | function M.generate_UUID_version_4() 29 | local UUID_template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' 30 | return string.gsub(UUID_template, '[xy]', function (c) 31 | local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb) 32 | local UUID, _ = string.format('%x', v) 33 | return UUID 34 | end) 35 | end 36 | 37 | M.set_random_seed() 38 | M.dummy_UUID = M.generate_UUID_version_4() -- dump first random value 39 | 40 | 41 | --print(M.generate_UUID_version_4()) 42 | --UUID, _ = M.generate_UUID_version_4() 43 | --print(UUID) 44 | 45 | return M 46 | -------------------------------------------------------------------------------- /defrs/utils/vec2d.lua: -------------------------------------------------------------------------------- 1 | --- 2D vector library 2 | -- Intended to work with any table that contains x,y component. 3 | -- Be efficient, simple and fast, accept tables as parameters, avoid unnecessary validations. 4 | -- Assumptions on this Doc: 5 | -- -Every time "vector" refer to any table with {x,y} components. A 2D vector. 6 | --@module vec2d.lua 7 | --@author Denys Almaral (denysalmaral.com) 8 | --@license MIT 9 | --@usage vec = require('vec2d') 10 | --@usage v={x=10,y=15} 11 | -- M.add(v, M.makeFromAngle(math.pi/6)) 12 | -- M.normalize(v) 13 | -- M.rotate(v, math.pi/4) 14 | 15 | --- Module return a table with all functions 16 | local M = {} 17 | 18 | ---Returns a new vector by copy 19 | -- @param v Vector 20 | -- @return a new vector cloned 21 | function M.makeFrom(v) 22 | return {x=v.x, y=v.y} 23 | end 24 | 25 | ---Sets x,y values to vDest vector 26 | function M.set(vDest, x, y) 27 | vDest.x = x 28 | vDest.y = y 29 | end 30 | 31 | --- Copy vector v to vDest 32 | function M.setFrom(vDest, v) 33 | vDest.x = v.x 34 | vDest.y = v.y 35 | end 36 | 37 | ---Adds v to vDest, result in vDest 38 | function M.add(vDest, v) 39 | vDest.x = vDest.x + v.x 40 | vDest.y = vDest.y + v.y 41 | end 42 | 43 | ---Sums v1+v2, result in vDest 44 | function M.sum(vDest, v1, v2) 45 | vDest.x = v1.x + v2.x 46 | vDest.y = v1.y + v2.y 47 | end 48 | 49 | --- Sum v1+v2, return a new vector with the sum 50 | function M.makeSum(v1, v2) 51 | return {x = v1.x + v2.x, 52 | y = v1.y + v2.y } 53 | end 54 | 55 | --- Substract V from vDest, result in vDest 56 | function M.sub(vDest, v) 57 | vDest.x = vDest.x - v.x 58 | vDest.y = vDest.y - v.y 59 | end 60 | 61 | --- Returns new vector = (v1-v2) 62 | function M.makeSub(v1, v2) 63 | return { x = v1.x -v2.y, 64 | y = v1.y -v2.y 65 | } 66 | end 67 | 68 | --- Scale vDest multiplying by num number 69 | function M.scale(vDest, num) 70 | vDest.x = vDest.x * num 71 | vDest.y = vDest.y * num 72 | end 73 | 74 | --- Returns a new vector from V*m; where V is vector and m is a number 75 | function M.makeScale(v, num) 76 | return { x = v.x * num, 77 | y = v.y * num } 78 | end 79 | 80 | ---Returns only Z float value from vector cross product v1 X v2 81 | function M.crossProd(v1, v2) 82 | return (v1.x* v2.y- v1.y* v2.x) 83 | end 84 | 85 | ---returns number vectors dot product v1 * v2 86 | function M.dotProd(v1, v2) 87 | return (v1.x* v2.x+ v1.y* v2.y) 88 | end 89 | 90 | ---Multiply vDist by v, result in vDist 91 | function M.multiply(vDest, v) 92 | vDest.x = vDest.x * v.x 93 | vDest.y = vDest.y * v.y 94 | end 95 | 96 | ---Returns new vector multiplied v1*v2 97 | function M.makeMultiply(v1, v2) 98 | return {v1.x*v2.x, v1.y*v2.y} 99 | end 100 | 101 | ---Returns vector length float 102 | function M.length(v) 103 | return math.sqrt(v.x*v.x + v.y*v.y) 104 | end 105 | 106 | ---Returns sqr( M.length(v) ) float 107 | function M.sqLength(v) 108 | return (v.x*v.x + v.y*v.y) 109 | end 110 | 111 | ---Normalizing vDest vector 112 | function M.normalize(vDest) 113 | local tmp = 1 / M.length(vDest) 114 | vDest.x = vDest.x * tmp 115 | vDest.y = vDest.y * tmp 116 | end 117 | 118 | ---Returns new normalized vector from V 119 | function M.makeNormalized(v) 120 | local tmp = 1 / M.length(v) 121 | return { 122 | v.x * tmp, 123 | v.y * tmp 124 | } 125 | end 126 | 127 | ---Rotate vDist vector, given float angle in radiants 128 | function M.rotate(vDest, angle) 129 | vDest.x = vDest.x * math.cos(angle) - vDest.y * math.sin(angle); 130 | vDest.y = vDest.x * math.sin(angle) + vDest.y * math.cos(angle); 131 | end 132 | 133 | ---Returns new vector from V rotated by float angle 134 | function M.makeRotated(v, angle) 135 | return { 136 | x = v.x * math.cos(angle) - v.y * math.sin(angle), 137 | y = v.x * math.sin(angle) + v.y * math.cos(angle) 138 | } 139 | end 140 | 141 | ---Returns a normalized vector with float angle in radians 142 | function M.makeFromAngle( angle ) 143 | return { 144 | x = math.cos(angle), 145 | y = math.sin(angle) 146 | } 147 | end 148 | 149 | return M 150 | -------------------------------------------------------------------------------- /examples/_render/custom/custom.render: -------------------------------------------------------------------------------- 1 | script: "/examples/_render/custom/custom.render_script" 2 | -------------------------------------------------------------------------------- /examples/_render/custom/custom.render_script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | self.tile_pred = render.predicate({"tile"}) 3 | self.gui_pred = render.predicate({"gui"}) 4 | self.text_pred = render.predicate({"text"}) 5 | self.particle_pred = render.predicate({"particle"}) 6 | self.mask_pred = render.predicate({"screenfade"}) 7 | 8 | self.clear_color = vmath.vector4(0, 0, 0, 0) 9 | self.clear_color.x = sys.get_config("render.clear_color_red", 0) 10 | self.clear_color.y = sys.get_config("render.clear_color_green", 0) 11 | self.clear_color.z = sys.get_config("render.clear_color_blue", 0) 12 | self.clear_color.w = sys.get_config("render.clear_color_alpha", 0) 13 | 14 | self.stencil_mask_enabled = true 15 | self.zoom = 1 16 | 17 | self.view = vmath.matrix4() 18 | end 19 | 20 | function update(self) 21 | render.set_depth_mask(true) 22 | render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0}) 23 | 24 | local original_width = render.get_width() 25 | local original_height = render.get_height() 26 | local current_width = render.get_window_width() 27 | local current_height = render.get_window_height() 28 | 29 | render.set_viewport(0, 0, current_width, current_height) 30 | render.set_view(self.view) 31 | 32 | render.set_depth_mask(false) 33 | render.disable_state(render.STATE_DEPTH_TEST) 34 | 35 | local width = render.get_width()*self.zoom 36 | local height = render.get_height()*self.zoom 37 | render.set_projection(vmath.matrix4_orthographic(0, width, 0, height, -1, 1)) 38 | 39 | if self.stencil_mask_enabled then 40 | -- Using the simple trick from Sven's post here: https://forum.defold.com/t/making-a-flashlight/286/3 41 | -- 1. We need to disable color drawing while rendering the mask 42 | render.set_color_mask(false, false, false, false) 43 | 44 | -- 2. Enable stencil test and setup stencil mask parameters 45 | render.enable_state(render.STATE_STENCIL_TEST) 46 | render.set_stencil_func(render.COMPARE_FUNC_ALWAYS, 1, 255) 47 | render.set_stencil_op(render.STENCIL_OP_KEEP, render.STENCIL_OP_KEEP, render.STENCIL_OP_REPLACE) 48 | render.set_stencil_mask(255) 49 | 50 | -- 3. Draw the mask 51 | render.set_view(vmath.matrix4()) 52 | render.set_projection(vmath.matrix4()) 53 | render.draw(self.mask_pred) 54 | 55 | -- 4. Update the stencil function to only let pixel pass that are equal to the mask result 56 | render.set_stencil_func(render.COMPARE_FUNC_EQUAL, 1, 255) 57 | 58 | -- 5. Re-enable color drawing 59 | render.set_color_mask(true, true, true, true) 60 | end 61 | 62 | -- 6. Continue as rendering usual! :) 63 | render.enable_state(render.STATE_BLEND) 64 | render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) 65 | render.disable_state(render.STATE_CULL_FACE) 66 | 67 | -- center (and zoom out if needed) 68 | local zoom_factor = math.min(math.min(current_width / original_width, current_height / original_height), 1) / self.zoom 69 | local projected_width = current_width / zoom_factor 70 | local projected_height = current_height / zoom_factor 71 | 72 | 73 | render.set_projection(vmath.matrix4_orthographic(0, projected_width, 0, projected_height, -1, 1)) 74 | 75 | -- Render the scene 76 | render.draw(self.tile_pred) 77 | render.draw(self.particle_pred) 78 | render.draw_debug3d() 79 | 80 | render.set_view(vmath.matrix4()) 81 | render.set_projection(vmath.matrix4_orthographic(0, width, 0, height, -1, 1)) 82 | 83 | render.enable_state(render.STATE_STENCIL_TEST) 84 | render.draw(self.gui_pred) 85 | render.draw(self.text_pred) 86 | render.disable_state(render.STATE_STENCIL_TEST) 87 | 88 | render.set_depth_mask(false) 89 | render.draw_debug2d() 90 | end 91 | 92 | function on_message(self, message_id, message) 93 | if message_id == hash("clear_color") then 94 | self.clear_color = message.color 95 | elseif message_id == hash("set_view_projection") then 96 | self.view = message.view 97 | elseif message_id == hash("disable_stencil_mask") then 98 | self.stencil_mask_enabled = false 99 | elseif message_id == hash("enable_stencil_mask") then 100 | self.stencil_mask_enabled = true 101 | elseif message_id == hash("zoom") then 102 | self.zoom = message.zoom 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /examples/_render/default.display_profiles: -------------------------------------------------------------------------------- 1 | profiles { 2 | name: "Landscape" 3 | qualifiers { 4 | width: 1280 5 | height: 720 6 | } 7 | } 8 | profiles { 9 | name: "Portrait" 10 | qualifiers { 11 | width: 720 12 | height: 1280 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/_render/default.render: -------------------------------------------------------------------------------- 1 | script: "/examples/_render/default.render_script" 2 | -------------------------------------------------------------------------------- /examples/_render/default.render_script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | self.tile_pred = render.predicate({"tile"}) 3 | self.gui_pred = render.predicate({"gui"}) 4 | self.text_pred = render.predicate({"text"}) 5 | self.particle_pred = render.predicate({"particle"}) 6 | 7 | self.clear_color = vmath.vector4(0, 0, 0, 0) 8 | self.clear_color.x = sys.get_config("render.clear_color_red", 0) 9 | self.clear_color.y = sys.get_config("render.clear_color_green", 0) 10 | self.clear_color.z = sys.get_config("render.clear_color_blue", 0) 11 | self.clear_color.w = sys.get_config("render.clear_color_alpha", 0) 12 | 13 | self.view = vmath.matrix4() 14 | end 15 | 16 | function update(self) 17 | render.set_depth_mask(true) 18 | render.set_stencil_mask(0xff) 19 | render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0}) 20 | 21 | render.set_viewport(0, 0, render.get_window_width(), render.get_window_height()) 22 | render.set_view(self.view) 23 | 24 | render.set_depth_mask(false) 25 | render.disable_state(render.STATE_DEPTH_TEST) 26 | render.disable_state(render.STATE_STENCIL_TEST) 27 | render.enable_state(render.STATE_BLEND) 28 | render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) 29 | render.disable_state(render.STATE_CULL_FACE) 30 | 31 | render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1000, 1000)) 32 | 33 | render.draw(self.tile_pred) 34 | render.draw(self.particle_pred) 35 | render.draw_debug3d() 36 | 37 | render.set_view(vmath.matrix4()) 38 | render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1)) 39 | 40 | render.enable_state(render.STATE_STENCIL_TEST) 41 | render.draw(self.gui_pred) 42 | render.draw(self.text_pred) 43 | render.disable_state(render.STATE_STENCIL_TEST) 44 | 45 | render.set_depth_mask(false) 46 | render.draw_debug2d() 47 | end 48 | 49 | function on_message(self, message_id, message) 50 | if message_id == hash("clear_color") then 51 | self.clear_color = message.color 52 | elseif message_id == hash("set_view_projection") then 53 | self.view = message.view 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /examples/_render/readme.txt: -------------------------------------------------------------------------------- 1 | The only thing this custom render script does is increase the render near/far range from -1 - 1 to -1000 to 1000 for general uses. -------------------------------------------------------------------------------- /examples/effects/spinning_aura/particles.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | particlefx.play("#particlefx") 3 | 4 | end 5 | -------------------------------------------------------------------------------- /examples/effects/spinning_aura/spinning_aura.script: -------------------------------------------------------------------------------- 1 | go.property("speed",2.5) 2 | 3 | function init(self) 4 | go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, go.get("#script", "speed")) 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /examples/input/4dir_move/4dir_move.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"script\"\n" 7 | " component: \"/examples/input/4dir_move/4dir_move.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "embedded_components {\n" 21 | " id: \"sprite\"\n" 22 | " type: \"sprite\"\n" 23 | " data: \"tile_set: \\\"/examples/toys/bouncer/logo.atlas\\\"\\n" 24 | "default_animation: \\\"logo\\\"\\n" 25 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 26 | "blend_mode: BLEND_MODE_ALPHA\\n" 27 | "\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "" 41 | position { 42 | x: 222.059 43 | y: 185.294 44 | z: 0.0 45 | } 46 | rotation { 47 | x: 0.0 48 | y: 0.0 49 | z: 0.0 50 | w: 1.0 51 | } 52 | scale3 { 53 | x: 1.0 54 | y: 1.0 55 | z: 1.0 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/input/4dir_move/4dir_move.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | msg.post(".", "acquire_input_focus") 3 | self.direction = vmath.vector3(1,0,0) 4 | self.position = vmath.vector3(100,100,0) 5 | self.turn_speed = 0.09 6 | self.moving = false 7 | self.speed = 10 8 | go.set_position(self.position) 9 | end 10 | 11 | 12 | function update(self, dt) 13 | self.direction = vmath.normalize(self.direction) 14 | --pprint(self.direction) 15 | if self.moving == true then 16 | self.position = self.position + self.direction * self.speed 17 | go.set_position(self.position) 18 | end 19 | self.moving = false 20 | end 21 | 22 | 23 | function on_input(self, action_id, action) 24 | if action_id == hash("w") or action_id == hash("up") then 25 | self.direction.y = self.direction.y + self.turn_speed 26 | self.moving = true 27 | end 28 | if action_id == hash("a") or action_id == hash("left") then 29 | self.direction.x = self.direction.x - self.turn_speed 30 | self.moving = true 31 | end 32 | if action_id == hash("s") or action_id == hash("down") then 33 | self.direction.y = self.direction.y - self.turn_speed 34 | self.moving = true 35 | end 36 | if action_id == hash("d") or action_id == hash("right") then 37 | self.direction.x = self.direction.x + self.turn_speed 38 | self.moving = true 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /examples/input/alt_f4/alt_f4.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "input_alt_f4" 5 | data: "components {\n" 6 | " id: \"script\"\n" 7 | " component: \"/defrs/scripts/handle_alt_f4.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "embedded_components {\n" 21 | " id: \"label\"\n" 22 | " type: \"label\"\n" 23 | " data: \"size {\\n" 24 | " x: 128.0\\n" 25 | " y: 32.0\\n" 26 | " z: 0.0\\n" 27 | " w: 0.0\\n" 28 | "}\\n" 29 | "scale {\\n" 30 | " x: 1.0\\n" 31 | " y: 1.0\\n" 32 | " z: 1.0\\n" 33 | " w: 0.0\\n" 34 | "}\\n" 35 | "color {\\n" 36 | " x: 1.0\\n" 37 | " y: 1.0\\n" 38 | " z: 1.0\\n" 39 | " w: 1.0\\n" 40 | "}\\n" 41 | "outline {\\n" 42 | " x: 0.0\\n" 43 | " y: 0.0\\n" 44 | " z: 0.0\\n" 45 | " w: 1.0\\n" 46 | "}\\n" 47 | "shadow {\\n" 48 | " x: 0.0\\n" 49 | " y: 0.0\\n" 50 | " z: 0.0\\n" 51 | " w: 1.0\\n" 52 | "}\\n" 53 | "leading: 1.0\\n" 54 | "tracking: 0.0\\n" 55 | "pivot: PIVOT_CENTER\\n" 56 | "blend_mode: BLEND_MODE_ALPHA\\n" 57 | "line_break: false\\n" 58 | "text: \\\"Press Alt + F4 to instantly close!\\\"\\n" 59 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 60 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 61 | "\"\n" 62 | " position {\n" 63 | " x: 0.0\n" 64 | " y: 0.0\n" 65 | " z: 0.0\n" 66 | " }\n" 67 | " rotation {\n" 68 | " x: 0.0\n" 69 | " y: 0.0\n" 70 | " z: 0.0\n" 71 | " w: 1.0\n" 72 | " }\n" 73 | "}\n" 74 | "embedded_components {\n" 75 | " id: \"label1\"\n" 76 | " type: \"label\"\n" 77 | " data: \"size {\\n" 78 | " x: 128.0\\n" 79 | " y: 32.0\\n" 80 | " z: 0.0\\n" 81 | " w: 0.0\\n" 82 | "}\\n" 83 | "scale {\\n" 84 | " x: 1.0\\n" 85 | " y: 1.0\\n" 86 | " z: 1.0\\n" 87 | " w: 0.0\\n" 88 | "}\\n" 89 | "color {\\n" 90 | " x: 1.0\\n" 91 | " y: 1.0\\n" 92 | " z: 1.0\\n" 93 | " w: 1.0\\n" 94 | "}\\n" 95 | "outline {\\n" 96 | " x: 0.0\\n" 97 | " y: 0.0\\n" 98 | " z: 0.0\\n" 99 | " w: 1.0\\n" 100 | "}\\n" 101 | "shadow {\\n" 102 | " x: 0.0\\n" 103 | " y: 0.0\\n" 104 | " z: 0.0\\n" 105 | " w: 1.0\\n" 106 | "}\\n" 107 | "leading: 1.0\\n" 108 | "tracking: 0.0\\n" 109 | "pivot: PIVOT_CENTER\\n" 110 | "blend_mode: BLEND_MODE_ALPHA\\n" 111 | "line_break: false\\n" 112 | "text: \\\"(Windows only!)\\\"\\n" 113 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 114 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 115 | "\"\n" 116 | " position {\n" 117 | " x: 0.0\n" 118 | " y: -26.179\n" 119 | " z: 0.0\n" 120 | " }\n" 121 | " rotation {\n" 122 | " x: 0.0\n" 123 | " y: 0.0\n" 124 | " z: 0.0\n" 125 | " w: 1.0\n" 126 | " }\n" 127 | "}\n" 128 | "" 129 | position { 130 | x: 807.374 131 | y: 433.365 132 | z: 0.0 133 | } 134 | rotation { 135 | x: 0.0 136 | y: 0.0 137 | z: 0.0 138 | w: 1.0 139 | } 140 | scale3 { 141 | x: 2.0 142 | y: 2.0 143 | z: 1.0 144 | } 145 | } 146 | embedded_instances { 147 | id: "screen_size" 148 | data: "components {\n" 149 | " id: \"gui\"\n" 150 | " component: \"/defrs/gui/screen_size.gui\"\n" 151 | " position {\n" 152 | " x: 0.0\n" 153 | " y: 0.0\n" 154 | " z: 0.0\n" 155 | " }\n" 156 | " rotation {\n" 157 | " x: 0.0\n" 158 | " y: 0.0\n" 159 | " z: 0.0\n" 160 | " w: 1.0\n" 161 | " }\n" 162 | "}\n" 163 | "" 164 | position { 165 | x: 0.0 166 | y: 0.0 167 | z: 0.0 168 | } 169 | rotation { 170 | x: 0.0 171 | y: 0.0 172 | z: 0.0 173 | w: 1.0 174 | } 175 | scale3 { 176 | x: 1.0 177 | y: 1.0 178 | z: 1.0 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /examples/input/multitouch/multitouch.script: -------------------------------------------------------------------------------- 1 | local pprint = require("defrs.utils.prettify") -- normal pprint doesn't work with defcon 2 | 3 | local sysinfo = sys.get_sys_info() 4 | 5 | function init(self) 6 | msg.post(".", "acquire_input_focus") 7 | end 8 | 9 | function final(self) 10 | -- Add finalization code here 11 | -- Remove this function if not needed 12 | end 13 | 14 | function update(self, dt) 15 | 16 | 17 | -- Add update code here 18 | -- Remove this function if not needed 19 | 20 | 21 | self.multitouch_count = 0 22 | end 23 | 24 | function on_message(self, message_id, message, sender) 25 | -- Add message-handling code here 26 | -- Remove this function if not needed 27 | 28 | end 29 | 30 | 31 | function on_input(self, action_id, action) 32 | if action_id == hash("touch") and sysinfo.system_name ~= "Android" and sysinfo.system_name ~= "iPhone OS" then 33 | label.set_text("#label", "Test this on a device with a touchscreen...") 34 | local position = vmath.vector3(action.x, action.y, 0.0) 35 | go.set_position(position, "/poof_1") 36 | particlefx.play("/poof_1#particlefx") 37 | end 38 | if action_id == hash("multitouch") and action.touch ~= nil then 39 | if action_id == hash("multitouch") then print("multitouch") end 40 | for i,v in ipairs(action.touch) do 41 | 42 | if v.released == false then self.multitouch_count = self.multitouch_count + 1 end 43 | local position = vmath.vector3(v.x, v.y, 0.0) 44 | go.set_position(position, "/poof_" .. v.id + 1 ) 45 | particlefx.play("/poof_" .. v.id + 1 .. "#particlefx") 46 | print(v.id) 47 | 48 | end 49 | label.set_text("#label", "Count: " .. self.multitouch_count .. " Raw: " .. #action.touch) 50 | print(count) 51 | end 52 | 53 | --if action_id == hash("touch") then print("touch") end 54 | end 55 | 56 | --[[ 57 | function on_input(self, action_id, action) 58 | if action_id == ACTION_TOUCH then 59 | if not self.multi_touch then 60 | handle_touch(self, action) 61 | end 62 | elseif action_id == ACTION_TOUCH_MULTI then 63 | self.multi_touch = true 64 | 65 | if not self.touch_id then 66 | local touch_id = #action.touch 67 | local touch = action.touch[touch_id] 68 | if touch.pressed and gui.pick_node(self.btn_stick, touch.x, touch.y) then 69 | self.touch_id = touch_id 70 | end 71 | end 72 | if self.touch_id then 73 | local touch = action.touch[self.touch_id] 74 | if touch then 75 | handle_touch(self, touch) 76 | if touch.released then 77 | self.touch_id = nil 78 | end 79 | else 80 | self.touch_id = nil 81 | end 82 | end 83 | end 84 | end 85 | --]] 86 | 87 | 88 | function on_reload(self) 89 | -- Add reload-handling code here 90 | -- Remove this function if not needed 91 | end 92 | -------------------------------------------------------------------------------- /examples/input/multitouch/particlefx_set_tint_color.script: -------------------------------------------------------------------------------- 1 | -- only works with first emitter, make custom script if you want more 2 | 3 | go.property("particlefx_tint",vmath.vector4(1.0, 1.0, 1.0, 1.0)) 4 | 5 | function init(self) 6 | particlefx.set_constant("/poof_1#particlefx", "emitter", "tint", vmath.vector4(1, 0, 0, 1)) 7 | 8 | end -------------------------------------------------------------------------------- /examples/input/multitouch/poof_1.particlefx: -------------------------------------------------------------------------------- 1 | emitters { 2 | id: "emitter" 3 | mode: PLAY_MODE_ONCE 4 | duration: 0.01 5 | space: EMISSION_SPACE_WORLD 6 | position { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | } 11 | rotation { 12 | x: 0.0 13 | y: 0.0 14 | z: 0.0 15 | w: 1.0 16 | } 17 | tile_source: "/defrs/assets/textures/auras/auras.atlas" 18 | animation: "aura_blue" 19 | material: "/builtins/materials/particlefx.material" 20 | blend_mode: BLEND_MODE_ADD 21 | particle_orientation: PARTICLE_ORIENTATION_DEFAULT 22 | inherit_velocity: 0.0 23 | max_particle_count: 1 24 | type: EMITTER_TYPE_CIRCLE 25 | start_delay: 0.0 26 | properties { 27 | key: EMITTER_KEY_SPAWN_RATE 28 | points { 29 | x: 0.0 30 | y: 1000.0 31 | t_x: 1.0 32 | t_y: 0.0 33 | } 34 | spread: 5.0 35 | } 36 | properties { 37 | key: EMITTER_KEY_SIZE_X 38 | points { 39 | x: 0.0 40 | y: 1.0 41 | t_x: 1.0 42 | t_y: 0.0 43 | } 44 | spread: 0.0 45 | } 46 | properties { 47 | key: EMITTER_KEY_SIZE_Y 48 | points { 49 | x: 0.0 50 | y: 1.0 51 | t_x: 1.0 52 | t_y: 0.0 53 | } 54 | spread: 0.0 55 | } 56 | properties { 57 | key: EMITTER_KEY_SIZE_Z 58 | points { 59 | x: 0.0 60 | y: 0.0 61 | t_x: 1.0 62 | t_y: 0.0 63 | } 64 | spread: 0.0 65 | } 66 | properties { 67 | key: EMITTER_KEY_PARTICLE_LIFE_TIME 68 | points { 69 | x: 0.0 70 | y: 0.6 71 | t_x: 1.0 72 | t_y: 0.0 73 | } 74 | spread: 0.0 75 | } 76 | properties { 77 | key: EMITTER_KEY_PARTICLE_SPEED 78 | points { 79 | x: 0.0 80 | y: 0.0 81 | t_x: 1.0 82 | t_y: 0.0 83 | } 84 | spread: 0.0 85 | } 86 | properties { 87 | key: EMITTER_KEY_PARTICLE_SIZE 88 | points { 89 | x: 0.0 90 | y: 45.0 91 | t_x: 1.0 92 | t_y: 0.0 93 | } 94 | spread: 0.0 95 | } 96 | properties { 97 | key: EMITTER_KEY_PARTICLE_RED 98 | points { 99 | x: 0.0 100 | y: 1.0 101 | t_x: 1.0 102 | t_y: 0.0 103 | } 104 | spread: 0.0 105 | } 106 | properties { 107 | key: EMITTER_KEY_PARTICLE_GREEN 108 | points { 109 | x: 0.0 110 | y: 1.0 111 | t_x: 1.0 112 | t_y: 0.0 113 | } 114 | spread: 0.0 115 | } 116 | properties { 117 | key: EMITTER_KEY_PARTICLE_BLUE 118 | points { 119 | x: 0.0 120 | y: 1.0 121 | t_x: 1.0 122 | t_y: 0.0 123 | } 124 | spread: 0.0 125 | } 126 | properties { 127 | key: EMITTER_KEY_PARTICLE_ALPHA 128 | points { 129 | x: 0.0 130 | y: 1.0 131 | t_x: 1.0 132 | t_y: 0.0 133 | } 134 | spread: 0.0 135 | } 136 | properties { 137 | key: EMITTER_KEY_PARTICLE_ROTATION 138 | points { 139 | x: 0.0 140 | y: 270.0 141 | t_x: 1.0 142 | t_y: 0.0 143 | } 144 | spread: 150.0 145 | } 146 | particle_properties { 147 | key: PARTICLE_KEY_SCALE 148 | points { 149 | x: 0.0 150 | y: 5.5367913 151 | t_x: 1.0 152 | t_y: 0.0 153 | } 154 | points { 155 | x: 1.0 156 | y: 0.3382353 157 | t_x: 0.10644245 158 | t_y: -0.99431884 159 | } 160 | } 161 | particle_properties { 162 | key: PARTICLE_KEY_RED 163 | points { 164 | x: 0.0 165 | y: 1.0 166 | t_x: 1.0 167 | t_y: 0.0 168 | } 169 | } 170 | particle_properties { 171 | key: PARTICLE_KEY_GREEN 172 | points { 173 | x: 0.0 174 | y: 1.0 175 | t_x: 1.0 176 | t_y: 0.0 177 | } 178 | } 179 | particle_properties { 180 | key: PARTICLE_KEY_BLUE 181 | points { 182 | x: 0.0 183 | y: 1.0 184 | t_x: 1.0 185 | t_y: 0.0 186 | } 187 | } 188 | particle_properties { 189 | key: PARTICLE_KEY_ALPHA 190 | points { 191 | x: 0.0 192 | y: 4.5487366 193 | t_x: 0.07194582 194 | t_y: 0.99740857 195 | } 196 | points { 197 | x: 0.7144144 198 | y: 1.1552035 199 | t_x: 0.30401823 200 | t_y: 0.9526662 201 | } 202 | points { 203 | x: 1.0 204 | y: 0.0 205 | t_x: 0.31981352 206 | t_y: -0.9474805 207 | } 208 | } 209 | particle_properties { 210 | key: PARTICLE_KEY_ROTATION 211 | points { 212 | x: 0.0 213 | y: 0.0 214 | t_x: 1.0 215 | t_y: 0.0 216 | } 217 | } 218 | size_mode: SIZE_MODE_MANUAL 219 | } 220 | -------------------------------------------------------------------------------- /examples/input/multitouch/poof_2.particlefx: -------------------------------------------------------------------------------- 1 | emitters { 2 | id: "emitter" 3 | mode: PLAY_MODE_ONCE 4 | duration: 0.01 5 | space: EMISSION_SPACE_WORLD 6 | position { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | } 11 | rotation { 12 | x: 0.0 13 | y: 0.0 14 | z: 0.0 15 | w: 1.0 16 | } 17 | tile_source: "/defrs/assets/textures/auras/auras.atlas" 18 | animation: "aura_blue" 19 | material: "/builtins/materials/particlefx.material" 20 | blend_mode: BLEND_MODE_ADD 21 | particle_orientation: PARTICLE_ORIENTATION_DEFAULT 22 | inherit_velocity: 0.0 23 | max_particle_count: 1 24 | type: EMITTER_TYPE_CIRCLE 25 | start_delay: 0.0 26 | properties { 27 | key: EMITTER_KEY_SPAWN_RATE 28 | points { 29 | x: 0.0 30 | y: 1000.0 31 | t_x: 1.0 32 | t_y: 0.0 33 | } 34 | spread: 5.0 35 | } 36 | properties { 37 | key: EMITTER_KEY_SIZE_X 38 | points { 39 | x: 0.0 40 | y: 1.0 41 | t_x: 1.0 42 | t_y: 0.0 43 | } 44 | spread: 0.0 45 | } 46 | properties { 47 | key: EMITTER_KEY_SIZE_Y 48 | points { 49 | x: 0.0 50 | y: 1.0 51 | t_x: 1.0 52 | t_y: 0.0 53 | } 54 | spread: 0.0 55 | } 56 | properties { 57 | key: EMITTER_KEY_SIZE_Z 58 | points { 59 | x: 0.0 60 | y: 0.0 61 | t_x: 1.0 62 | t_y: 0.0 63 | } 64 | spread: 0.0 65 | } 66 | properties { 67 | key: EMITTER_KEY_PARTICLE_LIFE_TIME 68 | points { 69 | x: 0.0 70 | y: 0.6 71 | t_x: 1.0 72 | t_y: 0.0 73 | } 74 | spread: 0.0 75 | } 76 | properties { 77 | key: EMITTER_KEY_PARTICLE_SPEED 78 | points { 79 | x: 0.0 80 | y: 0.0 81 | t_x: 1.0 82 | t_y: 0.0 83 | } 84 | spread: 0.0 85 | } 86 | properties { 87 | key: EMITTER_KEY_PARTICLE_SIZE 88 | points { 89 | x: 0.0 90 | y: 45.0 91 | t_x: 1.0 92 | t_y: 0.0 93 | } 94 | spread: 0.0 95 | } 96 | properties { 97 | key: EMITTER_KEY_PARTICLE_RED 98 | points { 99 | x: 0.0 100 | y: 0.0 101 | t_x: 1.0 102 | t_y: 0.0 103 | } 104 | spread: 0.0 105 | } 106 | properties { 107 | key: EMITTER_KEY_PARTICLE_GREEN 108 | points { 109 | x: 0.0 110 | y: 0.0 111 | t_x: 1.0 112 | t_y: 0.0 113 | } 114 | spread: 0.0 115 | } 116 | properties { 117 | key: EMITTER_KEY_PARTICLE_BLUE 118 | points { 119 | x: 0.0 120 | y: 1.0 121 | t_x: 1.0 122 | t_y: 0.0 123 | } 124 | spread: 0.0 125 | } 126 | properties { 127 | key: EMITTER_KEY_PARTICLE_ALPHA 128 | points { 129 | x: 0.0 130 | y: 1.0 131 | t_x: 1.0 132 | t_y: 0.0 133 | } 134 | spread: 0.0 135 | } 136 | properties { 137 | key: EMITTER_KEY_PARTICLE_ROTATION 138 | points { 139 | x: 0.0 140 | y: 270.0 141 | t_x: 1.0 142 | t_y: 0.0 143 | } 144 | spread: 150.0 145 | } 146 | particle_properties { 147 | key: PARTICLE_KEY_SCALE 148 | points { 149 | x: 0.0 150 | y: 5.5367913 151 | t_x: 1.0 152 | t_y: 0.0 153 | } 154 | points { 155 | x: 1.0 156 | y: 0.3382353 157 | t_x: 0.10644245 158 | t_y: -0.99431884 159 | } 160 | } 161 | particle_properties { 162 | key: PARTICLE_KEY_RED 163 | points { 164 | x: 0.0 165 | y: 1.0 166 | t_x: 1.0 167 | t_y: 0.0 168 | } 169 | } 170 | particle_properties { 171 | key: PARTICLE_KEY_GREEN 172 | points { 173 | x: 0.0 174 | y: 1.0 175 | t_x: 1.0 176 | t_y: 0.0 177 | } 178 | } 179 | particle_properties { 180 | key: PARTICLE_KEY_BLUE 181 | points { 182 | x: 0.0 183 | y: 1.0 184 | t_x: 1.0 185 | t_y: 0.0 186 | } 187 | } 188 | particle_properties { 189 | key: PARTICLE_KEY_ALPHA 190 | points { 191 | x: 0.0 192 | y: 4.5487366 193 | t_x: 0.07194582 194 | t_y: 0.99740857 195 | } 196 | points { 197 | x: 0.7144144 198 | y: 1.1552035 199 | t_x: 0.30401823 200 | t_y: 0.9526662 201 | } 202 | points { 203 | x: 1.0 204 | y: 0.0 205 | t_x: 0.31981352 206 | t_y: -0.9474805 207 | } 208 | } 209 | particle_properties { 210 | key: PARTICLE_KEY_ROTATION 211 | points { 212 | x: 0.0 213 | y: 0.0 214 | t_x: 1.0 215 | t_y: 0.0 216 | } 217 | } 218 | size_mode: SIZE_MODE_MANUAL 219 | } 220 | -------------------------------------------------------------------------------- /examples/input/multitouch/poof_3.particlefx: -------------------------------------------------------------------------------- 1 | emitters { 2 | id: "emitter" 3 | mode: PLAY_MODE_ONCE 4 | duration: 0.01 5 | space: EMISSION_SPACE_WORLD 6 | position { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | } 11 | rotation { 12 | x: 0.0 13 | y: 0.0 14 | z: 0.0 15 | w: 1.0 16 | } 17 | tile_source: "/defrs/assets/textures/auras/auras.atlas" 18 | animation: "aura_blue" 19 | material: "/builtins/materials/particlefx.material" 20 | blend_mode: BLEND_MODE_ADD 21 | particle_orientation: PARTICLE_ORIENTATION_DEFAULT 22 | inherit_velocity: 0.0 23 | max_particle_count: 1 24 | type: EMITTER_TYPE_CIRCLE 25 | start_delay: 0.0 26 | properties { 27 | key: EMITTER_KEY_SPAWN_RATE 28 | points { 29 | x: 0.0 30 | y: 1000.0 31 | t_x: 1.0 32 | t_y: 0.0 33 | } 34 | spread: 5.0 35 | } 36 | properties { 37 | key: EMITTER_KEY_SIZE_X 38 | points { 39 | x: 0.0 40 | y: 1.0 41 | t_x: 1.0 42 | t_y: 0.0 43 | } 44 | spread: 0.0 45 | } 46 | properties { 47 | key: EMITTER_KEY_SIZE_Y 48 | points { 49 | x: 0.0 50 | y: 1.0 51 | t_x: 1.0 52 | t_y: 0.0 53 | } 54 | spread: 0.0 55 | } 56 | properties { 57 | key: EMITTER_KEY_SIZE_Z 58 | points { 59 | x: 0.0 60 | y: 0.0 61 | t_x: 1.0 62 | t_y: 0.0 63 | } 64 | spread: 0.0 65 | } 66 | properties { 67 | key: EMITTER_KEY_PARTICLE_LIFE_TIME 68 | points { 69 | x: 0.0 70 | y: 0.6 71 | t_x: 1.0 72 | t_y: 0.0 73 | } 74 | spread: 0.0 75 | } 76 | properties { 77 | key: EMITTER_KEY_PARTICLE_SPEED 78 | points { 79 | x: 0.0 80 | y: 0.0 81 | t_x: 1.0 82 | t_y: 0.0 83 | } 84 | spread: 0.0 85 | } 86 | properties { 87 | key: EMITTER_KEY_PARTICLE_SIZE 88 | points { 89 | x: 0.0 90 | y: 45.0 91 | t_x: 1.0 92 | t_y: 0.0 93 | } 94 | spread: 0.0 95 | } 96 | properties { 97 | key: EMITTER_KEY_PARTICLE_RED 98 | points { 99 | x: 0.0 100 | y: 1.0 101 | t_x: 1.0 102 | t_y: 0.0 103 | } 104 | spread: 0.0 105 | } 106 | properties { 107 | key: EMITTER_KEY_PARTICLE_GREEN 108 | points { 109 | x: 0.0 110 | y: 0.0 111 | t_x: 1.0 112 | t_y: 0.0 113 | } 114 | spread: 0.0 115 | } 116 | properties { 117 | key: EMITTER_KEY_PARTICLE_BLUE 118 | points { 119 | x: 0.0 120 | y: 1.0 121 | t_x: 1.0 122 | t_y: 0.0 123 | } 124 | spread: 0.0 125 | } 126 | properties { 127 | key: EMITTER_KEY_PARTICLE_ALPHA 128 | points { 129 | x: 0.0 130 | y: 1.0 131 | t_x: 1.0 132 | t_y: 0.0 133 | } 134 | spread: 0.0 135 | } 136 | properties { 137 | key: EMITTER_KEY_PARTICLE_ROTATION 138 | points { 139 | x: 0.0 140 | y: 270.0 141 | t_x: 1.0 142 | t_y: 0.0 143 | } 144 | spread: 150.0 145 | } 146 | particle_properties { 147 | key: PARTICLE_KEY_SCALE 148 | points { 149 | x: 0.0 150 | y: 5.5367913 151 | t_x: 1.0 152 | t_y: 0.0 153 | } 154 | points { 155 | x: 1.0 156 | y: 0.3382353 157 | t_x: 0.10644245 158 | t_y: -0.99431884 159 | } 160 | } 161 | particle_properties { 162 | key: PARTICLE_KEY_RED 163 | points { 164 | x: 0.0 165 | y: 1.0 166 | t_x: 1.0 167 | t_y: 0.0 168 | } 169 | } 170 | particle_properties { 171 | key: PARTICLE_KEY_GREEN 172 | points { 173 | x: 0.0 174 | y: 1.0 175 | t_x: 1.0 176 | t_y: 0.0 177 | } 178 | } 179 | particle_properties { 180 | key: PARTICLE_KEY_BLUE 181 | points { 182 | x: 0.0 183 | y: 1.0 184 | t_x: 1.0 185 | t_y: 0.0 186 | } 187 | } 188 | particle_properties { 189 | key: PARTICLE_KEY_ALPHA 190 | points { 191 | x: 0.0 192 | y: 4.5487366 193 | t_x: 0.07194582 194 | t_y: 0.99740857 195 | } 196 | points { 197 | x: 0.7144144 198 | y: 1.1552035 199 | t_x: 0.30401823 200 | t_y: 0.9526662 201 | } 202 | points { 203 | x: 1.0 204 | y: 0.0 205 | t_x: 0.31981352 206 | t_y: -0.9474805 207 | } 208 | } 209 | particle_properties { 210 | key: PARTICLE_KEY_ROTATION 211 | points { 212 | x: 0.0 213 | y: 0.0 214 | t_x: 1.0 215 | t_y: 0.0 216 | } 217 | } 218 | size_mode: SIZE_MODE_MANUAL 219 | } 220 | -------------------------------------------------------------------------------- /examples/input/multitouch/poof_4.particlefx: -------------------------------------------------------------------------------- 1 | emitters { 2 | id: "emitter" 3 | mode: PLAY_MODE_ONCE 4 | duration: 0.01 5 | space: EMISSION_SPACE_WORLD 6 | position { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | } 11 | rotation { 12 | x: 0.0 13 | y: 0.0 14 | z: 0.0 15 | w: 1.0 16 | } 17 | tile_source: "/defrs/assets/textures/auras/auras.atlas" 18 | animation: "aura_blue" 19 | material: "/builtins/materials/particlefx.material" 20 | blend_mode: BLEND_MODE_ADD 21 | particle_orientation: PARTICLE_ORIENTATION_DEFAULT 22 | inherit_velocity: 0.0 23 | max_particle_count: 1 24 | type: EMITTER_TYPE_CIRCLE 25 | start_delay: 0.0 26 | properties { 27 | key: EMITTER_KEY_SPAWN_RATE 28 | points { 29 | x: 0.0 30 | y: 1000.0 31 | t_x: 1.0 32 | t_y: 0.0 33 | } 34 | spread: 5.0 35 | } 36 | properties { 37 | key: EMITTER_KEY_SIZE_X 38 | points { 39 | x: 0.0 40 | y: 1.0 41 | t_x: 1.0 42 | t_y: 0.0 43 | } 44 | spread: 0.0 45 | } 46 | properties { 47 | key: EMITTER_KEY_SIZE_Y 48 | points { 49 | x: 0.0 50 | y: 1.0 51 | t_x: 1.0 52 | t_y: 0.0 53 | } 54 | spread: 0.0 55 | } 56 | properties { 57 | key: EMITTER_KEY_SIZE_Z 58 | points { 59 | x: 0.0 60 | y: 0.0 61 | t_x: 1.0 62 | t_y: 0.0 63 | } 64 | spread: 0.0 65 | } 66 | properties { 67 | key: EMITTER_KEY_PARTICLE_LIFE_TIME 68 | points { 69 | x: 0.0 70 | y: 0.6 71 | t_x: 1.0 72 | t_y: 0.0 73 | } 74 | spread: 0.0 75 | } 76 | properties { 77 | key: EMITTER_KEY_PARTICLE_SPEED 78 | points { 79 | x: 0.0 80 | y: 0.0 81 | t_x: 1.0 82 | t_y: 0.0 83 | } 84 | spread: 0.0 85 | } 86 | properties { 87 | key: EMITTER_KEY_PARTICLE_SIZE 88 | points { 89 | x: 0.0 90 | y: 45.0 91 | t_x: 1.0 92 | t_y: 0.0 93 | } 94 | spread: 0.0 95 | } 96 | properties { 97 | key: EMITTER_KEY_PARTICLE_RED 98 | points { 99 | x: 0.0 100 | y: 1.0 101 | t_x: 1.0 102 | t_y: 0.0 103 | } 104 | spread: 0.0 105 | } 106 | properties { 107 | key: EMITTER_KEY_PARTICLE_GREEN 108 | points { 109 | x: 0.0 110 | y: 1.0 111 | t_x: 1.0 112 | t_y: 0.0 113 | } 114 | spread: 0.0 115 | } 116 | properties { 117 | key: EMITTER_KEY_PARTICLE_BLUE 118 | points { 119 | x: 0.0 120 | y: 0.0 121 | t_x: 1.0 122 | t_y: 0.0 123 | } 124 | spread: 0.0 125 | } 126 | properties { 127 | key: EMITTER_KEY_PARTICLE_ALPHA 128 | points { 129 | x: 0.0 130 | y: 1.0 131 | t_x: 1.0 132 | t_y: 0.0 133 | } 134 | spread: 0.0 135 | } 136 | properties { 137 | key: EMITTER_KEY_PARTICLE_ROTATION 138 | points { 139 | x: 0.0 140 | y: 270.0 141 | t_x: 1.0 142 | t_y: 0.0 143 | } 144 | spread: 150.0 145 | } 146 | particle_properties { 147 | key: PARTICLE_KEY_SCALE 148 | points { 149 | x: 0.0 150 | y: 5.5367913 151 | t_x: 1.0 152 | t_y: 0.0 153 | } 154 | points { 155 | x: 1.0 156 | y: 0.3382353 157 | t_x: 0.10644245 158 | t_y: -0.99431884 159 | } 160 | } 161 | particle_properties { 162 | key: PARTICLE_KEY_RED 163 | points { 164 | x: 0.0 165 | y: 1.0 166 | t_x: 1.0 167 | t_y: 0.0 168 | } 169 | } 170 | particle_properties { 171 | key: PARTICLE_KEY_GREEN 172 | points { 173 | x: 0.0 174 | y: 1.0 175 | t_x: 1.0 176 | t_y: 0.0 177 | } 178 | } 179 | particle_properties { 180 | key: PARTICLE_KEY_BLUE 181 | points { 182 | x: 0.0 183 | y: 1.0 184 | t_x: 1.0 185 | t_y: 0.0 186 | } 187 | } 188 | particle_properties { 189 | key: PARTICLE_KEY_ALPHA 190 | points { 191 | x: 0.0 192 | y: 4.5487366 193 | t_x: 0.07194582 194 | t_y: 0.99740857 195 | } 196 | points { 197 | x: 0.7144144 198 | y: 1.1552035 199 | t_x: 0.30401823 200 | t_y: 0.9526662 201 | } 202 | points { 203 | x: 1.0 204 | y: 0.0 205 | t_x: 0.31981352 206 | t_y: -0.9474805 207 | } 208 | } 209 | particle_properties { 210 | key: PARTICLE_KEY_ROTATION 211 | points { 212 | x: 0.0 213 | y: 0.0 214 | t_x: 1.0 215 | t_y: 0.0 216 | } 217 | } 218 | size_mode: SIZE_MODE_MANUAL 219 | } 220 | -------------------------------------------------------------------------------- /examples/input/multitouch/poof_5.particlefx: -------------------------------------------------------------------------------- 1 | emitters { 2 | id: "emitter" 3 | mode: PLAY_MODE_ONCE 4 | duration: 0.01 5 | space: EMISSION_SPACE_WORLD 6 | position { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | } 11 | rotation { 12 | x: 0.0 13 | y: 0.0 14 | z: 0.0 15 | w: 1.0 16 | } 17 | tile_source: "/defrs/assets/textures/auras/auras.atlas" 18 | animation: "aura_blue" 19 | material: "/builtins/materials/particlefx.material" 20 | blend_mode: BLEND_MODE_ADD 21 | particle_orientation: PARTICLE_ORIENTATION_DEFAULT 22 | inherit_velocity: 0.0 23 | max_particle_count: 1 24 | type: EMITTER_TYPE_CIRCLE 25 | start_delay: 0.0 26 | properties { 27 | key: EMITTER_KEY_SPAWN_RATE 28 | points { 29 | x: 0.0 30 | y: 1000.0 31 | t_x: 1.0 32 | t_y: 0.0 33 | } 34 | spread: 5.0 35 | } 36 | properties { 37 | key: EMITTER_KEY_SIZE_X 38 | points { 39 | x: 0.0 40 | y: 1.0 41 | t_x: 1.0 42 | t_y: 0.0 43 | } 44 | spread: 0.0 45 | } 46 | properties { 47 | key: EMITTER_KEY_SIZE_Y 48 | points { 49 | x: 0.0 50 | y: 1.0 51 | t_x: 1.0 52 | t_y: 0.0 53 | } 54 | spread: 0.0 55 | } 56 | properties { 57 | key: EMITTER_KEY_SIZE_Z 58 | points { 59 | x: 0.0 60 | y: 0.0 61 | t_x: 1.0 62 | t_y: 0.0 63 | } 64 | spread: 0.0 65 | } 66 | properties { 67 | key: EMITTER_KEY_PARTICLE_LIFE_TIME 68 | points { 69 | x: 0.0 70 | y: 0.6 71 | t_x: 1.0 72 | t_y: 0.0 73 | } 74 | spread: 0.0 75 | } 76 | properties { 77 | key: EMITTER_KEY_PARTICLE_SPEED 78 | points { 79 | x: 0.0 80 | y: 0.0 81 | t_x: 1.0 82 | t_y: 0.0 83 | } 84 | spread: 0.0 85 | } 86 | properties { 87 | key: EMITTER_KEY_PARTICLE_SIZE 88 | points { 89 | x: 0.0 90 | y: 45.0 91 | t_x: 1.0 92 | t_y: 0.0 93 | } 94 | spread: 0.0 95 | } 96 | properties { 97 | key: EMITTER_KEY_PARTICLE_RED 98 | points { 99 | x: 0.0 100 | y: 1.0 101 | t_x: 1.0 102 | t_y: 0.0 103 | } 104 | spread: 0.0 105 | } 106 | properties { 107 | key: EMITTER_KEY_PARTICLE_GREEN 108 | points { 109 | x: 0.0 110 | y: 0.0 111 | t_x: 1.0 112 | t_y: 0.0 113 | } 114 | spread: 0.0 115 | } 116 | properties { 117 | key: EMITTER_KEY_PARTICLE_BLUE 118 | points { 119 | x: 0.0 120 | y: 0.0 121 | t_x: 1.0 122 | t_y: 0.0 123 | } 124 | spread: 0.0 125 | } 126 | properties { 127 | key: EMITTER_KEY_PARTICLE_ALPHA 128 | points { 129 | x: 0.0 130 | y: 1.0 131 | t_x: 1.0 132 | t_y: 0.0 133 | } 134 | spread: 0.0 135 | } 136 | properties { 137 | key: EMITTER_KEY_PARTICLE_ROTATION 138 | points { 139 | x: 0.0 140 | y: 270.0 141 | t_x: 1.0 142 | t_y: 0.0 143 | } 144 | spread: 150.0 145 | } 146 | particle_properties { 147 | key: PARTICLE_KEY_SCALE 148 | points { 149 | x: 0.0 150 | y: 5.5367913 151 | t_x: 1.0 152 | t_y: 0.0 153 | } 154 | points { 155 | x: 1.0 156 | y: 0.3382353 157 | t_x: 0.10644245 158 | t_y: -0.99431884 159 | } 160 | } 161 | particle_properties { 162 | key: PARTICLE_KEY_RED 163 | points { 164 | x: 0.0 165 | y: 1.0 166 | t_x: 1.0 167 | t_y: 0.0 168 | } 169 | } 170 | particle_properties { 171 | key: PARTICLE_KEY_GREEN 172 | points { 173 | x: 0.0 174 | y: 1.0 175 | t_x: 1.0 176 | t_y: 0.0 177 | } 178 | } 179 | particle_properties { 180 | key: PARTICLE_KEY_BLUE 181 | points { 182 | x: 0.0 183 | y: 1.0 184 | t_x: 1.0 185 | t_y: 0.0 186 | } 187 | } 188 | particle_properties { 189 | key: PARTICLE_KEY_ALPHA 190 | points { 191 | x: 0.0 192 | y: 4.5487366 193 | t_x: 0.07194582 194 | t_y: 0.99740857 195 | } 196 | points { 197 | x: 0.7144144 198 | y: 1.1552035 199 | t_x: 0.30401823 200 | t_y: 0.9526662 201 | } 202 | points { 203 | x: 1.0 204 | y: 0.0 205 | t_x: 0.31981352 206 | t_y: -0.9474805 207 | } 208 | } 209 | particle_properties { 210 | key: PARTICLE_KEY_ROTATION 211 | points { 212 | x: 0.0 213 | y: 0.0 214 | t_x: 1.0 215 | t_y: 0.0 216 | } 217 | } 218 | size_mode: SIZE_MODE_MANUAL 219 | } 220 | -------------------------------------------------------------------------------- /examples/input/text_typing/text_typing.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | instances { 3 | id: "_screen_size" 4 | prototype: "/defrs/gui/screen_size.go" 5 | position { 6 | x: 0.0 7 | y: 0.0 8 | z: 0.0 9 | } 10 | rotation { 11 | x: 0.0 12 | y: 0.0 13 | z: 0.0 14 | w: 1.0 15 | } 16 | scale3 { 17 | x: 1.0 18 | y: 1.0 19 | z: 1.0 20 | } 21 | } 22 | scale_along_z: 0 23 | embedded_instances { 24 | id: "_labels" 25 | data: "embedded_components {\n" 26 | " id: \"label\"\n" 27 | " type: \"label\"\n" 28 | " data: \"size {\\n" 29 | " x: 512.0\\n" 30 | " y: 32.0\\n" 31 | " z: 0.0\\n" 32 | " w: 0.0\\n" 33 | "}\\n" 34 | "scale {\\n" 35 | " x: 1.0\\n" 36 | " y: 1.0\\n" 37 | " z: 1.0\\n" 38 | " w: 0.0\\n" 39 | "}\\n" 40 | "color {\\n" 41 | " x: 1.0\\n" 42 | " y: 1.0\\n" 43 | " z: 1.0\\n" 44 | " w: 1.0\\n" 45 | "}\\n" 46 | "outline {\\n" 47 | " x: 0.0\\n" 48 | " y: 0.0\\n" 49 | " z: 0.0\\n" 50 | " w: 1.0\\n" 51 | "}\\n" 52 | "shadow {\\n" 53 | " x: 0.0\\n" 54 | " y: 0.0\\n" 55 | " z: 0.0\\n" 56 | " w: 1.0\\n" 57 | "}\\n" 58 | "leading: 1.0\\n" 59 | "tracking: 0.0\\n" 60 | "pivot: PIVOT_CENTER\\n" 61 | "blend_mode: BLEND_MODE_ALPHA\\n" 62 | "line_break: true\\n" 63 | "text: \\\"WASD + Mouse\\\"\\n" 64 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 65 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 66 | "\"\n" 67 | " position {\n" 68 | " x: 0.0\n" 69 | " y: 337.481\n" 70 | " z: 0.0\n" 71 | " }\n" 72 | " rotation {\n" 73 | " x: 0.0\n" 74 | " y: 0.0\n" 75 | " z: 0.0\n" 76 | " w: 1.0\n" 77 | " }\n" 78 | "}\n" 79 | "" 80 | position { 81 | x: 800.0 82 | y: 60.0 83 | z: 0.0 84 | } 85 | rotation { 86 | x: 0.0 87 | y: 0.0 88 | z: 0.0 89 | w: 1.0 90 | } 91 | scale3 { 92 | x: 1.0 93 | y: 1.0 94 | z: 1.0 95 | } 96 | } 97 | embedded_instances { 98 | id: "text_typing" 99 | data: "components {\n" 100 | " id: \"script\"\n" 101 | " component: \"/examples/input/text_typing/text_typing.script\"\n" 102 | " position {\n" 103 | " x: 0.0\n" 104 | " y: 0.0\n" 105 | " z: 0.0\n" 106 | " }\n" 107 | " rotation {\n" 108 | " x: 0.0\n" 109 | " y: 0.0\n" 110 | " z: 0.0\n" 111 | " w: 1.0\n" 112 | " }\n" 113 | "}\n" 114 | "" 115 | position { 116 | x: 0.0 117 | y: 0.0 118 | z: 0.0 119 | } 120 | rotation { 121 | x: 0.0 122 | y: 0.0 123 | z: 0.0 124 | w: 1.0 125 | } 126 | scale3 { 127 | x: 1.0 128 | y: 1.0 129 | z: 1.0 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /examples/input/text_typing/text_typing.script: -------------------------------------------------------------------------------- 1 | local word_list_short = require("text.english_words_short") 2 | 3 | 4 | function init(self) 5 | math.randomseed( os.time() ) 6 | math.random();math.random();math.random(); 7 | -- Add initialization code here 8 | -- Remove this function if not needed 9 | msg.post(".", "acquire_input_focus") 10 | self.text_counter = 0 11 | self.last_text_counter = 0 12 | self.last_text = "" 13 | self.text = "" 14 | 15 | self.counter = 0 16 | 17 | self.word_list_count = #word_list_short 18 | end 19 | 20 | function final(self) 21 | -- Add finalization code here 22 | -- Remove this function if not needed 23 | end 24 | 25 | function update(self, dt) 26 | self.counter = self.counter + dt 27 | label.set_text("/_labels#label",self.text) 28 | 29 | if self.counter > 1 then 30 | self.counter = self.counter -1 31 | local random_word = word_list_short[math.random(1, self.word_list_count)] 32 | self.text = self.text .. " " .. random_word 33 | end 34 | end 35 | 36 | function on_message(self, message_id, message, sender) 37 | -- Add message-handling code here 38 | -- Remove this function if not needed 39 | end 40 | 41 | function on_input(self, action_id, action) 42 | if action_id == hash("text") then 43 | self.text = self.text .. action.text 44 | end 45 | if (action_id == hash("enter") or action_id == hash("enter_kp")) and action.released then 46 | self.text = self.text .. "\n" 47 | end 48 | if action_id == hash("backspace") and action.released then 49 | self.text = self.text:sub(1, -2) 50 | end 51 | -- Add input-handling code here 52 | -- Remove this function if not needed 53 | end 54 | 55 | function on_reload(self) 56 | -- Add reload-handling code here 57 | -- Remove this function if not needed 58 | end 59 | -------------------------------------------------------------------------------- /examples/tools/api_ext/api_ext.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"script\"\n" 7 | " component: \"/examples/tools/api_ext/api_ext.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "embedded_components {\n" 21 | " id: \"sprite\"\n" 22 | " type: \"sprite\"\n" 23 | " data: \"tile_set: \\\"/examples/toys/minesweeper/minesweeper_character.tilesource\\\"\\n" 24 | "default_animation: \\\"character_normal\\\"\\n" 25 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 26 | "blend_mode: BLEND_MODE_ALPHA\\n" 27 | "\"\n" 28 | " position {\n" 29 | " x: 105.983\n" 30 | " y: 111.111\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "" 41 | position { 42 | x: 0.0 43 | y: 0.0 44 | z: 0.0 45 | } 46 | rotation { 47 | x: 0.0 48 | y: 0.0 49 | z: 0.0 50 | w: 1.0 51 | } 52 | scale3 { 53 | x: 1.0 54 | y: 1.0 55 | z: 1.0 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/tools/api_ext/api_ext.script: -------------------------------------------------------------------------------- 1 | local sprite_ext = require("defrs.utils.api_ext") 2 | 3 | function init(self) 4 | sprite.play_animation("#sprite", "character_zombie") 5 | end 6 | 7 | function final(self) 8 | -- Add finalization code here 9 | -- Remove this function if not needed 10 | end 11 | 12 | function update(self, dt) 13 | -- Add update code here 14 | -- Remove this function if not needed 15 | end 16 | 17 | function on_message(self, message_id, message, sender) 18 | -- Add message-handling code here 19 | -- Remove this function if not needed 20 | end 21 | 22 | function on_input(self, action_id, action) 23 | -- Add input-handling code here 24 | -- Remove this function if not needed 25 | end 26 | 27 | function on_reload(self) 28 | -- Add reload-handling code here 29 | -- Remove this function if not needed 30 | end 31 | -------------------------------------------------------------------------------- /examples/tools/colors/colors.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | instances { 3 | id: "screen_size" 4 | prototype: "/defrs/gui/screen_size.go" 5 | position { 6 | x: 0.0 7 | y: 0.0 8 | z: 0.0 9 | } 10 | rotation { 11 | x: 0.0 12 | y: 0.0 13 | z: 0.0 14 | w: 1.0 15 | } 16 | scale3 { 17 | x: 1.0 18 | y: 1.0 19 | z: 1.0 20 | } 21 | } 22 | scale_along_z: 0 23 | embedded_instances { 24 | id: "labels" 25 | data: "components {\n" 26 | " id: \"script\"\n" 27 | " component: \"/examples/tools/colors/colors.script\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "embedded_components {\n" 41 | " id: \"label\"\n" 42 | " type: \"label\"\n" 43 | " data: \"size {\\n" 44 | " x: 128.0\\n" 45 | " y: 32.0\\n" 46 | " z: 0.0\\n" 47 | " w: 0.0\\n" 48 | "}\\n" 49 | "scale {\\n" 50 | " x: 1.0\\n" 51 | " y: 1.0\\n" 52 | " z: 1.0\\n" 53 | " w: 0.0\\n" 54 | "}\\n" 55 | "color {\\n" 56 | " x: 1.0\\n" 57 | " y: 1.0\\n" 58 | " z: 1.0\\n" 59 | " w: 1.0\\n" 60 | "}\\n" 61 | "outline {\\n" 62 | " x: 0.0\\n" 63 | " y: 0.0\\n" 64 | " z: 0.0\\n" 65 | " w: 1.0\\n" 66 | "}\\n" 67 | "shadow {\\n" 68 | " x: 0.0\\n" 69 | " y: 0.0\\n" 70 | " z: 0.0\\n" 71 | " w: 1.0\\n" 72 | "}\\n" 73 | "leading: 1.0\\n" 74 | "tracking: 0.0\\n" 75 | "pivot: PIVOT_CENTER\\n" 76 | "blend_mode: BLEND_MODE_ALPHA\\n" 77 | "line_break: false\\n" 78 | "text: \\\"The color of this will change over time.\\\"\\n" 79 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 80 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 81 | "\"\n" 82 | " position {\n" 83 | " x: 0.0\n" 84 | " y: 0.0\n" 85 | " z: 0.0\n" 86 | " }\n" 87 | " rotation {\n" 88 | " x: 0.0\n" 89 | " y: 0.0\n" 90 | " z: 0.0\n" 91 | " w: 1.0\n" 92 | " }\n" 93 | "}\n" 94 | "embedded_components {\n" 95 | " id: \"label2\"\n" 96 | " type: \"label\"\n" 97 | " data: \"size {\\n" 98 | " x: 128.0\\n" 99 | " y: 32.0\\n" 100 | " z: 0.0\\n" 101 | " w: 0.0\\n" 102 | "}\\n" 103 | "scale {\\n" 104 | " x: 1.0\\n" 105 | " y: 1.0\\n" 106 | " z: 1.0\\n" 107 | " w: 0.0\\n" 108 | "}\\n" 109 | "color {\\n" 110 | " x: 1.0\\n" 111 | " y: 1.0\\n" 112 | " z: 1.0\\n" 113 | " w: 1.0\\n" 114 | "}\\n" 115 | "outline {\\n" 116 | " x: 0.0\\n" 117 | " y: 0.0\\n" 118 | " z: 0.0\\n" 119 | " w: 1.0\\n" 120 | "}\\n" 121 | "shadow {\\n" 122 | " x: 0.0\\n" 123 | " y: 0.0\\n" 124 | " z: 0.0\\n" 125 | " w: 1.0\\n" 126 | "}\\n" 127 | "leading: 1.0\\n" 128 | "tracking: 0.0\\n" 129 | "pivot: PIVOT_CENTER\\n" 130 | "blend_mode: BLEND_MODE_ALPHA\\n" 131 | "line_break: false\\n" 132 | "text: \\\"The color of this will change over time.\\\"\\n" 133 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 134 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 135 | "\"\n" 136 | " position {\n" 137 | " x: 0.0\n" 138 | " y: -43.063\n" 139 | " z: 0.0\n" 140 | " }\n" 141 | " rotation {\n" 142 | " x: 0.0\n" 143 | " y: 0.0\n" 144 | " z: 0.0\n" 145 | " w: 1.0\n" 146 | " }\n" 147 | "}\n" 148 | "embedded_components {\n" 149 | " id: \"label3\"\n" 150 | " type: \"label\"\n" 151 | " data: \"size {\\n" 152 | " x: 128.0\\n" 153 | " y: 32.0\\n" 154 | " z: 0.0\\n" 155 | " w: 0.0\\n" 156 | "}\\n" 157 | "scale {\\n" 158 | " x: 1.0\\n" 159 | " y: 1.0\\n" 160 | " z: 1.0\\n" 161 | " w: 0.0\\n" 162 | "}\\n" 163 | "color {\\n" 164 | " x: 1.0\\n" 165 | " y: 1.0\\n" 166 | " z: 1.0\\n" 167 | " w: 1.0\\n" 168 | "}\\n" 169 | "outline {\\n" 170 | " x: 0.0\\n" 171 | " y: 0.0\\n" 172 | " z: 0.0\\n" 173 | " w: 1.0\\n" 174 | "}\\n" 175 | "shadow {\\n" 176 | " x: 0.0\\n" 177 | " y: 0.0\\n" 178 | " z: 0.0\\n" 179 | " w: 1.0\\n" 180 | "}\\n" 181 | "leading: 1.0\\n" 182 | "tracking: 0.0\\n" 183 | "pivot: PIVOT_CENTER\\n" 184 | "blend_mode: BLEND_MODE_ALPHA\\n" 185 | "line_break: false\\n" 186 | "text: \\\"The color of this will change over time.\\\"\\n" 187 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 188 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 189 | "\"\n" 190 | " position {\n" 191 | " x: 0.0\n" 192 | " y: -81.248\n" 193 | " z: 0.0\n" 194 | " }\n" 195 | " rotation {\n" 196 | " x: 0.0\n" 197 | " y: 0.0\n" 198 | " z: 0.0\n" 199 | " w: 1.0\n" 200 | " }\n" 201 | "}\n" 202 | "" 203 | position { 204 | x: 768.756 205 | y: 397.632 206 | z: 0.0 207 | } 208 | rotation { 209 | x: 0.0 210 | y: 0.0 211 | z: 0.0 212 | w: 1.0 213 | } 214 | scale3 { 215 | x: 1.0 216 | y: 1.0 217 | z: 1.0 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /examples/tools/colors/colors.script: -------------------------------------------------------------------------------- 1 | local colors = require("defrs.utils.colors") 2 | 3 | 4 | 5 | function init(self) 6 | pprint(colors.red) 7 | pprint(colors.get_random_color()) 8 | pprint(colors.hue_shift(colors.red,1)) 9 | 10 | self.timer = 0 11 | self.step = 1 12 | self.second_color = colors.blue 13 | 14 | end 15 | 16 | function update(self, dt) 17 | self.timer = self.timer + dt 18 | if self.timer > 1 then 19 | self.timer = self.timer - 1 20 | self.step = self.step + 1 21 | if self.step == 4 then 22 | self.step = 1 23 | end 24 | end 25 | if self.step == 1 then 26 | go.set("#label","color",colors.red) 27 | elseif self.step == 2 then 28 | go.set("#label","color",colors.magenta) 29 | elseif self.step == 3 then 30 | go.set("#label","color",colors.get_random_color()) 31 | end 32 | 33 | 34 | go.set("#label2","color",colors.hue_shift(self.second_color,math.cos(self.timer*10))) 35 | go.set("#label3","color",colors.hue_shift(self.second_color,self.timer*30)) 36 | end 37 | -------------------------------------------------------------------------------- /examples/tools/curves/dot.go: -------------------------------------------------------------------------------- 1 | embedded_components { 2 | id: "sprite" 3 | type: "sprite" 4 | data: "tile_set: \"/examples/toys/identicons/identicons.tilesource\"\n" 5 | "default_animation: \"1\"\n" 6 | "material: \"/defrs/materials/sprite_pixelart.material\"\n" 7 | "blend_mode: BLEND_MODE_ALPHA\n" 8 | "" 9 | position { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | } 14 | rotation { 15 | x: 0.0 16 | y: 0.0 17 | z: 0.0 18 | w: 1.0 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/tools/curves/pearl.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/examples/tools/curves/pearl.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | } 16 | embedded_components { 17 | id: "sprite" 18 | type: "sprite" 19 | data: "tile_set: \"/defrs/assets/textures/misc/misc.atlas\"\n" 20 | "default_animation: \"pearl\"\n" 21 | "material: \"/defrs/materials/sprite_normal.material\"\n" 22 | "blend_mode: BLEND_MODE_ALPHA\n" 23 | "" 24 | position { 25 | x: 0.0 26 | y: 0.0 27 | z: 0.0 28 | } 29 | rotation { 30 | x: 0.0 31 | y: 0.0 32 | z: 0.0 33 | w: 1.0 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/tools/curves/pearl.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | -- Add initialization code here 3 | -- Remove this function if not needed 4 | go.animate(".", "scale.x",go.PLAYBACK_LOOP_PINGPONG,go.get(".","scale.x") * 0.25,go.EASING_INOUTBACK,2) 5 | go.animate(".", "scale.y",go.PLAYBACK_LOOP_PINGPONG,go.get(".","scale.y") * 0.25,go.EASING_INOUTBACK,2) 6 | end 7 | 8 | function final(self) 9 | -- Add finalization code here 10 | -- Remove this function if not needed 11 | end 12 | 13 | function update(self, dt) 14 | -- Add update code here 15 | -- Remove this function if not needed 16 | end 17 | 18 | function on_message(self, message_id, message, sender) 19 | -- Add message-handling code here 20 | -- Remove this function if not needed 21 | end 22 | 23 | function on_input(self, action_id, action) 24 | -- Add input-handling code here 25 | -- Remove this function if not needed 26 | end 27 | 28 | function on_reload(self) 29 | -- Add reload-handling code here 30 | -- Remove this function if not needed 31 | end 32 | -------------------------------------------------------------------------------- /examples/tools/easing_equations/easing_equations.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | instances { 3 | id: "screen_size" 4 | prototype: "/defrs/gui/screen_size.go" 5 | position { 6 | x: 0.0 7 | y: 0.0 8 | z: 0.0 9 | } 10 | rotation { 11 | x: 0.0 12 | y: 0.0 13 | z: 0.0 14 | w: 1.0 15 | } 16 | scale3 { 17 | x: 1.0 18 | y: 1.0 19 | z: 1.0 20 | } 21 | } 22 | scale_along_z: 0 23 | embedded_instances { 24 | id: "go" 25 | data: "components {\n" 26 | " id: \"script\"\n" 27 | " component: \"/examples/tools/easing_equations/easing_equations.script\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "" 41 | position { 42 | x: 0.0 43 | y: 0.0 44 | z: 0.0 45 | } 46 | rotation { 47 | x: 0.0 48 | y: 0.0 49 | z: 0.0 50 | w: 1.0 51 | } 52 | scale3 { 53 | x: 1.0 54 | y: 1.0 55 | z: 1.0 56 | } 57 | } 58 | embedded_instances { 59 | id: "labels" 60 | data: "embedded_components {\n" 61 | " id: \"label\"\n" 62 | " type: \"label\"\n" 63 | " data: \"size {\\n" 64 | " x: 128.0\\n" 65 | " y: 32.0\\n" 66 | " z: 0.0\\n" 67 | " w: 0.0\\n" 68 | "}\\n" 69 | "scale {\\n" 70 | " x: 1.0\\n" 71 | " y: 1.0\\n" 72 | " z: 1.0\\n" 73 | " w: 0.0\\n" 74 | "}\\n" 75 | "color {\\n" 76 | " x: 1.0\\n" 77 | " y: 1.0\\n" 78 | " z: 1.0\\n" 79 | " w: 1.0\\n" 80 | "}\\n" 81 | "outline {\\n" 82 | " x: 0.0\\n" 83 | " y: 0.0\\n" 84 | " z: 0.0\\n" 85 | " w: 1.0\\n" 86 | "}\\n" 87 | "shadow {\\n" 88 | " x: 0.0\\n" 89 | " y: 0.0\\n" 90 | " z: 0.0\\n" 91 | " w: 1.0\\n" 92 | "}\\n" 93 | "leading: 1.0\\n" 94 | "tracking: 0.0\\n" 95 | "pivot: PIVOT_CENTER\\n" 96 | "blend_mode: BLEND_MODE_ALPHA\\n" 97 | "line_break: false\\n" 98 | "text: \\\"PRESS FACE TO RESTART\\\"\\n" 99 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 100 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 101 | "\"\n" 102 | " position {\n" 103 | " x: 0.0\n" 104 | " y: 330.935\n" 105 | " z: 0.0\n" 106 | " }\n" 107 | " rotation {\n" 108 | " x: 0.0\n" 109 | " y: 0.0\n" 110 | " z: 0.0\n" 111 | " w: 1.0\n" 112 | " }\n" 113 | "}\n" 114 | "" 115 | position { 116 | x: 810.138 117 | y: 61.747 118 | z: 0.0 119 | } 120 | rotation { 121 | x: 0.0 122 | y: 0.0 123 | z: 0.0 124 | w: 1.0 125 | } 126 | scale3 { 127 | x: 1.0 128 | y: 1.0 129 | z: 1.0 130 | } 131 | } 132 | embedded_instances { 133 | id: "visual" 134 | data: "embedded_components {\n" 135 | " id: \"sprite\"\n" 136 | " type: \"sprite\"\n" 137 | " data: \"tile_set: \\\"/examples/toys/bouncer/logo.atlas\\\"\\n" 138 | "default_animation: \\\"logo\\\"\\n" 139 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 140 | "blend_mode: BLEND_MODE_ALPHA\\n" 141 | "\"\n" 142 | " position {\n" 143 | " x: 0.0\n" 144 | " y: 0.0\n" 145 | " z: 0.0\n" 146 | " }\n" 147 | " rotation {\n" 148 | " x: 0.0\n" 149 | " y: 0.0\n" 150 | " z: 0.0\n" 151 | " w: 1.0\n" 152 | " }\n" 153 | "}\n" 154 | "" 155 | position { 156 | x: 160.515 157 | y: 157.698 158 | z: 0.0 159 | } 160 | rotation { 161 | x: 0.0 162 | y: 0.0 163 | z: 0.0 164 | w: 1.0 165 | } 166 | scale3 { 167 | x: 1.0 168 | y: 1.0 169 | z: 1.0 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /examples/tools/easing_equations/easing_equations.script: -------------------------------------------------------------------------------- 1 | local easing = require("defrs.utils.easing_equations") 2 | 3 | function init(self) 4 | self.timer = 0 5 | self.position = go.get_position("/visual") 6 | end 7 | 8 | function final(self) 9 | -- Add finalization code here 10 | -- Remove this function if not needed 11 | end 12 | 13 | function update(self, dt) 14 | 15 | 16 | self.timer = self.timer + dt 17 | 18 | local position = self.position 19 | 20 | 21 | position.y = easing.out_bounce(math.abs(math.sin(self.timer)),1,1.5,1) * -100 + 400 22 | 23 | 24 | go.set_position(position, "/visual") 25 | 26 | label.set_text("/labels#label",easing.out_bounce(math.abs(math.sin(self.timer)),1,1.5,1)) 27 | 28 | --easing.linear(math.abs(math.sin(self.timer),beginning_value,change,duration_total) 29 | --easing.out_bounce(time_current,beginning_value,change,duration_total) 30 | 31 | --easing.linear(time_current,beginning_value,change,duration_total) 32 | -- Remove this function if not needed 33 | end 34 | 35 | function on_message(self, message_id, message, sender) 36 | -- Add message-handling code here 37 | -- Remove this function if not needed 38 | end 39 | 40 | function on_input(self, action_id, action) 41 | -- Add input-handling code here 42 | -- Remove this function if not needed 43 | end 44 | 45 | function on_reload(self) 46 | -- Add reload-handling code here 47 | -- Remove this function if not needed 48 | end 49 | -------------------------------------------------------------------------------- /examples/tools/html_run_code/html_run_code.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"script\"\n" 7 | " component: \"/examples/tools/html_run_code/html_run_code.script\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "" 21 | position { 22 | x: 0.0 23 | y: 0.0 24 | z: 0.0 25 | } 26 | rotation { 27 | x: 0.0 28 | y: 0.0 29 | z: 0.0 30 | w: 1.0 31 | } 32 | scale3 { 33 | x: 1.0 34 | y: 1.0 35 | z: 1.0 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/tools/html_run_code/html_run_code.script: -------------------------------------------------------------------------------- 1 | 2 | 3 | function init(self) 4 | sysinfo = sys.get_sys_info() 5 | if sysinfo.system_name == "HTML5" then 6 | html5.run("alert_this('Hello! I am an alert box!!');") 7 | end 8 | end 9 | 10 | function final(self) 11 | -- Add finalization code here 12 | -- Remove this function if not needed 13 | end 14 | 15 | function update(self, dt) 16 | -- Add update code here 17 | -- Remove this function if not needed 18 | end 19 | 20 | function on_message(self, message_id, message, sender) 21 | -- Add message-handling code here 22 | -- Remove this function if not needed 23 | end 24 | 25 | function on_input(self, action_id, action) 26 | -- Add input-handling code here 27 | -- Remove this function if not needed 28 | end 29 | 30 | function on_reload(self) 31 | -- Add reload-handling code here 32 | -- Remove this function if not needed 33 | end 34 | -------------------------------------------------------------------------------- /examples/tools/html_run_code/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DefRS 1.0 10 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 74 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /examples/tools/ms_rng/ms_rng.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "ms_rng" 5 | children: "labels" 6 | data: "components {\n" 7 | " id: \"script\"\n" 8 | " component: \"/examples/tools/ms_rng/ms_rng.script\"\n" 9 | " position {\n" 10 | " x: 0.0\n" 11 | " y: 0.0\n" 12 | " z: 0.0\n" 13 | " }\n" 14 | " rotation {\n" 15 | " x: 0.0\n" 16 | " y: 0.0\n" 17 | " z: 0.0\n" 18 | " w: 1.0\n" 19 | " }\n" 20 | "}\n" 21 | "" 22 | position { 23 | x: 0.0 24 | y: 0.0 25 | z: 0.0 26 | } 27 | rotation { 28 | x: 0.0 29 | y: 0.0 30 | z: 0.0 31 | w: 1.0 32 | } 33 | scale3 { 34 | x: 1.0 35 | y: 1.0 36 | z: 1.0 37 | } 38 | } 39 | embedded_instances { 40 | id: "labels" 41 | data: "embedded_components {\n" 42 | " id: \"label\"\n" 43 | " type: \"label\"\n" 44 | " data: \"size {\\n" 45 | " x: 128.0\\n" 46 | " y: 32.0\\n" 47 | " z: 0.0\\n" 48 | " w: 0.0\\n" 49 | "}\\n" 50 | "scale {\\n" 51 | " x: 1.0\\n" 52 | " y: 1.0\\n" 53 | " z: 1.0\\n" 54 | " w: 0.0\\n" 55 | "}\\n" 56 | "color {\\n" 57 | " x: 1.0\\n" 58 | " y: 1.0\\n" 59 | " z: 1.0\\n" 60 | " w: 1.0\\n" 61 | "}\\n" 62 | "outline {\\n" 63 | " x: 0.0\\n" 64 | " y: 0.0\\n" 65 | " z: 0.0\\n" 66 | " w: 1.0\\n" 67 | "}\\n" 68 | "shadow {\\n" 69 | " x: 0.0\\n" 70 | " y: 0.0\\n" 71 | " z: 0.0\\n" 72 | " w: 1.0\\n" 73 | "}\\n" 74 | "leading: 1.0\\n" 75 | "tracking: 0.0\\n" 76 | "pivot: PIVOT_CENTER\\n" 77 | "blend_mode: BLEND_MODE_ALPHA\\n" 78 | "line_break: false\\n" 79 | "text: \\\"Read the console.\\\"\\n" 80 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 81 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 82 | "\"\n" 83 | " position {\n" 84 | " x: 0.0\n" 85 | " y: 0.0\n" 86 | " z: 0.0\n" 87 | " }\n" 88 | " rotation {\n" 89 | " x: 0.0\n" 90 | " y: 0.0\n" 91 | " z: 0.0\n" 92 | " w: 1.0\n" 93 | " }\n" 94 | "}\n" 95 | "" 96 | position { 97 | x: 768.756 98 | y: 397.632 99 | z: 0.0 100 | } 101 | rotation { 102 | x: 0.0 103 | y: 0.0 104 | z: 0.0 105 | w: 1.0 106 | } 107 | scale3 { 108 | x: 1.0 109 | y: 1.0 110 | z: 1.0 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /examples/tools/ms_rng/ms_rng.script: -------------------------------------------------------------------------------- 1 | local ms_rng = require("defrs.utils.mersennetwister") 2 | 3 | 4 | 5 | function init(self) 6 | 7 | ms_rng.seed_mt() 8 | -- 0 to 1, add more zeroes if needed 9 | print(ms_rng.random(0,1000) * 0.001) 10 | print(ms_rng.random(0,1000) * 0.001) 11 | print(ms_rng.random(0,1000) * 0.001) 12 | print(ms_rng.random(0,1000) * 0.001) 13 | print(ms_rng.random(0,1000) * 0.001) 14 | 15 | -- set seed, if seed is not set it will use os.time as seed 16 | ms_rng.seed_mt(777) 17 | -- min, max value 18 | -- what you want most of the time 19 | print(ms_rng.random(0,100)) 20 | print(ms_rng.random(0,100)) 21 | print(ms_rng.random(0,100)) 22 | print(ms_rng.random(0,100)) 23 | print(ms_rng.random(0,100)) 24 | 25 | ms_rng.seed_mt(777) 26 | print(ms_rng.random(1)) 27 | print(ms_rng.random(2)) 28 | print(ms_rng.random(3)) 29 | print(ms_rng.random(4)) 30 | print(ms_rng.random(5)) 31 | print(ms_rng.random(1)) 32 | print(ms_rng.random(2)) 33 | print(ms_rng.random(3)) 34 | print(ms_rng.random(4)) 35 | print(ms_rng.random(5)) 36 | print(ms_rng.random(1)) 37 | print(ms_rng.random(2)) 38 | print(ms_rng.random(3)) 39 | print(ms_rng.random(4)) 40 | print(ms_rng.random(5)) 41 | 42 | ms_rng.seed_mt(777) 43 | print(ms_rng.random()) 44 | print(ms_rng.random()) 45 | print(ms_rng.random()) 46 | print(ms_rng.random()) 47 | print(ms_rng.random()) 48 | print(ms_rng.random()) 49 | print(ms_rng.random()) 50 | print(ms_rng.random()) 51 | print(ms_rng.random()) 52 | print(ms_rng.random()) 53 | print(ms_rng.random()) 54 | print(ms_rng.random()) 55 | print(ms_rng.random()) 56 | print(ms_rng.random()) 57 | print(ms_rng.random()) 58 | 59 | end 60 | 61 | function final(self) 62 | -- Add finalization code here 63 | -- Remove this function if not needed 64 | end 65 | 66 | function update(self, dt) 67 | -- Add update code here 68 | -- Remove this function if not needed 69 | end 70 | 71 | function on_message(self, message_id, message, sender) 72 | -- Add message-handling code here 73 | -- Remove this function if not needed 74 | end 75 | 76 | function on_input(self, action_id, action) 77 | -- Add input-handling code here 78 | -- Remove this function if not needed 79 | end 80 | 81 | function on_reload(self) 82 | -- Add reload-handling code here 83 | -- Remove this function if not needed 84 | end 85 | -------------------------------------------------------------------------------- /examples/tools/texture_dynamic_buffer/buffer_controller.script: -------------------------------------------------------------------------------- 1 | local ms_rng = require("defrs.utils.mersennetwister") 2 | 3 | 4 | 5 | 6 | 7 | local function clear_texture(self, color) 8 | for y=0, self.size-1 do 9 | for x=0, self.size-1 do 10 | local index = y * self.size * 4 + x * 4 + 1 11 | self.stream[index + 0] = color.x 12 | self.stream[index + 1] = color.y 13 | self.stream[index + 2] = color.z 14 | self.stream[index + 3] = color.w 15 | end 16 | end 17 | 18 | end 19 | 20 | local function update_texture(self, time) 21 | for y=0, self.size-1 do 22 | for x=0, self.size-1 do 23 | local index = y * self.size * 4 + x * 4 + 1 24 | self.stream[index + 0] = self.clear_color.r * math.abs(math.sin(time)) 25 | self.stream[index + 1] = self.clear_color.g * ms_rng.random(1,2) 26 | self.stream[index + 2] = self.clear_color.b * math.abs(math.cos(time)) 27 | if y<10 then 28 | self.stream[index + 0] = self.clear_color.r * math.abs(math.sin(time)) * (self.clear_color.a * math.abs(math.cos(time))) 29 | self.stream[index + 1] = self.clear_color.g * ms_rng.random(1,2) * (self.clear_color.a * math.abs(math.cos(time))) 30 | self.stream[index + 2] = self.clear_color.b * math.abs(math.cos(time)) * (self.clear_color.a * math.abs(math.cos(time))) 31 | self.stream[index + 3] = self.clear_color.a * math.abs(math.cos(time)) 32 | elseif y>=25 and y < 35 then 33 | self.stream[index + 0] = 0 34 | self.stream[index + 1] = 0 35 | self.stream[index + 2] = 0 36 | self.stream[index + 3] = 0 37 | elseif y>=40 and y < 45 then 38 | self.stream[index + 0] = 100 39 | self.stream[index + 1] = 100 40 | self.stream[index + 2] = 100 41 | self.stream[index + 3] = 0 42 | 43 | else 44 | self.stream[index + 3] = self.clear_color.a 45 | end 46 | end 47 | end 48 | 49 | end 50 | 51 | 52 | local function reset(self) 53 | self.clear_color = {} 54 | self.clear_color.r = 175 55 | self.clear_color.g = 200 56 | self.clear_color.b = 125 57 | self.clear_color.a = 255 58 | 59 | clear_texture(self, vmath.vector4(self.clear_color.r, self.clear_color.g, self.clear_color.b, self.clear_color.a)) 60 | end 61 | 62 | 63 | function init(self) 64 | self.timer = 0 65 | 66 | local first_path = go.get("#sprite1", "texture0") 67 | local second_path = go.get("#sprite2", "texture0") 68 | --local first_buffer = resource.load(first_path) 69 | --resource.set_texture(path,table,buffer) 70 | 71 | 72 | math.randomseed(0xf3f3f3) 73 | 74 | self.size = 64 75 | 76 | self.textureheader = { width = self.size, 77 | height = self.size, 78 | type = resource.TEXTURE_TYPE_2D, 79 | format = resource.TEXTURE_FORMAT_RGBA, 80 | num_mip_maps = 1 } 81 | 82 | self.buffer = buffer.create(self.size * self.size, { {name=hash("rgba"), type = buffer.VALUE_TYPE_UINT8, count = 4 }}) 83 | self.stream = buffer.get_stream(self.buffer, hash("rgba")) 84 | 85 | reset(self) 86 | end 87 | 88 | function final(self) 89 | -- Add finalization code here 90 | -- Remove this function if not needed 91 | end 92 | 93 | function update(self, dt) 94 | 95 | self.timer = self.timer + dt 96 | 97 | 98 | update_texture(self, self.timer) 99 | 100 | label.set_text("#label",tostring(math.floor(self.timer * 100) * 0.01)) 101 | 102 | if self.buffer ~= nil then 103 | local path = go.get("#sprite1", "texture0") 104 | resource.set_texture(path,self.textureheader,self.buffer) 105 | 106 | local path2 = go.get("#sprite3", "texture0") 107 | resource.set_texture(path2,self.textureheader,self.buffer) 108 | 109 | local path3 = go.get("#sprite4", "texture0") 110 | resource.set_texture(path3,self.textureheader,self.buffer) 111 | 112 | local path4 = go.get("#sprite5", "texture0") 113 | resource.set_texture(path4,self.textureheader,self.buffer) 114 | end 115 | 116 | end 117 | 118 | function on_message(self, message_id, message, sender) 119 | -- Add message-handling code here 120 | -- Remove this function if not needed 121 | end 122 | 123 | function on_input(self, action_id, action) 124 | 125 | end 126 | 127 | function on_reload(self) 128 | -- Add reload-handling code here 129 | -- Remove this function if not needed 130 | end 131 | -------------------------------------------------------------------------------- /examples/tools/texture_dynamic_buffer/buffer_sprite_1.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/pyxels/buffer_sprite_1.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /examples/tools/texture_dynamic_buffer/buffer_sprite_2.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/pyxels/buffer_sprite_2.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /examples/tools/texture_dynamic_buffer/texture_64.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/examples/tools/texture_dynamic_buffer/texture_64_2.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /examples/tools/texture_dynamic_buffer/texture_64_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/tools/texture_dynamic_buffer/texture_64_2.png -------------------------------------------------------------------------------- /examples/toys/arc_swing/bouncer_ball.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/defrs/scripts/sprite_set_tint_color.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | properties { 16 | id: "tint" 17 | value: "0.9,0.9,1.0,1.0" 18 | type: PROPERTY_TYPE_VECTOR4 19 | } 20 | } 21 | embedded_components { 22 | id: "collisionobject" 23 | type: "collisionobject" 24 | data: "collision_shape: \"\"\n" 25 | "type: COLLISION_OBJECT_TYPE_DYNAMIC\n" 26 | "mass: 70.0\n" 27 | "friction: 0.01\n" 28 | "restitution: 0.8\n" 29 | "group: \"default\"\n" 30 | "mask: \"default\"\n" 31 | "embedded_collision_shape {\n" 32 | " shapes {\n" 33 | " shape_type: TYPE_SPHERE\n" 34 | " position {\n" 35 | " x: 0.0\n" 36 | " y: 0.0\n" 37 | " z: 0.0\n" 38 | " }\n" 39 | " rotation {\n" 40 | " x: 0.0\n" 41 | " y: 0.0\n" 42 | " z: 0.0\n" 43 | " w: 1.0\n" 44 | " }\n" 45 | " index: 0\n" 46 | " count: 1\n" 47 | " }\n" 48 | " data: 55.0\n" 49 | "}\n" 50 | "linear_damping: 0.0\n" 51 | "angular_damping: 0.0\n" 52 | "locked_rotation: false\n" 53 | "" 54 | position { 55 | x: 0.0 56 | y: 0.0 57 | z: 0.0 58 | } 59 | rotation { 60 | x: 0.0 61 | y: 0.0 62 | z: 0.0 63 | w: 1.0 64 | } 65 | } 66 | embedded_components { 67 | id: "sprite" 68 | type: "sprite" 69 | data: "tile_set: \"/defrs/assets/textures/misc/misc.atlas\"\n" 70 | "default_animation: \"pearl\"\n" 71 | "material: \"/builtins/materials/sprite.material\"\n" 72 | "blend_mode: BLEND_MODE_ALPHA\n" 73 | "" 74 | position { 75 | x: 0.0 76 | y: 0.0 77 | z: 0.0 78 | } 79 | rotation { 80 | x: 0.0 81 | y: 0.0 82 | z: 0.0 83 | w: 1.0 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /examples/toys/arc_swing/spacer.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/defrs/scripts/go_set_scale.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | properties { 16 | id: "scale" 17 | value: "0.125,0.125,1.0" 18 | type: PROPERTY_TYPE_VECTOR3 19 | } 20 | } 21 | embedded_components { 22 | id: "sprite" 23 | type: "sprite" 24 | data: "tile_set: \"/defrs/assets/textures/misc/misc.atlas\"\n" 25 | "default_animation: \"pearl\"\n" 26 | "material: \"/builtins/materials/sprite.material\"\n" 27 | "blend_mode: BLEND_MODE_ALPHA\n" 28 | "" 29 | position { 30 | x: 0.0 31 | y: 0.0 32 | z: 0.0 33 | } 34 | rotation { 35 | x: 0.0 36 | y: 0.0 37 | z: 0.0 38 | w: 1.0 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/toys/arc_swing/swing.script: -------------------------------------------------------------------------------- 1 | -- refactor = don't constantly create new vectors 2 | local swing_distance = 625 3 | 4 | function radian_to_vector(radian) 5 | return (vmath.vector3(math.cos(radian), math.sin(radian), 0.0)) 6 | end 7 | 8 | function init(self) 9 | go.set(".","scale.z",7 * math.pi / 6) 10 | go.animate(".","scale.z",go.PLAYBACK_LOOP_PINGPONG,11 * math.pi / 6,go.EASING_INOUTSINE,4) 11 | end 12 | 13 | function update(self, dt) 14 | local hanger_position = go.get_position("hanger") 15 | local position = hanger_position + radian_to_vector(go.get(".","scale.z")) * swing_distance 16 | go.set_position(position) 17 | end 18 | 19 | function on_message(self, message_id, message, sender) 20 | if message_id == hash("contact_point_response") then 21 | --pprint(message) 22 | --pprint(message.other_id) 23 | --msg.post(message.other_id, "apply_force", {force = vmath.vector3(10000.0, -10000, 0), position = go.get_position(message.other_id)}) 24 | msg.post(message.other_id, "apply_force", { force = message.normal * message.distance * -60000, position = message.position }) 25 | --msg.post("/bouncer_ball#collisionobject", "apply_force", { force = message.normal * message.distance * 100000, position = message.position }) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /examples/toys/bouncer/ball.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | msg.post(".", "acquire_input_focus") 3 | end 4 | 5 | function on_message(self, message_id, message, sender) 6 | if message_id == hash("ray_cast_response") then 7 | print("Pew!") 8 | end 9 | end 10 | 11 | function on_input(self, action_id, action) 12 | 13 | if action_id == hash("touch") then 14 | local click_location = vmath.vector3(action.screen_x, action.screen_y, 0) 15 | local ray_cast_groups = {hash("default")} 16 | local direction = vmath.vector3((click_location.x - go.get_position(".").x) * 1000,(click_location.y - go.get_position(".").y) * 1000,0 ) 17 | physics.ray_cast(go.get_position("."), click_location, ray_cast_groups, 0) 18 | msg.post("@render:", "draw_line", { start_point = go.get_position("."), end_point = click_location, color = vmath.vector4(1, 1, 1, 1) } ) 19 | msg.post("#collisionobject", "apply_force", { force = direction, position = click_location }) 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /examples/toys/bouncer/big_wall.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "embedded_components {\n" 6 | " id: \"collisionobject\"\n" 7 | " type: \"collisionobject\"\n" 8 | " data: \"collision_shape: \\\"\\\"\\n" 9 | "type: COLLISION_OBJECT_TYPE_STATIC\\n" 10 | "mass: 0.0\\n" 11 | "friction: 0.1\\n" 12 | "restitution: 0.5\\n" 13 | "group: \\\"default\\\"\\n" 14 | "mask: \\\"default\\\"\\n" 15 | "embedded_collision_shape {\\n" 16 | " shapes {\\n" 17 | " shape_type: TYPE_BOX\\n" 18 | " position {\\n" 19 | " x: 0.0\\n" 20 | " y: 0.0\\n" 21 | " z: 0.0\\n" 22 | " }\\n" 23 | " rotation {\\n" 24 | " x: 0.0\\n" 25 | " y: 0.0\\n" 26 | " z: 0.0\\n" 27 | " w: 1.0\\n" 28 | " }\\n" 29 | " index: 0\\n" 30 | " count: 3\\n" 31 | " }\\n" 32 | " data: 6239.8896\\n" 33 | " data: 6283.3467\\n" 34 | " data: 1.0\\n" 35 | "}\\n" 36 | "linear_damping: 0.0\\n" 37 | "angular_damping: 0.0\\n" 38 | "locked_rotation: false\\n" 39 | "\"\n" 40 | " position {\n" 41 | " x: 0.0\n" 42 | " y: 0.0\n" 43 | " z: 0.0\n" 44 | " }\n" 45 | " rotation {\n" 46 | " x: 0.0\n" 47 | " y: 0.0\n" 48 | " z: 0.0\n" 49 | " w: 1.0\n" 50 | " }\n" 51 | "}\n" 52 | "" 53 | position { 54 | x: 0.0 55 | y: 0.0 56 | z: 0.0 57 | } 58 | rotation { 59 | x: 0.0 60 | y: 0.0 61 | z: 0.0 62 | w: 1.0 63 | } 64 | scale3 { 65 | x: 1.0 66 | y: 1.0 67 | z: 1.0 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/toys/bouncer/ground.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "ground" 5 | children: "image_container" 6 | data: "embedded_components {\n" 7 | " id: \"collisionobject\"\n" 8 | " type: \"collisionobject\"\n" 9 | " data: \"collision_shape: \\\"\\\"\\n" 10 | "type: COLLISION_OBJECT_TYPE_STATIC\\n" 11 | "mass: 0.0\\n" 12 | "friction: 0.1\\n" 13 | "restitution: 0.5\\n" 14 | "group: \\\"default\\\"\\n" 15 | "mask: \\\"default\\\"\\n" 16 | "embedded_collision_shape {\\n" 17 | " shapes {\\n" 18 | " shape_type: TYPE_BOX\\n" 19 | " position {\\n" 20 | " x: 0.0\\n" 21 | " y: 0.0\\n" 22 | " z: 0.0\\n" 23 | " }\\n" 24 | " rotation {\\n" 25 | " x: 0.0\\n" 26 | " y: 0.0\\n" 27 | " z: 0.0\\n" 28 | " w: 1.0\\n" 29 | " }\\n" 30 | " index: 0\\n" 31 | " count: 3\\n" 32 | " }\\n" 33 | " data: 63.675686\\n" 34 | " data: 10.0\\n" 35 | " data: 500.0\\n" 36 | "}\\n" 37 | "linear_damping: 0.0\\n" 38 | "angular_damping: 0.0\\n" 39 | "locked_rotation: false\\n" 40 | "\"\n" 41 | " position {\n" 42 | " x: 0.0\n" 43 | " y: 0.0\n" 44 | " z: 0.0\n" 45 | " }\n" 46 | " rotation {\n" 47 | " x: 0.0\n" 48 | " y: 0.0\n" 49 | " z: 0.0\n" 50 | " w: 1.0\n" 51 | " }\n" 52 | "}\n" 53 | "" 54 | position { 55 | x: 0.0 56 | y: 0.0 57 | z: 0.0 58 | } 59 | rotation { 60 | x: 0.0 61 | y: 0.0 62 | z: 0.0 63 | w: 1.0 64 | } 65 | scale3 { 66 | x: 1.0 67 | y: 1.0 68 | z: 1.0 69 | } 70 | } 71 | embedded_instances { 72 | id: "image_container" 73 | data: "embedded_components {\n" 74 | " id: \"sprite\"\n" 75 | " type: \"sprite\"\n" 76 | " data: \"tile_set: \\\"/examples/toys/bouncer/logo.atlas\\\"\\n" 77 | "default_animation: \\\"logo\\\"\\n" 78 | "material: \\\"/builtins/materials/sprite.material\\\"\\n" 79 | "blend_mode: BLEND_MODE_ALPHA\\n" 80 | "\"\n" 81 | " position {\n" 82 | " x: 0.0\n" 83 | " y: 0.0\n" 84 | " z: 0.0\n" 85 | " }\n" 86 | " rotation {\n" 87 | " x: 0.0\n" 88 | " y: 0.0\n" 89 | " z: 0.0\n" 90 | " w: 1.0\n" 91 | " }\n" 92 | "}\n" 93 | "" 94 | position { 95 | x: 0.0 96 | y: 0.0 97 | z: 0.0 98 | } 99 | rotation { 100 | x: 0.0 101 | y: 0.0 102 | z: 0.0 103 | w: 1.0 104 | } 105 | scale3 { 106 | x: 1.0 107 | y: 0.154866 108 | z: 1.0 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /examples/toys/bouncer/ground_gen.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | collectionfactory.create("#groundfactory", go.get_position("."), go.get_rotation("."), {}, 2) 3 | end 4 | -------------------------------------------------------------------------------- /examples/toys/bouncer/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/bouncer/images/logo.png -------------------------------------------------------------------------------- /examples/toys/bouncer/logo.atlas: -------------------------------------------------------------------------------- 1 | images { 2 | image: "/examples/toys/bouncer/images/logo.png" 3 | } 4 | margin: 0 5 | extrude_borders: 0 6 | inner_padding: 0 7 | -------------------------------------------------------------------------------- /examples/toys/identicons/identicon_manager.script: -------------------------------------------------------------------------------- 1 | local objects = {} 2 | 3 | function create_objects() 4 | local total = 0 5 | local padding = 25 6 | for i = 1, 3, 1 do 7 | for j = 1, 3, 1 do 8 | total = total + 1 9 | objects[total] = factory.create("#factory", vmath.vector3(0.0 + (160+padding) * i +350, 0.0 + (160+padding) * j, 0.0)) 10 | end 11 | end 12 | end 13 | 14 | function on_input(self, action_id, action) 15 | if action_id == hash("touch") and action.pressed then 16 | for key, value in ipairs(objects) do 17 | msg.post(value,"randomize_tiles") 18 | end 19 | end 20 | end 21 | 22 | function init(self) 23 | msg.post(".", "acquire_input_focus") 24 | create_objects() 25 | end -------------------------------------------------------------------------------- /examples/toys/identicons/identicon_prefab.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/examples/toys/identicons/identicons.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | } 16 | components { 17 | id: "tilemap" 18 | component: "/examples/toys/identicons/identicons.tilemap" 19 | position { 20 | x: 0.0 21 | y: 0.0 22 | z: 0.0 23 | } 24 | rotation { 25 | x: 0.0 26 | y: 0.0 27 | z: 0.0 28 | w: 1.0 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/toys/identicons/identicons.script: -------------------------------------------------------------------------------- 1 | -- colors 1-14 are light colors 2 | -- colors 15-30 are dark colors 3 | 4 | 5 | 6 | go.property("seed",0) 7 | 8 | local rng = require("defrs.utils.rng") 9 | 10 | function purge_bad_rng() 11 | rng.random(); rng.random(); rng.random() 12 | -- we do this every time for each step to remove the initial bad RNG Lua can have 13 | -- otherwise you may get the same result every step...!!! 14 | end 15 | 16 | function clear_tilemap(color) 17 | for i = 1, 5, 1 do 18 | for j = 1, 5, 1 do 19 | tilemap.set_tile("#tilemap", "layer1", i, j, color) 20 | end 21 | end 22 | end 23 | 24 | function set_foreground(color) 25 | for i = 1, 3, 1 do 26 | for j = 1, 5, 1 do 27 | if rng.random(0, 1) == 1 then 28 | tilemap.set_tile("#tilemap", "layer1", i, j, color) 29 | if i == 1 then 30 | tilemap.set_tile("#tilemap", "layer1", 5, j, color) 31 | elseif i == 2 then 32 | tilemap.set_tile("#tilemap", "layer1", 4, j, color) 33 | end 34 | end 35 | end 36 | end 37 | end 38 | 39 | function set_foreground_seeded(color, step, seed) 40 | for i = 1, 3, 1 do 41 | for j = 1, 5, 1 do 42 | local flag = rng.random(0, 1) 43 | if flag == 1 then 44 | tilemap.set_tile("#tilemap", "layer1", i, j, color) 45 | if i == 1 then 46 | tilemap.set_tile("#tilemap", "layer1", 5, j, color) 47 | elseif i == 2 then 48 | tilemap.set_tile("#tilemap", "layer1", 4, j, color) 49 | end 50 | end 51 | step = step + 1; rng.randomseed(seed + step); purge_bad_rng() 52 | end 53 | end 54 | end 55 | 56 | 57 | function randomize_tiles() 58 | background_color = rng.random(1, 14) 59 | clear_tilemap(background_color) 60 | foreground_color = rng.random(15, 30) 61 | set_foreground(foreground_color) 62 | end 63 | 64 | function randomize_tiles_seeded(seed) 65 | local step = 0 66 | rng.randomseed(seed + step) 67 | background_color = rng.random(1, 14); step = step + 1; rng.randomseed(seed + step); purge_bad_rng() 68 | clear_tilemap(background_color) 69 | foreground_color = rng.random(15, 30); step = step + 1; rng.randomseed(seed + step); purge_bad_rng() 70 | set_foreground_seeded(foreground_color, step, seed) 71 | rng.setup_rng() -- when done make sure we reset the Random Number Generator so that it's OS based random 72 | end 73 | 74 | function init(self) 75 | if self.seed == 0.0 then 76 | randomize_tiles() 77 | else 78 | randomize_tiles_seeded(self.seed) 79 | end 80 | end 81 | 82 | function final(self) 83 | -- Add finalization code here 84 | -- Remove this function if not needed 85 | end 86 | 87 | function update(self, dt) 88 | -- Add update code here 89 | -- Remove this function if not needed 90 | end 91 | 92 | function on_message(self, message_id, message, sender) 93 | if message_id == hash("randomize_tiles") then 94 | randomize_tiles() 95 | end 96 | end 97 | 98 | function on_input(self, action_id, action) 99 | 100 | end 101 | 102 | function on_reload(self) 103 | -- Add reload-handling code here 104 | -- Remove this function if not needed 105 | end 106 | -------------------------------------------------------------------------------- /examples/toys/identicons/identicons.tilemap: -------------------------------------------------------------------------------- 1 | tile_set: "/examples/toys/identicons/identicons.tilesource" 2 | layers { 3 | id: "layer1" 4 | z: 0.0 5 | is_visible: 1 6 | cell { 7 | x: 0 8 | y: 0 9 | tile: 0 10 | h_flip: 0 11 | v_flip: 0 12 | } 13 | cell { 14 | x: 2 15 | y: 2 16 | tile: 0 17 | h_flip: 0 18 | v_flip: 0 19 | } 20 | cell { 21 | x: 3 22 | y: 4 23 | tile: 29 24 | h_flip: 0 25 | v_flip: 0 26 | } 27 | cell { 28 | x: 2 29 | y: 1 30 | tile: 29 31 | h_flip: 0 32 | v_flip: 0 33 | } 34 | cell { 35 | x: 2 36 | y: 4 37 | tile: 0 38 | h_flip: 0 39 | v_flip: 0 40 | } 41 | cell { 42 | x: 4 43 | y: 2 44 | tile: 0 45 | h_flip: 0 46 | v_flip: 0 47 | } 48 | cell { 49 | x: 1 50 | y: 0 51 | tile: 29 52 | h_flip: 0 53 | v_flip: 0 54 | } 55 | cell { 56 | x: 1 57 | y: 4 58 | tile: 29 59 | h_flip: 0 60 | v_flip: 0 61 | } 62 | cell { 63 | x: 4 64 | y: 0 65 | tile: 0 66 | h_flip: 0 67 | v_flip: 0 68 | } 69 | cell { 70 | x: 1 71 | y: 2 72 | tile: 29 73 | h_flip: 0 74 | v_flip: 0 75 | } 76 | cell { 77 | x: 0 78 | y: 1 79 | tile: 29 80 | h_flip: 0 81 | v_flip: 0 82 | } 83 | cell { 84 | x: 0 85 | y: 3 86 | tile: 29 87 | h_flip: 0 88 | v_flip: 0 89 | } 90 | cell { 91 | x: 2 92 | y: 3 93 | tile: 29 94 | h_flip: 0 95 | v_flip: 0 96 | } 97 | cell { 98 | x: 4 99 | y: 1 100 | tile: 29 101 | h_flip: 0 102 | v_flip: 0 103 | } 104 | cell { 105 | x: 4 106 | y: 3 107 | tile: 29 108 | h_flip: 0 109 | v_flip: 0 110 | } 111 | cell { 112 | x: 3 113 | y: 0 114 | tile: 29 115 | h_flip: 0 116 | v_flip: 0 117 | } 118 | cell { 119 | x: 2 120 | y: 0 121 | tile: 0 122 | h_flip: 0 123 | v_flip: 0 124 | } 125 | cell { 126 | x: 3 127 | y: 1 128 | tile: 0 129 | h_flip: 0 130 | v_flip: 0 131 | } 132 | cell { 133 | x: 3 134 | y: 2 135 | tile: 29 136 | h_flip: 0 137 | v_flip: 0 138 | } 139 | cell { 140 | x: 1 141 | y: 1 142 | tile: 0 143 | h_flip: 0 144 | v_flip: 0 145 | } 146 | cell { 147 | x: 0 148 | y: 2 149 | tile: 0 150 | h_flip: 0 151 | v_flip: 0 152 | } 153 | cell { 154 | x: 0 155 | y: 4 156 | tile: 0 157 | h_flip: 0 158 | v_flip: 0 159 | } 160 | cell { 161 | x: 1 162 | y: 3 163 | tile: 0 164 | h_flip: 0 165 | v_flip: 0 166 | } 167 | cell { 168 | x: 4 169 | y: 4 170 | tile: 0 171 | h_flip: 0 172 | v_flip: 0 173 | } 174 | cell { 175 | x: 3 176 | y: 3 177 | tile: 0 178 | h_flip: 0 179 | v_flip: 0 180 | } 181 | } 182 | material: "/builtins/materials/tile_map.material" 183 | blend_mode: BLEND_MODE_ALPHA 184 | -------------------------------------------------------------------------------- /examples/toys/identicons/identicons.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/pastel_tile_colors.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | animations { 9 | id: "1" 10 | start_tile: 1 11 | end_tile: 1 12 | playback: PLAYBACK_ONCE_FORWARD 13 | fps: 30 14 | flip_horizontal: 0 15 | flip_vertical: 0 16 | } 17 | extrude_borders: 2 18 | inner_padding: 0 19 | -------------------------------------------------------------------------------- /examples/toys/konami_code/konami_code.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | instances { 3 | id: "screen_size" 4 | prototype: "/defrs/gui/screen_size.go" 5 | position { 6 | x: 0.0 7 | y: 0.0 8 | z: 0.0 9 | } 10 | rotation { 11 | x: 0.0 12 | y: 0.0 13 | z: 0.0 14 | w: 1.0 15 | } 16 | scale3 { 17 | x: 1.0 18 | y: 1.0 19 | z: 1.0 20 | } 21 | } 22 | scale_along_z: 0 23 | embedded_instances { 24 | id: "konami_code" 25 | data: "components {\n" 26 | " id: \"script\"\n" 27 | " component: \"/examples/toys/konami_code/konami_code.script\"\n" 28 | " position {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " }\n" 33 | " rotation {\n" 34 | " x: 0.0\n" 35 | " y: 0.0\n" 36 | " z: 0.0\n" 37 | " w: 1.0\n" 38 | " }\n" 39 | "}\n" 40 | "embedded_components {\n" 41 | " id: \"label\"\n" 42 | " type: \"label\"\n" 43 | " data: \"size {\\n" 44 | " x: 128.0\\n" 45 | " y: 32.0\\n" 46 | " z: 0.0\\n" 47 | " w: 0.0\\n" 48 | "}\\n" 49 | "scale {\\n" 50 | " x: 1.0\\n" 51 | " y: 1.0\\n" 52 | " z: 1.0\\n" 53 | " w: 0.0\\n" 54 | "}\\n" 55 | "color {\\n" 56 | " x: 1.0\\n" 57 | " y: 1.0\\n" 58 | " z: 1.0\\n" 59 | " w: 1.0\\n" 60 | "}\\n" 61 | "outline {\\n" 62 | " x: 0.0\\n" 63 | " y: 0.0\\n" 64 | " z: 0.0\\n" 65 | " w: 1.0\\n" 66 | "}\\n" 67 | "shadow {\\n" 68 | " x: 0.0\\n" 69 | " y: 0.0\\n" 70 | " z: 0.0\\n" 71 | " w: 1.0\\n" 72 | "}\\n" 73 | "leading: 1.0\\n" 74 | "tracking: 0.0\\n" 75 | "pivot: PIVOT_CENTER\\n" 76 | "blend_mode: BLEND_MODE_ALPHA\\n" 77 | "line_break: false\\n" 78 | "text: \\\"Hmm...\\\"\\n" 79 | "font: \\\"/defrs/fonts/nes_chimera/nes_chimera.font\\\"\\n" 80 | "material: \\\"/defrs/fonts/materials/pixel_font.material\\\"\\n" 81 | "\"\n" 82 | " position {\n" 83 | " x: 0.0\n" 84 | " y: 0.0\n" 85 | " z: 0.0\n" 86 | " }\n" 87 | " rotation {\n" 88 | " x: 0.0\n" 89 | " y: 0.0\n" 90 | " z: 0.0\n" 91 | " w: 1.0\n" 92 | " }\n" 93 | "}\n" 94 | "embedded_components {\n" 95 | " id: \"sound\"\n" 96 | " type: \"sound\"\n" 97 | " data: \"sound: \\\"/examples/toys/konami_code/sawsquarenoise_-_01_-_Interstellar.ogg\\\"\\n" 98 | "looping: 1\\n" 99 | "group: \\\"master\\\"\\n" 100 | "gain: 1.0\\n" 101 | "\"\n" 102 | " position {\n" 103 | " x: 0.0\n" 104 | " y: 0.0\n" 105 | " z: 0.0\n" 106 | " }\n" 107 | " rotation {\n" 108 | " x: 0.0\n" 109 | " y: 0.0\n" 110 | " z: 0.0\n" 111 | " w: 1.0\n" 112 | " }\n" 113 | "}\n" 114 | "" 115 | position { 116 | x: 791.795 117 | y: 414.359 118 | z: 0.0 119 | } 120 | rotation { 121 | x: 0.0 122 | y: 0.0 123 | z: 0.0 124 | w: 1.0 125 | } 126 | scale3 { 127 | x: 1.0 128 | y: 1.0 129 | z: 1.0 130 | } 131 | } 132 | embedded_instances { 133 | id: "victory" 134 | data: "components {\n" 135 | " id: \"particlefx\"\n" 136 | " component: \"/examples/toys/konami_code/victory.particlefx\"\n" 137 | " position {\n" 138 | " x: 0.0\n" 139 | " y: 0.0\n" 140 | " z: 0.0\n" 141 | " }\n" 142 | " rotation {\n" 143 | " x: 0.0\n" 144 | " y: 0.0\n" 145 | " z: 0.0\n" 146 | " w: 1.0\n" 147 | " }\n" 148 | "}\n" 149 | "" 150 | position { 151 | x: 758.576 152 | y: 396.581 153 | z: 0.0 154 | } 155 | rotation { 156 | x: 0.0 157 | y: 0.0 158 | z: 0.0 159 | w: 1.0 160 | } 161 | scale3 { 162 | x: 1.0 163 | y: 1.0 164 | z: 1.0 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /examples/toys/konami_code/konami_code.script: -------------------------------------------------------------------------------- 1 | -- ↑ ↑ ↓ ↓ ← → ← → b a 2 | 3 | local colors = require("defrs.utils.colors") 4 | 5 | 6 | 7 | local sequence = {"up", "up", "down", "down", "left", "right", "left", "right", "b", "a"} 8 | 9 | function check_sequence(events, self) 10 | local matches = 0 11 | for key, value in ipairs(events) do 12 | if hash(sequence[key]) == value then 13 | matches = matches + 1 14 | else 15 | self.events = {} 16 | return false 17 | end 18 | if matches == #sequence then 19 | return true 20 | end 21 | end 22 | end 23 | 24 | function init(self) 25 | msg.post(".", "acquire_input_focus") 26 | self.events = {} 27 | 28 | self.timer = 0 29 | self.konami_code = false 30 | end 31 | 32 | 33 | function on_input(self, action_id, action) 34 | if action.released then 35 | local next_action = #self.events +1 36 | self.events[next_action] = hash(action_id) 37 | if(check_sequence(self.events, self)) then 38 | label.set_text("#label","Konami Code!") 39 | print("Konami Code!") 40 | particlefx.play("/victory#particlefx") 41 | self.events = {} 42 | self.konami_code = true 43 | go.animate(".","scale.x",go.PLAYBACK_LOOP_PINGPONG,5,go.EASING_INOUTEXPO,3) 44 | go.animate(".","scale.y",go.PLAYBACK_LOOP_PINGPONG,5.5,go.EASING_INOUTEXPO,3.1) 45 | msg.post("#sound", "play_sound", {delay = 0, gain = 0.5}) 46 | end 47 | pprint(self.events) 48 | end 49 | end 50 | 51 | function update(self, dt) 52 | self.timer = self.timer + dt 53 | 54 | if self.konami_code == true then 55 | go.set("#label","color",colors.get_random_color()) 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /examples/toys/konami_code/sawsquarenoise_-_01_-_Interstellar.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/konami_code/sawsquarenoise_-_01_-_Interstellar.ogg -------------------------------------------------------------------------------- /examples/toys/konami_code/sawsquarenoise_-_01_-_Interstellar_LICENSE.txt: -------------------------------------------------------------------------------- 1 | URL: http://freemusicarchive.org/music/sawsquarenoise/OverHeated_Alfa_02/Interstellar 2 | Comments: http://freemusicarchive.org/ 3 | Curator: 4 | Copyright: Attribution-NonCommercial-ShareAlike: http://creativecommons.org/licenses/by-nc-sa/4.0/ -------------------------------------------------------------------------------- /examples/toys/minesweeper/minesweeper_borders.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/minesweeper.png" 2 | tile_width: 16 3 | tile_height: 16 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | collision_groups: "default" 9 | animations { 10 | id: "anim" 11 | start_tile: 1 12 | end_tile: 1 13 | playback: PLAYBACK_ONCE_FORWARD 14 | fps: 30 15 | flip_horizontal: 0 16 | flip_vertical: 0 17 | } 18 | extrude_borders: 2 19 | inner_padding: 0 20 | -------------------------------------------------------------------------------- /examples/toys/minesweeper/minesweeper_cells.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/minesweeper.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | animations { 9 | id: "blank" 10 | start_tile: 1 11 | end_tile: 1 12 | playback: PLAYBACK_ONCE_FORWARD 13 | fps: 30 14 | flip_horizontal: 0 15 | flip_vertical: 0 16 | } 17 | extrude_borders: 2 18 | inner_padding: 0 19 | -------------------------------------------------------------------------------- /examples/toys/minesweeper/minesweeper_character.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/minesweeper.png" 2 | tile_width: 64 3 | tile_height: 64 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | collision_groups: "default" 9 | animations { 10 | id: "character_dead" 11 | start_tile: 8 12 | end_tile: 8 13 | playback: PLAYBACK_LOOP_FORWARD 14 | fps: 30 15 | flip_horizontal: 0 16 | flip_vertical: 0 17 | } 18 | animations { 19 | id: "character_normal" 20 | start_tile: 5 21 | end_tile: 5 22 | playback: PLAYBACK_ONCE_FORWARD 23 | fps: 30 24 | flip_horizontal: 0 25 | flip_vertical: 0 26 | } 27 | animations { 28 | id: "character_pressed" 29 | start_tile: 6 30 | end_tile: 6 31 | playback: PLAYBACK_ONCE_FORWARD 32 | fps: 30 33 | flip_horizontal: 0 34 | flip_vertical: 0 35 | } 36 | animations { 37 | id: "character_win" 38 | start_tile: 9 39 | end_tile: 9 40 | playback: PLAYBACK_ONCE_FORWARD 41 | fps: 30 42 | flip_horizontal: 0 43 | flip_vertical: 0 44 | } 45 | animations { 46 | id: "character_worried" 47 | start_tile: 7 48 | end_tile: 7 49 | playback: PLAYBACK_ONCE_FORWARD 50 | fps: 30 51 | flip_horizontal: 0 52 | flip_vertical: 0 53 | } 54 | animations { 55 | id: "character_zombie" 56 | start_tile: 10 57 | end_tile: 10 58 | playback: PLAYBACK_ONCE_FORWARD 59 | fps: 30 60 | flip_horizontal: 0 61 | flip_vertical: 0 62 | } 63 | extrude_borders: 2 64 | inner_padding: 0 65 | -------------------------------------------------------------------------------- /examples/toys/minesweeper/minesweeper_numbers.tilemap: -------------------------------------------------------------------------------- 1 | tile_set: "/examples/toys/minesweeper/minesweeper_numbers.tilesource" 2 | layers { 3 | id: "layer1" 4 | z: 0.0 5 | is_visible: 1 6 | cell { 7 | x: 0 8 | y: 0 9 | tile: 20 10 | h_flip: 0 11 | v_flip: 0 12 | } 13 | cell { 14 | x: 1 15 | y: 0 16 | tile: 20 17 | h_flip: 0 18 | v_flip: 0 19 | } 20 | cell { 21 | x: 2 22 | y: 0 23 | tile: 20 24 | h_flip: 0 25 | v_flip: 0 26 | } 27 | } 28 | material: "/defrs/materials/tile_map_pixelart.material" 29 | blend_mode: BLEND_MODE_ALPHA 30 | -------------------------------------------------------------------------------- /examples/toys/minesweeper/minesweeper_numbers.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/minesweeper.png" 2 | tile_width: 32 3 | tile_height: 64 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | collision_groups: "default" 9 | animations { 10 | id: "number_0" 11 | start_tile: 22 12 | end_tile: 22 13 | playback: PLAYBACK_ONCE_FORWARD 14 | fps: 30 15 | flip_horizontal: 0 16 | flip_vertical: 0 17 | } 18 | animations { 19 | id: "number_1" 20 | start_tile: 23 21 | end_tile: 23 22 | playback: PLAYBACK_ONCE_FORWARD 23 | fps: 30 24 | flip_horizontal: 0 25 | flip_vertical: 0 26 | } 27 | animations { 28 | id: "number_2" 29 | start_tile: 24 30 | end_tile: 24 31 | playback: PLAYBACK_ONCE_FORWARD 32 | fps: 30 33 | flip_horizontal: 0 34 | flip_vertical: 0 35 | } 36 | animations { 37 | id: "number_3" 38 | start_tile: 25 39 | end_tile: 25 40 | playback: PLAYBACK_ONCE_FORWARD 41 | fps: 30 42 | flip_horizontal: 0 43 | flip_vertical: 0 44 | } 45 | animations { 46 | id: "number_4" 47 | start_tile: 26 48 | end_tile: 26 49 | playback: PLAYBACK_ONCE_FORWARD 50 | fps: 30 51 | flip_horizontal: 0 52 | flip_vertical: 0 53 | } 54 | animations { 55 | id: "number_5" 56 | start_tile: 27 57 | end_tile: 27 58 | playback: PLAYBACK_ONCE_FORWARD 59 | fps: 30 60 | flip_horizontal: 0 61 | flip_vertical: 0 62 | } 63 | animations { 64 | id: "number_6" 65 | start_tile: 28 66 | end_tile: 28 67 | playback: PLAYBACK_ONCE_FORWARD 68 | fps: 30 69 | flip_horizontal: 0 70 | flip_vertical: 0 71 | } 72 | animations { 73 | id: "number_7" 74 | start_tile: 29 75 | end_tile: 29 76 | playback: PLAYBACK_ONCE_FORWARD 77 | fps: 30 78 | flip_horizontal: 0 79 | flip_vertical: 0 80 | } 81 | animations { 82 | id: "number_8" 83 | start_tile: 30 84 | end_tile: 30 85 | playback: PLAYBACK_ONCE_FORWARD 86 | fps: 30 87 | flip_horizontal: 0 88 | flip_vertical: 0 89 | } 90 | animations { 91 | id: "number_9" 92 | start_tile: 31 93 | end_tile: 31 94 | playback: PLAYBACK_ONCE_FORWARD 95 | fps: 30 96 | flip_horizontal: 0 97 | flip_vertical: 0 98 | } 99 | animations { 100 | id: "number_off" 101 | start_tile: 21 102 | end_tile: 21 103 | playback: PLAYBACK_ONCE_FORWARD 104 | fps: 30 105 | flip_horizontal: 0 106 | flip_vertical: 0 107 | } 108 | extrude_borders: 2 109 | inner_padding: 0 110 | -------------------------------------------------------------------------------- /examples/toys/orbit/crosshair.script: -------------------------------------------------------------------------------- 1 | local mouse_helper = require("defrs.utils.mouse_helper") 2 | 3 | function init(self) 4 | -- Add initialization code here 5 | -- Remove this function if not needed 6 | msg.post(".", "acquire_input_focus") 7 | self.mouse_x, self.mouse_y = 0.0, 0.0 8 | msg.post("#sprite", "play_animation", {id = hash("crosshair_19")}) 9 | end 10 | 11 | function final(self) 12 | -- Add finalization code here 13 | -- Remove this function if not needed 14 | end 15 | 16 | function update(self, dt) 17 | -- Add update code here 18 | -- Remove this function if not needed 19 | go.set_position(vmath.vector3(mouse_helper.mouse_x, mouse_helper.mouse_y, 0.0)) 20 | 21 | end 22 | 23 | function on_message(self, message_id, message, sender) 24 | -- Add message-handling code here 25 | -- Remove this function if not needed 26 | end 27 | 28 | function on_input(self, action_id, action) 29 | mouse_helper.mouse_x, mouse_helper.mouse_y = action.x, action.y 30 | 31 | if action_id == hash("touch") and action.pressed then 32 | msg.post("#sprite", "play_animation", {id = hash("crosshair_19_fire")}) 33 | end 34 | --pprint(action) 35 | end 36 | 37 | function on_reload(self) 38 | -- Add reload-handling code here 39 | -- Remove this function if not needed 40 | end 41 | -------------------------------------------------------------------------------- /examples/toys/orbit/crosshairs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/orbit/crosshairs.png -------------------------------------------------------------------------------- /examples/toys/orbit/crosshairs.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/orbit/crosshairs.pyxel -------------------------------------------------------------------------------- /examples/toys/orbit/crosshairs.tilesource: -------------------------------------------------------------------------------- 1 | image: "/examples/toys/orbit/crosshairs.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | animations { 9 | id: "crosshair_1" 10 | start_tile: 1 11 | end_tile: 1 12 | playback: PLAYBACK_ONCE_FORWARD 13 | fps: 30 14 | flip_horizontal: 0 15 | flip_vertical: 0 16 | } 17 | animations { 18 | id: "crosshair_10" 19 | start_tile: 10 20 | end_tile: 10 21 | playback: PLAYBACK_ONCE_FORWARD 22 | fps: 30 23 | flip_horizontal: 0 24 | flip_vertical: 0 25 | } 26 | animations { 27 | id: "crosshair_11" 28 | start_tile: 11 29 | end_tile: 11 30 | playback: PLAYBACK_ONCE_FORWARD 31 | fps: 30 32 | flip_horizontal: 0 33 | flip_vertical: 0 34 | } 35 | animations { 36 | id: "crosshair_12" 37 | start_tile: 12 38 | end_tile: 12 39 | playback: PLAYBACK_ONCE_FORWARD 40 | fps: 30 41 | flip_horizontal: 0 42 | flip_vertical: 0 43 | } 44 | animations { 45 | id: "crosshair_13" 46 | start_tile: 13 47 | end_tile: 13 48 | playback: PLAYBACK_ONCE_FORWARD 49 | fps: 30 50 | flip_horizontal: 0 51 | flip_vertical: 0 52 | } 53 | animations { 54 | id: "crosshair_14" 55 | start_tile: 14 56 | end_tile: 14 57 | playback: PLAYBACK_ONCE_FORWARD 58 | fps: 30 59 | flip_horizontal: 0 60 | flip_vertical: 0 61 | } 62 | animations { 63 | id: "crosshair_15" 64 | start_tile: 15 65 | end_tile: 15 66 | playback: PLAYBACK_ONCE_FORWARD 67 | fps: 30 68 | flip_horizontal: 0 69 | flip_vertical: 0 70 | } 71 | animations { 72 | id: "crosshair_16" 73 | start_tile: 16 74 | end_tile: 16 75 | playback: PLAYBACK_ONCE_FORWARD 76 | fps: 30 77 | flip_horizontal: 0 78 | flip_vertical: 0 79 | } 80 | animations { 81 | id: "crosshair_17" 82 | start_tile: 17 83 | end_tile: 17 84 | playback: PLAYBACK_ONCE_FORWARD 85 | fps: 30 86 | flip_horizontal: 0 87 | flip_vertical: 0 88 | } 89 | animations { 90 | id: "crosshair_18" 91 | start_tile: 18 92 | end_tile: 18 93 | playback: PLAYBACK_ONCE_FORWARD 94 | fps: 30 95 | flip_horizontal: 0 96 | flip_vertical: 0 97 | } 98 | animations { 99 | id: "crosshair_19" 100 | start_tile: 19 101 | end_tile: 19 102 | playback: PLAYBACK_ONCE_FORWARD 103 | fps: 30 104 | flip_horizontal: 0 105 | flip_vertical: 0 106 | } 107 | animations { 108 | id: "crosshair_19_fire" 109 | start_tile: 20 110 | end_tile: 23 111 | playback: PLAYBACK_ONCE_BACKWARD 112 | fps: 30 113 | flip_horizontal: 0 114 | flip_vertical: 0 115 | } 116 | animations { 117 | id: "crosshair_2" 118 | start_tile: 2 119 | end_tile: 2 120 | playback: PLAYBACK_ONCE_FORWARD 121 | fps: 30 122 | flip_horizontal: 0 123 | flip_vertical: 0 124 | } 125 | animations { 126 | id: "crosshair_3" 127 | start_tile: 3 128 | end_tile: 3 129 | playback: PLAYBACK_ONCE_FORWARD 130 | fps: 30 131 | flip_horizontal: 0 132 | flip_vertical: 0 133 | } 134 | animations { 135 | id: "crosshair_4" 136 | start_tile: 4 137 | end_tile: 4 138 | playback: PLAYBACK_ONCE_FORWARD 139 | fps: 30 140 | flip_horizontal: 0 141 | flip_vertical: 0 142 | } 143 | animations { 144 | id: "crosshair_5" 145 | start_tile: 5 146 | end_tile: 5 147 | playback: PLAYBACK_ONCE_FORWARD 148 | fps: 30 149 | flip_horizontal: 0 150 | flip_vertical: 0 151 | } 152 | animations { 153 | id: "crosshair_6" 154 | start_tile: 6 155 | end_tile: 6 156 | playback: PLAYBACK_ONCE_FORWARD 157 | fps: 30 158 | flip_horizontal: 0 159 | flip_vertical: 0 160 | } 161 | animations { 162 | id: "crosshair_7" 163 | start_tile: 7 164 | end_tile: 7 165 | playback: PLAYBACK_ONCE_FORWARD 166 | fps: 30 167 | flip_horizontal: 0 168 | flip_vertical: 0 169 | } 170 | animations { 171 | id: "crosshair_8" 172 | start_tile: 8 173 | end_tile: 8 174 | playback: PLAYBACK_ONCE_FORWARD 175 | fps: 30 176 | flip_horizontal: 0 177 | flip_vertical: 0 178 | } 179 | animations { 180 | id: "crosshair_9" 181 | start_tile: 9 182 | end_tile: 9 183 | playback: PLAYBACK_ONCE_FORWARD 184 | fps: 30 185 | flip_horizontal: 0 186 | flip_vertical: 0 187 | } 188 | extrude_borders: 2 189 | inner_padding: 0 190 | -------------------------------------------------------------------------------- /examples/toys/orbit/manager.script: -------------------------------------------------------------------------------- 1 | local orbs = {} 2 | 3 | local rng = require("defrs.utils.rng") 4 | 5 | function make_point(x,y) 6 | local count = #orbs + 1 7 | orbs[count] = factory.create("#factory", vmath.vector3(rng.random(25, 100), rng.random(25, 100), 0.0)) 8 | end 9 | 10 | 11 | 12 | 13 | function init(self) 14 | make_point() 15 | make_point() 16 | make_point() 17 | make_point() 18 | make_point() 19 | make_point() 20 | make_point() 21 | make_point() 22 | make_point() 23 | make_point() 24 | make_point() 25 | make_point() 26 | make_point() 27 | make_point() 28 | end 29 | 30 | function final(self) 31 | -- Add finalization code here 32 | -- Remove this function if not needed 33 | end 34 | 35 | function update(self, dt) 36 | -- Add update code here 37 | -- Remove this function if not needed 38 | end 39 | 40 | function on_message(self, message_id, message, sender) 41 | -- Add message-handling code here 42 | -- Remove this function if not needed 43 | end 44 | 45 | function on_input(self, action_id, action) 46 | -- Add input-handling code here 47 | -- Remove this function if not needed 48 | end 49 | 50 | function on_reload(self) 51 | -- Add reload-handling code here 52 | -- Remove this function if not needed 53 | end 54 | -------------------------------------------------------------------------------- /examples/toys/orbit/orb.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/defrs/scripts/sprite_set_tint_color.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | properties { 16 | id: "tint" 17 | value: "1.0,0.921,0.47,1.0" 18 | type: PROPERTY_TYPE_VECTOR4 19 | } 20 | } 21 | embedded_components { 22 | id: "sprite" 23 | type: "sprite" 24 | data: "tile_set: \"/builtins/graphics/particle_blob.tilesource\"\n" 25 | "default_animation: \"anim\"\n" 26 | "material: \"/defrs/materials/sprite_normal.material\"\n" 27 | "blend_mode: BLEND_MODE_ALPHA\n" 28 | "" 29 | position { 30 | x: 0.0 31 | y: 0.0 32 | z: 0.0 33 | } 34 | rotation { 35 | x: 0.0 36 | y: 0.0 37 | z: 0.0 38 | w: 1.0 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/toys/orbit/pixel_ship_freemove.script: -------------------------------------------------------------------------------- 1 | local mouse_helper = require("defrs.utils.mouse_helper") 2 | 3 | function init(self) 4 | -- Add initialization code here 5 | -- Remove this function if not needed 6 | self.impulse = vmath.vector3(0.0,0.0,0.0) 7 | msg.post(".", "acquire_input_focus") 8 | 9 | self.sun_position = go.get_position("sun") 10 | self.exhaust_playing = false 11 | end 12 | 13 | function final(self) 14 | -- Add finalization code here 15 | -- Remove this function if not needed 16 | end 17 | 18 | function update(self, dt) 19 | if self.exhaust_playing == false then 20 | particlefx.play("/exhaust#particlefx") 21 | self.exhaust_playing = true 22 | end 23 | if self.key_pressed == false then 24 | particlefx.stop("/exhaust#particlefx") 25 | self.exhaust_playing = false 26 | end 27 | 28 | self.position = go.get_position() 29 | 30 | self.impulse.x = math.min(self.impulse.x, 10) 31 | self.impulse.y = math.min(self.impulse.y, 10) 32 | 33 | self.look_at = (math.deg(math.atan2(self.position.x - mouse_helper.mouse_x, self.position.y - mouse_helper.mouse_y))) 34 | 35 | go.set(".", "euler.z", self.look_at * -1 - 90) 36 | go.set_position(go.get_position() + self.impulse) 37 | 38 | if self.position.x < 0 - 100 then 39 | self.position.x = self.position.x + 1600 + 200 40 | go.set_position(self.position) 41 | end 42 | if self.position.x > 1600 + 100 then 43 | self.position.x = self.position.x - 1600 - 200 44 | go.set_position(self.position) 45 | end 46 | if self.position.y < 0 - 100 then 47 | self.position.y = self.position.y + 800 + 200 48 | go.set_position(self.position) 49 | end 50 | if self.position.y > 800 + 100 then 51 | self.position.y = self.position.y - 800 - 200 52 | go.set_position(self.position) 53 | end 54 | 55 | if self.impulse.x > 0 then self.impulse.x = self.impulse.x - 0.001 end 56 | if self.impulse.x < 0 then self.impulse.x = self.impulse.x + 0.001 end 57 | if self.impulse.y > 0 then self.impulse.y = self.impulse.y - 0.001 end 58 | if self.impulse.y < 0 then self.impulse.y = self.impulse.y + 0.001 end 59 | 60 | -- (x2-x1,y2-y1) 61 | -- vn(x/Length(v), y/length(v)) 62 | 63 | local sun_direction = vmath.vector3(self.sun_position.x - self.position.x, self.sun_position.y - self.position.y, 0.0) 64 | --pprint("sun direction " .. sun_direction) 65 | local sun_impulse = vmath.vector3(sun_direction.x / vmath.length(sun_direction), sun_direction.y / vmath.length(sun_direction), 0.0) * 0.2 66 | --pprint("sun impulse " .. sun_impulse) 67 | self.impulse = self.impulse + sun_impulse 68 | 69 | self.key_pressed = false 70 | end 71 | 72 | function on_message(self, message_id, message, sender) 73 | -- Add message-handling code here 74 | -- Remove this function if not needed 75 | end 76 | 77 | function on_input(self, action_id, action) 78 | -- todo add acceleration when holding down keys 79 | 80 | 81 | if action_id == hash("w") then 82 | self.impulse = self.impulse + vmath.vector3(0.0, 0.25, 0.0) 83 | self.key_pressed = true 84 | end 85 | if action_id == hash("a") then 86 | self.impulse = self.impulse + vmath.vector3(-0.25, 0.0, 0.0) 87 | self.key_pressed = true 88 | end 89 | if action_id == hash("s") then 90 | self.impulse = self.impulse + vmath.vector3(0.0, -0.25, 0.0) 91 | self.key_pressed = true 92 | end 93 | if action_id == hash("d") then 94 | self.impulse = self.impulse + vmath.vector3(0.25, 0.0, 0.0) 95 | self.key_pressed = true 96 | end 97 | 98 | 99 | --if self.key_pressed == false then particlefx.play("/exhaust#particlefx") end 100 | --pprint(self.impulse) 101 | end 102 | 103 | function on_reload(self) 104 | -- Add reload-handling code here 105 | -- Remove this function if not needed 106 | end 107 | -------------------------------------------------------------------------------- /examples/toys/orbit/pixel_ships.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/orbit/pixel_ships.png -------------------------------------------------------------------------------- /examples/toys/orbit/pixel_ships.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/examples/toys/orbit/pixel_ships.pyxel -------------------------------------------------------------------------------- /examples/toys/orbit/pixel_ships.tilesource: -------------------------------------------------------------------------------- 1 | image: "/examples/toys/orbit/pixel_ships.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | animations { 9 | id: "anim" 10 | start_tile: 4 11 | end_tile: 4 12 | playback: PLAYBACK_ONCE_FORWARD 13 | fps: 30 14 | flip_horizontal: 0 15 | flip_vertical: 0 16 | } 17 | extrude_borders: 2 18 | inner_padding: 0 19 | -------------------------------------------------------------------------------- /examples/toys/orbit/ship.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | -- Add initialization code here 3 | -- Remove this function if not needed 4 | end 5 | 6 | function final(self) 7 | -- Add finalization code here 8 | -- Remove this function if not needed 9 | end 10 | 11 | function update(self, dt) 12 | -- Add update code here 13 | -- Remove this function if not needed 14 | end 15 | 16 | function on_message(self, message_id, message, sender) 17 | -- Add message-handling code here 18 | -- Remove this function if not needed 19 | end 20 | 21 | function on_input(self, action_id, action) 22 | -- Add input-handling code here 23 | -- Remove this function if not needed 24 | end 25 | 26 | function on_reload(self) 27 | -- Add reload-handling code here 28 | -- Remove this function if not needed 29 | end 30 | -------------------------------------------------------------------------------- /examples/toys/random_level/random_level.collection: -------------------------------------------------------------------------------- 1 | name: "default" 2 | scale_along_z: 0 3 | embedded_instances { 4 | id: "go" 5 | data: "components {\n" 6 | " id: \"tilemap\"\n" 7 | " component: \"/examples/toys/random_level/random_level.tilemap\"\n" 8 | " position {\n" 9 | " x: 0.0\n" 10 | " y: 0.0\n" 11 | " z: 0.0\n" 12 | " }\n" 13 | " rotation {\n" 14 | " x: 0.0\n" 15 | " y: 0.0\n" 16 | " z: 0.0\n" 17 | " w: 1.0\n" 18 | " }\n" 19 | "}\n" 20 | "components {\n" 21 | " id: \"script\"\n" 22 | " component: \"/examples/toys/random_level/random_level.script\"\n" 23 | " position {\n" 24 | " x: 0.0\n" 25 | " y: 0.0\n" 26 | " z: 0.0\n" 27 | " }\n" 28 | " rotation {\n" 29 | " x: 0.0\n" 30 | " y: 0.0\n" 31 | " z: 0.0\n" 32 | " w: 1.0\n" 33 | " }\n" 34 | "}\n" 35 | "" 36 | position { 37 | x: 0.0 38 | y: 0.0 39 | z: 0.0 40 | } 41 | rotation { 42 | x: 0.0 43 | y: 0.0 44 | z: 0.0 45 | w: 1.0 46 | } 47 | scale3 { 48 | x: 1.0 49 | y: 1.0 50 | z: 1.0 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/toys/random_level/random_level.script: -------------------------------------------------------------------------------- 1 | local level_id = "/go#tilemap" 2 | local number_of_gen_blocks = 5 3 | local target_level_size = 1024 4 | 5 | 6 | function clear_level(id) 7 | local x,y,w,h = tilemap.get_bounds(id) 8 | for i=1, w, 1 do 9 | for h=1, h, 1 do 10 | tilemap.set_tile(id,"layer1",i,h,1) 11 | end 12 | end 13 | end 14 | 15 | function init_starter_blocks(number, level_center_x, level_center_y) 16 | math.random(); math.random(); math.random() 17 | local blocks = {} 18 | for i=1, number, 1 do 19 | blocks[i] = {type = math.random(1,3), position_x = level_center_x, position_y = level_center_y} 20 | end 21 | return blocks 22 | end 23 | 24 | function tile_get(x,y, self) 25 | local return_value = nil 26 | if x < 1 or y < 1 then 27 | return_value = 1 28 | end 29 | if x > self.level_width or y > self.level_height then 30 | return_value = 1 31 | end 32 | return_value = return_value or tilemap.get_tile(level_id,"layer1",x,y) 33 | return return_value 34 | end 35 | 36 | function tile_set(x,y,value) 37 | tilemap.set_tile(level_id,"layer1",x,y,value) 38 | end 39 | 40 | function generate_level(target_size, self) 41 | local map_size = 0 42 | while map_size < target_size do 43 | for i=1, #self.blocks, 1 do 44 | local random_x = math.random(2, self.level_width - 1) 45 | local random_y = math.random(2, self.level_height - 1) 46 | if map_size == target_size then break end 47 | 48 | local diagonal_count = 0 49 | if (tile_get(random_x+1,random_y+1, self) == 0) then 50 | diagonal_count = diagonal_count + 1 51 | end 52 | if (tile_get(random_x-1,random_y-1, self) == 0) then 53 | diagonal_count = diagonal_count + 1 54 | end 55 | if (tile_get(random_x+1,random_y-1, self) == 0) then 56 | diagonal_count = diagonal_count + 1 57 | end 58 | if (tile_get(random_x-1,random_y+1, self) == 0) then 59 | diagonal_count = diagonal_count + 1 60 | end 61 | 62 | --print(diagonal_count) 63 | 64 | local cardinal_count = 0 65 | if diagonal_count == 0 or diagonal_count == 1 then 66 | if (tile_get(random_x+1,random_y, self) == 0) then 67 | cardinal_count = cardinal_count + 1 68 | end 69 | if (tile_get(random_x,random_y+1, self) == 0) then 70 | cardinal_count = cardinal_count + 1 71 | end 72 | if (tile_get(random_x-1,random_y, self) == 0) then 73 | cardinal_count = cardinal_count + 1 74 | end 75 | if (tile_get(random_x,random_y-1, self) == 0) then 76 | cardinal_count = cardinal_count + 1 77 | end 78 | 79 | if cardinal_count >= 1 then 80 | tile_set(random_x, random_y, 0) 81 | map_size = map_size + 1 82 | 83 | -- do extra stuff to this cell 84 | 85 | end 86 | 87 | 88 | end 89 | 90 | 91 | 92 | end 93 | --print(map_size) 94 | end 95 | -- finalize map such as placing doodads randomly in open spots 96 | end 97 | 98 | function random_level(self) 99 | 100 | clear_level(level_id) 101 | _,_,self.level_width,self.level_height = tilemap.get_bounds(level_id) 102 | self.blocks = init_starter_blocks(number_of_gen_blocks, math.floor(self.level_width / 2), math.floor(self.level_height / 2)) 103 | tilemap.set_tile(level_id,"layer1",math.floor(self.level_width / 2),math.floor(self.level_height / 2),0) 104 | generate_level(target_level_size, self) 105 | end 106 | 107 | function init(self) 108 | math.randomseed(os.time()); math.random(); math.random(); math.random() 109 | msg.post(".", "acquire_input_focus") 110 | random_level(self) 111 | 112 | end 113 | 114 | function final(self) 115 | -- Add finalization code here 116 | -- Remove this function if not needed 117 | end 118 | 119 | function update(self, dt) 120 | -- Add update code here 121 | -- Remove this function if not needed 122 | end 123 | 124 | function on_message(self, message_id, message, sender) 125 | -- Add message-handling code here 126 | -- Remove this function if not needed 127 | end 128 | 129 | function on_input(self, action_id, action) 130 | if action_id == hash("touch") and action.released then 131 | random_level(self) 132 | end 133 | end 134 | 135 | function on_reload(self) 136 | -- Add reload-handling code here 137 | -- Remove this function if not needed 138 | end 139 | -------------------------------------------------------------------------------- /examples/toys/rpg_movement/critters.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/critters2.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | animations { 9 | id: "bird_down" 10 | start_tile: 5 11 | end_tile: 5 12 | playback: PLAYBACK_ONCE_FORWARD 13 | fps: 30 14 | flip_horizontal: 0 15 | flip_vertical: 0 16 | } 17 | animations { 18 | id: "bunny_down" 19 | start_tile: 1 20 | end_tile: 1 21 | playback: PLAYBACK_ONCE_FORWARD 22 | fps: 30 23 | flip_horizontal: 0 24 | flip_vertical: 0 25 | } 26 | animations { 27 | id: "bunny_left" 28 | start_tile: 11 29 | end_tile: 11 30 | playback: PLAYBACK_ONCE_FORWARD 31 | fps: 30 32 | flip_horizontal: 0 33 | flip_vertical: 0 34 | } 35 | animations { 36 | id: "bunny_moving_down" 37 | start_tile: 1 38 | end_tile: 2 39 | playback: PLAYBACK_LOOP_FORWARD 40 | fps: 10 41 | flip_horizontal: 0 42 | flip_vertical: 0 43 | } 44 | animations { 45 | id: "bunny_moving_left" 46 | start_tile: 11 47 | end_tile: 12 48 | playback: PLAYBACK_LOOP_FORWARD 49 | fps: 10 50 | flip_horizontal: 0 51 | flip_vertical: 0 52 | } 53 | animations { 54 | id: "bunny_moving_right" 55 | start_tile: 3 56 | end_tile: 4 57 | playback: PLAYBACK_LOOP_FORWARD 58 | fps: 10 59 | flip_horizontal: 0 60 | flip_vertical: 0 61 | } 62 | animations { 63 | id: "bunny_moving_up" 64 | start_tile: 9 65 | end_tile: 10 66 | playback: PLAYBACK_LOOP_FORWARD 67 | fps: 10 68 | flip_horizontal: 0 69 | flip_vertical: 0 70 | } 71 | animations { 72 | id: "bunny_right" 73 | start_tile: 3 74 | end_tile: 3 75 | playback: PLAYBACK_ONCE_FORWARD 76 | fps: 30 77 | flip_horizontal: 0 78 | flip_vertical: 0 79 | } 80 | animations { 81 | id: "bunny_up" 82 | start_tile: 9 83 | end_tile: 9 84 | playback: PLAYBACK_ONCE_FORWARD 85 | fps: 30 86 | flip_horizontal: 0 87 | flip_vertical: 0 88 | } 89 | extrude_borders: 2 90 | inner_padding: 0 91 | -------------------------------------------------------------------------------- /examples/toys/shooter/mouse_checker.script: -------------------------------------------------------------------------------- 1 | function init(self) 2 | -- Add initialization code here 3 | -- Remove this function if not needed 4 | end 5 | 6 | function final(self) 7 | -- Add finalization code here 8 | -- Remove this function if not needed 9 | end 10 | 11 | function update(self, dt) 12 | -- Add update code here 13 | -- Remove this function if not needed 14 | end 15 | 16 | function on_message(self, message_id, message, sender) 17 | -- Add message-handling code here 18 | -- Remove this function if not needed 19 | end 20 | 21 | function on_input(self, action_id, action) 22 | -- Add input-handling code here 23 | -- Remove this function if not needed 24 | end 25 | 26 | function on_reload(self) 27 | -- Add reload-handling code here 28 | -- Remove this function if not needed 29 | end 30 | -------------------------------------------------------------------------------- /examples/toys/shooter/shooter_sprites.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/shooter_sprites.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | collision_groups: "default" 9 | animations { 10 | id: "anim" 11 | start_tile: 1 12 | end_tile: 1 13 | playback: PLAYBACK_ONCE_FORWARD 14 | fps: 30 15 | flip_horizontal: 0 16 | flip_vertical: 0 17 | } 18 | animations { 19 | id: "bullet" 20 | start_tile: 5 21 | end_tile: 5 22 | playback: PLAYBACK_ONCE_FORWARD 23 | fps: 30 24 | flip_horizontal: 0 25 | flip_vertical: 0 26 | } 27 | animations { 28 | id: "enemy_1" 29 | start_tile: 3 30 | end_tile: 3 31 | playback: PLAYBACK_ONCE_FORWARD 32 | fps: 30 33 | flip_horizontal: 0 34 | flip_vertical: 0 35 | } 36 | animations { 37 | id: "enemy_2" 38 | start_tile: 4 39 | end_tile: 4 40 | playback: PLAYBACK_ONCE_FORWARD 41 | fps: 30 42 | flip_horizontal: 0 43 | flip_vertical: 0 44 | } 45 | animations { 46 | id: "gun" 47 | start_tile: 2 48 | end_tile: 2 49 | playback: PLAYBACK_ONCE_FORWARD 50 | fps: 30 51 | flip_horizontal: 0 52 | flip_vertical: 0 53 | } 54 | animations { 55 | id: "player" 56 | start_tile: 1 57 | end_tile: 1 58 | playback: PLAYBACK_ONCE_FORWARD 59 | fps: 30 60 | flip_horizontal: 0 61 | flip_vertical: 0 62 | } 63 | extrude_borders: 2 64 | inner_padding: 0 65 | -------------------------------------------------------------------------------- /examples/toys/shooter/shooter_tiles.tilesource: -------------------------------------------------------------------------------- 1 | image: "/pyxels/shooter_tiles.png" 2 | tile_width: 32 3 | tile_height: 32 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "" 7 | material_tag: "tile" 8 | extrude_borders: 2 9 | inner_padding: 0 10 | -------------------------------------------------------------------------------- /examples/toys/shooter/tile_manager.script: -------------------------------------------------------------------------------- 1 | 2 | -- set wall to a kind of shape based on what tiles exist on its sides 3 | -- we want collisions to happen based on wall shape type 4 | -- a wall being next to another wall changes them to have a fixture mask 5 | 6 | local active_tilemap = "/walls#tilemap" 7 | 8 | function setup_wall_type() 9 | local active_tilemap = "/walls#tilemap" 10 | local walls = {} 11 | local size = {} 12 | size.x, size.y, size.w, size.h = tilemap.get_bounds(active_tilemap) 13 | pprint(size) 14 | for x=1, size.w, 1 do 15 | for y=1, size.h, 1 do 16 | if tilemap.get_tile(active_tilemap, "walls", x, y) ~= 0 then 17 | local north, west, south, east = get_neighbors(x,y,size.w,size.h) 18 | pprint(north .. " " .. west .. " " .. south .. " " .. east) 19 | local sum = 0 20 | if north > 0 then sum = sum + 1 end 21 | if west > 0 then sum = sum + 2 end 22 | if south > 0 then sum = sum + 4 end 23 | if east > 0 then sum = sum + 8 end 24 | if sum == 0 then sum = 16 end 25 | tilemap.set_tile(active_tilemap,"walls",x,y,sum) 26 | print(sum) 27 | end 28 | end 29 | end 30 | end 31 | 32 | function get_neighbors(x,y,w,h) 33 | local north, west, south, east = 0, 0, 0, 0 34 | print(x .. " " .. y) 35 | if y + 1 <= h then 36 | north = tilemap.get_tile(active_tilemap, "walls", x, y + 1) 37 | end 38 | if x - 1 > 0 then 39 | west = tilemap.get_tile(active_tilemap, "walls", x - 1, y) 40 | end 41 | if y - 1 > 0 then 42 | south = tilemap.get_tile(active_tilemap, "walls", x, y - 1) 43 | end 44 | if x + 1 <= w then 45 | east = tilemap.get_tile(active_tilemap, "walls", x + 1, y) 46 | end 47 | 48 | return north, west, south, east 49 | end 50 | 51 | function is_wall(tile_x, tile_y) 52 | 53 | local active_tile = tilemap.get_tile(active_tilemap, "walls", tile_x, tile_y) 54 | return (active_tile > 0) 55 | end 56 | 57 | function near_center(x,y) 58 | local tile_size = 32 59 | local tile_quarter = tile_size / 4 60 | return (x > tile_quarter and x < tile_size - tile_quarter and y > tile_quarter and y < tile_size - tile_quarter) 61 | end 62 | 63 | -- for bullet check if over tile then check if bullet is near enough to the center of the wall 64 | 65 | 66 | function init(self) 67 | self.wall_types = setup_wall_type() 68 | -- Add initialization code here 69 | -- Remove this function if not needed 70 | end 71 | 72 | function final(self) 73 | -- Add finalization code here 74 | -- Remove this function if not needed 75 | end 76 | 77 | function update(self, dt) 78 | -- Add update code here 79 | -- Remove this function if not needed 80 | end 81 | 82 | function on_message(self, message_id, message, sender) 83 | -- Add message-handling code here 84 | -- Remove this function if not needed 85 | end 86 | 87 | function on_input(self, action_id, action) 88 | -- Add input-handling code here 89 | -- Remove this function if not needed 90 | end 91 | 92 | function on_reload(self) 93 | -- Add reload-handling code here 94 | -- Remove this function if not needed 95 | end 96 | -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [project] 2 | title = DefRS 3 | version = 1.0 4 | dependencies = https://github.com/britzl/defcon/archive/master.zip, https://github.com/britzl/defnet/archive/3.1.zip 5 | custom_resources = text 6 | 7 | [input] 8 | game_binding = /input/game.input_bindingc 9 | 10 | [bootstrap] 11 | main_collection = /examples/input/4dir_move/4dir_move.collectionc 12 | render = /builtins/render/default.renderc 13 | 14 | [display] 15 | width = 1600 16 | height = 800 17 | samples = 0 18 | 19 | [physics] 20 | scale = 0.02 21 | debug = 0 22 | gravity_y = -1000.0 23 | 24 | [script] 25 | shared_state = 1 26 | 27 | [library] 28 | include_dirs = defrs 29 | 30 | [android] 31 | package = com.subsoap.deffx 32 | 33 | [ios] 34 | bundle_identifier = com.subsoap.deffx 35 | 36 | [osx] 37 | bundle_identifier = com.subsoap.deffx 38 | 39 | [windows] 40 | app_icon = /target_resources/windows/defold.ico 41 | 42 | [particle_fx] 43 | max_count = 256 44 | 45 | [html5] 46 | htmlfile = /examples/tools/html_run_code/index.html 47 | 48 | -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | key_trigger { 2 | input: KEY_LALT 3 | action: "alt" 4 | } 5 | key_trigger { 6 | input: KEY_RALT 7 | action: "alt" 8 | } 9 | key_trigger { 10 | input: KEY_F4 11 | action: "f4" 12 | } 13 | key_trigger { 14 | input: KEY_UP 15 | action: "up" 16 | } 17 | key_trigger { 18 | input: KEY_DOWN 19 | action: "down" 20 | } 21 | key_trigger { 22 | input: KEY_LEFT 23 | action: "left" 24 | } 25 | key_trigger { 26 | input: KEY_RIGHT 27 | action: "right" 28 | } 29 | key_trigger { 30 | input: KEY_A 31 | action: "a" 32 | } 33 | key_trigger { 34 | input: KEY_B 35 | action: "b" 36 | } 37 | key_trigger { 38 | input: KEY_W 39 | action: "w" 40 | } 41 | key_trigger { 42 | input: KEY_S 43 | action: "s" 44 | } 45 | key_trigger { 46 | input: KEY_D 47 | action: "d" 48 | } 49 | key_trigger { 50 | input: KEY_ENTER 51 | action: "enter" 52 | } 53 | key_trigger { 54 | input: KEY_KP_ENTER 55 | action: "enter_kp" 56 | } 57 | key_trigger { 58 | input: KEY_BACKSPACE 59 | action: "backspace" 60 | } 61 | mouse_trigger { 62 | input: MOUSE_BUTTON_1 63 | action: "touch" 64 | } 65 | mouse_trigger { 66 | input: MOUSE_BUTTON_2 67 | action: "right_click" 68 | } 69 | touch_trigger { 70 | input: TOUCH_MULTI 71 | action: "multitouch" 72 | } 73 | text_trigger { 74 | input: TEXT 75 | action: "text" 76 | } 77 | -------------------------------------------------------------------------------- /liveupdate.settings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/liveupdate.settings -------------------------------------------------------------------------------- /psds/auras.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/psds/auras.psd -------------------------------------------------------------------------------- /psds/defold.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/psds/defold.psd -------------------------------------------------------------------------------- /psds/defold2.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/psds/defold2.psd -------------------------------------------------------------------------------- /psds/pearl.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/psds/pearl.psd -------------------------------------------------------------------------------- /pyxels/buffer_sprite_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/buffer_sprite_1.png -------------------------------------------------------------------------------- /pyxels/buffer_sprite_1.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/buffer_sprite_1.pyxel -------------------------------------------------------------------------------- /pyxels/buffer_sprite_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/buffer_sprite_2.png -------------------------------------------------------------------------------- /pyxels/buffer_sprite_2.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/buffer_sprite_2.pyxel -------------------------------------------------------------------------------- /pyxels/critters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/critters.png -------------------------------------------------------------------------------- /pyxels/critters.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/critters.pyxel -------------------------------------------------------------------------------- /pyxels/critters2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/critters2.png -------------------------------------------------------------------------------- /pyxels/minesweeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/minesweeper.png -------------------------------------------------------------------------------- /pyxels/minesweeper.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/minesweeper.pyxel -------------------------------------------------------------------------------- /pyxels/pastel_tile_colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/pastel_tile_colors.png -------------------------------------------------------------------------------- /pyxels/pastel_tile_colors.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/pastel_tile_colors.pyxel -------------------------------------------------------------------------------- /pyxels/shooter_sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/shooter_sprites.png -------------------------------------------------------------------------------- /pyxels/shooter_sprites.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/shooter_sprites.pyxel -------------------------------------------------------------------------------- /pyxels/shooter_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/shooter_tiles.png -------------------------------------------------------------------------------- /pyxels/shooter_tiles.pyxel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/pyxels/shooter_tiles.pyxel -------------------------------------------------------------------------------- /target_resources/android/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/mipmap-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /target_resources/android/playstore-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/android/playstore-icon.png -------------------------------------------------------------------------------- /target_resources/html5/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | DefRS 13 | 90 | 91 | 92 | 93 | 94 | 95 |
96 | 97 |
98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /target_resources/html5/todo.txt: -------------------------------------------------------------------------------- 1 | - remake with latest generated html 2 | - setup fixed ratio render script -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-57x57@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-57x57@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-57x57@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-57x57@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-60x60@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-60x60@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-72x72@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-72x72@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-72x72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-72x72@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-76x76@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-76x76@3x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-Small-50x50@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-Small-50x50@1x.png -------------------------------------------------------------------------------- /target_resources/ios/AppIcon.appiconset/Icon-Small-50x50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/AppIcon.appiconset/Icon-Small-50x50@2x.png -------------------------------------------------------------------------------- /target_resources/ios/iTunesArtwork@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/iTunesArtwork@1x.png -------------------------------------------------------------------------------- /target_resources/ios/iTunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/iTunesArtwork@2x.png -------------------------------------------------------------------------------- /target_resources/ios/iTunesArtwork@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/ios/iTunesArtwork@3x.png -------------------------------------------------------------------------------- /target_resources/linux/defold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/linux/defold.png -------------------------------------------------------------------------------- /target_resources/macos/defold2.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/macos/defold2.icns -------------------------------------------------------------------------------- /target_resources/windows/defold.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subsoap/defrs/62de2106815532081e6e7e50b05346409a4fc0fd/target_resources/windows/defold.ico --------------------------------------------------------------------------------