Refactored player controls into PlayerInput class
This commit is contained in:
34
game.wren
34
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
|
||||
|
||||
Reference in New Issue
Block a user