Compare commits
No commits in common. '173a03a7dd978fb0bf882d0b2df37582a1be369e' and '77998a519707dac49a7563619f45f33251cf9d30' have entirely different histories.
173a03a7dd
...
77998a5197
@ -0,0 +1,2 @@
|
||||
* setup CI template in web server running on port 8000
|
||||
* setup mock bevy app running on port 8001 w/ first app running in iframe
|
||||
@ -1,104 +0,0 @@
|
||||
use bevy::{color::palettes::css::*, prelude::*};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.insert_resource(ClearColor(WHITE.into()))
|
||||
.add_event::<CameraMovement>()
|
||||
.add_systems(Startup, setup_2d)
|
||||
.add_systems(Update, (move_camera, track_camera_movement, parallax))
|
||||
.run();
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct ParallaxDistance(f32);
|
||||
|
||||
fn setup_2d(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Camera2d,
|
||||
AmbientLight {
|
||||
brightness: 160.0,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh2d(meshes.add(Rectangle::new(100.0, 100.0))),
|
||||
MeshMaterial2d(materials.add(Color::from(RED))),
|
||||
Transform::from_xyz(0.0, 0.0, -1.0),
|
||||
ParallaxDistance(1.0),
|
||||
children![(
|
||||
Text2d::new("Parallax Distance: 1"),
|
||||
TextColor(BLACK.into()),
|
||||
Transform::from_xyz(150.0, 50.0, 0.0)
|
||||
)],
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh2d(meshes.add(Rectangle::new(100.0, 100.0))),
|
||||
MeshMaterial2d(materials.add(Color::from(GREEN))),
|
||||
Transform::from_xyz(0.0, 0.0, -5.0),
|
||||
ParallaxDistance(5.0),
|
||||
children![(
|
||||
Text2d::new("Parallax Distance: 5"),
|
||||
TextColor(BLACK.into()),
|
||||
Transform::from_xyz(150.0, 0.0, 0.0)
|
||||
)],
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh2d(meshes.add(Rectangle::new(100.0, 100.0))),
|
||||
MeshMaterial2d(materials.add(Color::from(BLUE))),
|
||||
Transform::from_xyz(0.0, 0.0, -10.0),
|
||||
ParallaxDistance(10.0),
|
||||
children![(
|
||||
Text2d::new("Parallax Distance: 10"),
|
||||
TextColor(BLACK.into()),
|
||||
Transform::from_xyz(150.0, -50.0, 0.0)
|
||||
)],
|
||||
));
|
||||
}
|
||||
|
||||
fn move_camera(keys: Res<ButtonInput<KeyCode>>, mut camera: Single<&mut Transform, With<Camera>>) {
|
||||
const SPEED: f32 = 5.0;
|
||||
if keys.pressed(KeyCode::ArrowLeft) {
|
||||
camera.translation.x += SPEED;
|
||||
} else if keys.pressed(KeyCode::ArrowRight) {
|
||||
camera.translation.x -= SPEED;
|
||||
}
|
||||
|
||||
if keys.pressed(KeyCode::ArrowUp) {
|
||||
camera.translation.y -= SPEED;
|
||||
} else if keys.pressed(KeyCode::ArrowDown) {
|
||||
camera.translation.y += SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event)]
|
||||
struct CameraMovement(Vec3);
|
||||
|
||||
fn track_camera_movement(
|
||||
mut events: EventWriter<CameraMovement>,
|
||||
camera: Query<&Transform, (With<Camera>, Changed<Transform>)>,
|
||||
mut last: Local<Vec3>,
|
||||
) {
|
||||
camera.iter().for_each(|Transform { translation, .. }| {
|
||||
events.write(CameraMovement(*last - *translation));
|
||||
*last = *translation;
|
||||
});
|
||||
}
|
||||
|
||||
fn parallax(
|
||||
mut events: EventReader<CameraMovement>,
|
||||
mut query: Query<(&mut Transform, &ParallaxDistance)>,
|
||||
) {
|
||||
events.read().for_each(|CameraMovement(v)| {
|
||||
query.iter_mut().for_each(|(mut t, ParallaxDistance(d))| {
|
||||
t.translation -= v / (20.0 / d);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -1,138 +0,0 @@
|
||||
use bevy::{color::palettes::css::*, prelude::*};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
resolution: (640.0, 480.0).into(),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.insert_resource(ClearColor(WHITE.into()))
|
||||
.add_systems(Startup, setup_3d)
|
||||
.add_systems(Update, (move_camera_buttons, button_color))
|
||||
.run();
|
||||
}
|
||||
|
||||
fn setup_3d(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Camera::default(),
|
||||
Camera3d::default(),
|
||||
AmbientLight {
|
||||
brightness: 1280.0,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::default())),
|
||||
MeshMaterial3d(materials.add(StandardMaterial {
|
||||
base_color: RED.into(),
|
||||
..Default::default()
|
||||
})),
|
||||
Transform::from_xyz(0.0, 0.0, -5.0),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::default())),
|
||||
MeshMaterial3d(materials.add(StandardMaterial {
|
||||
base_color: GREEN.into(),
|
||||
..Default::default()
|
||||
})),
|
||||
Transform::from_xyz(0.0, 0.0, -10.0),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::default())),
|
||||
MeshMaterial3d(materials.add(StandardMaterial {
|
||||
base_color: BLUE.into(),
|
||||
..Default::default()
|
||||
})),
|
||||
Transform::from_xyz(0.0, 0.0, -20.0),
|
||||
));
|
||||
|
||||
commands
|
||||
.spawn(Node {
|
||||
align_self: AlignSelf::End,
|
||||
justify_self: JustifySelf::Center,
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn((
|
||||
Node {
|
||||
padding: UiRect::all(Val::Px(20.0)),
|
||||
margin: UiRect::all(Val::Px(10.0)),
|
||||
..default()
|
||||
},
|
||||
Button,
|
||||
children![
|
||||
Text::new("<-"),
|
||||
Node {
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
..default()
|
||||
},
|
||||
],
|
||||
Movement(0.1),
|
||||
BackgroundColor(ORANGE.into()),
|
||||
));
|
||||
parent.spawn((
|
||||
Node {
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
..default()
|
||||
},
|
||||
Text::new("movement"),
|
||||
TextColor(BLACK.into()),
|
||||
));
|
||||
parent.spawn((
|
||||
Node {
|
||||
padding: UiRect::all(Val::Px(20.0)),
|
||||
margin: UiRect::all(Val::Px(10.0)),
|
||||
..default()
|
||||
},
|
||||
Button,
|
||||
children![
|
||||
Text::new("->"),
|
||||
Node {
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
..default()
|
||||
},
|
||||
],
|
||||
Movement(-0.1),
|
||||
BackgroundColor(ORANGE.into()),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn button_color(
|
||||
mut query: Query<(&Interaction, &mut BackgroundColor), (Changed<Interaction>, With<Button>)>,
|
||||
) {
|
||||
query.iter_mut().for_each(|(i, mut bg)| {
|
||||
bg.0 = match i {
|
||||
Interaction::None => ORANGE.into(),
|
||||
Interaction::Hovered => ORANGE_RED.into(),
|
||||
Interaction::Pressed => RED.into(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Movement(f32);
|
||||
|
||||
fn move_camera_buttons(
|
||||
query: Query<(&Interaction, &Movement), With<Button>>,
|
||||
mut camera: Single<&mut Transform, With<Camera>>,
|
||||
) {
|
||||
query.iter().for_each(|(i, m)| {
|
||||
if let (Interaction::Pressed, Movement(speed)) = (i, m) {
|
||||
camera.translation.x += speed;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,155 +0,0 @@
|
||||
use avian3d::math::Vector;
|
||||
// TEMP
|
||||
use avian2d::prelude::*;
|
||||
use bevy::{color::palettes::css::*, prelude::*};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(PhysicsPlugins::default())
|
||||
.insert_resource(ClearColor(WHITE.into()))
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, move_player)
|
||||
.add_systems(Update, follow_player)
|
||||
.add_systems(Update, draw_gizmos)
|
||||
.add_systems(
|
||||
Update,
|
||||
event_detection.run_if(on_event::<CollisionStarted>.or(on_event::<CollisionEnded>)),
|
||||
)
|
||||
.add_observer(set_tree_position)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Player;
|
||||
|
||||
#[derive(Component)]
|
||||
struct RenderGizmo;
|
||||
|
||||
#[derive(Component)]
|
||||
struct PlayArea;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
struct TreePos(isize);
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
commands.spawn(Camera2d);
|
||||
|
||||
// Spawn "trees" (which are also sensors)
|
||||
[
|
||||
("TREE -3", -3),
|
||||
("TREE -2", -2),
|
||||
("TREE -2", -1),
|
||||
("TREE 1", 1),
|
||||
("TREE 2", 2),
|
||||
("TREE 3", 3),
|
||||
]
|
||||
.iter()
|
||||
.for_each(|(label, pos)| {
|
||||
commands.spawn((
|
||||
RigidBody::Static,
|
||||
Collider::rectangle(100.0, 250.0),
|
||||
Mesh2d(meshes.add(Rectangle::new(100.0, 250.0))),
|
||||
MeshMaterial2d(materials.add(Color::from(GREEN))),
|
||||
TreePos(*pos),
|
||||
children![Text2d::new(*label),],
|
||||
));
|
||||
});
|
||||
|
||||
commands.spawn((
|
||||
Player,
|
||||
RigidBody::Kinematic,
|
||||
ExternalImpulse::default().with_persistence(true),
|
||||
Collider::rectangle(50.0, 50.0),
|
||||
Mesh2d(meshes.add(Rectangle::new(50.0, 50.0))),
|
||||
MeshMaterial2d(materials.add(Color::from(RED))),
|
||||
children![
|
||||
(
|
||||
Text2d::new("PLAYER"),
|
||||
Transform::from_scale(Vec3::new(0.5, 0.5, 0.5)),
|
||||
),
|
||||
(
|
||||
Text2d::new("PLAY AREA"),
|
||||
Transform::from_xyz(0.0, 212.0, 1.0),
|
||||
TextColor(BLACK.into())
|
||||
),
|
||||
(
|
||||
RenderGizmo,
|
||||
PlayArea,
|
||||
Visibility::Visible,
|
||||
Transform::from_scale(Vec3::new(400.0, 400.0, 0.0)),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
fn set_tree_position(
|
||||
trigger: Trigger<OnAdd, TreePos>,
|
||||
tree_pos: Query<&TreePos>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let TreePos(pos) = tree_pos.get(trigger.target()).unwrap();
|
||||
let x = if (*pos) > 0 {
|
||||
(200.0 * (*pos) as f32) - 100.0
|
||||
} else {
|
||||
(200.0 * (*pos) as f32) + 100.0
|
||||
};
|
||||
let t = Transform::from_xyz(x, 0.0, 0.0);
|
||||
commands.entity(trigger.target()).insert(t);
|
||||
}
|
||||
|
||||
fn move_player(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut player: Single<&mut ExternalImpulse, With<Player>>,
|
||||
) {
|
||||
const SPEED: f32 = 5.0;
|
||||
if keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
player.set_impulse(Vec2::NEG_X * SPEED);
|
||||
} else if keyboard_input.pressed(KeyCode::ArrowRight) {
|
||||
player.set_impulse(Vec2::X * SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
fn follow_player(
|
||||
player: Query<&Transform, (With<Player>, Changed<Transform>)>,
|
||||
mut camera: Single<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||
) {
|
||||
player.iter().for_each(|pt| {
|
||||
camera.translation = pt.translation;
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_gizmos(mut gizmos: Gizmos, play_area: Single<&GlobalTransform, With<RenderGizmo>>) {
|
||||
gizmos.rect_2d(
|
||||
play_area.translation().truncate(),
|
||||
play_area.scale().truncate(),
|
||||
MAGENTA,
|
||||
)
|
||||
}
|
||||
|
||||
fn event_detection(
|
||||
mut start_events: EventReader<CollisionStarted>,
|
||||
mut end_events: EventReader<CollisionEnded>,
|
||||
player: Single<&Player>,
|
||||
trees: Query<&TreePos>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
debug_assert!(!(start_events.is_empty() && end_events.is_empty()));
|
||||
let s = start_events.read().map(|CollisionStarted(a, b)| (a, b));
|
||||
let e = end_events.read().map(|CollisionEnded(a, b)| (a, b));
|
||||
let mut events = s.chain(e);
|
||||
let current_tree = events.find_map(|(a, b)| {
|
||||
info!("{a:?}, {b:?}");
|
||||
trees.get(*a).or(trees.get(*b)).ok()
|
||||
});
|
||||
info!("{:?}", current_tree);
|
||||
if keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
// moving left
|
||||
} else if keyboard_input.pressed(KeyCode::ArrowRight) {
|
||||
// moving right
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
# Falling Blocks RPG
|
||||
|
||||
This game is inspired by both Tetris and Peglin.
|
||||
|
||||
Your goal is to play Tetris (or a similar falling block game) but while that is happening you are carrying out a 2d real-time combat RPG battle.
|
||||
|
||||
Between battles/levels you choose a different level to go to in an overworld, choose upgrades, perks, and maybe some other stuff!
|
||||
Loading…
Reference in New Issue