Skip to content

Commit

Permalink
modified screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
poopnugget142 committed Jul 23, 2024
1 parent 2ce6c9c commit 6692d1d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
31 changes: 23 additions & 8 deletions src/hand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ fn spawn_hand(
},
RigidBody::Dynamic,
Grabbable,
LinearDamping(1.0),
));

commands.spawn((
MaterialMesh2dBundle {
mesh: Mesh2dHandle(meshes.add(Rectangle::new(1280.0, 720.0))),
material: materials.add(Color::hsl(0.0, 0.50, 0.50)),
transform: Transform::from_xyz(0.0, 0.0, -2.0),
..default()
},
));

//Input map
Expand All @@ -71,6 +81,7 @@ fn spawn_hand(
fn drop(
mut commands: Commands,
hands: Query<(&ActionState<HandActions>, Entity, &Grabbing), With<CurrentHand>>,
joints: Query<&FixedJoint>,
mut objects: Query<&mut Transform>,
) {
if hands.is_empty() {
Expand All @@ -85,10 +96,14 @@ fn drop(

let mut hand_commands = commands.entity(hand);

let mut transform = objects.get_mut(grabbing.0).unwrap();

hand_commands.remove_children(&[grabbing.0]);
hand_commands.remove::<Grabbing>();
let joint = grabbing.0;

let object = joints.get(joint).unwrap().entity1;

commands.entity(joint).despawn();

let mut transform = objects.get_mut(object).unwrap();

transform.translation.z = -1.0;
}
Expand Down Expand Up @@ -121,14 +136,14 @@ fn grab(
for (bounding_box, object, mut object_transform) in hands_and_objects.p1().iter_mut() {
// Clicked on grabble thing attach to hand
if bounding_box.0.contains(hand_spot.truncate()) {
let mut hand_commands = commands.entity(hand);
hand_commands.insert(Grabbing(object));
// hand_commands.add_child(object);

let mut joint = FixedJoint::new(object, hand);
joint.local_anchor2 = Vec2::new(0.0, -HAND_OFFSET);

commands.spawn(joint);
let joint_commands = commands.spawn(joint);
let joint_entity = joint_commands.id();

let mut hand_commands = commands.entity(hand);
hand_commands.insert(Grabbing(joint_entity));

object_transform.translation.z = 1.0;
}
Expand Down
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use avian2d::prelude::*;
use bevy::asset::AssetMetaCheck;
use bevy::prelude::*;

use bevy::window::WindowResolution;
mod hand;

#[derive(Component)]
Expand All @@ -16,6 +16,9 @@ pub struct ImageSize(Vec2);
#[derive(Component)]
pub struct BoundingBox(Rect);

pub const SCREEN_W : f32 = 1280.0;
pub const SCREEN_H : f32 = 720.0;

fn main() {
let mut app = App::new();
app.add_plugins((
Expand All @@ -25,6 +28,13 @@ fn main() {
// See https://github.com/bevyengine/bevy_github_ci_template/issues/48.
meta_check: AssetMetaCheck::Never,
..default()
}).set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(SCREEN_W, SCREEN_H),
resizable: false,
..default()
}),
..default()
}),
PhysicsPlugins::default(),
PhysicsDebugPlugin::default(),
Expand Down

0 comments on commit 6692d1d

Please sign in to comment.