Bastien Sevajol 3 år sedan
förälder
incheckning
f988962d5e
2 ändrade filer med 32 tillägg och 19 borttagningar
  1. 1 1
      src/map/mod.rs
  2. 31 18
      src/scene/main.rs

+ 1 - 1
src/map/mod.rs Visa fil

@@ -44,7 +44,7 @@ fn get_tile_from_terrain_tileset_with_id(
44 44
             let relative_tile_height = tile_height as f32 / terrain_image_height as f32;
45 45
             let len_by_width = terrain_image_width / tile_width;
46 46
             let tile_y = tile.id / len_by_width;
47
-            let tile_x = tile.id  - (tile_y * len_by_width);
47
+            let tile_x = tile.id - (tile_y * len_by_width);
48 48
 
49 49
             return GameResult::Ok(Tile::from_str_id(
50 50
                 &str_id,

+ 31 - 18
src/scene/main.rs Visa fil

@@ -4,7 +4,7 @@ use std::f32::consts::FRAC_PI_2;
4 4
 
5 5
 use ggez::event::MouseButton;
6 6
 use ggez::graphics::{DrawMode, MeshBuilder, StrokeOptions};
7
-use ggez::input::keyboard::{KeyCode, pressed_keys};
7
+use ggez::input::keyboard::{pressed_keys, KeyCode};
8 8
 use ggez::timer::check_update_time;
9 9
 use ggez::{event, graphics, input, Context, GameResult};
10 10
 
@@ -69,29 +69,28 @@ pub struct MainState {
69 69
     scene_item_prepare_order: Option<SceneItemPrepareOrder>,
70 70
 }
71 71
 
72
-
73
-fn update_terrain_batch(mut terrain_batch: graphics::spritebatch::SpriteBatch,  map: &Map) -> graphics::spritebatch::SpriteBatch {
72
+fn update_terrain_batch(
73
+    mut terrain_batch: graphics::spritebatch::SpriteBatch,
74
+    map: &Map,
75
+) -> graphics::spritebatch::SpriteBatch {
74 76
     terrain_batch.clear();
75 77
     for ((grid_x, grid_y), tile) in map.tiles.iter() {
76
-            // FIXME pre compute these data
77
-            let src_x = tile.tile_x as f32 * tile.relative_tile_width;
78
-            let src_y = tile.tile_y as f32 * tile.relative_tile_height;
79
-            let dest_x = *grid_x as f32 * tile.tile_width as f32;
80
-            let dest_y = *grid_y as f32 * tile.tile_height as f32;
81
-            terrain_batch.add(
82
-                graphics::DrawParam::new()
78
+        // FIXME pre compute these data
79
+        let src_x = tile.tile_x as f32 * tile.relative_tile_width;
80
+        let src_y = tile.tile_y as f32 * tile.relative_tile_height;
81
+        let dest_x = *grid_x as f32 * tile.tile_width as f32;
82
+        let dest_y = *grid_y as f32 * tile.tile_height as f32;
83
+        terrain_batch.add(
84
+            graphics::DrawParam::new()
83 85
                 .src(graphics::Rect::new(
84 86
                     src_x,
85 87
                     src_y,
86 88
                     tile.relative_tile_width,
87 89
                     tile.relative_tile_height,
88 90
                 ))
89
-                .dest(ScenePoint::new(
90
-                    dest_x,
91
-                    dest_y,
92
-                ))
93
-            );
94
-        }
91
+                .dest(ScenePoint::new(dest_x, dest_y)),
92
+        );
93
+    }
95 94
 
96 95
     terrain_batch
97 96
 }
@@ -208,13 +207,27 @@ impl MainState {
208 207
         }
209 208
 
210 209
         if input::keyboard::is_key_pressed(ctx, KeyCode::F12) {
211
-            if  self.last_key_consumed.get(&KeyCode::F12).unwrap_or(&self.start).elapsed().as_millis() > 250 {
210
+            if self
211
+                .last_key_consumed
212
+                .get(&KeyCode::F12)
213
+                .unwrap_or(&self.start)
214
+                .elapsed()
215
+                .as_millis()
216
+                > 250
217
+            {
212 218
                 self.debug = !self.debug;
213 219
                 self.last_key_consumed.insert(KeyCode::F12, Instant::now());
214 220
             }
215 221
         }
216 222
         if input::keyboard::is_key_pressed(ctx, KeyCode::F10) {
217
-            if  self.last_key_consumed.get(&KeyCode::F10).unwrap_or(&self.start).elapsed().as_millis() > 250 {
223
+            if self
224
+                .last_key_consumed
225
+                .get(&KeyCode::F10)
226
+                .unwrap_or(&self.start)
227
+                .elapsed()
228
+                .as_millis()
229
+                > 250
230
+            {
218 231
                 self.debug_terrain = !self.debug_terrain;
219 232
                 self.last_key_consumed.insert(KeyCode::F10, Instant::now());
220 233
             }