main.rs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. use std::env;
  2. use std::path;
  3. use scene::main::MainState;
  4. use ggez::{event, GameResult};
  5. use glam::Vec2;
  6. mod behavior;
  7. mod physics;
  8. mod scene;
  9. mod ui;
  10. type Point2 = Vec2;
  11. type WindowPoint = Vec2;
  12. type Offset = Vec2;
  13. type ScenePoint = Vec2;
  14. type Vector2 = Vec2;
  15. const TARGET_FPS: u32 = 60; // execute update code 60x per seconds
  16. const META_EACH: u32 = 20; // execute meta code each 20 frames
  17. const PHYSICS_EACH: u32 = 10; // execute physics code each 10 frames
  18. const ANIMATE_EACH: u32 = 60; // execute animate code each 30 frames
  19. const SPRITE_EACH: u32 = 10; // change sprite animation tile 30 frames
  20. const MAX_FRAME_I: u32 = 4294967295; // max of frame_i used to calculate ticks
  21. const DISPLAY_OFFSET_BY: f32 = 3.0; // pixel offset by tick when player move screen display
  22. const DISPLAY_OFFSET_BY_SPEED: f32 = 10.0; // pixel offset by tick when player move screen display with speed
  23. const SCENE_ITEMS_SPRITE_SHEET_WIDTH: f32 = 800.0; // Width of sprite sheet
  24. const SCENE_ITEMS_SPRITE_SHEET_HEIGHT: f32 = 600.0; // Height of sprite sheet
  25. const UI_SPRITE_SHEET_WIDTH: f32 = 800.0; // Width of sprite sheet
  26. const UI_SPRITE_SHEET_HEIGHT: f32 = 600.0; // Height of sprite sheet
  27. const GRID_TILE_WIDTH: f32 = 5.0; // Width of one grid tile
  28. const GRID_TILE_HEIGHT: f32 = 5.0; // Height of one grid tile
  29. const DEFAULT_SELECTED_SQUARE_SIDE: f32 = 14.0;
  30. const DEFAULT_SELECTED_SQUARE_SIDE_HALF: f32 = DEFAULT_SELECTED_SQUARE_SIDE / 2.0;
  31. const SCENE_ITEMS_CHANGE_ERR_MSG: &str = "scene_items content change !";
  32. pub fn main() -> GameResult {
  33. let resource_dir = if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
  34. let mut path = path::PathBuf::from(manifest_dir);
  35. path.push("resources");
  36. path
  37. } else {
  38. path::PathBuf::from("./resources")
  39. };
  40. let cb = ggez::ContextBuilder::new("oc", "bux")
  41. .add_resource_path(resource_dir)
  42. .window_mode(ggez::conf::WindowMode::default().dimensions(800.0, 600.0));
  43. let (mut ctx, event_loop) = cb.build()?;
  44. let state = MainState::new(&mut ctx)?;
  45. event::run(ctx, event_loop, state)
  46. }