Skip to content
Snippets Groups Projects
Commit b3dd5cac authored by Per Lindgren's avatar Per Lindgren
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Add the contents of this file to `config.toml` to enable "fast build" configuration. Please read the notes below.
# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
# NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager:
# `brew install michaeleisel/zld/zld`
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y"]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=y"]
# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
#[profile.dev]
#debug = 1
\ No newline at end of file
/target
{
"cSpell.ignoreWords": [
"fixed",
"timestep"
]
}
\ No newline at end of file
This diff is collapsed.
[package]
name = "bevytest"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
#bevy = { version = "0.5.0", features = ["dynamic"] }
bevy = { version = "0.5.0" }
\ No newline at end of file
assets/Parts HD/arm.png

783 B

assets/Parts HD/body.png

1.29 KiB

assets/Parts HD/bodyBack.png

867 B

assets/Parts HD/hand.png

468 B

assets/Parts HD/head.png

2.53 KiB

assets/Parts HD/headBack.png

1.65 KiB

assets/Parts HD/headFocus.png

2.56 KiB

assets/Parts HD/headShock.png

2.49 KiB

assets/Parts HD/leg.png

460 B

assets/Parts HD/legBend.png

720 B

assets/character_zombie_sheet.png

102 KiB

#![allow(unused)]
use bevy::{core::FixedTimestep, prelude::*};
const PLAYER_SHEET: &str = "character_zombie_sheet.png";
fn main() {
App::build()
.insert_resource(ClearColor(Color::rgb(0.04, 0.04, 0.04)))
.insert_resource(WindowDescriptor {
title: "My Little Zombie".to_string(),
width: 1920.,
height: 1080.,
..Default::default()
})
.add_startup_system(setup.system())
// .add_system(player_movement.system())
.add_system_set(
SystemSet::new()
.with_run_criteria(FixedTimestep::step(1.0 / 60.0))
.with_system(player_movement.system()),
)
// .add_system_set(
// SystemSet::new()
// .with_run_criteria(FixedTimestep::step(1.0 / 10.0))
// .with_system(player_animation.system()),
// )
.add_plugins(DefaultPlugins)
.run();
}
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut windows: ResMut<Windows>,
) {
let mut window = windows.get_primary_mut().unwrap();
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
let bottom = -window.height() / 2.0;
let texture_handle = asset_server.load(PLAYER_SHEET);
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(96.0, 128.0), 9, 5);
let atlas_handle = texture_atlases.add(texture_atlas);
commands
.spawn_bundle(SpriteSheetBundle {
texture_atlas: atlas_handle,
transform: Transform {
translation: Vec3::new(0., bottom / 2.0, 10.0),
// scale: Vec3::new(1., 1., 1.0),
..Default::default()
},
..Default::default()
})
.insert(Player::default());
}
enum State {
Right,
Left,
Idle,
}
pub struct Player {
state: State,
index: u32,
}
impl Default for Player {
fn default() -> Self {
Player {
state: State::Idle,
index: 0,
}
}
}
// run each frame (60Hz)
fn player_movement(
keyboard_input: Res<Input<KeyCode>>,
mut query: Query<(&mut Player, &mut Transform, &mut TextureAtlasSprite)>,
) {
if let Ok((mut player, mut transform, mut sprite)) = query.single_mut() {
let (index, state, dir) = if keyboard_input.pressed(KeyCode::Left) {
match player.state {
State::Left => ((player.index + 1) % 8, State::Left, -2.),
_ => (1, State::Left, 1.),
}
} else {
(0, State::Idle, 0.)
};
player.state = state;
player.index = index;
sprite.index = if index == 0 { 0 } else { 4 * 9 - 1 + index };
transform.translation.x += dir;
}
}
// fn player_movement(mut head_positions: Query<(&SnakeHead, &mut Transform)>) {
// for (_head, mut transform) in head_positions.iter_mut() {
// transform.translation.y += 2.;
// }
// }
// pub struct PlayerPlugin;
// impl Plugin for PlayerPlugin {
// fn build(&self, app: &mut AppBuilder) {
// app.insert_resource(PlayerState::default())
// .add_startup_stage(
// "game_setup_actors",
// SystemStage::single(player_spawn.system()),
// )
// .add_system(player_movement.system())
// .add_system(player_fire.system())
// .add_system(laser_movement.system())
// .add_system_set(
// SystemSet::new()
// .with_run_criteria(FixedTimestep::step(0.5))
// .with_system(player_spawn.system()),
// );
// }
// }
// fn player_spawn(
// mut commands: Commands,
// materials: Res<Materials>,
// win_size: Res<WinSize>,
// time: Res<Time>,
// mut player_state: ResMut<PlayerState>,
// ) {
// let now = time.seconds_since_startup();
// let last_shot = player_state.last_shot;
// // spawn a sprite
// if !player_state.on && (last_shot == 0. || now > last_shot + PLAYER_RESPAWN_DELAY) {
// let bottom = -win_size.h / 2.;
// commands
// .spawn_bundle(SpriteBundle {
// material: materials.player.clone(),
// transform: Transform {
// translation: Vec3::new(0., bottom + 75. / 4. + 5., 10.),
// scale: Vec3::new(SCALE, SCALE, 1.),
// ..Default::default()
// },
// ..Default::default()
// })
// .insert(Player)
// .insert(PlayerReadyFire(true))
// .insert(Speed::default());
// player_state.spawned();
// }
// }
// fn player_fire(
// mut commands: Commands,
// kb: Res<Input<KeyCode>>,
// materials: Res<Materials>,
// mut query: Query<(&Transform, &mut PlayerReadyFire), With<Player>>,
// ) {
// if let Ok((player_tf, mut ready_fire)) = query.single_mut() {
// if ready_fire.0 && kb.pressed(KeyCode::Space) {
// let x = player_tf.translation.x;
// let y = player_tf.translation.y;
// let mut spawn_lasers = |x_offset: f32| {
// commands
// .spawn_bundle(SpriteBundle {
// material: materials.player_laser.clone(),
// transform: Transform {
// translation: Vec3::new(x + x_offset, y + 15., 0.),
// scale: Vec3::new(SCALE, SCALE, 1.),
// ..Default::default()
// },
// ..Default::default()
// })
// .insert(Laser)
// .insert(FromPlayer)
// .insert(Speed::default());
// };
// let x_offset = 144.0 / 4.0 - 5.0;
// spawn_lasers(x_offset);
// spawn_lasers(-x_offset);
// ready_fire.0 = false;
// }
// if kb.just_released(KeyCode::Space) {
// ready_fire.0 = true;
// }
// }
// }
// fn laser_movement(
// mut commands: Commands,
// win_size: Res<WinSize>,
// mut query: Query<(Entity, &Speed, &mut Transform), (With<Laser>, With<FromPlayer>)>,
// ) {
// for (laser_entity, speed, mut laser_tf) in query.iter_mut() {
// let translation = &mut laser_tf.translation;
// translation.y += speed.0 * TIME_STEP;
// if translation.y > win_size.h {
// commands.entity(laser_entity).despawn();
// }
// }
// }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment