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
|
|
|
mod food;
|
2021-10-03 19:49:30 +00:00
|
|
|
|
2021-10-03 20:23:57 +00:00
|
|
|
use crate::ant::Ant;
|
2021-10-06 00:56:06 +00:00
|
|
|
use constants::{MAP_HEIGHT, MAP_WIDTH};
|
2021-10-03 20:23:57 +00:00
|
|
|
use macroquad::prelude::*;
|
2021-10-03 10:39:27 +00:00
|
|
|
|
|
|
|
fn window_conf() -> Conf {
|
|
|
|
Conf {
|
2021-10-03 19:23:32 +00:00
|
|
|
window_title: "Ants".to_string(),
|
2021-10-03 10:39:27 +00:00
|
|
|
fullscreen: false,
|
2021-10-06 00:56:06 +00:00
|
|
|
window_width: MAP_WIDTH as i32,
|
|
|
|
window_height: MAP_HEIGHT as i32,
|
2021-10-03 10:39:27 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
2021-10-03 10:19:24 +00:00
|
|
|
}
|
2021-10-03 10:39:27 +00:00
|
|
|
|
2021-10-03 20:23:57 +00:00
|
|
|
trait Drawable {
|
|
|
|
fn draw(&self);
|
|
|
|
}
|
|
|
|
|
2021-10-03 10:39:27 +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(1024);
|
2021-10-03 19:59:18 +00:00
|
|
|
|
2021-10-03 10:39:27 +00:00
|
|
|
loop {
|
2021-10-06 00:56:06 +00:00
|
|
|
// fade trails (doesnt really work)
|
|
|
|
let frame_time = get_frame_time();
|
|
|
|
for x in 0..MAP_WIDTH {
|
|
|
|
for y in 0..MAP_HEIGHT {
|
|
|
|
let mut current_pixel = trail_map.get_pixel(x, y);
|
|
|
|
current_pixel.r -= 0.1 * frame_time;
|
|
|
|
current_pixel.g -= 0.1 * frame_time;
|
|
|
|
current_pixel.b -= 0.1 * frame_time;
|
|
|
|
trail_map.set_pixel(x, y, current_pixel);
|
|
|
|
}
|
|
|
|
}
|
2021-10-03 19:23:32 +00:00
|
|
|
// actions
|
2021-10-06 00:56:06 +00:00
|
|
|
ants.iter_mut()
|
|
|
|
.for_each(|ant| ant.walk(frame_time, &mut trail_map));
|
2021-10-03 10:39:27 +00:00
|
|
|
if is_key_down(KeyCode::Escape) || is_quit_requested() {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-03 20:23:57 +00:00
|
|
|
if is_mouse_button_down(MouseButton::Left) {
|
|
|
|
let mouse = mouse_position();
|
2021-10-06 00:56:06 +00:00
|
|
|
dbg!(&mouse);
|
|
|
|
//food.push(Food::new(Vec2::new(mouse.0, mouse.1)));
|
2021-10-03 20:23:57 +00:00
|
|
|
}
|
2021-10-03 10:39:27 +00:00
|
|
|
|
2021-10-03 19:23:32 +00:00
|
|
|
// 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-03 19:23:32 +00:00
|
|
|
ants.iter().for_each(|ant| ant.draw());
|
|
|
|
|
2021-10-03 10:39:27 +00:00
|
|
|
next_frame().await
|
|
|
|
}
|
2021-10-03 19:23:32 +00:00
|
|
|
}
|