ants/src/main.rs

60 lines
1.6 KiB
Rust
Raw Normal View History

2021-10-06 00:56:06 +00:00
extern crate macroquad;
2021-10-03 19:49:30 +00:00
mod ant;
mod constants;
2021-10-03 20:23:57 +00:00
use crate::ant::Ant;
2021-10-06 15:47:04 +00:00
use constants::*;
use macroquad::color::*;
2021-10-06 17:18:48 +00:00
use macroquad::input::{is_key_down, is_quit_requested, KeyCode};
2021-10-06 15:47:04 +00:00
use macroquad::miniquad::conf::Conf;
use macroquad::prelude::{
clear_background, draw_texture, get_frame_time, next_frame, Image, Texture2D,
};
2021-10-06 17:18:48 +00:00
use macroquad::text::draw_text;
use macroquad::time::get_fps;
fn window_conf() -> Conf {
Conf {
window_title: "Ants".to_string(),
fullscreen: false,
2021-10-06 00:56:06 +00:00
window_width: MAP_WIDTH as i32,
window_height: MAP_HEIGHT as i32,
2021-10-06 15:47:04 +00:00
window_resizable: false,
..Default::default()
}
2021-10-03 10:19:24 +00:00
}
#[macroquad::main(window_conf)]
async fn main() {
2021-10-06 00:56:06 +00:00
//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);
2021-10-03 19:59:18 +00:00
loop {
2021-10-06 00:56:06 +00:00
// fade trails (doesnt really work)
let frame_time = get_frame_time();
2021-10-06 09:30:53 +00:00
trail_map.bytes.iter_mut().for_each(|b| {
if *b > 0 {
*b -= 1;
2021-10-06 00:56:06 +00:00
}
2021-10-06 09:30:53 +00:00
});
// 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;
}
// render
2021-10-06 00:56:06 +00:00
clear_background(BLACK);
let texture = Texture2D::from_image(&trail_map);
draw_texture(texture, 0., 0., WHITE);
2021-10-06 17:18:48 +00:00
draw_text(&get_fps().to_string(), 0., 20., 20., WHITE);
next_frame().await
}
}