Skip to content

Commit

Permalink
Use circle for breakout example (bevyengine#5657)
Browse files Browse the repository at this point in the history
# Objective

- Replace the square with a circle in the breakout example.
- Fixes bevyengine#4324, adopted from bevyengine#4682 by @shaderduck.

## Solution
- Uses the Mesh2D APIs to draw a circle. The collision still uses the AABB algorithm, but it seems to be working fine, and I haven't seen any odd looking cases.
  • Loading branch information
tkgalk authored and maccesch committed Sep 28, 2022
1 parent 01dbd39 commit 01cf9f3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/games/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use bevy::{
prelude::*,
sprite::collide_aabb::{collide, Collision},
sprite::MaterialMesh2dBundle,
time::FixedTimestep,
};

Expand Down Expand Up @@ -171,7 +172,12 @@ struct Scoreboard {
}

// Add the game's entities to our world
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>,
) {
// Camera
commands.spawn_bundle(Camera2dBundle::default());

Expand Down Expand Up @@ -203,16 +209,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn()
.insert(Ball)
.insert_bundle(SpriteBundle {
transform: Transform {
scale: BALL_SIZE,
translation: BALL_STARTING_POSITION,
..default()
},
sprite: Sprite {
color: BALL_COLOR,
..default()
},
.insert_bundle(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::default().into()).into(),
material: materials.add(ColorMaterial::from(BALL_COLOR)),
transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE),
..default()
})
.insert(Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED));
Expand Down

0 comments on commit 01cf9f3

Please sign in to comment.