diff --git a/game.wren b/game.wren index 8ccac49..a1029bd 100644 --- a/game.wren +++ b/game.wren @@ -1,11 +1,12 @@ import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, TransformLinkAction import "luxe: world/scene" for Scene import "luxe: draw" for Draw, PathStyle -import "luxe: input" for Input, Key +import "luxe: input" for Input, Key, InputType, Scan import "luxe: assets" for Assets import "luxe: asset" for Asset import "luxe: math" for Math import "luxe: io" for IO +import "debug: debug" import "luxe: system/physics/box_collider3D.modifier" for BoxCollider3D import "luxe: system/physics/character3D.modifier" for Character3D @@ -37,6 +38,13 @@ class Game is Ready { Transform.set_pos_y(camera, 0.6) Input.set_mouse_capture(true) Input.set_mouse_visible(false) + + Input.listen_for(InputType.key_down) {|key, scan, repeat, mod| + if(scan == Scan.grave) { + _fpscam.enabled = !_fpscam.enabled + Input.set_mouse_visible(_fpscam.enabled) + } + } } //ready @@ -46,30 +54,6 @@ class Game is Ready { IO.shutdown() } - // if (_using_debug_cam) { - // _debug_cam.tick(delta) - // } - - if (Entity.valid(_player) && Character3D.has(_player)) { - var fore = Input.event_active("up", "game") ? -1 : 0 - var back = Input.event_active("down", "game") ? 1 : 0 - var left = Input.event_active("left", "game") ? -1 : 0 - var right = Input.event_active("right", "game") ? 1 : 0 - - var input = Transform.local_vector_to_world(camera, right + left, 0, fore + back) - input.y = 0 - Math.normalize(input) - input.y = Input.event_began("jump", "game") ? 2 : 0 - - Character3D.set.input(_player, input) - } - } //tick - set_use_debug_camera(use_debug: Bool) { - _using_debug_cam = use_debug - Input.set_mouse_capture(!use_debug) - Input.set_mouse_visible(use_debug) - } - } //Game diff --git a/luxe.project/assets.lx b/luxe.project/assets.lx index d456165..73278e3 100644 --- a/luxe.project/assets.lx +++ b/luxe.project/assets.lx @@ -152,6 +152,7 @@ { "3698d0c0-28c9-4090-9a8d-bdaf470353da" = "textures/env_lo/tex_road_plain_02.tres" } { "36b7af98-1ed5-44de-bd58-d328834923f9" = "textures/env_lo/tex_painted_eggshell.image.lx" } { "36e0aee8-7a4a-475f-a984-1d8b4b0f5eb2" = "luxe: build/empty.wren" } + { "36e95555-f26a-4b9c-86b7-1b14e6024bc5" = "debug: image/" } { "3708ef2a-0469-42c8-9bcd-b3290fa42199" = "luxe: test.wren" } { "37135904-49ba-4884-8371-27ae43be1504" = "textures/env_lo/tex_metal_15.png.import" } { "3741d639-5a93-4ea0-bcda-0c0e41c5039f" = "luxe: physics/default.collider.physics.lx" } @@ -160,6 +161,7 @@ { "38b045eb-6a8d-4972-a39e-9fe90e0f5853" = "luxe: build/ast/" } { "3a358a11-5d7c-4deb-9502-022878e17e6c" = "textures/env_lo/tex_stucco_01.tres" } { "3b33675c-609a-403b-b612-66bbf2111f6b" = "luxe: ui.wren" } + { "3b458842-5f25-4cd3-ad0a-02e3a2c8a4e5" = "debug: list_with_filter.wren" } { "3b488932-3466-41f6-8d5e-c981f0454eca" = "textures/env_lo/tex_roadside_03.png" } { "3b582b2e-3165-4282-bf54-817e9413bb77" = "luxe: asset/import/input.import.lx" } { "3bc41225-9f29-41da-86ea-9aa4cad85f78" = "luxe: blocks.wren" } @@ -171,6 +173,7 @@ { "3e3644fe-9cd2-425a-a5f4-ba049ad51635" = "textures/env_lo/tex_marble_01.png.import" } { "3e6b6abb-ad09-4c19-8c98-5bfae9698f4f" = "textures/env_lo/tex_brick_03.png.import" } { "3eccdec9-a2c0-4270-8714-2ff305443066" = "textures/env_lo/tex_carpet_green.png" } + { "3ed4acc2-447f-44c7-a2cf-dc1ee87cf12b" = "debug: image/close.image.lx" } { "3fe7353b-5129-46a2-a1a0-48f5538bb206" = "luxe: runtime.wren" } { "3ff6416d-b5d6-4af1-a033-9711c615ba19" = "textures/env_lo/tex_tile_tan_02.png.import" } { "4012141d-01d9-4ec5-9072-f8506d584de9" = "luxe: system/skin.modifier.wren" } @@ -227,6 +230,7 @@ { "505c9b4e-c532-4bea-980c-d448f362aacd" = "luxe: build/wrenalyzer/visitor.wren" } { "50e96084-8f2c-45fc-8fb3-ae1127b10c93" = "luxe: modifier/script.wren" } { "51370c3c-740d-47d4-a361-c40153f83a16" = "luxe: image/logo.sprite.sprite.lx" } + { "513895d1-a96f-4879-9d24-b18e3e96474c" = "debug: debug.wren" } { "51412908-c6d9-46b1-9bb4-2efbfa02da5d" = "textures/env_lo/tex_brick_07.image.lx" } { "5249ea90-34a9-441d-a6a0-9a94dd3a076d" = "luxe: system/physics/contact.block.wren" } { "524b0500-88d2-43a4-880e-7889fd67f2aa" = "luxe: ui/editor.panel.modifier.script.ui.lx" } @@ -259,6 +263,7 @@ { "5a8aeb53-efc2-4f74-900b-cd87ec4cdde3" = "luxe: ui/editor.panel.modifier.mesh.ui.lx" } { "5af597c0-408a-4eb5-a51f-deb472a57a81" = "maps/arena01_0_worldspawn.obj.assets/env_lo/" } { "5af6d2d4-409f-4137-853d-f211602615dd" = "textures/env_lo/tex_carpet_green.png.import" } + { "5b0c88c0-2795-4817-a4da-1830dc78ea4a" = "system/" } { "5b2f1286-d705-47eb-9235-5a7742d9637c" = "luxe: ui/editor.panel.outline.layer.ui.lx" } { "5bba6963-bd5a-44cf-aa7a-83aae1cff5e7" = "luxe: triangulate.wren" } { "5be49438-dcc7-4fd0-8dbd-eae90ce548d6" = "textures/env_lo/tex_metal_lightgray_02.image.lx" } @@ -337,6 +342,7 @@ { "72895c82-2455-48d3-85ad-9fe28ca440b1" = "luxe: material_basis/sprite_solid.material_basis.lx" } { "73297ab4-c1d7-4252-a10d-9fd1a10492c0" = "textures/env_lo/tex_brick_01.png.import" } { "739af380-5231-4bb0-9673-d9f30f2955fc" = "scene/player.scene/" } + { "73e8dd07-f63d-4f64-9df1-062d2e0923c3" = "debug: version.wren" } { "74a49f36-1b15-4147-a4e1-90a06125de54" = "textures/env_lo/tex_tile_06.png.import" } { "766456ef-364f-4dfd-a1fa-0aeeb07ae745" = "luxe: image/save.svg" } { "76f219bb-7e48-4faf-a16f-95a2e286a6ae" = "luxe: tiles/" } @@ -368,12 +374,14 @@ { "7fbee9fc-7689-4af6-b054-7442665e5d0f" = "maps/arena01_0_worldspawn.obj.assets/special/clip.material.lx" } { "7ff507de-40dd-41f0-bff0-0750a8aed36f" = "luxe: type/audio.ogg.asset.wren" } { "807c4fab-714b-40c4-aab1-b56693197ec5" = "textures/env_lo/tex_wood_03.png" } + { "8157474a-e066-4757-b3cf-0f34cc1a3641" = "system/player_input.modifier.wren" } { "815d1a05-79ee-42d2-959e-d235b9ad427b" = "luxe: type/anim/skeleton_clip.anim_track.wren" } { "81deec4d-3e64-4ae0-ac9f-00b2bee62c5b" = "textures/env_lo/tex_tile_tan_03.tres" } { "823564a1-4156-48c7-a08d-7f3af8b2de14" = "luxe: material/" } { "82cefa5c-a2be-4205-8627-5a361a9420d9" = "textures/env_lo/tex_tile_tan_01.tres" } { "82d871e3-c0b2-4550-9dcf-b0e512db39b6" = "textures/special/clip.png.import" } { "83527e80-d6f9-49fd-81a3-a861cd359b1d" = "luxe: id.wren" } + { "83e78c7f-c96e-4f60-9244-fec04c36c231" = "system/player_input.modifier.api.wren" } { "84513e56-8c2c-4638-b983-dd6f651af88f" = "luxe: material/logo.sprite.material.lx" } { "8479ffe5-6912-4fd1-bd04-c42222934166" = "luxe: sample/game.wren" } { "84e2a44c-4a34-4220-8bcd-ea5d3825b86d" = "textures/env_lo/tex_concrete_02.image.lx" } @@ -630,6 +638,7 @@ { "d3c73dc0-07be-4796-a489-bab975b462f4" = "luxe: build/reloader.wren" } { "d4b2f026-054d-439a-ba34-c4e5dbe678a8" = "textures/env_lo/tex_metal_black_01.tres" } { "d5088f85-6b2d-459b-978b-02b239248ae6" = "luxe: type/block.asset.wren" } + { "d590f413-b98d-4088-9fd6-3703eea07992" = "debug: image/close.png" } { "d5967a11-9edb-452e-a9ea-2e503c4c2a76" = "luxe: font/lato-italic.font.lx" } { "d60890f4-cd70-43b4-a6e0-647439c3f994" = "luxe: build/material_basis.wren" } { "d60d9864-2fe8-487c-ae79-1fcc72bec556" = "luxe: type/task.asset.wren" } diff --git a/luxe.project/modules.lx b/luxe.project/modules.lx index c361d81..1e762b7 100644 --- a/luxe.project/modules.lx +++ b/luxe.project/modules.lx @@ -1,6 +1,6 @@ modules = { camera = "1.0.6" func_luxe = "dev" - luxe = "2025.6.4" + luxe = "2025.6.5" debug = "dev" } // modules diff --git a/outline/inputs.input.lx b/outline/inputs.input.lx index 2643a2c..714516e 100644 --- a/outline/inputs.input.lx +++ b/outline/inputs.input.lx @@ -10,6 +10,8 @@ input = { right = { keys = ["key_d", "right"] } up = { keys = ["key_w", "up"] } down = { keys = ["key_s", "down"] } + + run = { keys = ["lshift"] } jump = { keys = ["space"] diff --git a/scene/player.scene/Player.entity.lx b/scene/player.scene/Player.entity.lx index d783f9e..b016d17 100644 --- a/scene/player.scene/Player.entity.lx +++ b/scene/player.scene/Player.entity.lx @@ -16,6 +16,9 @@ entity = { type = "luxe: system/physics/character3D.modifier" width = 0.3 } + { + type = "system/player_input.modifier" + } ] // modifiers name = "Player" uuid = "20ec0cdf-d909-4aea-a27e-5c697828e34d" diff --git a/system/folder.meta.lx b/system/folder.meta.lx new file mode 100644 index 0000000..49a8d01 --- /dev/null +++ b/system/folder.meta.lx @@ -0,0 +1,2 @@ +tags = [] +uuid = "5b0c88c0-2795-4817-a4da-1830dc78ea4a" diff --git a/system/player_input.modifier.api.wren b/system/player_input.modifier.api.wren new file mode 100644 index 0000000..67a4edf --- /dev/null +++ b/system/player_input.modifier.api.wren @@ -0,0 +1,135 @@ + +class Modifier { + static id : String { "system/player_input.modifier" } + static system(world: World) : System { World.get_system(world, Modifier.id) } + static get(entity: Entity) : Data { Mod.get(entity, Modifier.id) } + construct new(world: World) { + _world = world + _block = World.get_modifier_block(_world, Modifier.id) + } + world : World { _world } + attached_count : Num { Block.count(_block) } + + init(world: World) : None {} + pre(entity: Entity, data) : None {} + attach(entity: Entity, data) : None {} + detach(entity: Entity, data) : None {} + change(entity: Entity, change: ModifierChange) : None {} + tick(delta: Num) : None {} + + internal_tick(delta: Num) : None { + } + + editor_init(world: World) : None {} + editor_pre(entity: Entity, data) : None {} + editor_attach(entity: Entity, data) : None {} + editor_detach(entity: Entity, data) : None {} + editor_change(entity: Entity, change: ModifierChange) : None {} + + editor_tick(delta: Num) : None {} + + get(entity: Entity) : Data { Mod.get(entity, Modifier.id) } + each(fn: Fn) { + var count = attached_count + for(idx in 0 ... count) { + var inst = Block.get_at(_block, idx) + var data = Block.instance(_block, inst) + var entity = Block.get_handle(_block, inst, HandleTag.entity) + fn.call(entity, data) + } + } + each(start: Num, count: Num, fn: Fn) { + for(idx in start ... start + count) { + var inst = Block.get_at(_block, idx) + var data = Block.instance(_block, inst) + var entity = Block.get_handle(_block, inst, HandleTag.entity) + fn.call(entity, data) + } + } +} + +class API { + static id { Modifier.id } + static create(entity: Entity) { Mod.create(Modifier.id, entity) } + static has(entity: Entity) { Mod.has(Modifier.id, entity) } + static destroy(entity: Entity) { Mod.destroy(Modifier.id, entity) } + static get(entity: Entity) : Data { Mod.get(entity, Modifier.id) } + static system_in(world: World) : System { World.get_system(world, Modifier.id) } + static system(entity: Entity) : System { World.get_system(Entity.get_world(entity), Modifier.id) } + static count(world: World) : Num { system_in(world).attached_count } + static each(world: World, fn: Fn) : System { system_in(world).each(fn) } + static get : APIGet { APIGetter } + static set : APISet { APISetter } + static connect : APIWireConnect { APIWireConnects } + static send : APIWireSend { APIWireSends } +} + +class Fields { + static acceleration : String { "acceleration" } + static decelleration : String { "decelleration" } + static ground_check_dist : String { "ground_check_dist" } + static jump_impulse : String { "jump_impulse" } + static jump_force : String { "jump_force" } + static jump_force_falloff : String { "jump_force_falloff" } + static jump_grace_time : String { "jump_grace_time" } + static input_target : String { "input_target" } + static time_since_grounded : String { "time_since_grounded" } + static is_grounded : String { "is_grounded" } +} + +import "luxe: world/states" for AState, States, Op +#doc="The base class for a state, and our API for accessing it" +class State is AState { + construct create(in_name: String, in_parent: State) { super(in_name, in_parent) } + goto_on(entity: Entity, state: State, wire: Num) { this.goto_on(entity, state, This, wire) } +} + +class APIWireSend { + construct new() {} +} + +class APIWireConnect { + construct new() {} +} + +class APIGet { + construct new() {} + acceleration(entity: Entity) : Num { Modifier.get(entity).acceleration } + decelleration(entity: Entity) : Num { Modifier.get(entity).decelleration } + ground_check_dist(entity: Entity) : Num { Modifier.get(entity).ground_check_dist } + jump_impulse(entity: Entity) : Num { Modifier.get(entity).jump_impulse } + jump_force(entity: Entity) : Num { Modifier.get(entity).jump_force } + jump_force_falloff(entity: Entity) : Num { Modifier.get(entity).jump_force_falloff } + jump_grace_time(entity: Entity) : Num { Modifier.get(entity).jump_grace_time } + input_target(entity: Entity) : Float3 { Modifier.get(entity).input_target } + time_since_grounded(entity: Entity) : Num { Modifier.get(entity).time_since_grounded } + is_grounded(entity: Entity) : Bool { Modifier.get(entity).is_grounded } +} + +class APISet { + construct new() {} + acceleration(entity: Entity, value: Num) { Modifier.get(entity).acceleration = value } + decelleration(entity: Entity, value: Num) { Modifier.get(entity).decelleration = value } + ground_check_dist(entity: Entity, value: Num) { Modifier.get(entity).ground_check_dist = value } + jump_impulse(entity: Entity, value: Num) { Modifier.get(entity).jump_impulse = value } + jump_force(entity: Entity, value: Num) { Modifier.get(entity).jump_force = value } + jump_force_falloff(entity: Entity, value: Num) { Modifier.get(entity).jump_force_falloff = value } + jump_grace_time(entity: Entity, value: Num) { Modifier.get(entity).jump_grace_time = value } + input_target(entity: Entity, value: Float3) { Modifier.get(entity).input_target = value } + time_since_grounded(entity: Entity, value: Num) { Modifier.get(entity).time_since_grounded = value } + is_grounded(entity: Entity, value: Bool) { Modifier.get(entity).is_grounded = value } +} + +var APIGetter = APIGet.new() +var APISetter = APISet.new() +var APIWireSends = APIWireSend.new() +var APIWireConnects = APIWireConnect.new() + +import "system/player_input.modifier" for Data, System +import "luxe: world/world" for World, Wire +import "luxe: world" for Entity +import "luxe: world/modifier" for Modifier as Mod, ModifierChange +import "luxe: blocks" for Block +import "luxe: io" for HandleTag + + diff --git a/system/player_input.modifier.api.wren.meta.lx b/system/player_input.modifier.api.wren.meta.lx new file mode 100644 index 0000000..d234469 --- /dev/null +++ b/system/player_input.modifier.api.wren.meta.lx @@ -0,0 +1,2 @@ +tags = [] +uuid = "83e78c7f-c96e-4f60-9244-fec04c36c231" diff --git a/system/player_input.modifier.wren b/system/player_input.modifier.wren new file mode 100644 index 0000000..acc57ef --- /dev/null +++ b/system/player_input.modifier.wren @@ -0,0 +1,111 @@ +import "system/player_input.modifier.api" for API, Modifier, APIGet, APISet, Wire, Fields, State, Op +import "luxe: io" for IO +import "luxe: assets" for Strings +import "luxe: input" for Input +import "luxe: world" for Entity, World, Transform +import "luxe: math" for Math +import "luxe.project/asset" for Asset +import "luxe: system/physics/character3D.modifier" for Character3D +import "luxe: system/physics/physics3D.modifier" for Physics3D + +#block = data +class Data { + var acceleration: Num = 4.2 + var decelleration: Num = 3.0 + var ground_check_dist: Num = 0.05 + var jump_impulse: Num = 1.25 + var jump_grace_time: Num = 0.1 + + #hidden + var input_target: Float3 = [0, 0, 0] + + #hidden + var time_since_grounded: Num = 0 + + #hidden + var is_grounded: Bool = false +} + +#api +#display = "Player Input" +#desc = "**A new modifier**. You should update this description" +#icon = "luxe: image/modifier/modifier.svg" +class PlayerInput is API { + //add public facing API here +} + +#system +#phase(on, tick) +class System is Modifier { + EPSILON { 0.001 } + + //required atm + construct new(world: World) { super(world) } + + init(world: World) { + Log.print("init `%(This)` in world `%(world)`") + Physics3D.create_in(world) + _camera = Entity.get_named(world, "app.camera") + _world = world + } + + #hidden + attach(player: Entity, data: Data) { + Log.print("Attached!") + } + + #hidden + tick(delta: Num) { + each {|player: Entity, data: Data| + if (!Character3D.has(player)) return + + // Update grounded state + var now_grounded = check_grounded(player, data) + + if (data.is_grounded && !now_grounded && data.time_since_grounded < data.jump_grace_time) { + data.time_since_grounded = data.time_since_grounded + delta + + if (data.time_since_grounded >= data.jump_grace_time) { + data.is_grounded = false + } + } + + if (!data.is_grounded && now_grounded && Character3D.get.velocity(player).y <= 0) { + data.is_grounded = true + } + + // Update movement input + var fore = Input.event_active("up", "game") ? -1 : 0 + var back = Input.event_active("down", "game") ? 1 : 0 + var left = Input.event_active("left", "game") ? -1 : 0 + var right = Input.event_active("right", "game") ? 1 : 0 + data.input_target = Math.normalized(Math.mult(Transform.local_dir_to_world(_camera, right + left, 0, fore + back), [1, 0, 1])) + data.input_target = move_toward(Character3D.get.input(player), data.input_target, data, delta) + + if (Input.event_began("jump", "game") && data.is_grounded) { + data.time_since_grounded = 0 + data.input_target = Math.add(data.input_target, [0, data.jump_impulse, 0]) + data.is_grounded = false + + Transform.translate(player, 0, data.ground_check_dist + this.EPSILON, 0) + } else { + data.input_target = [data.input_target.x, 0, data.input_target.z] + } + + Character3D.set.input(player, data.input_target) + } + } + + check_grounded(player: Entity, data: Data): Bool { + var height = Character3D.get.height(player) * 0.5 + return Physics3D.cast_ray_closest(_world, Transform.get_pos_world(player), [0,-1,0], height + data.ground_check_dist) != null + } + + move_toward(from: Float3, to: Float3, data: Data, delta: Num) { + var pos_delta: Float3 = Math.sub(to, from) + var pos_len: Num = Math.length(pos_delta) + var speed = Math.length(from) < Math.length(to) ? delta * data.acceleration : delta * data.decelleration + return pos_len <= delta || pos_len < this.EPSILON ? to : Math.add(from, Math.scale(Math.div(pos_delta, pos_len), speed)) + } + +} \ No newline at end of file diff --git a/system/player_input.modifier.wren.meta.lx b/system/player_input.modifier.wren.meta.lx new file mode 100644 index 0000000..320c987 --- /dev/null +++ b/system/player_input.modifier.wren.meta.lx @@ -0,0 +1,2 @@ +tags = [] +uuid = "8157474a-e066-4757-b3cf-0f34cc1a3641"