summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-21 19:33:05 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-21 19:33:05 +0100
commit585d82473ccf566965ded0e50eea1669c3e1cdf3 (patch)
treef63ce7448ad95ae7ac4b2bed11550a315e9db0e6 /src/main.rs
parent420d0f36adeed7fa254497b49ef91a7574628082 (diff)
moving more to constants
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index 164ffe3..624aa5b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -40,7 +40,12 @@ pub fn setup(
let background = asset_server.load("background.png");
let tileset = asset_server.load("tileset.png");
- let atlas = TextureAtlas::from_grid(tileset, Vec2::new(16.0, 16.0), 4, 5);
+ let atlas = TextureAtlas::from_grid(
+ tileset,
+ Vec2::new(constants::TILE_SIZE, constants::TILE_SIZE),
+ 4,
+ 5,
+ );
let atlas_handle = texture_atlases.add(atlas);
commands
@@ -53,7 +58,7 @@ pub fn setup(
y: 0.0,
z: 0.0,
},
- scale: Vec3::splat(3.5),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
},
..Default::default()
@@ -67,7 +72,7 @@ pub fn setup(
y: -200.0,
z: 0.0,
},
- scale: Vec3::splat(3.5),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
},
..Default::default()
@@ -79,28 +84,28 @@ pub fn setup(
transform: Transform {
translation: Vec3 {
x: 225.0,
- y: -200.0 + (-16.0) * 3.5,
+ y: -200.0 + (-constants::TILE_SIZE) * constants::TILE_SCALE,
z: 0.0,
},
- scale: Vec3::splat(3.5),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
},
..Default::default()
});
- for i in 0..constants::COLUMNS {
- for j in 0..constants::ROWS {
+ for i in 0..constants::GRID_SIZE {
+ for j in 0..constants::GRID_SIZE {
commands
.spawn(SpriteSheetBundle {
texture_atlas: atlas_handle.clone(),
sprite: TextureAtlasSprite::new(constants::TILESHEET_NONE1),
transform: Transform {
translation: Vec3 {
- x: ((i as f32) * 16.0 * 3.5) - 320.0,
- y: ((j as f32) * 16.0 * 3.5) - 160.0,
+ x: ((i as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 320.0,
+ y: ((j as f32) * constants::TILE_SIZE * constants::TILE_SCALE) - 160.0,
z: 1.0,
},
- scale: Vec3::splat(3.5),
+ scale: Vec3::splat(constants::TILE_SCALE),
..Default::default()
},
..Default::default()
@@ -161,13 +166,17 @@ fn cosmonaut_detect_system(
.get_primary()
.and_then(|window| window.cursor_position())
{
- cursor_position.x -= 400.0 - 16.0 * 3.5 * 0.5;
- cursor_position.y -= 300.0 - 16.0 * 3.5 * 0.5;
+ cursor_position.x -=
+ (constants::WINDOW_WIDTH / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5;
+ cursor_position.y -=
+ (constants::WINDOW_HEIGHT / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5;
for (transform, sprite) in cell_query.iter_mut() {
if transform.translation.x < cursor_position.x
- && transform.translation.x + 16.0 * 3.5 > cursor_position.x
+ && transform.translation.x + constants::TILE_SIZE * constants::TILE_SCALE
+ > cursor_position.x
&& transform.translation.y < cursor_position.y
- && transform.translation.y + 16.0 * 3.5 > cursor_position.y
+ && transform.translation.y + constants::TILE_SIZE * constants::TILE_SCALE
+ > cursor_position.y
&& sprite.index == constants::TILESHEET_COSMONAUT1
{
commands
@@ -191,8 +200,10 @@ fn mouse_system(
.get_primary()
.and_then(|window| window.cursor_position())
{
- cursor_position.x -= 400.0 - 16.0 * 3.5 * 0.5;
- cursor_position.y -= 300.0 - 16.0 * 3.5 * 0.5;
+ cursor_position.x -=
+ (constants::WINDOW_WIDTH / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5;
+ cursor_position.y -=
+ (constants::WINDOW_HEIGHT / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5;
for (cell, _, mut sprite) in cell_query.iter_mut() {
if cell.selected {
@@ -204,14 +215,15 @@ fn mouse_system(
}
}
- for (mut cell, transform, mut sprite) in cell_query.iter_mut() {
+ for (mut cell, transform, _) in cell_query.iter_mut() {
if transform.translation.x < cursor_position.x
- && transform.translation.x + 16.0 * 3.5 > cursor_position.x
+ && transform.translation.x + constants::TILE_SIZE * constants::TILE_SCALE
+ > cursor_position.x
&& transform.translation.y < cursor_position.y
- && transform.translation.y + 16.0 * 3.5 > cursor_position.y
+ && transform.translation.y + constants::TILE_SIZE * constants::TILE_SCALE
+ > cursor_position.y
{
cell.hovered = true;
- sprite.color.set_a(0.5);
if mouse_button_input.just_pressed(MouseButton::Left) {
cell.selected = true;
}
@@ -273,8 +285,8 @@ pub fn main() {
App::build()
.add_resource(WindowDescriptor {
title: "gems".to_string(),
- width: 800.0,
- height: 600.0,
+ width: constants::WINDOW_WIDTH,
+ height: constants::WINDOW_HEIGHT,
resizable: false,
..Default::default()
})