Compare commits
2
Commits
main
..
d81e4dec13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d81e4dec13
|
||
|
|
19e19cabef
|
No files matched your search
Vendored
-3
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"editor.formatOnSave": true
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,3 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.18.1"
|
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.
|
Before Width: | Height: | Size: 264 KiB |
@@ -1,8 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
-79
@@ -1,17 +1,4 @@
|
|||||||
use bevy::render::settings::Backends;
|
use bevy::prelude::*;
|
||||||
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 GRAVITY: f32 = -1800.0;
|
||||||
const JUMP_VEL: f32 = 600.0;
|
const JUMP_VEL: f32 = 600.0;
|
||||||
@@ -23,62 +10,23 @@ struct Player {
|
|||||||
on_ground: bool,
|
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() {
|
fn main() {
|
||||||
let mut app = App::new();
|
App::new()
|
||||||
app.add_plugins(
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
DefaultPlugins
|
primary_window: Some(Window {
|
||||||
.set(RenderPlugin {
|
title: "Berry Dash RS".into(),
|
||||||
render_creation: RenderCreation::Automatic(WgpuSettings {
|
resize_constraints: WindowResizeConstraints {
|
||||||
backends: Some(
|
min_width: 800.0,
|
||||||
#[cfg(target_os = "windows")]
|
min_height: 600.0,
|
||||||
Backends::DX12,
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
Backends::VULKAN,
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
Backends::METAL,
|
|
||||||
),
|
|
||||||
..default()
|
..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()
|
||||||
}),
|
}),
|
||||||
)
|
..default()
|
||||||
.add_systems(Startup, setup)
|
}))
|
||||||
.add_systems(Update, update_position);
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Update, update_position)
|
||||||
#[cfg(target_os = "windows")]
|
.run();
|
||||||
app.add_systems(Startup, set_window_icon);
|
|
||||||
|
|
||||||
app.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {
|
||||||
@@ -87,11 +35,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&
|
|||||||
|
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Player {
|
Player { x: 0.5, vel_y: 0.0, on_ground: true },
|
||||||
x: 0.5,
|
|
||||||
vel_y: 0.0,
|
|
||||||
on_ground: true,
|
|
||||||
},
|
|
||||||
Sprite::from_image(asset_server.load("Icons/bird_1.png")),
|
Sprite::from_image(asset_server.load("Icons/bird_1.png")),
|
||||||
Transform::from_xyz(0.0, bottom, 0.0),
|
Transform::from_xyz(0.0, bottom, 0.0),
|
||||||
));
|
));
|
||||||
@@ -112,17 +56,11 @@ fn update_position(
|
|||||||
for (mut player, mut transform, mut sprite) in &mut query {
|
for (mut player, mut transform, mut sprite) in &mut query {
|
||||||
let half_sprite = 64.0 / width;
|
let half_sprite = 64.0 / width;
|
||||||
|
|
||||||
if keys.pressed(KeyCode::ArrowLeft)
|
if keys.pressed(KeyCode::ArrowLeft) || keys.pressed(KeyCode::KeyA) || keys.pressed(KeyCode::KeyJ) {
|
||||||
|| keys.pressed(KeyCode::KeyA)
|
|
||||||
|| keys.pressed(KeyCode::KeyJ)
|
|
||||||
{
|
|
||||||
player.x -= speed * dt / width;
|
player.x -= speed * dt / width;
|
||||||
sprite.flip_x = false;
|
sprite.flip_x = false;
|
||||||
}
|
}
|
||||||
if keys.pressed(KeyCode::ArrowRight)
|
if keys.pressed(KeyCode::ArrowRight) || keys.pressed(KeyCode::KeyD) || keys.pressed(KeyCode::KeyL) {
|
||||||
|| keys.pressed(KeyCode::KeyD)
|
|
||||||
|| keys.pressed(KeyCode::KeyL)
|
|
||||||
{
|
|
||||||
player.x += speed * dt / width;
|
player.x += speed * dt / width;
|
||||||
sprite.flip_x = true;
|
sprite.flip_x = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user