init
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
5576
Cargo.lock
generated
Normal file
8
Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "bevy_stock_photo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = "0.17.3"
|
||||||
|
rand = "0.9.2"
|
||||||
BIN
assets/bus/basicbus.png
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
assets/people/.DS_Store
vendored
Normal file
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 148 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 422 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 153 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 153 KiB |
BIN
assets/people/david/.DS_Store
vendored
Normal file
BIN
assets/people/david/man-blue-shirt-smiling-with-backpack.png
Normal file
|
After Width: | Height: | Size: 13 MiB |
BIN
assets/people/david/man-his-back-with-his-hands-up.png
Normal file
|
After Width: | Height: | Size: 14 MiB |
BIN
assets/people/david/man-making-horns-with-one-hand_1187-1792.png
Normal file
|
After Width: | Height: | Size: 185 KiB |
BIN
assets/people/david/man-smiling-pointing-himself_1187-1843.png
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
assets/people/david/man-smiling-with-raised-finger.png
Normal file
|
After Width: | Height: | Size: 14 MiB |
BIN
assets/people/david/man-smiling-with-raised-fists_1187-1916.png
Normal file
|
After Width: | Height: | Size: 972 KiB |
BIN
assets/people/david/man-touching-air-with-finger_1187-1912.png
Normal file
|
After Width: | Height: | Size: 248 KiB |
BIN
assets/people/david/man-with-arms-crossed-side.png
Normal file
|
After Width: | Height: | Size: 6 MiB |
BIN
assets/people/david/man-with-arms-crossed.png
Normal file
|
After Width: | Height: | Size: 3.5 MiB |
BIN
assets/people/david/man-with-face-pain-touching-his-stomach.png
Normal file
|
After Width: | Height: | Size: 15 MiB |
BIN
assets/people/david/man-with-hand-his-chest.png
Normal file
|
After Width: | Height: | Size: 15 MiB |
BIN
assets/people/david/man-with-pain-face-touching-trapeze.png
Normal file
|
After Width: | Height: | Size: 14 MiB |
BIN
assets/people/david/man-with-thumbs-up_1187-1772.png
Normal file
|
After Width: | Height: | Size: 238 KiB |
BIN
assets/people/david/sad-man.png
Normal file
|
After Width: | Height: | Size: 18 MiB |
BIN
assets/people/david/smiling-man-with-letter-h.png
Normal file
|
After Width: | Height: | Size: 14 MiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 132 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 137 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 667 KiB |
BIN
assets/people/geoff/man-proud-himself_1368-7643.png
Normal file
|
After Width: | Height: | Size: 135 KiB |
BIN
assets/people/geoff/man-proud-himself_1368-7645.png
Normal file
|
After Width: | Height: | Size: 133 KiB |
BIN
assets/people/lewis/angry-man-with-raised-hands_1149-1463.png
Normal file
|
After Width: | Height: | Size: 278 KiB |
|
After Width: | Height: | Size: 239 KiB |
BIN
assets/people/lewis/cheerful-man-greeting_1149-1465.png
Normal file
|
After Width: | Height: | Size: 244 KiB |
BIN
assets/people/lewis/cheerful-man-with-hat-posing_1149-1462.png
Normal file
|
After Width: | Height: | Size: 241 KiB |
|
After Width: | Height: | Size: 253 KiB |
BIN
assets/people/lewis/confused-man-trying-listen_1149-1466.png
Normal file
|
After Width: | Height: | Size: 794 KiB |
|
After Width: | Height: | Size: 275 KiB |
|
After Width: | Height: | Size: 641 KiB |
|
After Width: | Height: | Size: 245 KiB |
BIN
assets/people/lewis/man-with-one-hand-one-ear_1187-2164.png
Normal file
|
After Width: | Height: | Size: 236 KiB |
BIN
assets/people/lewis/man-with-some-joking-glasses_1187-2219.png
Normal file
|
After Width: | Height: | Size: 248 KiB |
|
After Width: | Height: | Size: 244 KiB |
BIN
assets/people/lewis/scared-guy-covering-his-ears_1149-1467.png
Normal file
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 252 KiB |
109
src/main.rs
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor};
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct PlayerVWBus;
|
||||||
|
|
||||||
|
const PLAYER_SPEED: f32 = 100.;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_systems(Startup, (setup_scene, spawn_bus, spawn_enemy))
|
||||||
|
.add_systems(Update, (move_player, follow_player))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_scene(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
) {
|
||||||
|
commands.spawn((
|
||||||
|
Mesh2d(meshes.add(Rectangle::new(1000., 70.))),
|
||||||
|
MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))),
|
||||||
|
));
|
||||||
|
|
||||||
|
commands.spawn((Camera2d, Bloom::NATURAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_bus(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
let texture = asset_server.load("bus/basicbus.png");
|
||||||
|
commands.spawn((
|
||||||
|
PlayerVWBus,
|
||||||
|
Sprite {
|
||||||
|
image: texture,
|
||||||
|
custom_size: Some(Vec2::new(192., 133.)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Transform::from_xyz(2., 0., 3.),
|
||||||
|
Anchor::CENTER,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_enemy(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
) {
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
for _ in 0..10 {
|
||||||
|
commands.spawn((
|
||||||
|
Mesh2d(meshes.add(Circle::new(10.))),
|
||||||
|
MeshMaterial2d(materials.add(Color::srgb(1.1, 0.2, 0.3))),
|
||||||
|
Transform::from_xyz(
|
||||||
|
rng.random_range(-600..600) as f32,
|
||||||
|
rng.random_range(-600..600) as f32,
|
||||||
|
1.,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_player(
|
||||||
|
mut player: Single<&mut Transform, With<PlayerVWBus>>,
|
||||||
|
mut player_sprite: Single<&mut Sprite, With<PlayerVWBus>>,
|
||||||
|
time: Res<Time>,
|
||||||
|
kb_input: Res<ButtonInput<KeyCode>>,
|
||||||
|
) {
|
||||||
|
let mut direction = Vec2::ZERO;
|
||||||
|
|
||||||
|
if kb_input.pressed(KeyCode::KeyW) {
|
||||||
|
direction.y += 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
if kb_input.pressed(KeyCode::KeyS) {
|
||||||
|
direction.y -= 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
if kb_input.pressed(KeyCode::KeyA) {
|
||||||
|
direction.x -= 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
if kb_input.pressed(KeyCode::KeyD) {
|
||||||
|
direction.x += 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
let move_delta = direction.normalize_or_zero() * PLAYER_SPEED * time.delta_secs();
|
||||||
|
player.translation += move_delta.extend(0.);
|
||||||
|
|
||||||
|
if direction.x > 0. {
|
||||||
|
player_sprite.flip_x = true;
|
||||||
|
} else if direction.x < 0. {
|
||||||
|
player_sprite.flip_x = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn follow_player(
|
||||||
|
mut camera: Single<&mut Transform, (With<Camera2d>, Without<PlayerVWBus>)>,
|
||||||
|
player: Single<&Transform, (With<PlayerVWBus>, Without<Camera2d>)>,
|
||||||
|
time: Res<Time>,
|
||||||
|
) {
|
||||||
|
let Vec3 { x, y, .. } = player.translation;
|
||||||
|
let direction = Vec3::new(x, y, camera.translation.z);
|
||||||
|
|
||||||
|
camera
|
||||||
|
.translation
|
||||||
|
.smooth_nudge(&direction, 10., time.delta_secs());
|
||||||
|
}
|
||||||