Browse Source

upgrade to ggez 6.0rc1

Bastien Sevajol 3 years ago
parent
commit
69dca4a6f2
6 changed files with 967 additions and 703 deletions
  1. 1 0
      .gitignore
  2. 948 683
      Cargo.lock
  3. 2 4
      Cargo.toml
  4. BIN
      resources/map1bg.png
  5. BIN
      resources/test.png
  6. 16 16
      src/main.rs

+ 1 - 0
.gitignore View File

1
 /target
1
 /target
2
 .idea
2
 .idea
3
+*~

File diff suppressed because it is too large
+ 948 - 683
Cargo.lock


+ 2 - 4
Cargo.toml View File

4
 authors = ["Sevajol Bastien <contact@bux.fr>"]
4
 authors = ["Sevajol Bastien <contact@bux.fr>"]
5
 edition = "2018"
5
 edition = "2018"
6
 
6
 
7
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
-
9
 [dependencies]
7
 [dependencies]
10
-ggez = "0.5.1"
11
-glam = "0.14.0"
8
+ggez = { git = "https://github.com/ggez/ggez", tag = "0.6.0-rc0" }
9
+glam = "0.12.0"

BIN
resources/map1bg.png View File


BIN
resources/test.png View File


+ 16 - 16
src/main.rs View File

2
 use ggez::event::KeyCode;
2
 use ggez::event::KeyCode;
3
 use ggez::graphics;
3
 use ggez::graphics;
4
 use ggez::graphics::{DrawMode, MeshBuilder};
4
 use ggez::graphics::{DrawMode, MeshBuilder};
5
-use ggez::nalgebra as na;
6
 use ggez::timer::check_update_time;
5
 use ggez::timer::check_update_time;
7
 use ggez::{event, input};
6
 use ggez::{event, input};
8
 use ggez::{Context, GameResult};
7
 use ggez::{Context, GameResult};
10
 use std::env;
9
 use std::env;
11
 use std::path;
10
 use std::path;
12
 
11
 
12
+type Point2 = Vec2;
13
 type Vector2 = Vec2;
13
 type Vector2 = Vec2;
14
 
14
 
15
 const TARGET_FPS: u32 = 60; // execute update code 60x per seconds
15
 const TARGET_FPS: u32 = 60; // execute update code 60x per seconds
90
 }
90
 }
91
 
91
 
92
 struct SceneItem {
92
 struct SceneItem {
93
-    position: na::Point2<f32>,
93
+    position: Point2,
94
     state: ItemState,
94
     state: ItemState,
95
     meta_events: Vec<MetaEvent>,
95
     meta_events: Vec<MetaEvent>,
96
     current_frame: u16,
96
     current_frame: u16,
97
 }
97
 }
98
 
98
 
99
 impl SceneItem {
99
 impl SceneItem {
100
-    pub fn new(position: na::Point2<f32>, state: ItemState) -> Self {
100
+    pub fn new(position: Point2, state: ItemState) -> Self {
101
         let sprite_type = state.sprite_type();
101
         let sprite_type = state.sprite_type();
102
         Self {
102
         Self {
103
             position,
103
             position,
129
                 sprite_info.relative_tile_height,
129
                 sprite_info.relative_tile_height,
130
             ))
130
             ))
131
             .rotation(90.0f32.to_radians())
131
             .rotation(90.0f32.to_radians())
132
-            .offset(na::Point2::new(0.5, 0.5))
132
+            .offset(Point2::new(0.5, 0.5))
133
     }
133
     }
134
 }
134
 }
135
 
135
 
147
     map_batch: graphics::spritebatch::SpriteBatch,
147
     map_batch: graphics::spritebatch::SpriteBatch,
148
     scene_items: Vec<SceneItem>,
148
     scene_items: Vec<SceneItem>,
149
     physics_events: Vec<PhysicEvent>,
149
     physics_events: Vec<PhysicEvent>,
150
-    display_offset: na::Point2<f32>,
150
+    display_offset: Point2,
151
 }
151
 }
152
 
152
 
153
 impl MainState {
153
 impl MainState {
167
                 };
167
                 };
168
 
168
 
169
                 scene_items.push(SceneItem::new(
169
                 scene_items.push(SceneItem::new(
170
-                    na::Point2::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
170
+                    Point2::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
171
                     ItemState::new(current_behavior),
171
                     ItemState::new(current_behavior),
172
                 ));
172
                 ));
173
             }
173
             }
179
             map_batch,
179
             map_batch,
180
             scene_items,
180
             scene_items,
181
             physics_events: vec![],
181
             physics_events: vec![],
182
-            display_offset: na::Point2::new(0.0, 0.0),
182
+            display_offset: Point2::new(0.0, 0.0),
183
         };
183
         };
184
         Ok(s)
184
         Ok(s)
185
     }
185
     }
274
         }
274
         }
275
     }
275
     }
276
 
276
 
277
-    fn position_with_display_offset(&self, position: &na::Point2<f32>) -> na::Point2<f32> {
278
-        na::Point2::new(
277
+    fn position_with_display_offset(&self, position: &Point2) -> Point2 {
278
+        Point2::new(
279
             position.x + self.display_offset.x,
279
             position.x + self.display_offset.x,
280
             position.y + self.display_offset.y,
280
             position.y + self.display_offset.y,
281
         )
281
         )
344
                 2.0,
344
                 2.0,
345
                 2.0,
345
                 2.0,
346
                 graphics::WHITE,
346
                 graphics::WHITE,
347
-            );
347
+            )?;
348
         }
348
         }
349
         self.map_batch.add(
349
         self.map_batch.add(
350
             graphics::DrawParam::new()
350
             graphics::DrawParam::new()
351
                 .src(graphics::Rect::new(0.0, 0.0, 1.0, 1.0))
351
                 .src(graphics::Rect::new(0.0, 0.0, 1.0, 1.0))
352
-                .dest(na::Point2::new(0.0, 0.0)),
352
+                .dest(Point2::new(0.0, 0.0)),
353
         );
353
         );
354
 
354
 
355
         let mesh = mesh_builder.build(ctx)?;
355
         let mesh = mesh_builder.build(ctx)?;
357
             ctx,
357
             ctx,
358
             &self.map_batch,
358
             &self.map_batch,
359
             graphics::DrawParam::new()
359
             graphics::DrawParam::new()
360
-                .dest(self.position_with_display_offset(&na::Point2::new(0.0, 0.0))),
360
+                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
361
         )?;
361
         )?;
362
         graphics::draw(
362
         graphics::draw(
363
             ctx,
363
             ctx,
364
             &self.sprite_sheet_batch,
364
             &self.sprite_sheet_batch,
365
             graphics::DrawParam::new()
365
             graphics::DrawParam::new()
366
-                .dest(self.position_with_display_offset(&na::Point2::new(0.0, 0.0))),
366
+                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
367
         )?;
367
         )?;
368
         graphics::draw(
368
         graphics::draw(
369
             ctx,
369
             ctx,
370
             &mesh,
370
             &mesh,
371
             graphics::DrawParam::new()
371
             graphics::DrawParam::new()
372
-                .dest(self.position_with_display_offset(&na::Point2::new(0.0, 0.0))),
372
+                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
373
         )?;
373
         )?;
374
 
374
 
375
         self.sprite_sheet_batch.clear();
375
         self.sprite_sheet_batch.clear();
393
     let cb = ggez::ContextBuilder::new("oc", "bux")
393
     let cb = ggez::ContextBuilder::new("oc", "bux")
394
         .add_resource_path(resource_dir)
394
         .add_resource_path(resource_dir)
395
         .window_mode(ggez::conf::WindowMode::default().dimensions(800.0, 600.0));
395
         .window_mode(ggez::conf::WindowMode::default().dimensions(800.0, 600.0));
396
-    let (ctx, event_loop) = &mut cb.build()?;
396
+    let (mut ctx, event_loop) = cb.build()?;
397
 
397
 
398
-    let state = &mut MainState::new(ctx)?;
398
+    let state = MainState::new(&mut ctx)?;
399
     event::run(ctx, event_loop, state)
399
     event::run(ctx, event_loop, state)
400
 }
400
 }