vec2

Function vec2 

Source
pub const fn vec2(x: f32, y: f32) -> Vec2
Expand description

Creates a 2-dimensional vector.

Examples found in repository?
examples/transform.rs (line 17)
15    fn default() -> Self {
16        Self {
17            position: vec2(800., 600.) / 2., // window center
18            scale: Vec2::splat(8.),
19            angle: 0.,
20            creature: Texture::load_with("examples/tiles.png", Origin::CENTER)
21                .slice(Rect::new(27, 9, 8, 8)),
22        }
23    }
More examples
Hide additional examples
examples/soko.rs (line 50)
39    fn new() -> Self {
40        let tiles = Texture::load("examples/tiles.png");
41
42        let object_slice = tiles.slice(Rect::new(0, 9, 8, 8));
43        let target_slice = tiles.slice(Rect::new(9, 9, 8, 8));
44        let player_slice = tiles.slice(Rect::new(27, 9, 8, 8));
45        let mut wall_slices = Vec::new();
46        for x in 0..4 {
47            wall_slices.push(tiles.slice(Rect::new(x * 9, 0, 8, 8)));
48        }
49
50        let mut player = Entity::new(player_slice, vec2(0., 0.));
51        let mut objects = Vec::new();
52        let mut targets = Vec::new();
53        let mut walls = Vec::new();
54        let map = Vec::from_iter(MAP.split('\n').map(|line| Vec::from_iter(line.chars())));
55
56        for (y, line) in map.iter().enumerate() {
57            for (x, tile) in line.iter().enumerate() {
58                let position = vec2(x as f32, y as f32);
59                match tile {
60                    'O' => targets.push(Entity::new(target_slice.clone(), position)),
61                    '*' => objects.push(Entity::new(object_slice.clone(), position)),
62                    '@' => {
63                        targets.push(Entity::new(target_slice.clone(), position));
64                        objects.push(Entity::new(object_slice.clone(), position));
65                    }
66                    'P' => player.position = position,
67                    '#' => {
68                        let left = map[y].get(x.wrapping_sub(1)) == Some(&'#');
69                        let right = map[y].get(x + 1) == Some(&'#');
70                        let i = left as usize * 2 + right as usize;
71
72                        walls.push(Entity::new(wall_slices[i].clone(), position));
73                    }
74                    _ => continue,
75                }
76            }
77        }
78
79        Self {
80            player,
81            objects,
82            targets,
83            walls,
84            won: false,
85        }
86    }