Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Engel Simulator 2020
Engel Simulator 2020
Commits
1651cea3
Commit
1651cea3
authored
Dec 27, 2020
by
Rahix
🦀
Browse files
Merge 'Framerate and movement fixed'
Closes #19 and #20 See merge request
engel-simulator-2020/game!32
parents
7f9c2534
df971876
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/resources/clock.rs
View file @
1651cea3
...
...
@@ -3,6 +3,9 @@ use crate::utils;
pub
struct
Clock
{
perf
:
web_sys
::
Performance
,
start
:
f64
,
last_tick
:
f64
,
frame_delta
:
f32
,
pub
max_delta
:
f32
,
}
impl
Clock
{
...
...
@@ -12,11 +15,24 @@ impl Clock {
.expect
(
"cannot access `window.performance`"
);
let
start
=
perf
.now
();
Clock
{
perf
,
start
}
Clock
{
perf
,
start
,
frame_delta
:
0.03
,
last_tick
:
start
,
max_delta
:
0.1
,
}
}
pub
fn
frame_delta
(
&
self
)
->
f32
{
0.1
self
.frame_delta
}
pub
fn
update
(
&
mut
self
,
timestamp
:
f64
)
{
let
timestamp
=
timestamp
/
1000.0
;
self
.frame_delta
=
self
.max_delta
.min
((
timestamp
-
self
.last_tick
)
as
f32
);
self
.last_tick
=
timestamp
;
crate
::
console_log!
(
"Frame delta: {}"
,
self
.frame_delta
());
}
pub
fn
wall_time
(
&
self
)
->
f64
{
...
...
src/states/ingame.rs
View file @
1651cea3
...
...
@@ -113,22 +113,30 @@ impl gamestate::State for InGameState {
.get_mut
(
&
mut
self
.world
,
player
)
.unwrap
();
match
event
{
gamestate
::
Event
::
KeyDown
(
"w"
)
=>
player_movable
.velocity.y
=
-
5
0.0
,
gamestate
::
Event
::
KeyDown
(
"w"
)
=>
player_movable
.velocity.y
=
-
30
0.0
,
gamestate
::
Event
::
KeyUp
(
"w"
)
=>
player_movable
.velocity.y
=
0.0
,
gamestate
::
Event
::
KeyDown
(
"a"
)
=>
player_movable
.velocity.x
=
-
5
0.0
,
gamestate
::
Event
::
KeyDown
(
"a"
)
=>
player_movable
.velocity.x
=
-
30
0.0
,
gamestate
::
Event
::
KeyUp
(
"a"
)
=>
player_movable
.velocity.x
=
0.0
,
gamestate
::
Event
::
KeyDown
(
"s"
)
=>
player_movable
.velocity.y
=
5
0.0
,
gamestate
::
Event
::
KeyDown
(
"s"
)
=>
player_movable
.velocity.y
=
30
0.0
,
gamestate
::
Event
::
KeyUp
(
"s"
)
=>
player_movable
.velocity.y
=
0.0
,
gamestate
::
Event
::
KeyDown
(
"d"
)
=>
player_movable
.velocity.x
=
5
0.0
,
gamestate
::
Event
::
KeyDown
(
"d"
)
=>
player_movable
.velocity.x
=
30
0.0
,
gamestate
::
Event
::
KeyUp
(
"d"
)
=>
player_movable
.velocity.x
=
0.0
,
_
=>
(),
}
if
player_movable
.velocity.x
!=
0.0
||
player_movable
.velocity.y
!=
0.0
{
player_movable
.velocity
=
player_movable
.velocity
.normalize
()
*
300.0
;
}
gamestate
::
Transition
::
Keep
}
fn
update
(
&
mut
self
,
_
timestamp
:
f64
)
->
gamestate
::
Transition
{
fn
update
(
&
mut
self
,
timestamp
:
f64
)
->
gamestate
::
Transition
{
use
legion
::
IntoQuery
;
self
.resources
.get_mut
::
<
resources
::
Clock
>
()
.unwrap
()
.update
(
timestamp
);
{
let
rendering
=
self
.resources.get
::
<
resources
::
Rendering
>
()
.unwrap
();
rendering
.set_transform
(
1.0
,
0.0
,
0.0
,
1.0
,
0.0
,
0.0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment