-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathplayer.rs
More file actions
64 lines (51 loc) · 1.62 KB
/
player.rs
File metadata and controls
64 lines (51 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use engine::{Actor, EngineState};
use engine::gfx::{Camera, CameraProps, ProjectionMode};
use std::sync::Arc;
/// A Player in the CodeVR scene, handles its own movement and editing the CodeVR scene.
pub struct Player {
// Local State
health: [i32; 2],
// Engine State
camera: Option<Arc<Camera>>,
engine: Option<EngineState>,
}
/// Local Logic
impl Player {
pub fn new() -> Player {
Player {
health: [100, 100],
camera: None,
engine: None,
}
}
}
/// Actor Logic
impl Actor for Player {
// Mount engine state
fn start(&mut self, mut engine: EngineState) {
{
// Add reference to camera
let mut gfx = engine.gfx.lock().unwrap();
self.camera = Some(gfx.camera(CameraProps {
projection_mode: ProjectionMode::Perspective,
to: [4., 4., 4.],
from: [0., 0., 0.],
fov: 75.0,
}));
}
self.engine = Some(engine);
}
// Update Engine State
fn update(&mut self) {
if let Some(ref mut engine) = self.engine {
// Destroy self if we're out of health
if self.health[0] < 1 {
//engine.scene.destroy(|actor| true);
}
// Check inputs
let cam_x = engine.input_axis(String::from("look_right"));
let cam_y = engine.input_axis(String::from("look_up"));
//self.camera.unwrap().rotate(cam_x, cam_y, 0.);
}
}
}