Skip to content

Commit

Permalink
Added a background image for and started on the basic battle scene.
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn authored and StarArawn committed Apr 16, 2021
1 parent 37d1f82 commit a168fdf
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A rogue-like game built in bevy and rust.

### Credits:
- `Toen's Medieval Strategy Sprite Pack` - Created by Andre Mari Coppola (http://toen.itch.io/toens-medieval-strategy)
- `GLACIAL MOUNTAINS: PARALLAX BACKGROUND` - GLACIAL MOUNTAINS: PARALLAX BACKGROUND (license: http://creativecommons.org/licenses/by/4.0/)

### Twitch Stream/Youtube playlist:
Twitch streams can be found here:
Expand Down
Binary file added assets/textures/backgrounds/battle1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/battle-mock.ase
Binary file not shown.
Binary file removed assets/textures/spider_sprite.png~
Binary file not shown.
32 changes: 20 additions & 12 deletions src/game/camera/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy::{
render::camera::Camera,
};
use bevy::render::camera::CameraProjection;
use crate::game::GameState;
use crate::game::{GameState, gameplay::battle};

use super::CustomOrthographicProjection;

Expand All @@ -29,12 +29,29 @@ impl Default for KeyboardConf {
}

pub fn camera_movement(
asset_server: Res<AssetServer>,
mut commands: Commands,
mut game_state: ResMut<State<GameState>>,
time: Res<Time>,
windows: Res<Windows>,
mut keyboard_input: ResMut<Input<KeyCode>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut query: Query<(&mut Camera, &mut Transform, &mut CustomOrthographicProjection)>,
time: Res<Time>,
windows: Res<Windows>,
) {
if keyboard_input.just_pressed(KeyCode::P) {
if *game_state.current() == GameState::MapView {
game_state.set(GameState::BattleView).unwrap();
battle::spawn_battle_screen(battle::BattleLocation::Mountains, &mut commands, &asset_server, &mut materials);
} else if *game_state.current() == GameState::BattleView {
game_state.set(GameState::MapView).unwrap();
}
keyboard_input.update();
}

if *game_state.current() == GameState::BattleView {
return;
}

for (mut camera, mut transform, mut projection) in query.iter_mut() {
let mut direction = Vec3::ZERO;
let scale = projection.scale;
Expand Down Expand Up @@ -65,15 +82,6 @@ pub fn camera_movement(
projection.scale = scale;
}

if keyboard_input.just_pressed(KeyCode::P) {
if *game_state.current() == GameState::MapView {
game_state.set(GameState::BattleView).unwrap();
} else if *game_state.current() == GameState::BattleView {
game_state.set(GameState::MapView).unwrap();
}
keyboard_input.update();
}

projection.update(windows.get_primary().unwrap().width(), windows.get_primary().unwrap().height());
camera.projection_matrix = projection.get_projection_matrix();
camera.depth_calculation = projection.depth_calculation();
Expand Down
33 changes: 33 additions & 0 deletions src/game/gameplay/battle/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use bevy::prelude::*;

use crate::game::GameState;

pub enum BattleLocation {
Mountains,
}

pub fn get_battle_location_texture(battle_location: BattleLocation) -> &'static str {
match battle_location {
BattleLocation::Mountains => {
"textures/backgrounds/battle1.png"
},
_ => panic!("No matching background texture found for battle location.")
}
}

pub fn spawn_battle_screen(
battle_location: BattleLocation,
commands: &mut Commands,
asset_server: &Res<AssetServer>,
materials: &mut ResMut<Assets<ColorMaterial>>,
) {
let texture_handle: Handle<Texture> = asset_server.load(get_battle_location_texture(battle_location));
let background_sprite = materials.add(texture_handle.into());
commands.spawn()
.insert_bundle(SpriteBundle {
material: background_sprite,
transform: Transform::from_xyz(0.0, 0.0, 10.0),
..Default::default()
})
.insert(GameState::BattleView);
}
3 changes: 2 additions & 1 deletion src/game/gameplay/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod player;
pub mod enemy;
pub mod enemy;
pub mod battle;

0 comments on commit a168fdf

Please sign in to comment.