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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
extern crate gate;
use gate::{App, Audio};
use gate::app_info::AppInfo;
use gate::input::*;
use gate::renderer::{Renderer, Affine};
mod asset_id { include!(concat!(env!("OUT_DIR"), "/asset_id.rs")); }
use asset_id::*;
mod geometry;
use geometry::*;
mod entities;
use entities::bug::Bug;
struct BugBasherGame {
bugs: Vec<Bug>
}
impl App<AssetId> for BugBasherGame {
fn start(&mut self, _audio: &mut Audio<AssetId>) {
}
fn advance(&mut self, seconds: f64, _audio: &mut Audio<AssetId>) -> bool {
self.bugs.retain(|b| b.alive);
for bug in self.bugs.iter_mut() {
bug.advance(seconds);
}
true
}
fn input(&mut self, evt: InputEvent, _audio: &mut Audio<AssetId>) -> bool {
match evt {
InputEvent::MousePressed(MouseButton::Left, x, y) => {
for bug in self.bugs.iter_mut() {
bug.click(Vec2d { x, y });
}
},
_ => {}
}
true
}
fn render(&mut self, renderer: &mut Renderer<AssetId>) {
renderer.clear((255,255,255));
{
let mut renderer = renderer.sprite_mode();
for bug in &self.bugs {
renderer.draw(
&Affine::translate(bug.pos.x, bug.pos.y).pre_rotate(bug.rotation),
SpriteId::Bug
);
}
}
}
}
impl BugBasherGame {
}
fn main() {
let info = AppInfo::with_app_height(1000.).title("Bug Basher").build();
gate::run(info, BugBasherGame {
bugs: vec!(
Bug::new(500., 200., 0.3),
Bug::new(-200., -200., 1.5),
Bug::new(-1000., 200., 0.),
Bug::new(1200., 0., 0.3),
Bug::new(-1300., 0., 1.5),
Bug::new(0., 1100., 0.),
Bug::new(0., -1500., 0.3),
Bug::new(300., -1200., 1.5),
)
});
}
|