mirror of
https://github.com/edg-l/teecity.git
synced 2024-11-09 09:38:22 +00:00
guns
This commit is contained in:
parent
820444654a
commit
d4498482f7
|
@ -11,11 +11,12 @@ use crate::{
|
||||||
pub struct Player;
|
pub struct Player;
|
||||||
|
|
||||||
pub fn add_player(mut commands: Commands, server: Res<AssetServer>) {
|
pub fn add_player(mut commands: Commands, server: Res<AssetServer>) {
|
||||||
let handle: Handle<Image> = server.load("skins/default.png");
|
let skin_handle: Handle<Image> = server.load("skins/default.png");
|
||||||
|
let game_handle: Handle<Image> = server.load("game.png");
|
||||||
|
|
||||||
let tee_bundle = TeeBundle::new("Player", Vec3::new(32.0, 32.0, 0.0));
|
let tee_bundle = TeeBundle::new("Player", Vec3::new(32.0, 32.0, 0.0));
|
||||||
|
|
||||||
let tee_bundle_children = TeeBundleChildren::new(handle);
|
let tee_bundle_children = TeeBundleChildren::new(skin_handle, game_handle);
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
|
@ -25,6 +26,7 @@ pub fn add_player(mut commands: Commands, server: Res<AssetServer>) {
|
||||||
AimTarget::default(),
|
AimTarget::default(),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
|
parent.spawn(tee_bundle_children.weapon);
|
||||||
parent.spawn(tee_bundle_children.body);
|
parent.spawn(tee_bundle_children.body);
|
||||||
parent.spawn(tee_bundle_children.left_foot);
|
parent.spawn(tee_bundle_children.left_foot);
|
||||||
parent.spawn(tee_bundle_children.right_foot);
|
parent.spawn(tee_bundle_children.right_foot);
|
||||||
|
|
78
src/tee.rs
78
src/tee.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::borrow::Cow;
|
use std::{borrow::Cow, default};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
@ -14,6 +14,16 @@ pub struct LeftFoot;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct RightFoot;
|
pub struct RightFoot;
|
||||||
|
|
||||||
|
#[derive(Component, Default)]
|
||||||
|
pub enum Weapon {
|
||||||
|
Gun,
|
||||||
|
#[default]
|
||||||
|
Grenade,
|
||||||
|
Katana,
|
||||||
|
Laser,
|
||||||
|
Shotgun,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct TeeBundle {
|
pub struct TeeBundle {
|
||||||
pub tee: Tee,
|
pub tee: Tee,
|
||||||
|
@ -29,6 +39,7 @@ pub struct TeePartBundle<T: Component> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TeeBundleChildren {
|
pub struct TeeBundleChildren {
|
||||||
|
pub weapon: TeePartBundle<Weapon>,
|
||||||
pub body: TeePartBundle<Body>,
|
pub body: TeePartBundle<Body>,
|
||||||
pub left_foot: TeePartBundle<LeftFoot>,
|
pub left_foot: TeePartBundle<LeftFoot>,
|
||||||
pub right_foot: TeePartBundle<RightFoot>,
|
pub right_foot: TeePartBundle<RightFoot>,
|
||||||
|
@ -48,11 +59,24 @@ impl TeeBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TeeBundleChildren {
|
impl TeeBundleChildren {
|
||||||
pub fn new(handle: Handle<Image>) -> Self {
|
pub fn new(skin_handle: Handle<Image>, game_handle: Handle<Image>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
weapon: TeePartBundle {
|
||||||
|
sprite: SpriteBundle {
|
||||||
|
texture: game_handle,
|
||||||
|
sprite: Sprite {
|
||||||
|
rect: Some(Weapon::default().get_texture_rect()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
transform: Weapon::default().get_transform(),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
marker: Weapon::default(),
|
||||||
|
name: Name::new("Weapon"),
|
||||||
|
},
|
||||||
body: TeePartBundle {
|
body: TeePartBundle {
|
||||||
sprite: SpriteBundle {
|
sprite: SpriteBundle {
|
||||||
texture: handle.clone(),
|
texture: skin_handle.clone(),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
rect: Some(Rect::from_corners(Vec2::ZERO, Vec2::new(96.0, 96.0))),
|
rect: Some(Rect::from_corners(Vec2::ZERO, Vec2::new(96.0, 96.0))),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -65,7 +89,7 @@ impl TeeBundleChildren {
|
||||||
},
|
},
|
||||||
left_foot: TeePartBundle {
|
left_foot: TeePartBundle {
|
||||||
sprite: SpriteBundle {
|
sprite: SpriteBundle {
|
||||||
texture: handle.clone(),
|
texture: skin_handle.clone(),
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
|
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -79,7 +103,7 @@ impl TeeBundleChildren {
|
||||||
},
|
},
|
||||||
right_foot: TeePartBundle {
|
right_foot: TeePartBundle {
|
||||||
sprite: SpriteBundle {
|
sprite: SpriteBundle {
|
||||||
texture: handle,
|
texture: skin_handle,
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
|
rect: Some(Rect::new(96.0 * 2.0, 32.0, 96.0 * 2.0 + 64.0, 32.0 + 32.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -96,6 +120,50 @@ impl TeeBundleChildren {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Weapon {
|
||||||
|
pub fn get_texture_rect(&self) -> Rect {
|
||||||
|
match self {
|
||||||
|
Weapon::Gun => Rect::new(64.0, 32.0 + 96.0, 64.0 + 128.0, 32.0 + 96.0 + 64.0),
|
||||||
|
Weapon::Shotgun => Rect::new(
|
||||||
|
64.0,
|
||||||
|
32.0 + 96.0 + 64.0,
|
||||||
|
64.0 + 256.0,
|
||||||
|
32.0 + 96.0 + 64.0 + 64.0,
|
||||||
|
),
|
||||||
|
Weapon::Grenade => Rect::new(
|
||||||
|
64.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 2.0,
|
||||||
|
64.0 + 256.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 2.0 + 64.0,
|
||||||
|
),
|
||||||
|
Weapon::Katana => Rect::new(
|
||||||
|
64.0 + 32.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 3.0,
|
||||||
|
64.0 + 256.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 3.0 + 64.0,
|
||||||
|
),
|
||||||
|
Weapon::Laser => Rect::new(
|
||||||
|
64.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 4.0,
|
||||||
|
64.0 + 224.0,
|
||||||
|
32.0 + 96.0 + 64.0 * 4.0 + 96.0,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_transform(&self) -> Transform {
|
||||||
|
match self {
|
||||||
|
Weapon::Katana => Transform::from_xyz(11.5, 50.0, 0.25)
|
||||||
|
.with_scale(Vec3::splat(0.5))
|
||||||
|
.with_rotation(Quat::from_rotation_z(1.8)),
|
||||||
|
Weapon::Gun => Transform::from_xyz(2.0, 38.0, 0.25),
|
||||||
|
_ => Transform::from_xyz(2.0, 60.0, 0.25)
|
||||||
|
.with_scale(Vec3::splat(0.5))
|
||||||
|
.with_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pub fn add_tee(commands: Commands, handle: Handle<Image>, translation: Vec3, name: &str) {
|
pub fn add_tee(commands: Commands, handle: Handle<Image>, translation: Vec3, name: &str) {
|
||||||
TeeBundle {
|
TeeBundle {
|
||||||
|
|
Loading…
Reference in a new issue