Compare commits
4 Commits
ee95440d04
...
236bb69be1
| Author | SHA1 | Date |
|---|---|---|
|
|
236bb69be1 | 2 years ago |
|
|
c586c87afe | 2 years ago |
|
|
dcbd33e136 | 2 years ago |
|
|
9d0a79f2fd | 2 years ago |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "core"
|
||||
description = "The Core Module For the Game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
physics = { workspace = true }
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use physics::{PhysicsPlugin, components::Velocity};
|
||||
|
||||
pub struct CorePlugin;
|
||||
impl Plugin for CorePlugin
|
||||
{
|
||||
fn build(&self, app: &mut App)
|
||||
{
|
||||
app.add_plugins(PhysicsPlugin)
|
||||
.add_systems(Startup, setup);
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, server: Res<AssetServer>, mut ambient_light: ResMut<AmbientLight>)
|
||||
{
|
||||
ambient_light.brightness = 200.0;
|
||||
|
||||
// CAMERA
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(0.0, 0.0, -25.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
|
||||
// LIGHT
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
intensity: 2_000_000.0,
|
||||
range: 100.0,
|
||||
radius: 10.0,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(0.0, 5.0, -5.0),
|
||||
..default()
|
||||
});
|
||||
|
||||
// BRICK
|
||||
let brick_handle: Handle<Scene> = server.load("brick.glb#Scene0");
|
||||
commands.spawn(SceneBundle {
|
||||
scene: brick_handle,
|
||||
transform: Transform::from_xyz(0.0, 7.0, 0.0),
|
||||
.. default()
|
||||
});
|
||||
|
||||
// BALL
|
||||
let ball_handle: Handle<Scene> = server.load("ball.glb#Scene0");
|
||||
commands.spawn((SceneBundle {
|
||||
scene: ball_handle,
|
||||
transform: Transform::from_xyz(0.0, -7.75, 0.0),
|
||||
..default()
|
||||
},
|
||||
Velocity::new(8.0, 8.0, 0.0)));
|
||||
|
||||
// PADDLE
|
||||
let paddle_handle: Handle<Scene> = server.load("paddle.glb#Scene0");
|
||||
commands.spawn(SceneBundle {
|
||||
scene: paddle_handle,
|
||||
transform: Transform::from_xyz(0.0, -8.0, 0.0),
|
||||
..default()
|
||||
});
|
||||
|
||||
// WALLS
|
||||
let wall_handle: Handle<Scene> = server.load("wall.glb#Scene0");
|
||||
commands.spawn(SceneBundle {
|
||||
scene: wall_handle.clone(),
|
||||
transform: Transform::from_xyz(13.0, 0.0, 0.0),
|
||||
..default()
|
||||
});
|
||||
|
||||
commands.spawn(SceneBundle {
|
||||
scene: wall_handle.clone(),
|
||||
transform: Transform::from_xyz(-13.0, 0.0, 0.0),
|
||||
..default()
|
||||
});
|
||||
|
||||
commands.spawn(SceneBundle {
|
||||
scene: wall_handle.clone(),
|
||||
transform: Transform::from_rotation(Quat::from_rotation_z(3.14159 * 0.5))
|
||||
.with_translation(Vec3::new(0.0, 10.0, 0.0)),
|
||||
..default()
|
||||
});
|
||||
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
pub mod core;
|
||||
@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
// pub struct MovementPlugin;
|
||||
// impl Plugin for MovementPlugin
|
||||
// {
|
||||
// fn build(&self, app: &mut App)
|
||||
// {
|
||||
// app.add_systems(Update, update_movement);
|
||||
// }
|
||||
// }
|
||||
|
||||
// COMPONENTS
|
||||
|
||||
|
||||
// SYSTEMS
|
||||
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "physics"
|
||||
description = "The Physics Module For the Game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,126 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Velocity
|
||||
{
|
||||
pub value: Vec3,
|
||||
}
|
||||
|
||||
impl Default for Velocity
|
||||
{
|
||||
fn default() -> Self
|
||||
{
|
||||
Self { value: Vec3::new(0.0, 0.0, 0.0)}
|
||||
}
|
||||
}
|
||||
|
||||
impl Velocity
|
||||
{
|
||||
pub fn new(x: f32, y: f32, z: f32) -> Self{
|
||||
Self { value: Vec3::new(x, y, z) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct AABB
|
||||
{
|
||||
min_extents: Vec3,
|
||||
max_extents: Vec3,
|
||||
half_size: Vec3,
|
||||
}
|
||||
|
||||
impl AABB
|
||||
{
|
||||
// CONSTRUCTORS
|
||||
pub fn from_point_and_size(center: Vec3, dimensions: Vec3) -> Self
|
||||
{
|
||||
let half_size = dimensions * 0.5;
|
||||
Self {
|
||||
min_extents: center - half_size,
|
||||
max_extents: center + half_size,
|
||||
half_size
|
||||
}
|
||||
}
|
||||
|
||||
// ACCESSORS
|
||||
pub fn get_center_point(&self) -> Vec3
|
||||
{
|
||||
Vec3::new(self.min_extents.x + self.half_size.x,
|
||||
self.min_extents.y + self.half_size.y,
|
||||
self.min_extents.z + self.half_size.z)
|
||||
}
|
||||
|
||||
pub fn get_half_size(&self) -> Vec3
|
||||
{
|
||||
self.half_size.clone()
|
||||
}
|
||||
|
||||
// INTERFACE METHODS
|
||||
pub fn set_position(&mut self, position: Vec3)
|
||||
{
|
||||
self.min_extents = Vec3::new(
|
||||
position.x - self.half_size.x,
|
||||
position.y - self.half_size.y,
|
||||
position.z - self.half_size.z);
|
||||
|
||||
self.max_extents = Vec3::new(
|
||||
position.x + self.half_size.x,
|
||||
position.y + self.half_size.y,
|
||||
position.z + self.half_size.z);
|
||||
}
|
||||
|
||||
pub fn set_size(&mut self, size: Vec3)
|
||||
{
|
||||
let center = self.get_center_point();
|
||||
self.half_size = size * 0.5;
|
||||
|
||||
self.min_extents = Vec3::new(
|
||||
center.x - self.half_size.x,
|
||||
center.y - self.half_size.y,
|
||||
center.z - self.half_size.z);
|
||||
|
||||
self.max_extents = Vec3::new(
|
||||
center.x + self.half_size.x,
|
||||
center.y + self.half_size.y,
|
||||
center.z + self.half_size.z);
|
||||
}
|
||||
|
||||
pub fn translate(&mut self, translation: Vec3)
|
||||
{
|
||||
self.min_extents.x += translation.x;
|
||||
self.min_extents.y += translation.y;
|
||||
self.min_extents.z += translation.z;
|
||||
|
||||
self.max_extents.x += translation.x;
|
||||
self.max_extents.y += translation.y;
|
||||
self.max_extents.z += translation.z;
|
||||
}
|
||||
|
||||
pub fn contains_point(&self, test_point: Vec3) -> bool
|
||||
{
|
||||
if test_point.x < self.min_extents.x { return false; }
|
||||
if test_point.y < self.min_extents.y { return false; }
|
||||
if test_point.z < self.min_extents.z { return false; }
|
||||
|
||||
if test_point.x > self.max_extents.x { return false; }
|
||||
if test_point.y > self.max_extents.y { return false; }
|
||||
if test_point.z > self.max_extents.z { return false; }
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub fn intersects_with(&self, other: &AABB) -> bool
|
||||
{
|
||||
if self.min_extents.x > other.max_extents.x ||
|
||||
other.min_extents.x > self.max_extents.x { return false }
|
||||
|
||||
if self.min_extents.y > other.max_extents.y ||
|
||||
other.min_extents.y > self.max_extents.y { return false }
|
||||
|
||||
if self.min_extents.z > other.max_extents.z ||
|
||||
other.min_extents.z > self.max_extents.z { return false }
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
|
||||
pub mod components;
|
||||
pub mod systems;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct PhysicsPlugin;
|
||||
impl Plugin for PhysicsPlugin
|
||||
{
|
||||
fn build(&self, app: &mut App)
|
||||
{
|
||||
app.add_systems(Update, systems::update_movement);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::components::Velocity;
|
||||
|
||||
pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>)
|
||||
{
|
||||
for (velocity, mut transform) in moving_objects.iter_mut()
|
||||
{
|
||||
transform.translation += velocity.value * time.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
// extern crate hello;
|
||||
use hello::hello::HelloPlugin;
|
||||
// use hello::hello::HelloPlugin;
|
||||
use core::core::CorePlugin;
|
||||
|
||||
fn main()
|
||||
{
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins, HelloPlugin))
|
||||
.add_plugins((DefaultPlugins, CorePlugin))
|
||||
.run();
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue