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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use nalgebra as na;
use raylib::prelude::*;
use crate::{
discord::DiscordChannel,
global_resource_package::GlobalResources,
rendering::utilities::{anim_texture::AnimatedTexture, map_render::MapRenderer},
};
#[derive(Debug)]
pub struct TestFoxScene {
fox_animation: AnimatedTexture,
world_map: MapRenderer,
camera: Camera2D,
}
impl TestFoxScene {
pub fn new(raylib_handle: &mut RaylibHandle, thread: &RaylibThread) -> Self {
let fox = AnimatedTexture::new(raylib_handle, thread, "chr", "testFox").unwrap();
let map_renderer = MapRenderer::new("map_gameMap.tmx", raylib_handle, thread).unwrap();
let camera = Camera2D {
target: Vector2 { x: 0.0, y: 0.0 },
offset: Vector2 {
x: raylib_handle.get_screen_width() as f32,
y: (raylib_handle.get_screen_height() as f32) * -0.5,
},
rotation: 0.0,
zoom: 1.0,
};
Self {
fox_animation: fox,
world_map: map_renderer,
camera,
}
}
pub async fn render_frame(
&mut self,
raylib: &mut RaylibHandle,
rl_thread: &RaylibThread,
discord: &DiscordChannel,
global_resources: &GlobalResources,
) {
let mut draw = raylib.begin_drawing(rl_thread);
draw.clear_background(Color::WHITE);
self.fox_animation.render_automatic(
&mut draw,
na::Vector2::new(0.0, 0.0),
None,
None,
None,
None,
);
if draw.is_key_down(KeyboardKey::KEY_W) {
self.camera.target.y -= 5.0;
}
if draw.is_key_down(KeyboardKey::KEY_S) {
self.camera.target.y += 5.0;
}
if draw.is_key_down(KeyboardKey::KEY_A) {
self.camera.target.x -= 5.0;
}
if draw.is_key_down(KeyboardKey::KEY_D) {
self.camera.target.x += 5.0;
}
{
let mut ctx2d = draw.begin_mode2D(self.camera);
self.world_map.render_map(&mut ctx2d, &self.camera, true);
}
}
}