very simple game base
All checks were successful
Build Bevy Game (Linux) / build (push) Successful in 19m17s
All checks were successful
Build Bevy Game (Linux) / build (push) Successful in 19m17s
This commit is contained in:
parent
1d5ef2006a
commit
27da890604
5 changed files with 32 additions and 42 deletions
BIN
assets/sprites/kirby.png
Normal file
BIN
assets/sprites/kirby.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 140 KiB |
BIN
assets/sprites/lana.png
Normal file
BIN
assets/sprites/lana.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 354 KiB |
5
src/camera.rs
Normal file
5
src/camera.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use bevy::{prelude::*, render::renderer};
|
||||
|
||||
pub fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
19
src/kirby.rs
Normal file
19
src/kirby.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use bevy::{prelude::*, render::renderer};
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Transform, Sprite)]
|
||||
pub struct Kirby();
|
||||
|
||||
pub fn kirby_spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let sprite = Sprite::from_image(asset_server.load("sprites/kirby.png"));
|
||||
commands.spawn((Kirby(), Transform::from_xyz(0.0, 0.0, 0.0), sprite));
|
||||
}
|
||||
|
||||
pub fn kirby_input(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
// query: Query<&mut Transform, With<Kirby>>,
|
||||
) {
|
||||
if keyboard_input.pressed(KeyCode::Space) {
|
||||
println!("SUCKING");
|
||||
}
|
||||
}
|
||||
50
src/main.rs
50
src/main.rs
|
|
@ -1,49 +1,15 @@
|
|||
use bevy::prelude::*;
|
||||
use camera::spawn_camera;
|
||||
use kirby::kirby_input;
|
||||
use kirby::kirby_spawn;
|
||||
mod camera;
|
||||
mod kirby;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(HelloPlugin)
|
||||
.add_systems(Startup, spawn_camera)
|
||||
.add_systems(Startup, kirby_spawn)
|
||||
.add_systems(Update, kirby_input)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Person;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Name(String);
|
||||
|
||||
fn add_people(mut commands: Commands) {
|
||||
commands.spawn((Person, Name("Elaina Proctor".to_string())));
|
||||
commands.spawn((Person, Name("Renzo Hume".to_string())));
|
||||
commands.spawn((Person, Name("Zayna Nieves".to_string())));
|
||||
}
|
||||
|
||||
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||||
if timer.0.tick(time.delta()).just_finished() {
|
||||
for name in &query {
|
||||
println!("hello {}!", name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
for mut name in &mut query {
|
||||
if name.0 == "Elaina Proctor" {
|
||||
name.0 = "Elaina Hume".to_string();
|
||||
break; // We don't need to change any other names.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
pub struct HelloPlugin;
|
||||
|
||||
impl Plugin for HelloPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, add_people);
|
||||
app.add_systems(Update, (update_people, greet_people).chain());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue