Game runs again, but not playable

This commit is contained in:
Daniel Flanagan 2024-07-30 12:11:31 -05:00
parent d431756ce1
commit 3d5df31da7
5 changed files with 91 additions and 80 deletions

10
Cargo.lock generated
View file

@ -294,6 +294,7 @@ version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e938630e9f472b1899c78ef84aa907081b23bad8333140e2295c620485b6ee7"
dependencies = [
"bevy_dylib",
"bevy_internal",
]
@ -469,6 +470,15 @@ dependencies = [
"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]]
name = "bevy_ecs"
version = "0.14.0"

View file

@ -23,7 +23,7 @@ bevy = { version = "0.14.0", default-features = false, features = [
"wav", # sound files
# TODO: would be nice to get this working while developing
# "dynamic_linking",
"dynamic_linking",
# NOTE: Features we may want at some point.
# "vorbis", # music -- maybe mp3?

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy::render::camera::Camera;
pub fn startup(mut commands: Commands) {
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
let bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
// bundle.0.projection.scale = 1;
commands.spawn(bundle);
}

View file

@ -35,11 +35,6 @@ struct InGameSet;
fn main() {
let mut app = App::new();
app.init_resource::<assets::AssetLoader>();
app.insert_state(View::default());
app.insert_state(Game::default());
app.add_plugins((
DefaultPlugins
.set(WindowPlugin {
@ -59,6 +54,9 @@ fn main() {
.set(ImagePlugin::default_nearest()),
FrameTimeDiagnosticsPlugin,
))
.init_resource::<assets::AssetLoader>()
.insert_state(View::default())
.insert_state(Game::default())
.add_systems(OnEnter(View::MainMenu), main_menu::startup)
.add_systems(OnExit(View::MainMenu), main_menu::exit)
.add_systems(OnEnter(View::InGame), (player::startup, statue::startup))

View file

@ -101,91 +101,94 @@ pub fn controls(
mut next_state: ResMut<NextState<crate::View>>,
mut crosshair_q: Query<&mut Transform, With<Crosshair>>,
) {
let (mut sprite, mut texture, mut heading, player_entity) = player_q.single_mut();
let (camera, camera_transform) = cam_q.single();
if let Ok((mut sprite, mut texture, mut heading, player_entity)) = player_q.get_single_mut() {
let (camera, camera_transform) = cam_q.single();
let mouse_world_position = win_q
.single()
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(&GlobalTransform::from_xyz(0., 0., 0.), cursor))
.map(|ray| ray.origin.truncate());
let mouse_world_position = win_q
.single()
.cursor_position()
.and_then(|cursor| {
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 Ok(mut t) = crosshair_q.get_single_mut() {
t.look_at(Vec3::ZERO, pos.extend(0.));
t.translation = camera_transform.translation();
if let Some(pos) = mouse_world_position {
if let Ok(mut t) = crosshair_q.get_single_mut() {
t.look_at(Vec3::ZERO, pos.extend(0.));
t.translation = camera_transform.translation();
}
}
}
**heading = Vec2::ZERO;
for button in mouse_input.get_just_pressed() {
match button {
MouseButton::Left => {
if let Some(world_position) = win_q
.single()
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
.map(|ray| ray.origin.truncate())
{
let spos = world_position.extend(-world_position.y);
let statue_texture = asset_server.load("img/Props.png").clone();
commands.spawn((
Statue,
SpriteSheetBundle {
texture: statue_texture,
atlas: TextureAtlas {
layout: assets.images.statue.clone(),
index: 0,
**heading = Vec2::ZERO;
for button in mouse_input.get_just_pressed() {
match button {
MouseButton::Left => {
if let Some(world_position) = win_q
.single()
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
.map(|ray| ray.origin.truncate())
{
let spos = world_position.extend(-world_position.y);
let statue_texture = asset_server.load("img/Props.png").clone();
commands.spawn((
Statue,
SpriteSheetBundle {
texture: statue_texture,
atlas: TextureAtlas {
layout: assets.images.statue.clone(),
index: 0,
},
transform: Transform::from_translation(spos),
..Default::default()
},
transform: Transform::from_translation(spos),
..Default::default()
},
));
));
}
}
_ => {}
}
_ => {}
}
}
for key in input.get_just_pressed() {
match key {
KeyCode::Escape => next_state.set(crate::View::MainMenu),
KeyCode::Enter => next_state.set(crate::View::MainMenu),
KeyCode::Space => {
let child = commands
.spawn(AudioSourceBundle {
source: assets.sounds.meow.clone(),
settings: PlaybackSettings::DESPAWN.with_spatial(false),
})
.id();
commands.entity(player_entity).push_children(&[child]);
for key in input.get_just_pressed() {
match key {
KeyCode::Escape => next_state.set(crate::View::MainMenu),
KeyCode::Enter => next_state.set(crate::View::MainMenu),
KeyCode::Space => {
let child = commands
.spawn(AudioSourceBundle {
source: assets.sounds.meow.clone(),
settings: PlaybackSettings::DESPAWN.with_spatial(false),
})
.id();
commands.entity(player_entity).push_children(&[child]);
}
_ => {}
}
_ => {}
}
}
for key in input.get_pressed() {
match key {
KeyCode::KeyA | KeyCode::ArrowLeft => {
**heading -= Vec2::X;
for key in input.get_pressed() {
match key {
KeyCode::KeyA | KeyCode::ArrowLeft => {
**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. {
texture.index = 0;
} else if heading.y > 0. {
texture.index = 1;
} else if heading.x != 0. {
texture.index = 2;
sprite.flip_x = heading.x > 0.;
if heading.y < 0. {
texture.index = 0;
} else if heading.y > 0. {
texture.index = 1;
} else if heading.x != 0. {
texture.index = 2;
sprite.flip_x = heading.x > 0.;
}
}
}