main.rs 2.0KB

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