forked from Lncvrt/berry-dash-rs
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
853085c219
|
||
|
|
dcf241a12b
|
||
|
|
5ba37fe26d
|
||
|
|
8b27bcd1cf
|
||
|
|
dc4d882c6b
|
||
|
|
ac6dcecf74
|
||
|
|
743037141f
|
||
|
|
f44d0ad502 | ||
|
|
e1f7968ae1 |
No files matched your search
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
@@ -5,3 +5,10 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.18.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
image = "0.25.10"
|
||||
winit = "0.30.13"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.build-dependencies]
|
||||
winresource = "0.1.31"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 264 KiB |
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
#[cfg(target_os = "windows")]
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
|
||||
let mut res = winresource::WindowsResource::new();
|
||||
res.set_icon("assets/Icon.ico");
|
||||
res.compile().unwrap();
|
||||
}
|
||||
}
|
||||
+87
-24
@@ -1,4 +1,17 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::settings::Backends;
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
render::{
|
||||
RenderPlugin,
|
||||
settings::{RenderCreation, WgpuSettings},
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use {
|
||||
bevy::{ecs::system::NonSendMarker, winit::WINIT_WINDOWS},
|
||||
winit::window::Icon,
|
||||
};
|
||||
|
||||
const GRAVITY: f32 = -1800.0;
|
||||
const JUMP_VEL: f32 = 600.0;
|
||||
@@ -10,23 +23,62 @@ struct Player {
|
||||
on_ground: bool,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn set_window_icon(_marker: NonSendMarker) {
|
||||
let (icon_rgba, icon_width, icon_height) = {
|
||||
let image = image::open("assets/Icon.png")
|
||||
.expect("Failed to open icon path")
|
||||
.into_rgba8();
|
||||
let (width, height) = image.dimensions();
|
||||
(image.into_raw(), width, height)
|
||||
};
|
||||
let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height).unwrap();
|
||||
|
||||
WINIT_WINDOWS.with_borrow(|winit_windows| {
|
||||
for window in winit_windows.windows.values() {
|
||||
window.set_window_icon(Some(icon.clone()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Berry Dash RS".into(),
|
||||
resize_constraints: WindowResizeConstraints {
|
||||
min_width: 800.0,
|
||||
min_height: 600.0,
|
||||
let mut app = App::new();
|
||||
app.add_plugins(
|
||||
DefaultPlugins
|
||||
.set(RenderPlugin {
|
||||
render_creation: RenderCreation::Automatic(WgpuSettings {
|
||||
backends: Some(
|
||||
#[cfg(target_os = "windows")]
|
||||
Backends::DX12,
|
||||
#[cfg(target_os = "linux")]
|
||||
Backends::VULKAN,
|
||||
#[cfg(target_os = "macos")]
|
||||
Backends::METAL,
|
||||
),
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Berry Dash RS".into(),
|
||||
resize_constraints: WindowResizeConstraints {
|
||||
min_width: 800.0,
|
||||
min_height: 600.0,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, update_position)
|
||||
.run();
|
||||
)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, update_position);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
app.add_systems(Startup, set_window_icon);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {
|
||||
@@ -35,7 +87,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&
|
||||
|
||||
commands.spawn(Camera2d);
|
||||
commands.spawn((
|
||||
Player { x: 0.5, vel_y: 0.0, on_ground: true },
|
||||
Player {
|
||||
x: 0.5,
|
||||
vel_y: 0.0,
|
||||
on_ground: true,
|
||||
},
|
||||
Sprite::from_image(asset_server.load("Icons/bird_1.png")),
|
||||
Transform::from_xyz(0.0, bottom, 0.0),
|
||||
));
|
||||
@@ -56,22 +112,29 @@ fn update_position(
|
||||
for (mut player, mut transform, mut sprite) in &mut query {
|
||||
let half_sprite = 64.0 / width;
|
||||
|
||||
if keys.pressed(KeyCode::ArrowLeft) || keys.pressed(KeyCode::KeyA) || keys.pressed(KeyCode::KeyJ) {
|
||||
if keys.pressed(KeyCode::ArrowLeft)
|
||||
|| keys.pressed(KeyCode::KeyA)
|
||||
|| keys.pressed(KeyCode::KeyJ)
|
||||
{
|
||||
player.x -= speed * dt / width;
|
||||
sprite.flip_x = false;
|
||||
}
|
||||
if keys.pressed(KeyCode::ArrowRight) || keys.pressed(KeyCode::KeyD) || keys.pressed(KeyCode::KeyL) {
|
||||
if keys.pressed(KeyCode::ArrowRight)
|
||||
|| keys.pressed(KeyCode::KeyD)
|
||||
|| keys.pressed(KeyCode::KeyL)
|
||||
{
|
||||
player.x += speed * dt / width;
|
||||
sprite.flip_x = true;
|
||||
}
|
||||
player.x = player.x.clamp(half_sprite, 1.0 - half_sprite);
|
||||
|
||||
let jump = keys.just_pressed(KeyCode::Space)
|
||||
|| keys.just_pressed(KeyCode::ArrowUp)
|
||||
|| keys.just_pressed(KeyCode::KeyW)
|
||||
|| keys.just_pressed(KeyCode::KeyS)
|
||||
|| keys.just_pressed(KeyCode::KeyI)
|
||||
|| keys.just_pressed(KeyCode::KeyK);
|
||||
let jump = keys.pressed(KeyCode::Space)
|
||||
|| keys.pressed(KeyCode::ArrowUp)
|
||||
|| keys.pressed(KeyCode::ArrowDown)
|
||||
|| keys.pressed(KeyCode::KeyW)
|
||||
|| keys.pressed(KeyCode::KeyS)
|
||||
|| keys.pressed(KeyCode::KeyI)
|
||||
|| keys.pressed(KeyCode::KeyK);
|
||||
if jump && player.on_ground {
|
||||
player.vel_y = JUMP_VEL;
|
||||
player.on_ground = false;
|
||||
@@ -88,4 +151,4 @@ fn update_position(
|
||||
|
||||
transform.translation.x = (player.x - 0.5) * width;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user