Browse Source

sprite_info in object

Bastien Sevajol 3 years ago
parent
commit
49dfb7998a
1 changed files with 8 additions and 9 deletions
  1. 8 9
      src/main.rs

+ 8 - 9
src/main.rs View File

8
 use std::path;
8
 use std::path;
9
 
9
 
10
 struct SpriteInfo {
10
 struct SpriteInfo {
11
-    source: graphics::Rect,
11
+    start: na::Point2<f32>,
12
     tile_count: u16,
12
     tile_count: u16,
13
     relative_tile_width: f32,
13
     relative_tile_width: f32,
14
     relative_tile_height: f32,
14
     relative_tile_height: f32,
15
 }
15
 }
16
 
16
 
17
 impl SpriteInfo {
17
 impl SpriteInfo {
18
-    pub fn new(source: graphics::Rect, tile_count: u16) -> Self {
18
+    pub fn new(start: na::Point2<f32>, tile_count: u16) -> Self {
19
         let relative_tile_width: f32 = 1.0 / tile_count as f32;
19
         let relative_tile_width: f32 = 1.0 / tile_count as f32;
20
         Self {
20
         Self {
21
-            source,
21
+            start,
22
             tile_count,
22
             tile_count,
23
             relative_tile_width,
23
             relative_tile_width,
24
             relative_tile_height: 1.0,
24
             relative_tile_height: 1.0,
27
 
27
 
28
     pub fn from_type(type_: &SpriteType) -> Self {
28
     pub fn from_type(type_: &SpriteType) -> Self {
29
         match type_ {
29
         match type_ {
30
-            SpriteType::WalkingSoldier => Self::new(graphics::Rect::new(0.0, 0.0, 128.0, 24.0), 7),
30
+            SpriteType::WalkingSoldier => Self::new(na::Point2::new(0.0, 0.0), 7),
31
         }
31
         }
32
     }
32
     }
33
 }
33
 }
50
 }
50
 }
51
 
51
 
52
 struct SceneItem {
52
 struct SceneItem {
53
-    current_sprite_type: SpriteType,
53
+    sprite_info: SpriteInfo,
54
     position: na::Point2<f32>,
54
     position: na::Point2<f32>,
55
 }
55
 }
56
 
56
 
57
 impl SceneItem {
57
 impl SceneItem {
58
-    pub fn new(current_sprite_type: SpriteType, position: na::Point2<f32>) -> Self {
58
+    pub fn new(sprite_type: SpriteType, position: na::Point2<f32>) -> Self {
59
         Self {
59
         Self {
60
-            current_sprite_type,
60
+            sprite_info: SpriteInfo::from_type(&sprite_type),
61
             position,
61
             position,
62
         }
62
         }
63
     }
63
     }
107
         graphics::clear(ctx, graphics::BLACK);
107
         graphics::clear(ctx, graphics::BLACK);
108
 
108
 
109
         for scene_item in self.scene_items.iter() {
109
         for scene_item in self.scene_items.iter() {
110
-            let sprite_info = SpriteInfo::from_type(&scene_item.current_sprite_type);
111
-            let sprite_batch_part = sprite_batch_part_from_sprite_info(&sprite_info, self.i)
110
+            let sprite_batch_part = sprite_batch_part_from_sprite_info(&scene_item.sprite_info, self.i)
112
                 .dest(scene_item.position.clone());
111
                 .dest(scene_item.position.clone());
113
             self.scene_items_sprite_batch.add(sprite_batch_part);
112
             self.scene_items_sprite_batch.add(sprite_batch_part);
114
         }
113
         }