Game runs again, but not playable
This commit is contained in:
parent
d431756ce1
commit
3d5df31da7
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -294,6 +294,7 @@ version = "0.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8e938630e9f472b1899c78ef84aa907081b23bad8333140e2295c620485b6ee7"
|
checksum = "8e938630e9f472b1899c78ef84aa907081b23bad8333140e2295c620485b6ee7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bevy_dylib",
|
||||||
"bevy_internal",
|
"bevy_internal",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -469,6 +470,15 @@ dependencies = [
|
||||||
"const-fnv1a-hash",
|
"const-fnv1a-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bevy_dylib"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8494bf550eb30f570da1563217bcea25530cf29b35d35887ca6c2d76a411d00"
|
||||||
|
dependencies = [
|
||||||
|
"bevy_internal",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_ecs"
|
name = "bevy_ecs"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
|
|
|
@ -23,7 +23,7 @@ bevy = { version = "0.14.0", default-features = false, features = [
|
||||||
"wav", # sound files
|
"wav", # sound files
|
||||||
|
|
||||||
# TODO: would be nice to get this working while developing
|
# TODO: would be nice to get this working while developing
|
||||||
# "dynamic_linking",
|
"dynamic_linking",
|
||||||
|
|
||||||
# NOTE: Features we may want at some point.
|
# NOTE: Features we may want at some point.
|
||||||
# "vorbis", # music -- maybe mp3?
|
# "vorbis", # music -- maybe mp3?
|
||||||
|
|
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
||||||
use bevy::render::camera::Camera;
|
use bevy::render::camera::Camera;
|
||||||
|
|
||||||
pub fn startup(mut commands: Commands) {
|
pub fn startup(mut commands: Commands) {
|
||||||
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
|
let bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
|
||||||
// bundle.0.projection.scale = 1;
|
// bundle.0.projection.scale = 1;
|
||||||
commands.spawn(bundle);
|
commands.spawn(bundle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,6 @@ struct InGameSet;
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
|
||||||
app.init_resource::<assets::AssetLoader>();
|
|
||||||
|
|
||||||
app.insert_state(View::default());
|
|
||||||
app.insert_state(Game::default());
|
|
||||||
|
|
||||||
app.add_plugins((
|
app.add_plugins((
|
||||||
DefaultPlugins
|
DefaultPlugins
|
||||||
.set(WindowPlugin {
|
.set(WindowPlugin {
|
||||||
|
@ -59,6 +54,9 @@ fn main() {
|
||||||
.set(ImagePlugin::default_nearest()),
|
.set(ImagePlugin::default_nearest()),
|
||||||
FrameTimeDiagnosticsPlugin,
|
FrameTimeDiagnosticsPlugin,
|
||||||
))
|
))
|
||||||
|
.init_resource::<assets::AssetLoader>()
|
||||||
|
.insert_state(View::default())
|
||||||
|
.insert_state(Game::default())
|
||||||
.add_systems(OnEnter(View::MainMenu), main_menu::startup)
|
.add_systems(OnEnter(View::MainMenu), main_menu::startup)
|
||||||
.add_systems(OnExit(View::MainMenu), main_menu::exit)
|
.add_systems(OnExit(View::MainMenu), main_menu::exit)
|
||||||
.add_systems(OnEnter(View::InGame), (player::startup, statue::startup))
|
.add_systems(OnEnter(View::InGame), (player::startup, statue::startup))
|
||||||
|
|
149
src/player.rs
149
src/player.rs
|
@ -101,91 +101,94 @@ pub fn controls(
|
||||||
mut next_state: ResMut<NextState<crate::View>>,
|
mut next_state: ResMut<NextState<crate::View>>,
|
||||||
mut crosshair_q: Query<&mut Transform, With<Crosshair>>,
|
mut crosshair_q: Query<&mut Transform, With<Crosshair>>,
|
||||||
) {
|
) {
|
||||||
let (mut sprite, mut texture, mut heading, player_entity) = player_q.single_mut();
|
if let Ok((mut sprite, mut texture, mut heading, player_entity)) = player_q.get_single_mut() {
|
||||||
let (camera, camera_transform) = cam_q.single();
|
let (camera, camera_transform) = cam_q.single();
|
||||||
|
|
||||||
let mouse_world_position = win_q
|
let mouse_world_position = win_q
|
||||||
.single()
|
.single()
|
||||||
.cursor_position()
|
.cursor_position()
|
||||||
.and_then(|cursor| camera.viewport_to_world(&GlobalTransform::from_xyz(0., 0., 0.), cursor))
|
.and_then(|cursor| {
|
||||||
.map(|ray| ray.origin.truncate());
|
camera.viewport_to_world(&GlobalTransform::from_xyz(0., 0., 0.), cursor)
|
||||||
|
})
|
||||||
|
.map(|ray| ray.origin.truncate());
|
||||||
|
|
||||||
if let Some(pos) = mouse_world_position {
|
if let Some(pos) = mouse_world_position {
|
||||||
if let Ok(mut t) = crosshair_q.get_single_mut() {
|
if let Ok(mut t) = crosshair_q.get_single_mut() {
|
||||||
t.look_at(Vec3::ZERO, pos.extend(0.));
|
t.look_at(Vec3::ZERO, pos.extend(0.));
|
||||||
t.translation = camera_transform.translation();
|
t.translation = camera_transform.translation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
**heading = Vec2::ZERO;
|
**heading = Vec2::ZERO;
|
||||||
for button in mouse_input.get_just_pressed() {
|
for button in mouse_input.get_just_pressed() {
|
||||||
match button {
|
match button {
|
||||||
MouseButton::Left => {
|
MouseButton::Left => {
|
||||||
if let Some(world_position) = win_q
|
if let Some(world_position) = win_q
|
||||||
.single()
|
.single()
|
||||||
.cursor_position()
|
.cursor_position()
|
||||||
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
|
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
|
||||||
.map(|ray| ray.origin.truncate())
|
.map(|ray| ray.origin.truncate())
|
||||||
{
|
{
|
||||||
let spos = world_position.extend(-world_position.y);
|
let spos = world_position.extend(-world_position.y);
|
||||||
let statue_texture = asset_server.load("img/Props.png").clone();
|
let statue_texture = asset_server.load("img/Props.png").clone();
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Statue,
|
Statue,
|
||||||
SpriteSheetBundle {
|
SpriteSheetBundle {
|
||||||
texture: statue_texture,
|
texture: statue_texture,
|
||||||
atlas: TextureAtlas {
|
atlas: TextureAtlas {
|
||||||
layout: assets.images.statue.clone(),
|
layout: assets.images.statue.clone(),
|
||||||
index: 0,
|
index: 0,
|
||||||
|
},
|
||||||
|
transform: Transform::from_translation(spos),
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
transform: Transform::from_translation(spos),
|
));
|
||||||
..Default::default()
|
}
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
for key in input.get_just_pressed() {
|
||||||
for key in input.get_just_pressed() {
|
match key {
|
||||||
match key {
|
KeyCode::Escape => next_state.set(crate::View::MainMenu),
|
||||||
KeyCode::Escape => next_state.set(crate::View::MainMenu),
|
KeyCode::Enter => next_state.set(crate::View::MainMenu),
|
||||||
KeyCode::Enter => next_state.set(crate::View::MainMenu),
|
KeyCode::Space => {
|
||||||
KeyCode::Space => {
|
let child = commands
|
||||||
let child = commands
|
.spawn(AudioSourceBundle {
|
||||||
.spawn(AudioSourceBundle {
|
source: assets.sounds.meow.clone(),
|
||||||
source: assets.sounds.meow.clone(),
|
settings: PlaybackSettings::DESPAWN.with_spatial(false),
|
||||||
settings: PlaybackSettings::DESPAWN.with_spatial(false),
|
})
|
||||||
})
|
.id();
|
||||||
.id();
|
commands.entity(player_entity).push_children(&[child]);
|
||||||
commands.entity(player_entity).push_children(&[child]);
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
for key in input.get_pressed() {
|
||||||
for key in input.get_pressed() {
|
match key {
|
||||||
match key {
|
KeyCode::KeyA | KeyCode::ArrowLeft => {
|
||||||
KeyCode::KeyA | KeyCode::ArrowLeft => {
|
**heading -= Vec2::X;
|
||||||
**heading -= Vec2::X;
|
}
|
||||||
|
KeyCode::KeyD | KeyCode::ArrowRight => {
|
||||||
|
**heading += Vec2::X;
|
||||||
|
}
|
||||||
|
KeyCode::KeyW | KeyCode::ArrowUp => {
|
||||||
|
**heading += Vec2::Y;
|
||||||
|
}
|
||||||
|
KeyCode::KeyS | KeyCode::ArrowDown => {
|
||||||
|
**heading -= Vec2::Y;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
KeyCode::KeyD | KeyCode::ArrowRight => {
|
|
||||||
**heading += Vec2::X;
|
|
||||||
}
|
|
||||||
KeyCode::KeyW | KeyCode::ArrowUp => {
|
|
||||||
**heading += Vec2::Y;
|
|
||||||
}
|
|
||||||
KeyCode::KeyS | KeyCode::ArrowDown => {
|
|
||||||
**heading -= Vec2::Y;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
if heading.y < 0. {
|
||||||
if heading.y < 0. {
|
texture.index = 0;
|
||||||
texture.index = 0;
|
} else if heading.y > 0. {
|
||||||
} else if heading.y > 0. {
|
texture.index = 1;
|
||||||
texture.index = 1;
|
} else if heading.x != 0. {
|
||||||
} else if heading.x != 0. {
|
texture.index = 2;
|
||||||
texture.index = 2;
|
sprite.flip_x = heading.x > 0.;
|
||||||
sprite.flip_x = heading.x > 0.;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue