Skip to content

Commit

Permalink
tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 14, 2024
1 parent 12ad2f1 commit 83ac3f2
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 16 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="Me9ZB76oxBjpsiCgyJ6LKQ==" type=module>import init, * as bindings from './magiacircle-b4af609aae1fb5f7.js';
const wasm = await init('./magiacircle-b4af609aae1fb5f7_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="6CfCBwx09ryd8Lim1T2Vlw==" type=module>import init, * as bindings from './magiacircle-291a6129168c6c1d.js';
const wasm = await init('./magiacircle-291a6129168c6c1d_bg.wasm');


window.wasmBindings = bindings;


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>
dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));</script><title>magiacircle 0.1</title><link crossorigin href=./magiacircle-291a6129168c6c1d.js integrity=sha384-cw7GXfaOaG9myJmCnQh2oopNwhZWIrodHvIS2qCh6kwLV+q4p1UhqMLvK4ruf1we rel=modulepreload><link as=fetch crossorigin href=./magiacircle-291a6129168c6c1d_bg.wasm integrity=sha384-S0Co4+XLoDd9K86QvNMGMYLc/BNeu9xTrsLMN3qO7b6CUvg1Kh2a2wrlx7G2OMtX rel=preload type=application/wasm></head><body></body></html>
1 change: 1 addition & 0 deletions docs/magiacircle-291a6129168c6c1d.js

Large diffs are not rendered by default.

Binary file not shown.
1 change: 0 additions & 1 deletion docs/magiacircle-b4af609aae1fb5f7.js

This file was deleted.

1 change: 1 addition & 0 deletions src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum GameEntity {
Routes,
StoneLantern,
Spell,
Crate,
}

#[derive(Component)]
Expand Down
50 changes: 38 additions & 12 deletions src/entity/chest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ const ENTITY_WIDTH: f32 = 8.0;

const ENTITY_HEIGHT: f32 = 8.0;

#[derive(Clone, Copy, PartialEq, Eq, Reflect, Default)]
pub enum ChestType {
#[default]
Chest,
Crate,
}

#[derive(Default, Component, Reflect)]
struct Chest {
pub chest_type: ChestType,
pub golds: i32,
}

/// チェストを生成します
/// 指定する位置はスプライトの左上ではなく、重心のピクセル座標です
pub fn spawn_chest(commands: &mut Commands, aseprite: Handle<Aseprite>, x: f32, y: f32) {
pub fn spawn_chest(
commands: &mut Commands,
aseprite: Handle<Aseprite>,
x: f32,
y: f32,
chest_type: ChestType,
) {
let tx = x + ENTITY_WIDTH - TILE_SIZE / 2.0;
let ty = y - ENTITY_HEIGHT + TILE_SIZE / 2.0;
commands
Expand All @@ -31,7 +45,13 @@ pub fn spawn_chest(commands: &mut Commands, aseprite: Handle<Aseprite>, x: f32,
life: 30,
amplitude: 0.0,
},
Chest { golds: 10 },
Chest {
chest_type,
golds: match chest_type {
ChestType::Chest => 10,
ChestType::Crate => 0,
},
},
EntityDepth,
Transform::from_translation(Vec3::new(tx, ty, 0.0)),
GlobalTransform::default(),
Expand All @@ -47,7 +67,11 @@ pub fn spawn_chest(commands: &mut Commands, aseprite: Handle<Aseprite>, x: f32,
BreakableSprite,
AsepriteSliceBundle {
aseprite: aseprite,
slice: "chest".into(),
slice: match chest_type {
ChestType::Chest => "chest",
ChestType::Crate => "crate",
}
.into(),
..default()
},
));
Expand All @@ -56,24 +80,26 @@ pub fn spawn_chest(commands: &mut Commands, aseprite: Handle<Aseprite>, x: f32,

fn break_chest(
mut commands: Commands,
query: Query<(Entity, &Breakable, &Transform), With<Chest>>,
query: Query<(Entity, &Breakable, &Transform, &Chest)>,
assets: Res<GameAssets>,
mut writer: EventWriter<GameCommand>,
) {
for (entity, breakabke, transform) in query.iter() {
for (entity, breakabke, transform, chest) in query.iter() {
if breakabke.life <= 0 {
commands.entity(entity).despawn_recursive();
writer.send(GameCommand::SEKuzureru(Some(
transform.translation.truncate(),
)));

for _ in 0..(3 + random::<i32>().abs() % 10) {
spawn_gold(
&mut commands,
&assets,
transform.translation.x,
transform.translation.y,
);
if chest.chest_type == ChestType::Chest {
for _ in 0..(3 + random::<i32>().abs() % 10) {
spawn_gold(
&mut commands,
&assets,
transform.translation.x,
transform.translation.y,
);
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::enemy::slime::spawn_slime;
use crate::entity::book_shelf::spawn_book_shelf;
use crate::entity::broken_magic_circle::spawn_broken_magic_circle;
use crate::entity::chest::spawn_chest;
use crate::entity::chest::ChestType;
use crate::entity::magic_circle::spawn_magic_circle;
use crate::entity::magic_circle::MagicCircleDestination;
use crate::entity::spell::spawn_spell_entity;
Expand Down Expand Up @@ -333,6 +334,16 @@ fn spawn_entities(mut commands: &mut Commands, assets: &Res<GameAssets>, chunk:
assets.atlas.clone(),
tx + TILE_HALF,
ty - TILE_HALF,
ChestType::Chest,
);
}
GameEntity::Crate => {
spawn_chest(
&mut commands,
assets.atlas.clone(),
tx + TILE_HALF,
ty - TILE_HALF,
ChestType::Crate,
);
}
GameEntity::MagicCircle => {
Expand Down
7 changes: 7 additions & 0 deletions src/world/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ pub fn image_to_tilemap(
});
entities.push((GameEntity::Spell, x, y));
}
(102, 57, 49, 255) => {
tiles.push(LevelTileMapile {
tile: Tile::StoneTile,
biome: Biome::SafeZone,
});
entities.push((GameEntity::Crate, x, y));
}
_ => {
tiles.push(LevelTileMapile {
tile: Tile::Blank,
Expand Down

0 comments on commit 83ac3f2

Please sign in to comment.