-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9260e93
commit 73ff91b
Showing
7 changed files
with
144 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Credits | ||
|
||
## Audio | ||
|
||
- [explosion.ogg](https://freesound.org/people/Werra/sounds/244394/) - edited |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use bevy::prelude::*; | ||
use bevy_cameraman::Cameraman; | ||
|
||
const DEBUG: bool = false; | ||
|
||
pub struct AudioPlugin; | ||
|
||
impl Plugin for AudioPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(PostStartup, setup); | ||
} | ||
} | ||
|
||
fn setup(mut commands: Commands, query_camera: Query<Entity, With<Cameraman>>) { | ||
let gap = 200.; | ||
let listener = SpatialListener::new(gap); | ||
|
||
for entity in &query_camera { | ||
let mut cmd = commands.entity(entity); | ||
let cmd = cmd.insert((SpatialBundle::default(), listener.clone())); | ||
|
||
if DEBUG { | ||
cmd.with_children(|parent| { | ||
// left ear | ||
parent.spawn(SpriteBundle { | ||
sprite: Sprite { | ||
color: Color::RED, | ||
custom_size: Some(Vec2::splat(20.0)), | ||
..default() | ||
}, | ||
transform: Transform::from_xyz(-gap / 2.0, 0.0, 0.0), | ||
..default() | ||
}); | ||
|
||
// right ear | ||
parent.spawn(SpriteBundle { | ||
sprite: Sprite { | ||
color: Color::GREEN, | ||
custom_size: Some(Vec2::splat(20.0)), | ||
..default() | ||
}, | ||
transform: Transform::from_xyz(gap / 2.0, 0.0, 0.0), | ||
..default() | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,70 @@ | ||
<html> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>An other bevy 2D game</title> | ||
<style> | ||
body { | ||
background: linear-gradient( | ||
45deg, | ||
#4b0082 0%, | ||
#8a2be2 100% | ||
); | ||
background: linear-gradient(45deg, #4b0082 0%, #8a2be2 100%); | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
height: 100vh; | ||
margin: 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; | ||
color: #ffffff; | ||
} | ||
|
||
h1 { | ||
font-size: 2.5em; | ||
text-align: center; | ||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); | ||
padding: 2em; | ||
margin: 0; /* Remove default margin for better alignment */ | ||
} | ||
canvas { | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); | ||
outline: none; | ||
|
||
button { | ||
background-color: #ff8c00; | ||
color: #ffffff; | ||
font-size: 1.5em; | ||
padding: 0.5em 1em; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
button:hover { | ||
background-color: #ffa500; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>An other bevy 2D game</h1> | ||
<button onclick="play()">Play</button> | ||
<script type="module"> | ||
import init from './wasm_game.js' | ||
init() | ||
</script> | ||
<script> | ||
interval = setInterval(function () { | ||
let canvas = document.getElementsByTagName("canvas")[0] | ||
import init from "./wasm_game.js"; | ||
|
||
window.play = function () { | ||
// Hide header and button | ||
document.querySelector("h1").style.display = "none"; | ||
document.querySelector("button").style.display = "none"; | ||
|
||
// Call your initialization function | ||
init(); | ||
|
||
// Focus on the canvas | ||
let interval = setInterval(function () { | ||
let canvas = document.getElementsByTagName("canvas")[0]; | ||
if (canvas) { | ||
canvas.focus() | ||
clearInterval(interval) | ||
canvas.focus(); | ||
clearInterval(interval); | ||
} | ||
}, 100) | ||
}, 100); | ||
}; | ||
</script> | ||
</body> | ||
</html> |