Skip to content

Commit

Permalink
Adding a bullet image to the ui to differentiate our two numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
druerridge committed Feb 26, 2019
1 parent 55cd6a5 commit f89a02d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ fn load_level(texture_manager:&mut TextureManager, sound_manager:&mut SoundManag
let hand_gun_image_id= image_map.insert(hand_gun_image);
let selected_hand_gun_image: G2dTexture = asset_loader.load_texture("textures/GunGunV1_selected.png");
let selected_hand_gun_image_id= image_map.insert(selected_hand_gun_image);
let bullet_image: G2dTexture = asset_loader.load_texture("textures/bullet.png");
let bullet_image_id= image_map.insert(bullet_image);
let hand_gun: RefCell<MetaGun> = RefCell::new( MetaGun {
gun_sound: gun_sound.clone(),
gun_texture: gun_gun.clone(),
gun_image_id: hand_gun_image_id,
selected_gun_texture: gun_gun_selected.clone(),
selected_gun_image_id: selected_hand_gun_image_id,
bullet_texture: bullet.clone(),
bullet_image_id: bullet_image_id,
bullet_sound: sound_manager.get("sounds\\boop.ogg"),
gun_strategy: Box::new(HandGun {
should_delete: false
Expand All @@ -225,6 +228,7 @@ fn load_level(texture_manager:&mut TextureManager, sound_manager:&mut SoundManag
selected_gun_texture: axe_gun_texture_selected.clone(),
selected_gun_image_id: selected_gun_axe_image_id,
bullet_texture: bullet.clone(),
bullet_image_id: bullet_image_id,
bullet_sound: sound_manager.get("sounds\\boop.ogg"),
gun_strategy: Box::new(GunAxe {
should_delete: false
Expand Down
1 change: 1 addition & 0 deletions src/meta_gun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct MetaGun {
pub selected_gun_image_id: conrod_core::image::Id,
pub gun_sound: Rc<RefCell<Sound>>,
pub bullet_texture: Rc<G2dTexture>,
pub bullet_image_id: conrod_core::image::Id,
pub bullet_sound: Rc<RefCell<Sound>>,
pub gun_strategy: Box<GunStrategy>,
pub shots_taken: usize, // drinks all around https://www.youtube.com/watch?v=XNtTEibFvlQ
Expand Down
1 change: 1 addition & 0 deletions src/ui_widget_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ widget_ids! {
guns_hud[],
shots_taken_hud[],
bullets_remaining_hud[],
bullets_hud[],

// Main Menu World List
world_list[],
Expand Down
25 changes: 17 additions & 8 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use conrod_core::widget::Widget;
use crate::fps_counter::FpsCounter;
use conrod_core::position::Positionable;
use conrod_core::position::Sizeable;
use crate::gun::BULLET_SCALE;

const ENEMY_LAYER: usize = 1;
const PROJECTILE_LAYER: usize = 2;
Expand Down Expand Up @@ -209,10 +210,11 @@ impl World {
ui_bundle.ids.guns_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());
ui_bundle.ids.shots_taken_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());
ui_bundle.ids.bullets_remaining_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());
ui_bundle.ids.bullets_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());

let mut ui_cell = ui_bundle.conrod_ui.set_widgets();
conrod_core::widget::Canvas::new()
.pad(30.0)
.pad(40.0)
.color(conrod_core::color::TRANSPARENT)
.set(ui_bundle.ids.canvas, &mut ui_cell);

Expand Down Expand Up @@ -244,15 +246,23 @@ impl World {
self.player.borrow().gun_templates[i].borrow().gun_texture.clone()
};

let mut image = conrod_core::widget::Image::new(gun_image_id)
let mut gun_image = conrod_core::widget::Image::new(gun_image_id)
.w_h(gun_texture.get_width() as f64, gun_texture.get_height() as f64);

if id_gun_right == ui_bundle.ids.canvas {
image = image.top_right_of(id_gun_right);
gun_image = gun_image.top_right_of(id_gun_right);
} else {
image = image.left_from(id_gun_right, width_gun_right);
gun_image = gun_image.left_from(id_gun_right, width_gun_right);
}
image.set(ui_bundle.ids.guns_hud[i], &mut ui_cell);
gun_image.set(ui_bundle.ids.guns_hud[i], &mut ui_cell);

let bullet_image_id = self.player.borrow().gun_templates[i].borrow().bullet_image_id;
let bullet_texture = self.player.borrow().gun_templates[i].borrow().bullet_texture.clone();
conrod_core::widget::Image::new(bullet_image_id)
.w_h((BULLET_SCALE * 1.5) * bullet_texture.get_width() as f64, (BULLET_SCALE * 1.5) * bullet_texture.get_height() as f64)
.down_from(ui_bundle.ids.guns_hud[i], 30.0)
.align_middle_x_of(ui_bundle.ids.guns_hud[i])
.set(ui_bundle.ids.bullets_hud[i], &mut ui_cell);

// draw guns depth remaining
let gun_depth_remaining_text = if self.player.borrow().gun_templates[i].borrow().has_gun_depth() {
Expand All @@ -266,7 +276,7 @@ impl World {
conrod_core::widget::Text::new(gun_depth_remaining_text.as_str())
.font_size(18)
.color(conrod_core::color::WHITE)
.mid_bottom_of(ui_bundle.ids.guns_hud[i])
.right_from(ui_bundle.ids.guns_hud[i], 8.0)
.set(ui_bundle.ids.shots_taken_hud[i], &mut ui_cell);

// draw bullets remaining
Expand All @@ -277,11 +287,10 @@ impl World {
};

let bullets_remaining_text = format!("{}/{}", bullets_remaining, 1);

conrod_core::widget::Text::new(bullets_remaining_text.as_str())
.font_size(18)
.color(conrod_core::color::WHITE)
.down_from(ui_bundle.ids.shots_taken_hud[i], 18.0)
.right_from(ui_bundle.ids.bullets_hud[i], 8.0)
.set(ui_bundle.ids.bullets_remaining_hud[i], &mut ui_cell);

id_gun_right = ui_bundle.ids.guns_hud[i];
Expand Down

0 comments on commit f89a02d

Please sign in to comment.