mirror of
https://github.com/Mercantec-GHC/h5-projekt-mst.git
synced 2026-08-27 05:37:39 +02:00
add obstacle
This commit is contained in:
parent
f9af4ffe28
commit
af06d8f387
@ -19,6 +19,7 @@ use crate::{
|
|||||||
|
|
||||||
struct Skateboard {
|
struct Skateboard {
|
||||||
pos: V3,
|
pos: V3,
|
||||||
|
size: V3,
|
||||||
vel: V3,
|
vel: V3,
|
||||||
rot: V3,
|
rot: V3,
|
||||||
nyoom_factor: f64,
|
nyoom_factor: f64,
|
||||||
@ -30,13 +31,15 @@ impl Skateboard {
|
|||||||
self.vel.0 = self.pivot_deg * delta_time.as_secs_f64();
|
self.vel.0 = self.pivot_deg * delta_time.as_secs_f64();
|
||||||
self.pos += self.vel * delta_time.as_secs_f64();
|
self.pos += self.vel * delta_time.as_secs_f64();
|
||||||
self.nyoom_factor += 16.0 * delta_time.as_secs_f64();
|
self.nyoom_factor += 16.0 * delta_time.as_secs_f64();
|
||||||
|
|
||||||
// rot.0 += delta_time.as_secs_f64() * PI * 1.0;
|
|
||||||
// rot.1 += delta_time.as_secs_f64() * PI * 0.2;
|
|
||||||
// rot.2 += delta_time.as_secs_f64() * PI * 2.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&self, scene: &mut Scene) {
|
fn render(&self, scene: &mut Scene) {
|
||||||
|
scene.draw_shape(
|
||||||
|
self.pos,
|
||||||
|
&Shape::new_cube(self.size),
|
||||||
|
Color::Green,
|
||||||
|
Color::Black,
|
||||||
|
);
|
||||||
let board_size = V3(0.175, 0.005, 0.05);
|
let board_size = V3(0.175, 0.005, 0.05);
|
||||||
let trucks = {
|
let trucks = {
|
||||||
let anchor_size = V3(0.005, 0.01, 0.005);
|
let anchor_size = V3(0.005, 0.01, 0.005);
|
||||||
@ -162,6 +165,7 @@ impl Game {
|
|||||||
Self {
|
Self {
|
||||||
skateboard: Skateboard {
|
skateboard: Skateboard {
|
||||||
pos: V3(0.0, -0.15, -0.4),
|
pos: V3(0.0, -0.15, -0.4),
|
||||||
|
size: V3(0.1, 0.05, 0.2),
|
||||||
vel: V3(0.0, 0.0, 0.2),
|
vel: V3(0.0, 0.0, 0.2),
|
||||||
rot: V3(0.0, PI * 0.5, 0.0),
|
rot: V3(0.0, PI * 0.5, 0.0),
|
||||||
nyoom_factor: 0.0,
|
nyoom_factor: 0.0,
|
||||||
@ -248,18 +252,13 @@ struct Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum ObjectKind {
|
enum ObjectKind {
|
||||||
Section {
|
|
||||||
objects: Vec<ObjectKind>,
|
|
||||||
pos: V3,
|
|
||||||
vel: V3,
|
|
||||||
},
|
|
||||||
Obstacle {
|
Obstacle {
|
||||||
pos: V3,
|
pos: V3,
|
||||||
vel: V3,
|
vel: V3,
|
||||||
|
size: V3,
|
||||||
},
|
},
|
||||||
Ground {
|
Ground {
|
||||||
pos: V3,
|
pos: V3,
|
||||||
vel: V3,
|
|
||||||
rot: V3,
|
rot: V3,
|
||||||
grid_item_size: f64,
|
grid_item_size: f64,
|
||||||
grid_width: i32,
|
grid_width: i32,
|
||||||
@ -314,23 +313,14 @@ impl Object {
|
|||||||
ObjectKind::Obstacle { pos, vel, .. } => {
|
ObjectKind::Obstacle { pos, vel, .. } => {
|
||||||
*pos += *vel * delta_time.as_secs_f64();
|
*pos += *vel * delta_time.as_secs_f64();
|
||||||
}
|
}
|
||||||
ObjectKind::Ground { pos, vel, .. } => {
|
ObjectKind::Ground { .. } => {}
|
||||||
|
|
||||||
// *vel += V3(vel.0, vel.1, vel.0 - 0.01 * delta_time.as_secs_f64());
|
|
||||||
}
|
|
||||||
ObjectKind::Section { objects, .. } => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&self, scene: &mut Scene) {
|
fn render(&self, scene: &mut Scene) {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
ObjectKind::Obstacle { pos, .. } => {
|
ObjectKind::Obstacle { pos, size, .. } => {
|
||||||
scene.draw_shape(
|
scene.draw_shape(pos, &Shape::new_cube(size), Color::Red, Color::Black);
|
||||||
pos,
|
|
||||||
&Shape::new_cube(V3(0.2, 0.1, 0.2)),
|
|
||||||
Color::Green,
|
|
||||||
Color::Black,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
ObjectKind::Ground {
|
ObjectKind::Ground {
|
||||||
pos,
|
pos,
|
||||||
@ -351,7 +341,6 @@ impl Object {
|
|||||||
let ground = ShapeGroup::new(shapes);
|
let ground = ShapeGroup::new(shapes);
|
||||||
ground.draw(pos, scene, Color::Cyan, Color::Black);
|
ground.draw(pos, scene, Color::Cyan, Color::Black);
|
||||||
}
|
}
|
||||||
ObjectKind::Section { ref objects, .. } => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,20 +355,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
});
|
});
|
||||||
let objects: Vec<ObjectKind> = vec![
|
let objects: Vec<ObjectKind> = vec![
|
||||||
ObjectKind::Ground {
|
ObjectKind::Ground {
|
||||||
pos: V3(0.0, -0.35, -0.4),
|
pos: V3(0.0, -0.25, -0.4),
|
||||||
vel: V3(0.0, 0.0, 0.0),
|
|
||||||
rot: V3(0.0, 0.0, 0.0),
|
rot: V3(0.0, 0.0, 0.0),
|
||||||
grid_item_size: 0.1,
|
grid_item_size: 0.1,
|
||||||
grid_width: 10,
|
grid_width: 10,
|
||||||
grid_depth: 20,
|
grid_depth: 40,
|
||||||
},
|
},
|
||||||
ObjectKind::Ground {
|
ObjectKind::Obstacle {
|
||||||
pos: V3(0.0, -0.35, 1.6),
|
pos: V3(0.0, -0.248, 1.0),
|
||||||
vel: V3(0.0, 0.0, 0.0),
|
vel: V3(0.0, 0.0, 0.0),
|
||||||
rot: V3(0.0, 0.0, 0.0),
|
size: V3(0.1, 0.1, 0.1),
|
||||||
grid_item_size: 0.1,
|
|
||||||
grid_width: 10,
|
|
||||||
grid_depth: 20,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user