~starkingdoms/starkingdoms

ref: 494c0b1ca0e58be47c24cf6fd937b57dea1cd1f5 starkingdoms/crates/client/src/ecs.rs -rw-r--r-- 2.1 KiB
494c0b1c — ghostly_zsh player and parts rendering, but jk it doesnt work 9 months ago
                                                                                
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
94
95
96
97
98
99
100
101
use bevy_ecs::bundle::Bundle;
use bevy_ecs::component::Component;
use bevy_ecs::event::Event;
use bevy_ecs::system::Resource;
use nalgebra::Matrix3;
use starkingdoms_common::packet::Packet;
use starkingdoms_common::PlanetType;

#[derive(Component, Debug, Clone, Copy)]
pub struct Translation {
    pub x: f32,
    pub y: f32,
}
impl Translation {
    pub fn as_matrix(&self) -> Matrix3<f32> {
        Matrix3::from_iterator([
            1.0, 0.0, self.x,
            0.0, 1.0, self.y,
            0.0, 0.0, 1.0,
        ])
    }
}

#[derive(Component, Debug, Clone, Copy)]
pub struct Shear {
    pub x: f32,
    pub y: f32,
}
impl Shear {
    pub fn as_matrix(&self) -> Matrix3<f32> {
        Matrix3::from_iterator([
            1.0, self.x, 0.0,
            self.y, 1.0, 0.0,
            0.0, 0.0, 1.0,
        ])
    }
}

#[derive(Component, Debug, Clone, Copy)]
pub struct Scale {
    pub width: f32,
    pub height: f32,
}
impl Scale {
    pub fn as_matrix(&self) -> Matrix3<f32> {
        Matrix3::from_iterator([
            self.width, 0.0, 0.0,
            0.0, self.height, 0.0,
            0.0, 0.0, 1.0
        ])
    }
}
#[derive(Component, Debug, Clone, Copy)]
pub struct Rotation {
    pub radians: f32
}
impl Rotation {
    pub fn as_matrix(&self) -> Matrix3<f32> {
        let x = self.radians.cos();
        let y = self.radians.sin();
        Matrix3::from_iterator([
            x, y, 0.0,
            -y, x, 0.0,
            0.0, 0.0, 1.0
        ])
    }
}

#[derive(Component, Debug, Clone)]
pub struct SpriteTexture {
    pub texture: String,
}

#[derive(Bundle)]
pub struct SpriteBundle {
    pub position: Translation,
    pub shear: Shear,
    pub scale: Scale,
    pub texture: SpriteTexture,
    pub rotation: Rotation
}

#[derive(Resource, Debug)]
pub struct Camera {
    pub x: f32,
    pub y: f32,
    pub shear_x: f32,
    pub shear_y: f32,
    pub zoom: f32,
}

#[derive(Component, Debug, Clone, Copy)]
pub struct Player;

#[derive(Component, Debug, Clone, Copy)]
pub struct Planet(PlanetType);

#[derive(Event, Clone, PartialEq)]
pub struct SendPacket(pub Packet);
#[derive(Event, Clone, PartialEq)]
pub struct RecvPacket(pub Packet);