- File Changes
- .gitignore
- Cargo.toml
- src/animator.rs
- src/physics.rs
- assets/bardo.png
- assets/darkdimension.png
- assets/reaper.png
- src/keyboard.rs
- src/main.rs
- src/components.rs
- assets
-
src
- animator.rs
- components.rs
- keyboard.rs
- main.rs
- physics.rs
- .gitignore
- Cargo.toml
+4
-0
src/components.rs
1 | 1 |
|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
|
8 | 8 |
|
9 | 9 |
|
10 | 10 |
|
11 | 11 |
|
12 | 12 |
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
13 | 17 |
|
14 | 18 |
|
15 | 19 |
|
16 | 20 |
|
17 | 21 |
|
18 | 22 |
|
19 | 23 |
|
20 | 24 |
|
21 | 25 |
|
22 | 26 |
|
23 | 27 |
|
24 | 28 |
|
25 | 29 |
|
26 | 30 |
|
27 | 31 |
|
28 | 32 |
|
29 | 33 |
|
30 | 34 |
|
31 | 35 |
|
32 | 36 |
|
33 | 37 |
|
34 | 38 |
|
35 | 39 |
|
36 | 40 |
|
37 | 41 |
|
38 | 42 |
|
39 | 43 |
|
40 | 44 |
|
41 | 45 |
|
42 | 46 |
|
43 | 47 |
|
44 | 48 |
|
+36
-0
src/keyboard.rs
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 |
|
+22
-12
src/main.rs
1 | 1 |
|
2 | 2 |
|
3 | 3 |
|
4 |
|
|
4 | 5 |
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
|
8 | 9 |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
|
12 | 13 |
|
13 | 14 |
|
14 | 15 |
|
15 | 16 |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
20 | 24 |
|
21 | 25 |
|
22 | 26 |
|
23 | 27 |
|
24 | 28 |
|
25 | 29 |
|
26 | 30 |
|
27 | 31 |
|
28 | 32 |
|
29 | 33 |
|
30 | 34 |
|
31 | 35 |
|
32 | 36 |
|
33 | 37 |
|
34 | 38 |
|
35 | 39 |
|
36 | 40 |
|
37 | 41 |
|
38 | 42 |
|
39 | 43 |
|
40 | 44 |
|
41 | 45 |
|
42 | 46 |
|
43 | 47 |
|
44 | 48 |
|
45 | 49 |
|
46 | 50 |
|
47 | 51 |
|
48 | 52 |
|
49 | 53 |
|
50 | 54 |
|
51 | 55 |
|
52 | 56 |
|
53 | 57 |
|
54 | 58 |
|
55 | 59 |
|
56 | 60 |
|
57 | 61 |
|
58 | 62 |
|
59 | 63 |
|
60 | 64 |
|
61 | 65 |
|
62 | 66 |
|
63 | 67 |
|
64 | 68 |
|
65 | 69 |
|
66 | 70 |
|
67 | 71 |
|
68 | 72 |
|
69 | 73 |
|
70 | 74 |
|
71 | 75 |
|
72 | 76 |
|
73 | 77 |
|
74 | 78 |
|
75 | 79 |
|
76 | 80 |
|
77 | 81 |
|
78 | 82 |
|
79 | 83 |
|
80 | 84 |
|
81 | 85 |
|
82 | 86 |
|
83 | 87 |
|
84 | 88 |
|
85 | 89 |
|
86 | 90 |
|
87 | 91 |
|
88 | 92 |
|
89 | 93 |
|
90 | 94 |
|
91 | 95 |
|
92 | 96 |
|
93 | 97 |
|
94 | 98 |
|
95 | 99 |
|
96 | 100 |
|
97 | 101 |
|
98 | 102 |
|
99 | 103 |
|
100 | 104 |
|
101 | 105 |
|
102 | 106 |
|
103 | 107 |
|
104 |
|
|
105 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
106 | 111 |
|
107 | 112 |
|
108 | 113 |
|
109 | 114 |
|
110 | 115 |
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
111 | 120 |
|
112 | 121 |
|
113 | 122 |
|
114 | 123 |
|
115 | 124 |
|
116 | 125 |
|
117 | 126 |
|
118 | 127 |
|
119 | 128 |
|
120 | 129 |
|
121 | 130 |
|
122 | 131 |
|
123 | 132 |
|
124 | 133 |
|
125 | 134 |
|
126 | 135 |
|
136 |
|
|
127 | 137 |
|
128 | 138 |
|
129 | 139 |
|
130 | 140 |
|
131 | 141 |
|
132 | 142 |
|
133 | 143 |
|
134 | 144 |
|
135 | 145 |
|
146 |
|
|
147 |
|
|
136 | 148 |
|
137 | 149 |
|
138 | 150 |
|
139 | 151 |
|
140 | 152 |
|
141 | 153 |
|
142 | 154 |
|
143 | 155 |
|
144 |
|
|
145 |
|
|
156 |
|
|
146 | 157 |
|
147 | 158 |
|
148 |
|
|
149 |
|
|
159 |
|
|
150 | 160 |
|
151 | 161 |
|
152 |
|
|
153 |
|
|
162 |
|
|
154 | 163 |
|
155 | 164 |
|
156 |
|
|
157 |
|
|
165 |
|
|
158 | 166 |
|
159 | 167 |
|
160 | 168 |
|
161 | 169 |
|
162 | 170 |
|
163 |
|
|
171 |
|
|
164 | 172 |
|
165 | 173 |
|
166 | 174 |
|
167 | 175 |
|
168 | 176 |
|
177 |
|
|
178 |
|
|
169 | 179 |
|
170 | 180 |
|
171 | 181 |
|
172 | 182 |
|
173 | 183 |
|
174 | 184 |
|
175 | 185 |
|
176 | 186 |
|
177 | 187 |
|
178 | 188 |
|
179 | 189 |
|
180 | 190 |
|
181 | 191 |
|
182 | 192 |
|
+4
-0
src/components.rs
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
4 |
|
5 |
|
5 |
|
6 |
|
6 |
|
7 |
|
7 |
|
8 |
|
8 |
|
9 |
|
9 |
|
10 |
|
10 |
|
11 |
|
11 |
|
12 |
|
12 |
|
13 |
|
||
14 |
|
||
15 |
|
||
16 |
|
||
13 |
|
17 |
|
14 |
|
18 |
|
15 |
|
19 |
|
16 |
|
20 |
|
17 |
|
21 |
|
18 |
|
22 |
|
19 |
|
23 |
|
20 |
|
24 |
|
21 |
|
25 |
|
22 |
|
26 |
|
23 |
|
27 |
|
24 |
|
28 |
|
25 |
|
29 |
|
26 |
|
30 |
|
27 |
|
31 |
|
28 |
|
32 |
|
29 |
|
33 |
|
30 |
|
34 |
|
31 |
|
35 |
|
32 |
|
36 |
|
33 |
|
37 |
|
34 |
|
38 |
|
35 |
|
39 |
|
36 |
|
40 |
|
37 |
|
41 |
|
38 |
|
42 |
|
39 |
|
43 |
|
40 |
|
44 |
|
41 |
|
45 |
|
42 |
|
46 |
|
43 |
|
47 |
|
44 |
|
48 |
|
+36
-0
src/keyboard.rs
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 |
|
+22
-12
src/main.rs
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
||
4 |
|
5 |
|
5 |
|
6 |
|
6 |
|
7 |
|
7 |
|
8 |
|
8 |
|
9 |
|
9 |
|
10 |
|
10 |
|
11 |
|
11 |
|
12 |
|
12 |
|
13 |
|
13 |
|
14 |
|
14 |
|
15 |
|
15 |
|
16 |
|
16 |
|
17 |
|
17 |
|
18 |
|
18 |
|
19 |
|
19 |
|
20 |
|
21 |
|
||
22 |
|
||
23 |
|
||
20 |
|
24 |
|
21 |
|
25 |
|
22 |
|
26 |
|
23 |
|
27 |
|
24 |
|
28 |
|
25 |
|
29 |
|
26 |
|
30 |
|
27 |
|
31 |
|
28 |
|
32 |
|
29 |
|
33 |
|
30 |
|
34 |
|
31 |
|
35 |
|
32 |
|
36 |
|
33 |
|
37 |
|
34 |
|
38 |
|
35 |
|
39 |
|
36 |
|
40 |
|
37 |
|
41 |
|
38 |
|
42 |
|
39 |
|
43 |
|
40 |
|
44 |
|
41 |
|
45 |
|
42 |
|
46 |
|
43 |
|
47 |
|
44 |
|
48 |
|
45 |
|
49 |
|
46 |
|
50 |
|
47 |
|
51 |
|
48 |
|
52 |
|
49 |
|
53 |
|
50 |
|
54 |
|
51 |
|
55 |
|
52 |
|
56 |
|
53 |
|
57 |
|
54 |
|
58 |
|
55 |
|
59 |
|
56 |
|
60 |
|
57 |
|
61 |
|
58 |
|
62 |
|
59 |
|
63 |
|
60 |
|
64 |
|
61 |
|
65 |
|
62 |
|
66 |
|
63 |
|
67 |
|
64 |
|
68 |
|
65 |
|
69 |
|
66 |
|
70 |
|
67 |
|
71 |
|
68 |
|
72 |
|
69 |
|
73 |
|
70 |
|
74 |
|
71 |
|
75 |
|
72 |
|
76 |
|
73 |
|
77 |
|
74 |
|
78 |
|
75 |
|
79 |
|
76 |
|
80 |
|
77 |
|
81 |
|
78 |
|
82 |
|
79 |
|
83 |
|
80 |
|
84 |
|
81 |
|
85 |
|
82 |
|
86 |
|
83 |
|
87 |
|
84 |
|
88 |
|
85 |
|
89 |
|
86 |
|
90 |
|
87 |
|
91 |
|
88 |
|
92 |
|
89 |
|
93 |
|
90 |
|
94 |
|
91 |
|
95 |
|
92 |
|
96 |
|
93 |
|
97 |
|
94 |
|
98 |
|
95 |
|
99 |
|
96 |
|
100 |
|
97 |
|
101 |
|
98 |
|
102 |
|
99 |
|
103 |
|
100 |
|
104 |
|
101 |
|
105 |
|
102 |
|
106 |
|
103 |
|
107 |
|
104 |
|
108 |
|
105 |
|
109 |
|
110 |
|
||
106 |
|
111 |
|
107 |
|
112 |
|
108 |
|
113 |
|
109 |
|
114 |
|
110 |
|
115 |
|
116 |
|
||
117 |
|
||
118 |
|
||
119 |
|
||
111 |
|
120 |
|
112 |
|
121 |
|
113 |
|
122 |
|
114 |
|
123 |
|
115 |
|
124 |
|
116 |
|
125 |
|
117 |
|
126 |
|
118 |
|
127 |
|
119 |
|
128 |
|
120 |
|
129 |
|
121 |
|
130 |
|
122 |
|
131 |
|
123 |
|
132 |
|
124 |
|
133 |
|
125 |
|
134 |
|
126 |
|
135 |
|
136 |
|
||
127 |
|
137 |
|
128 |
|
138 |
|
129 |
|
139 |
|
130 |
|
140 |
|
131 |
|
141 |
|
132 |
|
142 |
|
133 |
|
143 |
|
134 |
|
144 |
|
135 |
|
145 |
|
146 |
|
||
147 |
|
||
136 |
|
148 |
|
137 |
|
149 |
|
138 |
|
150 |
|
139 |
|
151 |
|
140 |
|
152 |
|
141 |
|
153 |
|
142 |
|
154 |
|
143 |
|
155 |
|
144 |
|
156 |
|
145 |
|
||
146 |
|
157 |
|
147 |
|
158 |
|
148 |
|
159 |
|
149 |
|
||
150 |
|
160 |
|
151 |
|
161 |
|
152 |
|
162 |
|
153 |
|
||
154 |
|
163 |
|
155 |
|
164 |
|
156 |
|
165 |
|
157 |
|
||
158 |
|
166 |
|
159 |
|
167 |
|
160 |
|
168 |
|
161 |
|
169 |
|
162 |
|
170 |
|
163 |
|
171 |
|
164 |
|
172 |
|
165 |
|
173 |
|
166 |
|
174 |
|
167 |
|
175 |
|
168 |
|
176 |
|
177 |
|
||
178 |
|
||
169 |
|
179 |
|
170 |
|
180 |
|
171 |
|
181 |
|
172 |
|
182 |
|
173 |
|
183 |
|
174 |
|
184 |
|
175 |
|
185 |
|
176 |
|
186 |
|
177 |
|
187 |
|
178 |
|
188 |
|
179 |
|
189 |
|
180 |
|
190 |
|
181 |
|
191 |
|
182 |
|
192 |
|
/target
**/*.rs.bk
[package]
name = "game-tutorial"
version = "0.1.0"
authors = ["Sunjay Varma <[email protected]>"]
edition = "2018"
[dependencies]
specs = "0.14"
specs-derive = "0.4"
[dependencies.sdl2]
version = "0.32.1"
default-features = false
features = ["image"]
use specs::prelude::*;
use crate::components::*;
pub struct Animator;
impl<'a> System<'a> for Animator {
type SystemData = (
WriteStorage<'a, MovementAnimation>,
WriteStorage<'a, Sprite>,
ReadStorage<'a, Velocity>,
);
fn run(&mut self, mut data: Self::SystemData) {
use self::Direction::*;
//TODO: This code can be made nicer and more idiomatic using more pattern matching.
// Look up "rust irrefutable patterns" and use them here.
for (anim, sprite, vel) in (&mut data.0, &mut data.1, &data.2).join() {
if vel.speed == 0 {
continue;
}
let frames = match vel.direction {
Left => &anim.left_frames,
Right => &anim.right_frames,
Up => &anim.up_frames,
Down => &anim.down_frames,
};
anim.current_frame = (anim.current_frame + 1) % frames.len();
*sprite = frames[anim.current_frame].clone();
}
}
}
use specs::prelude::*;
use specs_derive::Component;
use sdl2::rect::{Point, Rect};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Up,
Down,
Left,
Right,
}
#[derive(Component, Debug, Default)]
#[storage(NullStorage)]
pub struct KeyboardControlled;
/// The current position of a given entity
#[derive(Component, Debug)]
#[storage(VecStorage)]
pub struct Position(pub Point);
/// The current speed and direction of a given entity
#[derive(Component, Debug)]
#[storage(VecStorage)]
pub struct Velocity {
pub speed: i32,
pub direction: Direction,
}
#[derive(Component, Debug, Clone)]
#[storage(VecStorage)]
pub struct Sprite {
/// The specific spritesheet to render from
pub spritesheet: usize,
/// The current region of the spritesheet to be rendered
pub region: Rect,
}
#[derive(Component, Debug)]
#[storage(VecStorage)]
pub struct MovementAnimation {
// The current frame in the animation of the direction this entity is moving in
pub current_frame: usize,
pub up_frames: Vec<Sprite>,
pub down_frames: Vec<Sprite>,
pub left_frames: Vec<Sprite>,
pub right_frames: Vec<Sprite>,
}
use specs::prelude::*;
use crate::components::*;
use super::MovementCommand;
const PLAYER_MOVEMENT_SPEED: i32 = 20;
pub struct Keyboard;
impl<'a> System<'a> for Keyboard {
type SystemData = (
ReadExpect<'a, Option<MovementCommand>>,
ReadStorage<'a, KeyboardControlled>,
WriteStorage<'a, Velocity>,
);
fn run(&mut self, mut data: Self::SystemData) {
//TODO: This code can be made nicer and more idiomatic using more pattern matching.
// Look up "rust irrefutable patterns" and use them here.
let movement_command = match &*data.0 {
Some(movement_command) => movement_command,
None => return, // no change
};
for (_, vel) in (&data.1, &mut data.2).join() {
match movement_command {
&MovementCommand::Move(direction) => {
vel.speed = PLAYER_MOVEMENT_SPEED;
vel.direction = direction;
},
MovementCommand::Stop => vel.speed = 0,
}
}
}
}
mod components;
mod physics;
mod animator;
mod keyboard;
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::render::{WindowCanvas, Texture};
use sdl2::rect::{Point, Rect};
// "self" imports the "image" module itself as well as everything else we listed
use sdl2::image::{self, LoadTexture, InitFlag};
use specs::prelude::*;
use std::time::Duration;
use crate::components::*;
pub enum MovementCommand {
Stop,
Move(Direction),
}
/// Returns the row of the spritesheet corresponding to the given direction
fn direction_spritesheet_row(direction: Direction) -> i32 {
use self::Direction::*;
match direction {
Up => 3,
Down => 0,
Left => 1,
Right => 2,
}
}
/// Create animation frames for the standard character spritesheet
fn character_animation_frames(spritesheet: usize, top_left_frame: Rect, direction: Direction) -> Vec<Sprite> {
// All assumptions about the spritesheets are now encapsulated in this function instead of in
// the design of our entire system. We can always replace this function, but replacing the
// entire system is harder.
let (frame_width, frame_height) = top_left_frame.size();
let y_offset = top_left_frame.y() + frame_height as i32 * direction_spritesheet_row(direction);
let mut frames = Vec::new();
for i in 0..3 {
frames.push(Sprite {
spritesheet,
region: Rect::new(
top_left_frame.x() + frame_width as i32 * i,
y_offset,
frame_width,
frame_height,
),
})
}
frames
}
fn render(
canvas: &mut WindowCanvas,
color: Color,
texture: &Texture,
player: &Player,
) -> Result<(), String> {
canvas.set_draw_color(color);
canvas.clear();
let (width, height) = canvas.output_size()?;
let (frame_width, frame_height) = player.sprite.size();
let current_frame = Rect::new(
player.sprite.x() + frame_width as i32 * player.current_frame,
player.sprite.y() + frame_height as i32 * direction_spritesheet_row(player.direction),
frame_width,
frame_height,
);
// Treat the center of the screen as the (0, 0) coordinate
let screen_position = player.position + Point::new(width as i32 / 2, height as i32 / 2);
let screen_rect = Rect::from_center(screen_position, frame_width, frame_height);
canvas.copy(texture, current_frame, screen_rect)?;
canvas.present();
Ok(())
}
fn main() -> Result<(), String> {
let sdl_context = sdl2::init()?;
let video_subsystem = sdl_context.video()?;
// Leading "_" tells Rust that this is an unused variable that we don't care about. It has to
// stay unused because if we don't have any variable at all then Rust will treat it as a
// temporary value and drop it right away!
let _image_context = image::init(InitFlag::PNG | InitFlag::JPG)?;
let window = video_subsystem.window("game tutorial", 800, 600)
.position_centered()
.build()
.expect("could not initialize video subsystem");
let mut canvas = window.into_canvas().build()
.expect("could not make a canvas");
let texture_creator = canvas.texture_creator();
let mut dispatcher = DispatcherBuilder::new()
.with(keyboard::Keyboard, "Keyboard", &[])
.with(physics::Physics, "Physics", &["Keyboard"])
.with(animator::Animator, "Animator", &["Keyboard"])
.build();
let mut world = World::new();
dispatcher.setup(&mut world.res);
// Initialize resource
let movement_command: Option<MovementCommand> = None;
world.add_resource(movement_command);
let textures = [
texture_creator.load_texture("assets/bardo.png")?,
];
// First texture in textures array
let player_spritesheet = 0;
let player_top_left_frame = Rect::new(0, 0, 26, 36);
let player_animation = MovementAnimation {
current_frame: 0,
up_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Up),
down_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Down),
left_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Left),
right_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Right),
};
world.create_entity()
.with(KeyboardControlled)
.with(Position(Point::new(0, 0)))
.with(Velocity {speed: 0, direction: Direction::Right})
.with(player_animation.right_frames[0].clone())
.with(player_animation)
.build();
let mut event_pump = sdl_context.event_pump()?;
let mut i = 0;
'running: loop {
// None - no change, Some(MovementCommand) - perform movement
let mut movement_command = None;
// Handle events
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running;
},
Event::KeyDown { keycode: Some(Keycode::Left), repeat: false, .. } => {
movement_command = Some(MovementCommand::Move(Direction::Left));
},
Event::KeyDown { keycode: Some(Keycode::Right), repeat: false, .. } => {
movement_command = Some(MovementCommand::Move(Direction::Right));
},
Event::KeyDown { keycode: Some(Keycode::Up), repeat: false, .. } => {
movement_command = Some(MovementCommand::Move(Direction::Up));
},
Event::KeyDown { keycode: Some(Keycode::Down), repeat: false, .. } => {
movement_command = Some(MovementCommand::Move(Direction::Down));
},
Event::KeyUp { keycode: Some(Keycode::Left), repeat: false, .. } |
Event::KeyUp { keycode: Some(Keycode::Right), repeat: false, .. } |
Event::KeyUp { keycode: Some(Keycode::Up), repeat: false, .. } |
Event::KeyUp { keycode: Some(Keycode::Down), repeat: false, .. } => {
movement_command = Some(MovementCommand::Stop);
},
_ => {}
}
}
*world.write_resource() = movement_command;
// Update
i = (i + 1) % 255;
dispatcher.dispatch(&mut world.res);
world.maintain();
// Render
render(&mut canvas, Color::RGB(i, 64, 255 - i), &texture, &player)?;
// Time management!
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 20));
}
Ok(())
}
use specs::prelude::*;
use crate::components::*;
pub struct Physics;
impl<'a> System<'a> for Physics {
type SystemData = (WriteStorage<'a, Position>, ReadStorage<'a, Velocity>);
fn run(&mut self, mut data: Self::SystemData) {
use self::Direction::*;
//TODO: This code can be made nicer and more idiomatic using more pattern matching.
// Look up "rust irrefutable patterns" and use them here.
for (pos, vel) in (&mut data.0, &data.1).join() {
match vel.direction {
Left => {
pos.0 = pos.0.offset(-vel.speed, 0);
},
Right => {
pos.0 = pos.0.offset(vel.speed, 0);
},
Up => {
pos.0 = pos.0.offset(0, -vel.speed);
},
Down => {
pos.0 = pos.0.offset(0, vel.speed);
},
}
}
}
}