feat: Initial commit

This commit is contained in:
uttarayan21
2024-06-16 21:02:22 +05:30
commit d96fd68357
7 changed files with 708 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
use macroquad::prelude::*;
use once_cell::sync::Lazy;
pub struct Character {
pos: Vec2,
pointing: Vec2,
velocity: Vec2,
}
// static BACKGROUND_TEXTURE: Lazy<Texture2D> =
// Lazy::new(|| Texture2D::from_file_with_format(include_bytes!("../assets/grass.png"), None));
#[macroquad::main("Tadventure")]
async fn main() {
let mut character = Character::new(
Vec2::new(100.0, 100.0),
Vec2::new(0.0, 0.0),
vec2(0f32, 0f32),
);
let mut cursor = Cursor::new();
loop {
clear_background(GREEN);
// draw_texture(&BACKGROUND_TEXTURE, 0.0, 0.0, WHITE);
character.handle_inputs();
character.draw();
cursor.handle_mouse();
cursor.draw();
next_frame().await
}
}
impl Character {
pub fn new(pos: Vec2, pointing: Vec2, velocity: Vec2) -> Self {
Self {
pos,
pointing,
velocity,
}
}
pub fn handle_inputs(&mut self) {
self.handle_mouse();
let distance = self.pos.distance(self.pointing);
self.pos = self.pos.move_towards(self.pointing, distance / 15f32);
}
pub fn handle_mouse(&mut self) {
let mouse_pos = mouse_position();
self.pointing = vec2(mouse_pos.0, mouse_pos.1);
}
pub fn draw(&self) {
draw_circle(self.pos.x, self.pos.y, 16.0, BLUE);
draw_line(
self.pos.x,
self.pos.y,
self.pointing.x,
self.pointing.y,
5.0,
RED,
);
}
}
pub struct Cursor {
pos: Vec2,
}
impl Cursor {
pub fn new() -> Self {
Self {
pos: vec2(0.0, 0.0),
}
}
pub fn handle_mouse(&mut self) {
let mouse_pos = mouse_position();
self.pos = vec2(mouse_pos.0, mouse_pos.1);
}
pub fn draw(&self) {
draw_triangle(
self.pos,
self.pos + vec2(10.0, 14.0),
self.pos + vec2(-2.0, 16.0),
RED,
);
}
}
pub struct Enemy {
pos: Vec2,
}