fix: 5890 set upper bound for vertical jump (#6034)

This commit is contained in:
Deep Vora 2024-09-06 11:00:42 -05:00 committed by GitHub
parent 0e352f5b34
commit 50b71287ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,19 +34,29 @@ impl Bunny {
self.position[0] += self.velocity[0] * delta;
self.position[1] += self.velocity[1] * delta;
self.velocity[1] += GRAVITY * delta;
if (self.velocity[0] > 0.0 && self.position[0] + 0.5 * BUNNY_SIZE > extent[0] as f32)
|| (self.velocity[0] < 0.0 && self.position[0] - 0.5 * BUNNY_SIZE < 0.0)
{
self.velocity[0] *= -1.0;
}
if self.velocity[1] < 0.0 && self.position[1] < 0.5 * BUNNY_SIZE {
self.velocity[1] *= -1.0;
}
// Top boundary check
if self.velocity[1] > 0.0 && self.position[1] + 0.5 * BUNNY_SIZE > extent[1] as f32 {
self.velocity[1] *= -1.0;
}
}
}
/// Example struct holds references to wgpu resources and frame persistent data
struct Example {
view: wgpu::TextureView,
sampler: wgpu::Sampler,
global_bind_group_layout: wgpu::BindGroupLayout,
global_group: wgpu::BindGroup,
local_group: wgpu::BindGroup,
pipeline: wgpu::RenderPipeline,
@ -286,6 +296,7 @@ impl crate::framework::Example for Example {
size: [BUNNY_SIZE; 2],
pad: [0.0; 2],
};
let global_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("global"),
contents: bytemuck::bytes_of(&globals),
@ -335,6 +346,9 @@ impl crate::framework::Example for Example {
let rng = WyRand::new_seed(42);
let mut ex = Example {
view,
sampler,
global_bind_group_layout,
pipeline,
global_group,
local_group,
@ -366,11 +380,51 @@ impl crate::framework::Example for Example {
fn resize(
&mut self,
_sc_desc: &wgpu::SurfaceConfiguration,
_device: &wgpu::Device,
sc_desc: &wgpu::SurfaceConfiguration,
device: &wgpu::Device,
_queue: &wgpu::Queue,
) {
//empty
self.extent = [sc_desc.width, sc_desc.height];
let globals = Globals {
mvp: glam::Mat4::orthographic_rh(
0.0,
sc_desc.width as f32,
0.0,
sc_desc.height as f32,
-1.0,
1.0,
)
.to_cols_array_2d(),
size: [BUNNY_SIZE; 2],
pad: [0.0; 2],
};
let global_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("global"),
contents: bytemuck::bytes_of(&globals),
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::UNIFORM,
});
let global_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &self.global_bind_group_layout,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: global_buffer.as_entire_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::TextureView(&self.view),
},
wgpu::BindGroupEntry {
binding: 2,
resource: wgpu::BindingResource::Sampler(&self.sampler),
},
],
label: None,
});
self.global_group = global_group;
}
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {