Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use engine::world;
- use glutin_window::GlutinWindow as Window;
- use opengl_graphics::{ GlGraphics, OpenGL };
- use piston::input::*;
- use graphics::*;
- use grenderer::unitcolors;
- use piston::window::Window as PistonWindow;
- const TILES_PER_LINE: u64 = 32;
- pub struct Game<'a> {
- pub gameworld: world::World<'a>,
- pub gamedraw: GlGraphics,
- pub gamewindow: Window,
- pub backround: [f32; 4],
- pub tiles: [[[f32; 4]; 32]; 32],
- pub viewzone: [u64; 2],
- }
- impl<'a> Game<'a> {
- pub fn render(&mut self, args: &RenderArgs) {
- let backround = self.backround;
- let window = &self.gamewindow;
- let tiles = &self.tiles;
- let tilespace_x = (window.size().width / 4) * 3;
- let tilespace_y = (window.size().height / 4) * 3;
- let tilesize = tilespace_x as u64 / TILES_PER_LINE;
- let square = rectangle::square(0.0, 0.0, tilesize as f64);
- self.gamedraw.draw(args.viewport(), |c, gl| {
- clear(backround, gl);
- let mut posmultx = 0;
- let mut posmulty = 0;
- for i in tiles {
- posmulty=0;
- for j in i {
- let transform = c.transform.trans((posmultx*tilesize) as f64, (posmulty*tilesize) as f64)
- .rot_rad(0.0)
- .trans(tilesize as f64 * -1.0, tilesize as f64 * -1.0);
- rectangle(*j, square, transform, gl);
- posmulty += 1;
- }
- posmultx += 1;
- }
- });
- }
- pub fn update(&mut self, args: &UpdateArgs) {
- let mut posx = 0;
- let mut posy = 0;
- let mut newtiles: [[[f32; 4]; 32]; 32] = [[[0.0; 4]; 32]; 32];
- for i in &self.tiles {
- posy=0;
- for j in i {
- match self.gameworld.unitmap.get(&world::Position { x: (posx + self.viewzone[0]) as i64, y: (posy + self.viewzone[1]) as i64}) {
- Some(unit) => {
- newtiles[posx as usize][posy as usize] = unitcolors::matchunit(&unit)
- }
- None => {
- newtiles[posx as usize][posy as usize] = [1.0; 4]
- }
- }
- posy += 1;
- }
- posx += 1;
- }
- self.tiles = newtiles;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement