Skip to content

Commit

Permalink
Merge pull request #82 from nkc-ug/future/efect
Browse files Browse the repository at this point in the history
鳴き声追加
  • Loading branch information
Yuma-Satake authored Aug 28, 2023
2 parents e825aee + 126fbe7 commit 32b9ada
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Binary file added src/Audio/やぎの鳴き声.mp3
Binary file not shown.
13 changes: 12 additions & 1 deletion src/components/EvolutionWalk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import yagi_yorokobi_right from '../assets/yagi_yorokobi_right.png';
import yagi_ikari_right from '../assets/yagi_iakri_right.png';
import yagi_kanasimi_right from '../assets/yagi_kanasimi_right.png';
import yagi_tanosii_right from '../assets/yagi_tanosii_right.png';
import yagi_efect from '../Audio/やぎの鳴き声.mp3';

type Props = {
typeId: number;
Expand Down Expand Up @@ -43,6 +44,15 @@ const EvolutionWalk: FC<Props> = ({ typeId, containerSize }) => {
};
}, [containerSize]);

const [play, isPlaying] = useState(true);
const yagiAudio = () => {
isPlaying(!play);
new Audio(yagi_efect).play();
};
const audioPlay = () => {
yagiAudio();
};

const getImagePath = (typeId: number) => {
switch (typeId) {
case 1:
Expand All @@ -59,7 +69,7 @@ const EvolutionWalk: FC<Props> = ({ typeId, containerSize }) => {
};

const backgroundImage = getImagePath(typeId);

return (
<div
style={{
Expand All @@ -80,6 +90,7 @@ const EvolutionWalk: FC<Props> = ({ typeId, containerSize }) => {
top: `${position.y}px`,
transition: 'left 3s ease-in-out, top 3s ease-in-out', // 移動アニメーションの時間を延長(2秒)
}}
onClick={audioPlay}
/>
</div>
);
Expand Down
39 changes: 26 additions & 13 deletions src/components/NormalWalk.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useRef, useEffect, useState, FC } from 'react';
import yagi_left from '../assets/yagi_left.png';
import yagi_right from '../assets/yagi_right.png';
import yagi_efect from '../Audio/やぎの鳴き声.mp3';
import { Button } from '@mui/material';

type Props = {
containerSize: {
Expand Down Expand Up @@ -37,6 +39,15 @@ const NormalWalk: FC<Props> = ({ containerSize }) => {

const backgroundImage = position.x > containerSize.width / 3 ? yagi_right : yagi_left;

const [play, isPlaying] = useState(true);
const yagiAudio = () => {
isPlaying(!play);
new Audio(yagi_efect).play();
};
const audioPlay = () => {
yagiAudio();
};

return (
<div
style={{
Expand All @@ -45,19 +56,21 @@ const NormalWalk: FC<Props> = ({ containerSize }) => {
height: '100%',
}}
>
<div
ref={walkerRef}
style={{
position: 'absolute',
width: '130px',
height: '130px',
backgroundImage: `url(${backgroundImage})`,
backgroundSize: 'cover',
left: `${position.x}px`,
top: `${position.y}px`,
transition: 'left 3s ease-in-out, top 3s ease-in-out', // 移動アニメーションの時間を延長(3秒)
}}
/>
<Button variant="text" onClick={audioPlay}>
<div
ref={walkerRef}
style={{
position: 'absolute',
width: '130px',
height: '130px',
backgroundImage: `url(${backgroundImage})`,
backgroundSize: 'cover',
left: `${position.x}px`,
top: `${position.y}px`,
transition: 'left 3s ease-in-out, top 3s ease-in-out', // 移動アニメーションの時間を延長(3秒)
}}
/>
</Button>
</div>
);
};
Expand Down

0 comments on commit 32b9ada

Please sign in to comment.