mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
chore: renamed the resources directory to res
This commit is contained in:
parent
05a4679f38
commit
913f200a63
22 changed files with 1273 additions and 1105 deletions
|
@ -1,73 +1,73 @@
|
|||
use comet::prelude::*;
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
use comet_input::keyboard::Key;
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Takes all the textures from resources/textures and puts them into a texture atlas
|
||||
renderer.initialize_atlas();
|
||||
// Takes all the textures from res/textures and puts them into a texture atlas
|
||||
renderer.initialize_atlas();
|
||||
|
||||
let camera = app.new_entity();
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
let camera = app.new_entity();
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
let e1 = app.new_entity();
|
||||
let e1 = app.new_entity();
|
||||
|
||||
app.add_component(e1, Transform2D::new());
|
||||
app.add_component(e1, Transform2D::new());
|
||||
|
||||
let mut renderer2d = Render2D::new();
|
||||
renderer2d.set_texture(r"resources/textures/comet_icon.png");
|
||||
renderer2d.set_visibility(true);
|
||||
let mut renderer2d = Render2D::new();
|
||||
renderer2d.set_texture(r"res/textures/comet_icon.png");
|
||||
renderer2d.set_visibility(true);
|
||||
|
||||
app.add_component(e1, renderer2d);
|
||||
app.add_component(e1, renderer2d);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
handle_input(app, dt);
|
||||
handle_input(app, dt);
|
||||
|
||||
renderer.render_scene_2d(app.scene());
|
||||
renderer.render_scene_2d(app.scene());
|
||||
}
|
||||
|
||||
fn handle_input(app: &mut App, dt: f32) {
|
||||
if app.key_held(Key::KeyW)
|
||||
|| app.key_held(Key::KeyA)
|
||||
|| app.key_held(Key::KeyS)
|
||||
|| app.key_held(Key::KeyD)
|
||||
{
|
||||
update_position(
|
||||
app.input_manager().clone(),
|
||||
app.get_component_mut::<Transform2D>(1).unwrap(),
|
||||
dt
|
||||
);
|
||||
}
|
||||
if app.key_held(Key::KeyW)
|
||||
|| app.key_held(Key::KeyA)
|
||||
|| app.key_held(Key::KeyS)
|
||||
|| app.key_held(Key::KeyD)
|
||||
{
|
||||
update_position(
|
||||
app.input_manager().clone(),
|
||||
app.get_component_mut::<Transform2D>(1).unwrap(),
|
||||
dt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_position(input: WinitInputHelper, transform: &mut Transform2D, dt: f32) {
|
||||
let mut direction = v2::ZERO;
|
||||
let mut direction = v2::ZERO;
|
||||
|
||||
if input.key_held(Key::KeyW) {
|
||||
direction += v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyA) {
|
||||
direction -= v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyS) {
|
||||
direction -= v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyD) {
|
||||
direction += v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyW) {
|
||||
direction += v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyA) {
|
||||
direction -= v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyS) {
|
||||
direction -= v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyD) {
|
||||
direction += v2::X;
|
||||
}
|
||||
|
||||
// If check to prevent division by zero and the comet to fly off into infinity...
|
||||
if direction != v2::ZERO {
|
||||
let normalized_dir = direction.normalize();
|
||||
let displacement = normalized_dir * 777.7 * dt;
|
||||
transform.translate(displacement);
|
||||
}
|
||||
// If check to prevent division by zero and the comet to fly off into infinity...
|
||||
if direction != v2::ZERO {
|
||||
let normalized_dir = direction.normalize();
|
||||
let displacement = normalized_dir * 777.7 * dt;
|
||||
transform.translate(displacement);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.with_title("Simple Move 2D")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
App::new()
|
||||
.with_title("Simple Move 2D")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
|
@ -1,42 +1,45 @@
|
|||
use comet::prelude::*;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Loading the font from the resources/fonts directory with a rendered size of 77px
|
||||
renderer.load_font("./resources/fonts/PressStart2P-Regular.ttf", 77.0);
|
||||
// Loading the font from the res/fonts directory with a rendered size of 77px
|
||||
renderer.load_font("./res/fonts/PressStart2P-Regular.ttf", 77.0);
|
||||
|
||||
// Setting up camera
|
||||
let camera = app.new_entity();
|
||||
|
||||
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
// Creating the text entity
|
||||
let text = app.new_entity();
|
||||
app.add_component(text, Transform2D::new());
|
||||
app.add_component(text, Text::new(
|
||||
"comet", // The content of the text
|
||||
"./resources/fonts/PressStart2P-Regular.ttf", // The used font (right now exact to the font path)
|
||||
77.0, // Pixel size at which the font will be drawn
|
||||
true, // Should the text be visible
|
||||
sRgba::<f32>::from_hex("#abb2bfff") // Color of the text
|
||||
));
|
||||
app.add_component(
|
||||
text,
|
||||
Text::new(
|
||||
"comet", // The content of the text
|
||||
"./res/fonts/PressStart2P-Regular.ttf", // The used font (right now exact to the font path)
|
||||
77.0, // Pixel size at which the font will be drawn
|
||||
true, // Should the text be visible
|
||||
sRgba::<f32>::from_hex("#abb2bfff"), // Color of the text
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
// Getting the windows size
|
||||
let size = renderer.size();
|
||||
|
||||
|
||||
// Recalculating the position of the text every frame to ensure the same relative position
|
||||
let transform = app.get_component_mut::<Transform2D>(1).unwrap();
|
||||
transform.position_mut().set_x(-((size.width-50) as f32));
|
||||
transform.position_mut().set_y((size.height-100) as f32);
|
||||
transform.position_mut().set_x(-((size.width - 50) as f32));
|
||||
transform.position_mut().set_y((size.height - 100) as f32);
|
||||
|
||||
renderer.render_scene_2d(app.scene());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
App::new()
|
||||
.with_preset(App2D)
|
||||
.with_title("Simple Text")
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
.with_title("Simple Text")
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
use comet::prelude::*;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Creating a texture atlas from the provided textures in the vector
|
||||
renderer.set_texture_atlas_by_paths(vec!["./resources/textures/comet_icon.png".to_string()]);
|
||||
// Creating a texture atlas from the provided textures in the vector
|
||||
renderer.set_texture_atlas_by_paths(vec!["./res/textures/comet_icon.png".to_string()]);
|
||||
|
||||
// Creating a camera entity
|
||||
let cam = app.new_entity();
|
||||
app.add_component(cam, Transform2D::new());
|
||||
app.add_component(cam, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
// Creating a camera entity
|
||||
let cam = app.new_entity();
|
||||
app.add_component(cam, Transform2D::new());
|
||||
app.add_component(cam, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
// Creating a textured entity
|
||||
let e0 = app.new_entity();
|
||||
app.add_component(e0, Transform2D::new());
|
||||
// Creating a textured entity
|
||||
let e0 = app.new_entity();
|
||||
app.add_component(e0, Transform2D::new());
|
||||
|
||||
let mut render = Render2D::new();
|
||||
render.set_visibility(true);
|
||||
render.set_texture("./resources/textures/comet_icon.png");
|
||||
let mut render = Render2D::new();
|
||||
render.set_visibility(true);
|
||||
render.set_texture("./res/textures/comet_icon.png");
|
||||
|
||||
app.add_component(e0, render);
|
||||
app.add_component(e0, render);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
renderer.render_scene_2d(app.scene())
|
||||
renderer.render_scene_2d(app.scene())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.with_title("Textured Entity")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
App::new()
|
||||
.with_title("Textured Entity")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue