first_person_player: finished first pass of movement and input
This commit is contained in:
@ -29,7 +29,16 @@ class Modifier {
|
|||||||
editor_tick(delta: Num) : None {}
|
editor_tick(delta: Num) : None {}
|
||||||
|
|
||||||
get(entity: Entity) : Data { Mod.get(entity, Modifier.id) }
|
get(entity: Entity) : Data { Mod.get(entity, Modifier.id) }
|
||||||
each(fn: Fn) {
|
|
||||||
|
list() : List {
|
||||||
|
var list = []
|
||||||
|
each {|entity: Entity, unused|
|
||||||
|
list.add(entity)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
each(fn: Fn) : None {
|
||||||
var count = attached_count
|
var count = attached_count
|
||||||
for(idx in 0 ... count) {
|
for(idx in 0 ... count) {
|
||||||
var inst = Block.get_at(_block, idx)
|
var inst = Block.get_at(_block, idx)
|
||||||
@ -38,7 +47,8 @@ class Modifier {
|
|||||||
fn.call(entity, data)
|
fn.call(entity, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
each(start: Num, count: Num, fn: Fn) {
|
|
||||||
|
each(start: Num, count: Num, fn: Fn) : None {
|
||||||
for(idx in start ... start + count) {
|
for(idx in start ... start + count) {
|
||||||
var inst = Block.get_at(_block, idx)
|
var inst = Block.get_at(_block, idx)
|
||||||
var data = Block.instance(_block, inst)
|
var data = Block.instance(_block, inst)
|
||||||
@ -58,6 +68,7 @@ class API {
|
|||||||
static system(entity: Entity) : System { World.get_system(Entity.get_world(entity), 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 count(world: World) : Num { system_in(world).attached_count }
|
||||||
static each(world: World, fn: Fn) : System { system_in(world).each(fn) }
|
static each(world: World, fn: Fn) : System { system_in(world).each(fn) }
|
||||||
|
static with(world: World) : List { system_in(world).list() }
|
||||||
static get : APIGet { APIGetter }
|
static get : APIGet { APIGetter }
|
||||||
static set : APISet { APISetter }
|
static set : APISet { APISetter }
|
||||||
static connect : APIWireConnect { APIWireConnects }
|
static connect : APIWireConnect { APIWireConnects }
|
||||||
@ -65,6 +76,24 @@ class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Fields {
|
class Fields {
|
||||||
|
static acceleration : String { "acceleration" }
|
||||||
|
static decelleration : String { "decelleration" }
|
||||||
|
static speed_run : String { "speed_run" }
|
||||||
|
static speed_walk : String { "speed_walk" }
|
||||||
|
static ground_check_dist : String { "ground_check_dist" }
|
||||||
|
static jump_impulse : String { "jump_impulse" }
|
||||||
|
static jump_grace_time : String { "jump_grace_time" }
|
||||||
|
static event_forward : String { "event_forward" }
|
||||||
|
static event_backward : String { "event_backward" }
|
||||||
|
static event_strafe_left : String { "event_strafe_left" }
|
||||||
|
static event_strafe_right : String { "event_strafe_right" }
|
||||||
|
static event_sprint : String { "event_sprint" }
|
||||||
|
static event_jump : String { "event_jump" }
|
||||||
|
static input_target : String { "input_target" }
|
||||||
|
static target_speed : String { "target_speed" }
|
||||||
|
static time_since_grounded : String { "time_since_grounded" }
|
||||||
|
static is_grounded : String { "is_grounded" }
|
||||||
|
static movement_active : String { "movement_active" }
|
||||||
}
|
}
|
||||||
|
|
||||||
import "luxe: world/states" for AState, States, Op
|
import "luxe: world/states" for AState, States, Op
|
||||||
@ -84,10 +113,46 @@ class APIWireConnect {
|
|||||||
|
|
||||||
class APIGet {
|
class APIGet {
|
||||||
construct new() {}
|
construct new() {}
|
||||||
|
acceleration(entity: Entity) : Num { Modifier.get(entity).acceleration }
|
||||||
|
decelleration(entity: Entity) : Num { Modifier.get(entity).decelleration }
|
||||||
|
speed_run(entity: Entity) : Num { Modifier.get(entity).speed_run }
|
||||||
|
speed_walk(entity: Entity) : Num { Modifier.get(entity).speed_walk }
|
||||||
|
ground_check_dist(entity: Entity) : Num { Modifier.get(entity).ground_check_dist }
|
||||||
|
jump_impulse(entity: Entity) : Num { Modifier.get(entity).jump_impulse }
|
||||||
|
jump_grace_time(entity: Entity) : Num { Modifier.get(entity).jump_grace_time }
|
||||||
|
event_forward(entity: Entity) : String { Modifier.get(entity).event_forward }
|
||||||
|
event_backward(entity: Entity) : String { Modifier.get(entity).event_backward }
|
||||||
|
event_strafe_left(entity: Entity) : String { Modifier.get(entity).event_strafe_left }
|
||||||
|
event_strafe_right(entity: Entity) : String { Modifier.get(entity).event_strafe_right }
|
||||||
|
event_sprint(entity: Entity) : String { Modifier.get(entity).event_sprint }
|
||||||
|
event_jump(entity: Entity) : String { Modifier.get(entity).event_jump }
|
||||||
|
input_target(entity: Entity) : Float3 { Modifier.get(entity).input_target }
|
||||||
|
target_speed(entity: Entity) : Num { Modifier.get(entity).target_speed }
|
||||||
|
time_since_grounded(entity: Entity) : Num { Modifier.get(entity).time_since_grounded }
|
||||||
|
is_grounded(entity: Entity) : Bool { Modifier.get(entity).is_grounded }
|
||||||
|
movement_active(entity: Entity) : Bool { Modifier.get(entity).movement_active }
|
||||||
}
|
}
|
||||||
|
|
||||||
class APISet {
|
class APISet {
|
||||||
construct new() {}
|
construct new() {}
|
||||||
|
acceleration(entity: Entity, value: Num) { Modifier.get(entity).acceleration = value }
|
||||||
|
decelleration(entity: Entity, value: Num) { Modifier.get(entity).decelleration = value }
|
||||||
|
speed_run(entity: Entity, value: Num) { Modifier.get(entity).speed_run = value }
|
||||||
|
speed_walk(entity: Entity, value: Num) { Modifier.get(entity).speed_walk = 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_grace_time(entity: Entity, value: Num) { Modifier.get(entity).jump_grace_time = value }
|
||||||
|
event_forward(entity: Entity, value: String) { Modifier.get(entity).event_forward = value }
|
||||||
|
event_backward(entity: Entity, value: String) { Modifier.get(entity).event_backward = value }
|
||||||
|
event_strafe_left(entity: Entity, value: String) { Modifier.get(entity).event_strafe_left = value }
|
||||||
|
event_strafe_right(entity: Entity, value: String) { Modifier.get(entity).event_strafe_right = value }
|
||||||
|
event_sprint(entity: Entity, value: String) { Modifier.get(entity).event_sprint = value }
|
||||||
|
event_jump(entity: Entity, value: String) { Modifier.get(entity).event_jump = value }
|
||||||
|
input_target(entity: Entity, value: Float3) { Modifier.get(entity).input_target = value }
|
||||||
|
target_speed(entity: Entity, value: Num) { Modifier.get(entity).target_speed = 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 }
|
||||||
|
movement_active(entity: Entity, value: Bool) { Modifier.get(entity).movement_active = value }
|
||||||
}
|
}
|
||||||
|
|
||||||
var APIGetter = APIGet.new()
|
var APIGetter = APIGet.new()
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
tags = []
|
tags = []
|
||||||
uuid = "a6edbb1f-6920-484a-9f7f-82485d7054f9"
|
uuid = "6ae99a95-7a4b-4567-858a-27f36837fbfb"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import "system/first_person_player.modifier.api" for API, Modifier, APIGet, APISet, Wire, Fields, State, Op
|
import "fpkit: system/first_person_player.modifier.api" for API, Modifier, APIGet, APISet, Wire, Fields, State, Op
|
||||||
import "luxe: io" for IO
|
import "luxe: io" for IO
|
||||||
import "luxe: assets" for Strings
|
import "luxe: assets" for Strings
|
||||||
import "luxe: input" for Input
|
import "luxe: input" for Input
|
||||||
@ -18,6 +18,13 @@ class Data {
|
|||||||
var jump_impulse: Num = 20
|
var jump_impulse: Num = 20
|
||||||
var jump_grace_time: Num = 0.1
|
var jump_grace_time: Num = 0.1
|
||||||
|
|
||||||
|
var event_forward: String = "up"
|
||||||
|
var event_backward: String = "down"
|
||||||
|
var event_strafe_left: String = "left"
|
||||||
|
var event_strafe_right: String = "right"
|
||||||
|
var event_sprint: String = "run"
|
||||||
|
var event_jump: String = "jump"
|
||||||
|
|
||||||
#hidden
|
#hidden
|
||||||
var input_target: Float3 = [0, 0, 0]
|
var input_target: Float3 = [0, 0, 0]
|
||||||
|
|
||||||
@ -35,10 +42,10 @@ class Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#api
|
#api
|
||||||
#display = "First-Person Player"
|
#display = "FPKit: First-Person Player"
|
||||||
#desc = "**Player movement system**. Takes the player's input and moves the player's character."
|
#desc = "**Player movement system**. Takes the player's input and moves the player's character."
|
||||||
#icon = "luxe: image/modifier/modifier.svg"
|
#icon = "luxe: image/modifier/modifier.svg"
|
||||||
class PlayerInput is API {
|
class FirstPersonPlayer is API {
|
||||||
set_movement_active(entity: Entity, active: Bool) {
|
set_movement_active(entity: Entity, active: Bool) {
|
||||||
system(entity).movement_active = active
|
system(entity).movement_active = active
|
||||||
}
|
}
|
||||||
@ -60,14 +67,12 @@ class System is Modifier {
|
|||||||
_world = world
|
_world = world
|
||||||
}
|
}
|
||||||
|
|
||||||
#hidden
|
|
||||||
attach(player: Entity, data: Data) {
|
attach(player: Entity, data: Data) {
|
||||||
if (!Character3D.has(player)) return
|
if (!Character3D.has(player)) return
|
||||||
Character3D.set.speed(player, data.speed_walk)
|
Character3D.set.speed(player, data.speed_walk)
|
||||||
data.target_speed = data.speed_walk
|
data.target_speed = data.speed_walk
|
||||||
}
|
}
|
||||||
|
|
||||||
#hidden
|
|
||||||
tick(delta: Num) {
|
tick(delta: Num) {
|
||||||
each {|player: Entity, data: Data|
|
each {|player: Entity, data: Data|
|
||||||
if (!Character3D.has(player)) return
|
if (!Character3D.has(player)) return
|
||||||
@ -87,6 +92,12 @@ class System is Modifier {
|
|||||||
data.is_grounded = true
|
data.is_grounded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get player's movement input
|
||||||
|
var fore = Input.event_active(data.event_forward, "game") ? -1 : 0
|
||||||
|
var back = Input.event_active(data.event_backward, "game") ? 1 : 0
|
||||||
|
var left = Input.event_active(data.event_strafe_left, "game") ? -1 : 0
|
||||||
|
var right = Input.event_active(data.event_strafe_right, "game") ? 1 : 0
|
||||||
|
|
||||||
// Turn this into a Float3 of (Left/Right, 0, Forward/Backward) that is relative to the player's facing direction
|
// Turn this into a Float3 of (Left/Right, 0, Forward/Backward) that is relative to the player's facing direction
|
||||||
data.input_target = Math.normalized(Math.mult(Transform.local_dir_to_world(_camera, right + left, 0, fore + back), [1, 0, 1]))
|
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_vec(Character3D.get.input(player), data.input_target, data, delta * 6)
|
data.input_target = move_toward_vec(Character3D.get.input(player), data.input_target, data, delta * 6)
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
tags = []
|
tags = []
|
||||||
uuid = "ca5d1912-99bd-483c-8bc2-f76151287ffb"
|
uuid = "0a5ec330-27c1-49b2-855f-c39c9c0ab39b"
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
tags = []
|
|
||||||
uuid = "d23d2a2e-e607-495b-81c6-a0413bbc9ca8"
|
|
||||||
Reference in New Issue
Block a user