-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgame_context.rs
More file actions
55 lines (45 loc) · 1.21 KB
/
game_context.rs
File metadata and controls
55 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use peacock::graphics::{self, DrawTextParams, Font, Text};
use peacock::{ContextBuilder, Result, State, Vector2f};
type Context = peacock::Context<GameContext>;
struct GameContext {
font: Font,
}
impl GameContext {
fn new(ctx: &mut peacock::Context<()>) -> Result<Self> {
Ok(Self {
font: Font::from_file(ctx, "examples/res/Roboto-Regular.ttf", 24)?,
})
}
}
struct GameContextExample {
message: Text,
}
impl GameContextExample {
fn new(ctx: &mut Context) -> Result<Self> {
Ok(Self {
message: Text::new(ctx, "Hello", &ctx.game().font)?,
})
}
}
impl State for GameContextExample {
type Context = GameContext;
fn update(&mut self, _ctx: &mut Context) -> Result<()> {
Ok(())
}
fn draw(&mut self, ctx: &mut Context, _dt: f64) -> Result<()> {
graphics::draw(
ctx,
&self.message,
&DrawTextParams {
position: Vector2f::ZERO,
..Default::default()
},
)?;
Ok(())
}
}
fn main() -> Result<()> {
ContextBuilder::new("Game Context", 1920, 1080)
.build(GameContext::new)?
.run_with_result(GameContextExample::new)
}