mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: reformat examples/sokol/particles *.v files
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// Copyright(C) 2019 Lars Pontoppidan. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license file distributed with this software package
|
||||
|
||||
module particle
|
||||
|
||||
import vec2
|
||||
@@ -8,21 +7,16 @@ import sokol.sgl
|
||||
|
||||
const (
|
||||
default_life_time = 1000
|
||||
default_v_color = Color{93, 136, 193, 255 }
|
||||
default_v_color = Color{93, 136, 193, 255}
|
||||
)
|
||||
|
||||
/*
|
||||
* Module public
|
||||
*/
|
||||
// * Module public
|
||||
pub fn new(location vec2.Vec2) &Particle {
|
||||
|
||||
p := &Particle {
|
||||
location: location,
|
||||
velocity: vec2.Vec2{0,0}
|
||||
acceleration: vec2.Vec2{0,0}
|
||||
|
||||
p := &Particle{
|
||||
location: location
|
||||
velocity: vec2.Vec2{0, 0}
|
||||
acceleration: vec2.Vec2{0, 0}
|
||||
color: default_v_color
|
||||
|
||||
life_time: default_life_time
|
||||
life_time_init: default_life_time
|
||||
}
|
||||
@@ -33,20 +27,15 @@ fn remap(v, min, max, new_min, new_max f64) f64 {
|
||||
return (((v - min) * (new_max - new_min)) / (max - min)) + new_min
|
||||
}
|
||||
|
||||
/*
|
||||
* Particle
|
||||
*/
|
||||
// * Particle
|
||||
pub struct Particle {
|
||||
|
||||
mut:
|
||||
location vec2.Vec2
|
||||
velocity vec2.Vec2
|
||||
acceleration vec2.Vec2
|
||||
|
||||
color Color
|
||||
|
||||
life_time f64
|
||||
life_time_init f64
|
||||
location vec2.Vec2
|
||||
velocity vec2.Vec2
|
||||
acceleration vec2.Vec2
|
||||
color Color
|
||||
life_time f64
|
||||
life_time_init f64
|
||||
}
|
||||
|
||||
pub fn (mut p Particle) update(dt f64) {
|
||||
@@ -54,16 +43,13 @@ pub fn (mut p Particle) update(dt f64) {
|
||||
acc.multiply_f64(dt)
|
||||
p.velocity = p.velocity.add(acc)
|
||||
p.location = p.location.add(p.velocity)
|
||||
|
||||
lt := p.life_time - (1000 * dt)
|
||||
if lt > 0 {
|
||||
p.life_time = lt
|
||||
|
||||
p.color.r = p.color.r - 1 //byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.r))
|
||||
p.color.g = p.color.g - 1 //byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.g))
|
||||
p.color.b = p.color.b - 1 //byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.b))
|
||||
|
||||
//p.color.a = byte(remap(p.life_time,0.0,p.life_time_init,0,255))
|
||||
p.color.r = p.color.r - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.r))
|
||||
p.color.g = p.color.g - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.g))
|
||||
p.color.b = p.color.b - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.b))
|
||||
// p.color.a = byte(remap(p.life_time,0.0,p.life_time_init,0,255))
|
||||
} else {
|
||||
p.life_time = 0
|
||||
}
|
||||
@@ -75,9 +61,7 @@ pub fn (p Particle) is_dead() bool {
|
||||
|
||||
pub fn (p Particle) draw() {
|
||||
l := p.location
|
||||
|
||||
sgl.c4b(p.color.r, p.color.g, p.color.b, p.color.a)
|
||||
|
||||
lx := f32(l.x)
|
||||
ly := f32(l.y)
|
||||
sgl.v2f(lx, ly)
|
||||
@@ -90,10 +74,8 @@ pub fn (mut p Particle) reset() {
|
||||
p.location.zero()
|
||||
p.acceleration.zero()
|
||||
p.velocity.zero()
|
||||
|
||||
//p.color = Color{93, 136, 193, 255}
|
||||
// p.color = Color{93, 136, 193, 255}
|
||||
p.color = default_v_color
|
||||
|
||||
p.life_time = default_life_time
|
||||
p.life_time_init = p.life_time
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user