Skip to content

Commit

Permalink
chore: minor changes + conf
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Jul 24, 2020
1 parent 0c94a1c commit de3b20b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -7,3 +7,8 @@ edition = "2018"
[dependencies]
ggez = "0.5.1"
cgmath = { version = "0.17", features = ["mint"]}


[[bin]]
name="generate_conf"
path="./bin/generate_conf.rs"
11 changes: 11 additions & 0 deletions bin/generate_conf.rs
@@ -0,0 +1,11 @@
use std::fs::File;

use ggez;

pub fn main() -> ggez::GameResult {
let conf = ggez::conf::Conf::new();
let mut config_file = File::create("conf.toml")?;
conf.to_toml_file(&mut config_file);
println!("Generated conf.toml");
Ok(())
}
27 changes: 27 additions & 0 deletions resources/conf.toml
@@ -0,0 +1,27 @@
[window_mode]
width = 800.0
height = 600.0
maximized = false
fullscreen_type = "Windowed"
borderless = false
min_width = 0.0
min_height = 0.0
max_width = 0.0
max_height = 0.0
resizable = true

[window_setup]
title = "batufo"
samples = "Zero"
vsync = true
icon = "/icons/app-icon.png"
srgb = true

[backend]
type = "OpenGL"
major = 3
minor = 2

[modules]
gamepad = false
audio = true
Binary file added resources/icons/app-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 16 additions & 28 deletions src/main.rs
@@ -1,37 +1,28 @@
//! Basic hello world example.

use std::env;
use std::path;

use cgmath;
use ggez;

use ggez::event;
use ggez::graphics;
use ggez::{Context, GameResult};
use std::env;
use std::path;

// First we make a structure to contain the game's state
struct MainState {
frames: usize,
text: graphics::Text,
font: graphics::Font,
}

impl MainState {
fn new(ctx: &mut Context) -> GameResult<MainState> {
// The ttf file will be in your resources directory. Later, we
// will mount that directory so we can omit it in the path here.
let font = graphics::Font::new(ctx, "/fonts/RobotoMono.ttf")?;
let text = graphics::Text::new(("Hello world!", font, 48.0));

let s = MainState { frames: 0, text };
let s = MainState { frames: 0, font };
Ok(s)
}
}

// Then we implement the `ggez:event::EventHandler` trait on it, which
// requires callbacks for updating and drawing the game state each frame.
//
// The `EventHandler` trait also contains callbacks for event handling
// that you can override if you wish, but the defaults are fine.
impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
Ok(())
Expand All @@ -40,10 +31,15 @@ impl event::EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx, [0.1, 0.2, 0.3, 1.0].into());

// Drawables are drawn from their top-left corner.
let offset = self.frames as f32 / 10.0;
let dest_point = cgmath::Point2::new(offset, offset);
graphics::draw(ctx, &self.text, (dest_point,))?;
let text = graphics::Text::new((
format!("Frame: {}, Hello world! at {}", self.frames, offset),
self.font,
48.0,
));

graphics::draw(ctx, &text, (dest_point,))?;
graphics::present(ctx)?;

self.frames += 1;
Expand All @@ -55,17 +51,7 @@ impl event::EventHandler for MainState {
}
}

// Now our main function, which does three things:
//
// * First, create a new `ggez::ContextBuilder`
// object which contains configuration info on things such
// as screen resolution and window title.
// * Second, create a `ggez::game::Game` object which will
// do the work of creating our MainState and running our game.
// * Then, just call `game.run()` which runs the `Game` mainloop.
pub fn main() -> GameResult {
// We add the CARGO_MANIFEST_DIR/resources to the resource paths
// so that ggez will look in our cargo project directory for files.
let resource_dir = if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
let mut path = path::PathBuf::from(manifest_dir);
path.push("resources");
Expand All @@ -74,8 +60,10 @@ pub fn main() -> GameResult {
path::PathBuf::from("./resources")
};

let cb = ggez::ContextBuilder::new("helloworld", "ggez").add_resource_path(resource_dir);
let (ctx, event_loop) = &mut cb.build()?;
let context_builder = ggez::ContextBuilder::new("batufo", "Thorsten Lorenz")
.with_conf_file(true)
.add_resource_path(resource_dir);
let (ctx, event_loop) = &mut context_builder.build()?;

let state = &mut MainState::new(ctx)?;
event::run(ctx, event_loop, state)
Expand Down

0 comments on commit de3b20b

Please sign in to comment.