Skip to content

Commit

Permalink
pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 14, 2024
1 parent eac22c9 commit 12ad2f1
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 46 deletions.
Binary file modified assets/image/atlas.aseprite
Binary file not shown.
Binary file modified assets/image/level.aseprite
Binary file not shown.
Binary file modified docs/assets/image/atlas.aseprite
Binary file not shown.
Binary file modified docs/assets/image/level.aseprite
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script integrity=sha384-DXfxbHnmRjXl3uhZSP4S1IWEe3DfX/sHDa2A7iHxmUB6Ag+87PaP8wV2AtDOwHfm src=./restart-audio-context-8127143435824044.js type=module></script><link href=assets/favicon.png rel=icon><link href=./index-56627a79e0752a1c.css integrity=sha384-m/ivHNojsD/VAvwMMce+fhrN8VxOZuZt5hms1JExuO36KLCDKKRGDtjLXSlnQq0B rel=stylesheet><script nonce="wsuQeCEKHtA4rKSztp9Hdw==" type=module>import init, * as bindings from './magiacircle-59bad22095567cda.js';
const wasm = await init('./magiacircle-59bad22095567cda_bg.wasm');
<script integrity=sha384-DXfxbHnmRjXl3uhZSP4S1IWEe3DfX/sHDa2A7iHxmUB6Ag+87PaP8wV2AtDOwHfm src=./restart-audio-context-8127143435824044.js type=module></script><link href=assets/favicon.png rel=icon><link href=./index-56627a79e0752a1c.css integrity=sha384-m/ivHNojsD/VAvwMMce+fhrN8VxOZuZt5hms1JExuO36KLCDKKRGDtjLXSlnQq0B rel=stylesheet><script nonce="Me9ZB76oxBjpsiCgyJ6LKQ==" type=module>import init, * as bindings from './magiacircle-b4af609aae1fb5f7.js';
const wasm = await init('./magiacircle-b4af609aae1fb5f7_bg.wasm');


window.wasmBindings = bindings;


dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));</script><title>magiacircle 0.1</title><link crossorigin href=./magiacircle-59bad22095567cda.js integrity=sha384-SOxngPK6iQ6Fs3oa6/H8Qd+NX2F0ClO4onZSmw5YzB1hSmnczALUItlD8VuX3q10 rel=modulepreload><link as=fetch crossorigin href=./magiacircle-59bad22095567cda_bg.wasm integrity=sha384-lV7zosZi8MqlpbE4S/XDCotQUabq/M+vsBgCL2yIUsETa6mjDEqnF2l2kgoS1EIn rel=preload type=application/wasm></head><body></body></html>
dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));</script><title>magiacircle 0.1</title><link crossorigin href=./magiacircle-b4af609aae1fb5f7.js integrity=sha384-lBja7M85zHHJOjc3CJpCwvM3uQLt218xKIfiXVj3mosAJcxZeXUxuWoQyaLi+jvf rel=modulepreload><link as=fetch crossorigin href=./magiacircle-b4af609aae1fb5f7_bg.wasm integrity=sha384-QxYtpwaXdgUIBr26k8RA2fn2WPWYQglOEu3njA7gPmfPSWL+bTsoxAoRiAfAgP+1 rel=preload type=application/wasm></head><body></body></html>
1 change: 0 additions & 1 deletion docs/magiacircle-59bad22095567cda.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/magiacircle-b4af609aae1fb5f7.js

Large diffs are not rendered by default.

Binary file not shown.
5 changes: 3 additions & 2 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ pub const MAGIC_CIRCLE_GROUP: Group = Group::GROUP_8;
pub const PIXELS_PER_METER: f32 = 16.0;

// UI階層

pub const OVERLAY_Z_INDEX: i32 = 10000;

pub const POINTER_Z_INDEX: i32 = 5000;

pub const GAME_MENU_Z_INDEX: i32 = 2000;

pub const WAND_EDITOR_FLOATING_Z_INDEX: i32 = 1600;

pub const WAND_EDITOR_Z_INDEX: i32 = 1500;

pub const POINTER_Z_INDEX: i32 = 1100;

pub const HUD_Z_INDEX: i32 = 1000;
2 changes: 1 addition & 1 deletion src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn run_game() {
primary_window: Some(Window {
position: WindowPosition::Centered(MonitorSelection::Current),
cursor: Cursor {
// visible: false,
visible: false,
..default()
},
title: "magiacircle 0.1".to_string(),
Expand Down
52 changes: 19 additions & 33 deletions src/hud/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::constant::POINTER_Z_INDEX;
use crate::states::GameMenuState;
use crate::{asset::GameAssets, constant::TILE_SIZE, input::MyGamepad, states::GameState};
use crate::{controller::player::Player, entity::actor::Actor};
use bevy::{prelude::*, window::PrimaryWindow};
Expand All @@ -11,17 +10,7 @@ struct Pointer;
fn setup_pointer(mut commands: Commands, assets: Res<GameAssets>) {
commands.spawn((
Pointer,
StateScoped(GameState::InGame),
ImageBundle {
style: Style {
position_type: PositionType::Absolute,
top: Val::Px(0.0),
left: Val::Px(0.0),
width: Val::Px(13.0 * 2.0),
height: Val::Px(13.0 * 2.0),

..default()
},
z_index: ZIndex::Global(POINTER_Z_INDEX),
..default()
},
Expand All @@ -34,33 +23,30 @@ fn setup_pointer(mut commands: Commands, assets: Res<GameAssets>) {
}

fn update_pointer_image_by_angle(
player_query: Query<(&Actor, &GlobalTransform), With<Player>>,
mut pointer_query: Query<&mut Style, With<Pointer>>,
camera_query: Query<(&Camera, &GlobalTransform), (With<Camera2d>, Without<Player>)>,
q_window: Query<&Window, With<PrimaryWindow>>,
) {
if let Ok((player, player_transform)) = player_query.get_single() {
if let Ok(mut pointer_style) = pointer_query.get_single_mut() {
if let Ok((camera, camera_global_transform)) = camera_query.get_single() {
let pointer_in_world = player_transform.translation().truncate() + player.pointer;

if let Some(pointer_in_screen) =
camera.world_to_viewport(camera_global_transform, pointer_in_world.extend(0.0))
{
// AsepriteSliceUiBundle に Aseprite のアンカーは効かないことに注意
// スライスのサイズは 13ピクセルで、それを2倍に拡大してその半分だけずらして中央ぞろえするので -13
pointer_style.left = Val::Px(pointer_in_screen.x - 13.0);
pointer_style.top = Val::Px(pointer_in_screen.y - 13.0);
}
if let Ok(mut pointer_style) = pointer_query.get_single_mut() {
if let Ok(window) = q_window.get_single() {
if let Some(cursor_in_screen) = window.cursor_position() {
// AsepriteSliceUiBundle に Aseprite のアンカーは効かないことに注意
// スライスのサイズは 13ピクセルで、それを2倍に拡大してその半分だけずらして中央ぞろえするので -13
pointer_style.left = Val::Px((cursor_in_screen.x - 13.0).floor());
pointer_style.top = Val::Px((cursor_in_screen.y - 13.0).floor());
pointer_style.display = Display::default();
} else {
pointer_style.display = Display::None;
}
}
}
}

/// マウスポインタの位置を参照してプレイヤーアクターのポインターを設定します
/// この関数はプレイヤーのモジュールに移動する?
fn update_pointer_by_mouse(
mut player_query: Query<(&mut Actor, &GlobalTransform), With<Player>>,
q_window: Query<&Window, With<PrimaryWindow>>,
camera_query: Query<(&Camera, &GlobalTransform), (With<Camera2d>, Without<Player>)>,
state: Res<State<GameMenuState>>,
) {
if let Ok((mut player, player_transform)) = player_query.get_single_mut() {
if let Ok(window) = q_window.get_single() {
Expand All @@ -69,10 +55,8 @@ fn update_pointer_by_mouse(
if let Some(mouse_in_world) =
camera.viewport_to_world(camera_global_transform, cursor_in_screen)
{
if *state.get() == GameMenuState::Closed {
player.pointer = mouse_in_world.origin.truncate()
- player_transform.translation().truncate();
}
player.pointer = mouse_in_world.origin.truncate()
- player_transform.translation().truncate();
}
}
}
Expand Down Expand Up @@ -112,15 +96,17 @@ pub struct PointerPlugin;

impl Plugin for PointerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::InGame), setup_pointer)
app.add_systems(OnExit(GameState::Setup), setup_pointer)
.add_systems(
Update,
(
update_pointer_image_by_angle,
update_pointer_by_mouse,
update_pointer_by_gamepad,
)
.run_if(in_state(GameState::InGame)),
.run_if(in_state(GameState::InGame).or_else(
in_state(GameState::MainMenu).or_else(in_state(GameState::NameInput)),
)),
);
}
}
12 changes: 6 additions & 6 deletions src/spell_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct SpellProps {

const MAGIC_BOLT: SpellProps = SpellProps {
name: "マジックボルト",
description: "魔力の塊を発射する、最も基本的な魔法です。",
description: "魔力の塊を発射する、最も基本的な攻撃魔法です。",
mana_drain: 50,
cast_delay: 10,
icon: "bullet_magic_bolt",
Expand All @@ -64,9 +64,9 @@ const MAGIC_BOLT: SpellProps = SpellProps {
};

const PURPLE_BOLT: SpellProps = SpellProps {
name: "スライム弾",
name: "魔力の塊",
description:
"紫色のエネルギー弾を発射します。動きは遅く威力も低いですが、少ない魔力でも発射できます。",
"紫色のエネルギー弾を発射します。動きは遅く威力も低いですが、少ない魔力で発射できます。",
mana_drain: 10,
cast_delay: 120,
icon: "bullet_purple",
Expand All @@ -85,8 +85,8 @@ const PURPLE_BOLT: SpellProps = SpellProps {
};

const SLIME_CHARGE: SpellProps = SpellProps {
name: "スライムチャージ",
description: "ぷにぷにとした塊で殴りつけます。やわらかいのであまり痛くありませんが、相手を大きく吹き飛ばします。",
name: "スライムの塊",
description: "ぷにぷにとした塊で殴りつけます。痛くはありませんが、相手を大きく吹き飛ばします。",
mana_drain: 200,
cast_delay: 30,
icon: "bullet_slime_charge",
Expand All @@ -95,7 +95,7 @@ const SLIME_CHARGE: SpellProps = SpellProps {
collier_radius: 5.0,
speed: 2.0,
lifetime: 5,
damage: 10,
damage: 1,
impulse: 40000.0,
scattering: 0.0,
light_intensity: 0.0,
Expand Down

0 comments on commit 12ad2f1

Please sign in to comment.