Compare commits
4 Commits
fdce0a7d3b
...
10e1ef8107
Author | SHA1 | Date |
---|---|---|
Mark | 10e1ef8107 | |
Mark | e2f9d427b5 | |
Mark | ed03e8a523 | |
Mark | 74e8fed1b6 |
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 45f65b6a639f3e59d9d1db2a4cf452fe406bd4b2
|
Subproject commit 7b00da4f1971908d389d906fe537bfecd3d03b50
|
|
@ -4,8 +4,8 @@ name = "12 Autumn above"
|
||||||
|
|
||||||
[object.star]
|
[object.star]
|
||||||
sprite = "star::star"
|
sprite = "star::star"
|
||||||
position = [0.0, 0.0, 20.0]
|
position = [0.0, 0.0, 30.0]
|
||||||
size = 1000
|
size = 2000
|
||||||
|
|
||||||
|
|
||||||
[object.earth]
|
[object.earth]
|
||||||
|
|
|
@ -11,6 +11,8 @@ pub struct Game {
|
||||||
pub player: Ship,
|
pub player: Ship,
|
||||||
pub system: System,
|
pub system: System,
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
|
paused: bool,
|
||||||
|
pub time_scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
|
@ -24,6 +26,8 @@ impl Game {
|
||||||
zoom: 500.0,
|
zoom: 500.0,
|
||||||
},
|
},
|
||||||
system: System::new(&ct.systems[0]),
|
system: System::new(&ct.systems[0]),
|
||||||
|
paused: false,
|
||||||
|
time_scale: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +43,17 @@ impl Game {
|
||||||
self.input.process_scroll(delta, phase)
|
self.input.process_scroll(delta, phase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_paused(&mut self, pause: bool) {
|
||||||
|
if pause {
|
||||||
|
self.paused = true;
|
||||||
|
self.input.release_all()
|
||||||
|
} else {
|
||||||
|
self.paused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
let t: f32 = self.last_update.elapsed().as_secs_f32();
|
let t: f32 = self.last_update.elapsed().as_secs_f32() * self.time_scale;
|
||||||
|
|
||||||
if self.input.key_thrust {
|
if self.input.key_thrust {
|
||||||
self.player.physicsbody.thrust(50.0 * t);
|
self.player.physicsbody.thrust(50.0 * t);
|
||||||
|
|
|
@ -19,6 +19,12 @@ impl InputStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn release_all(&mut self) {
|
||||||
|
self.key_left = false;
|
||||||
|
self.key_right = false;
|
||||||
|
self.key_thrust = false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_key(&mut self, state: &ElementState, key: &VirtualKeyCode) {
|
pub fn process_key(&mut self, state: &ElementState, key: &VirtualKeyCode) {
|
||||||
let down = state == &ElementState::Pressed;
|
let down = state == &ElementState::Pressed;
|
||||||
match key {
|
match key {
|
||||||
|
|
|
@ -30,7 +30,6 @@ async fn run(mut game: game::Game) -> Result<()> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
Event::RedrawRequested(window_id) if window_id == gpu.window().id() => {
|
Event::RedrawRequested(window_id) if window_id == gpu.window().id() => {
|
||||||
gpu.update();
|
|
||||||
game.update();
|
game.update();
|
||||||
match gpu.render(&game) {
|
match gpu.render(&game) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
@ -54,6 +53,9 @@ async fn run(mut game: game::Game) -> Result<()> {
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == gpu.window.id() => {
|
} if window_id == gpu.window.id() => {
|
||||||
match event {
|
match event {
|
||||||
|
WindowEvent::Focused(state) => {
|
||||||
|
game.set_paused(!state);
|
||||||
|
}
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
|
|
|
@ -194,8 +194,6 @@ impl GPUState {
|
||||||
self.update_starfield_buffer(game)
|
self.update_starfield_buffer(game)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {}
|
|
||||||
|
|
||||||
/// Make a SpriteInstance for each of the game's visible sprites.
|
/// Make a SpriteInstance for each of the game's visible sprites.
|
||||||
/// Will panic if SPRITE_INSTANCE_LIMIT is exceeded.
|
/// Will panic if SPRITE_INSTANCE_LIMIT is exceeded.
|
||||||
///
|
///
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn vertex_main(
|
||||||
fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
return textureSampleLevel(
|
return textureSampleLevel(
|
||||||
texture_array[in.index],
|
texture_array[in.index],
|
||||||
sampler_array[in.index],
|
sampler_array[0],
|
||||||
in.texture_coords,
|
in.texture_coords,
|
||||||
0.0
|
0.0
|
||||||
).rgba;
|
).rgba;
|
||||||
|
|
|
@ -135,7 +135,7 @@ fn fragment_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
|
|
||||||
return textureSampleLevel(
|
return textureSampleLevel(
|
||||||
texture_array[global.starfield_texture.x],
|
texture_array[global.starfield_texture.x],
|
||||||
sampler_array[global.starfield_texture.x],
|
sampler_array[0],
|
||||||
in.texture_coords,
|
in.texture_coords,
|
||||||
0.0
|
0.0
|
||||||
).rgba * vec4<f32>(
|
).rgba * vec4<f32>(
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl TextureArray {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||||
count: NonZeroU32::new(loader.texture_data.len() as u32),
|
count: NonZeroU32::new(1),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -80,7 +80,7 @@ impl TextureArray {
|
||||||
},
|
},
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
resource: wgpu::BindingResource::SamplerArray(&[&sampler].repeat(views.len())),
|
resource: wgpu::BindingResource::SamplerArray(&[&sampler]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue