ants/src/main.rs

63 lines
1.7 KiB
Rust

extern crate macroquad;
mod ant;
mod constants;
use crate::ant::Ant;
use constants::*;
use macroquad::color::*;
use macroquad::input::{
is_key_down, is_mouse_button_down, is_quit_requested, mouse_position, KeyCode, MouseButton,
};
use macroquad::miniquad::conf::Conf;
use macroquad::prelude::{
clear_background, draw_texture, get_frame_time, next_frame, Image, Texture2D,
};
fn window_conf() -> Conf {
Conf {
window_title: "Ants".to_string(),
fullscreen: false,
window_width: MAP_WIDTH as i32,
window_height: MAP_HEIGHT as i32,
window_resizable: false,
..Default::default()
}
}
#[macroquad::main(window_conf)]
async fn main() {
//let map = load_texture("map_scaled.png").await.unwrap();
let mut trail_map = Image::gen_image_color(MAP_WIDTH as u16, MAP_HEIGHT as u16, BLACK);
let mut ants = Ant::init(8);
loop {
// fade trails (doesnt really work)
let frame_time = get_frame_time();
trail_map.bytes.iter_mut().for_each(|b| {
if *b > 0 {
*b -= 1;
}
});
// actions
ants.iter_mut().for_each(|ant| {
ant.walk(frame_time, &mut trail_map);
ant.draw(&mut trail_map);
});
if is_key_down(KeyCode::Escape) || is_quit_requested() {
return;
}
if is_mouse_button_down(MouseButton::Left) {
let mouse = mouse_position();
dbg!(&mouse);
//food.push(Food::new(Vec2::new(mouse.0, mouse.1)));
}
// render
clear_background(BLACK);
let texture = Texture2D::from_image(&trail_map);
draw_texture(texture, 0., 0., WHITE);
next_frame().await
}
}