Unify trail definition for both hitscan and bullet weapons (closes #10)
This commit is contained in:
parent
c96c5c95ac
commit
0bee8f9118
9
DOCS.md
9
DOCS.md
@ -77,10 +77,11 @@ Actions are tables containing info about how they should work. Actions also supp
|
||||
* It takes either a Minetest physics table or the string `"FREEZE"`, which will block the player
|
||||
* If this parameter is declared, `slow_down_user` won't get called
|
||||
* `sound`: (string) ⚡️🥏👊 the sound to play when the action is run
|
||||
* `trail`: (table) ⚡️👊 the trail the action should leave. Fields are:
|
||||
* `image`: (string) the particle to spawn
|
||||
* `amount`: (int) how many particles to draw along the line
|
||||
* `size`: (int) the size of each particle
|
||||
* `trail`: (table) ⚡️🥏👊 the trail the action should leave. Fields are:
|
||||
* `image`: (string) the particle to spawn -- TODO: rendi obbligatorio
|
||||
* `amount`: (int) how many particles to draw along the line. In `bullet` type it's the amount to spawn every second. Defaults to `5` in non bullet types and to `2` in bullet types
|
||||
* `size`: (int) the size of each particle. Default is `1`
|
||||
* `life`: (int) how's gonna last, in seconds. Default is `0.3`
|
||||
* `on_use`: (function(player, weapon, action, \<pointed_thing>)) ⚡️🥏👊 additional behaviour when the action is successfully run
|
||||
* `pointed_thing` is only passed with custom and punch action types
|
||||
* if `continuous_fire` is on, the callback is run repeatedly
|
||||
|
@ -23,6 +23,7 @@ end
|
||||
----------------------------------------------
|
||||
|
||||
function generate_entity(w_name, def, action)
|
||||
|
||||
local bullet = {
|
||||
initial_properties = {
|
||||
name = def.name,
|
||||
@ -48,7 +49,7 @@ function generate_entity(w_name, def, action)
|
||||
_explosion = def.explosion,
|
||||
_remove_on_contact = def.remove_on_contact,
|
||||
|
||||
_bullet_trail = def.trail, -- TODO: time qui è expirationtime (life?); amount qui è interval (amount?)
|
||||
_bullet_trail = action.trail,
|
||||
_spawn_particle_time = 0,
|
||||
|
||||
_gravity = def.gravity,
|
||||
@ -59,6 +60,12 @@ function generate_entity(w_name, def, action)
|
||||
_is_sliding = false, -- per capire se si sta muovendo su superfici piane (granate)
|
||||
}
|
||||
|
||||
-- più chiaro di amount, ma al tempo stesso mantengo standard con altre armi nella dichiarazione
|
||||
if bullet._bullet_trail then
|
||||
bullet._bullet_trail.interval = 20 / (bullet._bullet_trail.amount or 2)
|
||||
bullet._bullet_trail.amount = nil
|
||||
end
|
||||
|
||||
function bullet:_destroy()
|
||||
if self._explosion then
|
||||
spawn_particles_sphere(self.object:get_pos(), self._explosion.texture)
|
||||
@ -95,7 +102,7 @@ function generate_entity(w_name, def, action)
|
||||
|
||||
|
||||
function bullet:on_step(dtime, moveresult)
|
||||
self._curr_lifetime = self._curr_lifetime + dtime
|
||||
self._curr_lifetime = self._curr_lifetime + (dtime * 1.6) -- per convertire in secondi
|
||||
|
||||
if self._curr_lifetime >= self._lifetime then
|
||||
self:_destroy()
|
||||
@ -112,9 +119,9 @@ function generate_entity(w_name, def, action)
|
||||
-- Aggiunge le particelle di tracciamento
|
||||
minetest.add_particle({
|
||||
pos = obj:get_pos(),
|
||||
velocity = vector.divide(velocity, 2),
|
||||
velocity = vector.divide(velocity, 5),
|
||||
acceleration = vector.divide(obj:get_acceleration(), -5),
|
||||
expirationtime = self._bullet_trail.life,
|
||||
expirationtime = self._bullet_trail.life or 0.3,
|
||||
size = self._bullet_trail.size,
|
||||
texture = self._bullet_trail.image
|
||||
})
|
||||
|
@ -680,7 +680,6 @@ function attack_bullet(user, action)
|
||||
|
||||
-- TODO: non si può fare su on_activate quello che segue?
|
||||
local bullet_ent = bullet:get_luaentity()
|
||||
bullet_ent._action = table.copy(action)
|
||||
|
||||
local speed = bullet_ent._speed
|
||||
local dir = user:get_look_dir()
|
||||
@ -942,8 +941,8 @@ function draw_particles(particle, dir, origin, range, pierce)
|
||||
local check_coll = not pierce
|
||||
|
||||
minetest.add_particlespawner({
|
||||
amount = particle.amount,
|
||||
time = 0.3, -- TODO: meglio funzione che approssima distanza? Time era 0.3, min/max erano impact_dist/(range * 1.5)
|
||||
amount = particle.amount or 5,
|
||||
time = particle.life or 0.3,
|
||||
pos = vector.new(origin),
|
||||
vel = vector.multiply(dir, range),
|
||||
size = particle.size or 1,
|
||||
|
@ -27,6 +27,13 @@ weapons_lib.register_weapon("weapons_lib:test3", {
|
||||
-- TODO: trail direttamente nel proiettile o mantengo coerenza con armi generiche?
|
||||
-- `damage` x es. ora lo prende da qua, non da proiettile; eviterei forse 1 e 1
|
||||
|
||||
trail = {
|
||||
image = "test1_trail2.png",
|
||||
life = 1,
|
||||
size = 2,
|
||||
amount = 5, -- 20/amount
|
||||
},
|
||||
|
||||
bullet = {
|
||||
name = "weapons_lib:bullet_test", -- TODO: ha senso impostare il nome?
|
||||
|
||||
@ -48,13 +55,6 @@ weapons_lib.register_weapon("weapons_lib:test3", {
|
||||
gravity = false,
|
||||
|
||||
-- TODO particelle per quando svanisce? Tipo effetto fumo
|
||||
|
||||
trail = {
|
||||
image = "test1_trail2.png",
|
||||
life = 1,
|
||||
size = 2,
|
||||
interval = 5, -- in step
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user