Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ bevy = { version = "0.6" }
bevy_ecs_tilemap = "0.5"
bevy_egui = "0.11"
bevy_rapier2d = "0.12"
anyhow = "1.0"
anyhow = "1.0"
leafwing-input-manager = "0.2"
1 change: 1 addition & 0 deletions assets/asset-licenses.csv
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Asset Name,License,Author,Link
images/player.png,Unknown,clipartstation.com,https://clipartstation.com/human-figure-clipart-4/
Binary file added assets/images/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy::window::WindowMode;
use bevy_egui::EguiPlugin;

mod menus;
mod player;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this at least for the time being into the singleplayer crate (it's unlikely we will have multiplayer within the frame of this jam).

mod singleplayer;
mod utils;

Expand Down Expand Up @@ -39,4 +40,3 @@ fn main() {
.add_state(GameState::MainMenu)
.run();
}

7 changes: 7 additions & 0 deletions src/menus/common.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! Some UI utility functions and structs.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't really add anything useful (it's clear what the statement does already), would recommend removing


use bevy::prelude::*;

/// Marks a UI element as disabled.
#[derive(Component)]
pub struct Disabled;

pub const NORMAL_COLOR: UiColor = UiColor(Color::rgb(0.15, 0.15, 0.15));
pub const HOVERED_COLOR: UiColor = UiColor(Color::rgb(0.25, 0.25, 0.25));
pub const PRESSED_COLOR: UiColor = UiColor(Color::rgb(0.35, 0.75, 0.35));

/// Creates the [`Style`]s that we add to most buttons.
pub fn button_style() -> Style {
Style {
size: Size::new(Val::Px(150.0), Val::Px(35.0)),
Expand All @@ -17,6 +21,7 @@ pub fn button_style() -> Style {
}
}

/// Creates the [`Style`]s that we add to most text.
pub fn text_style() -> Style {
Style {
align_self: AlignSelf::Center,
Expand All @@ -26,6 +31,7 @@ pub fn text_style() -> Style {
}
}

/// Creates the [`TextStyle`]s that we add to most text.
pub fn text_textstyle(asset_server: &AssetServer) -> TextStyle {
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
Expand All @@ -42,6 +48,7 @@ pub fn text_textstyle_disabled(asset_server: &AssetServer) -> TextStyle {
}
}

/// Creates the [`TextAlignment`]s that we add to most buttons.
pub fn button_text_alignment() -> TextAlignment {
TextAlignment {
horizontal: HorizontalAlign::Center,
Expand Down
41 changes: 41 additions & 0 deletions src/player/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use bevy::prelude::*;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before I would move this into singleplayer and rename it to player.rs as it probably won't need its own folder

use leafwing_input_manager::prelude::*;

pub fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn_bundle(SpriteBundle {
texture: asset_server.load("images/player.png"),
transform: Transform::from_xyz(0., 0., 0.),
sprite: Sprite {
custom_size: Some(Vec2::new(32.0, 64.0)),
..Default::default()
},
..Default::default()
})
.insert(Player)
.insert_bundle(InputManagerBundle::<Action> {
// Stores "which virtual action buttons are currently pressed"
action_state: ActionState::default(),
// Stores how those actions relate to inputs from your player
input_map: InputMap::new([
(Action::MoveLeft, KeyCode::A),
(Action::MoveRight, KeyCode::D),
]),
});
}

pub fn cleanup_player(mut commands: Commands, query: Query<Entity, With<Player>>) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably not necessary - full scene transitions can just despawn everything. In player death scenarios, the systems that detect/cause them would likely despawn the player themselves

commands.entity(query.single()).despawn();
}

/// The player.
#[derive(Debug, Component, Clone, Copy)]
pub struct Player;

/// The possible keyboard button actions a player can do.
#[allow(missing_docs)]
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub enum Action {
MoveLeft,
MoveRight,
}
8 changes: 7 additions & 1 deletion src/singleplayer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;

use crate::player;
use crate::GameState;

pub struct SinglePlayerScene;
Expand All @@ -10,7 +11,12 @@ impl Plugin for SinglePlayerScene {
app.add_plugin(TilemapPlugin)
.add_system(crate::utils::set_texture_filters_to_nearest)
.add_system_set(
SystemSet::on_enter(GameState::Playing).with_system(singleplayer_setup),
SystemSet::on_enter(GameState::Playing)
.with_system(singleplayer_setup.label("2d_map_setup"))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the next line is a hacky way to integrate the singleplayer and player crates together. Does anybody have a better idea?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. Alternatively you can create a single setup system and from there call the create map and create player fns but then you would need to pass in the system params.

.with_system(player::setup_player.after("2d_map_setup")),
)
.add_system_set(
SystemSet::on_exit(GameState::Playing).with_system(player::cleanup_player),
);
}
}
Expand Down