Player data is now gotten from JSON (this is a suprise tool that will help us later :3)
parent
c243404bba
commit
e752bcd86e
|
@ -5,3 +5,5 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.12.0"
|
bevy = "0.12.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"speed":0.3,
|
||||||
|
"movement":[10.0,0.0]
|
||||||
|
}
|
10
src/main.rs
10
src/main.rs
|
@ -1,6 +1,8 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component, Serialize, Deserialize)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub speed: f32,
|
pub speed: f32,
|
||||||
pub movement: Vec2,
|
pub movement: Vec2,
|
||||||
|
@ -31,6 +33,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
|
||||||
let texture = asset_server.load("blobcat_hertog.png");
|
let texture = asset_server.load("blobcat_hertog.png");
|
||||||
|
let json_file = fs::read_to_string("./data/player_data.json").expect("Error Reading Player Data");
|
||||||
|
let player_data: Player = serde_json::from_str::<Player>(&json_file).expect("Error serializing to JSON");
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
SpriteBundle {
|
SpriteBundle {
|
||||||
|
@ -42,8 +46,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Player {
|
Player {
|
||||||
speed: 0.3,
|
speed: player_data.speed,
|
||||||
movement: Vec2::new( 10.0, 0.0 )
|
movement: Vec2::new( player_data.movement[0], player_data.movement[1] )
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue