Refactorización sistema disparos

This commit is contained in:
dariasteam 2017-07-30 03:15:46 +01:00
parent bed979c668
commit ef0376a717
28 changed files with 127 additions and 96 deletions

View file

@ -36,14 +36,14 @@ world = null
transparent_bg = false
render_target/enabled = false
render_target/v_flip = false
render_target/clear_on_new_frame = true
render_target/clear_on_new_frame = false
render_target/filter = false
render_target/gen_mipmaps = false
render_target/update_mode = 3
audio_listener/enable_2d = true
audio_listener/enable_3d = false
physics/object_picking = false
gui/disable_input = true
gui/disable_input = false
[node name="Node2D" parent="Control/Viewport" instance=ExtResource( 2 )]

View file

@ -20,7 +20,6 @@ var life = 3
# var a = 2
# var b = "textvar"
func on_update_milk_bar(var maxm, var value):
get_node("Control/Milk/Milkbar") .set_value(value * maxm / 100)
@ -116,7 +115,7 @@ func _on_Bttn_S_released():
# MIX
func _on_Bttn_AS_pressed():
Input.action_press("ui_change_weapon")
Input.action_press("ui_change_weapon")
func _on_Bttn_AS_released():
Input.action_release("ui_change_weapon")
Input.action_release("ui_change_weapon")

View file

@ -1,19 +1,13 @@
[gd_scene load_steps=6 format=1]
[gd_scene load_steps=4 format=1]
[ext_resource path="res://manzana.gd" type="Script" id=1]
[ext_resource path="res://manzana.tex" type="Texture" id=2]
[ext_resource path="res://leche.png" type="Texture" id=3]
[sub_resource type="RectangleShape2D" id=1]
custom_solver_bias = 0.0
extents = Vector2( 13, 13 )
[sub_resource type="ColorRamp" id=2]
offsets = FloatArray( 0, 1 )
colors = ColorArray( 0.361877, 1, 0.00390625, 1, 0.126633, 0.753906, 0.753906, 1 )
[node name="Apple" type="Area2D"]
transform/pos = Vector2( -608, -672 )
@ -45,35 +39,6 @@ shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="Particles2D" type="Particles2D" parent="."]
transform/pos = Vector2( -4.03009, 8.29175 )
config/amount = 10
config/lifetime = 2.0
config/process_mode = 1
config/half_extents = Vector2( 32, 32 )
config/texture = ExtResource( 3 )
params/direction = 0.0
params/spread = 180.0
params/linear_velocity = 70.0
params/spin_velocity = 0.0
params/orbit_velocity = 3.0
params/gravity_direction = 0.0
params/gravity_strength = 9.8
params/radial_accel = 0.0
params/tangential_accel = 0.0
params/damping = 0.0
params/initial_angle = 0.0
params/initial_size = 0.7
params/final_size = 0.0
params/hue_variation = 0.67
params/anim_speed_scale = 1.0
params/anim_initial_pos = 0.0
randomness/direction = 0.98
randomness/spread = -0.52
randomness/final_size = 0.39
color/color_ramp = SubResource( 2 )
[connection signal="body_enter" from="." to="." method="_on_Area2D_body_enter"]

View file

@ -50,12 +50,33 @@ func die_by_jump():
func die():
dissapear()
func on_opacity_low ():
sprite.set_modulate(Color("fb12e7"))
func on_opacity_high ():
sprite.set_modulate(Color("00ffff"))
func decrease_life (value):
hit_single.set_emitting(false)
hit_single.set_emitting(true)
var t1 = Timer.new()
var t2 = Timer.new()
t1.set_wait_time(0.07)
t2.set_wait_time(0.07)
t1.set_one_shot(true)
t2.set_one_shot(true)
t1.connect("timeout",self,"on_opacity_low")
t2.connect("timeout",self,"on_opacity_high")
add_child(t1)
add_child(t2)
t1.start()
yield(t1, "timeout")
t2.start()
yield(t2, "timeout")
sprite.set_modulate(Color("ffffff"))
if (life > 0):
life -= value
if (life <= 0):
if (life <= 0):
die()
func _fixed_process(delta):

View file

@ -157,7 +157,7 @@ trigger = true
transform/pos = Vector2( 3.8147e-06, 0 )
frames = SubResource( 8 )
animation = "walking"
frame = 4
frame = 6
playing = true
[node name="hit_ray_particle" type="Particles2D" parent="."]

BIN
express.zip Normal file

Binary file not shown.

BIN
express_1.zip Normal file

Binary file not shown.

View file

@ -36,7 +36,7 @@ export(int) var milk_level = 0
export(int) var invulneravility_time = 16
func is_falling ():
return velocity.y < 0
return velocity.y > 0
func get_max_milk():
return max_milk
@ -111,6 +111,7 @@ func _fixed_process(delta):
if (Input.is_action_pressed("ui_jump")):
if (jumping and can_jump_more() and jump_key_pressed):
velocity.y = - JUMP_SPEED + (MAX_JUMP_TIME - jump_time) * 20
sprite.stop()
jumping = true
elif(can_jump and !jump_key_pressed):
velocity.y = - JUMP_SPEED
@ -161,6 +162,7 @@ func _fixed_process(delta):
# Control de colisiones
if (is_colliding()):
sprite.play("")
var normal = get_collision_normal()
if (normal.y > 0.5 and jumping):
# Está chocandose contra el techo
@ -184,8 +186,39 @@ func _fixed_process(delta):
else:
can_jump = false
func key_left_pressed():
pass
func _ready():
connect("update_milk",get_tree().get_nodes_in_group("control")[0],"on_update_milk_bar")
emit_signal("update_milk", get_max_milk(), get_milk_level());
emit_signal("update_milk", get_max_milk(), get_milk_level())
set_fixed_process(true)
set_process_input(true)
func _input(ev):
if (ev.is_action_pressed("ui_left")):
print("ui_left on")
elif (ev.is_action_released("ui_left")):
print("ui_left off")
if (ev.is_action_pressed("ui_right")):
print("ui_right on")
elif (ev.is_action_released("ui_right")):
print("ui_right off")
if (ev.is_action_pressed("ui_up")):
print("ui_up on")
elif (ev.is_action_released("ui_up")):
print("ui_up off")
if (ev.is_action_pressed("ui_down")):
print("ui_down on")
elif (ev.is_action_released("ui_down")):
print("ui_down off")
if (ev.is_action_pressed("ui_jump")):
print("ui_jump on")
elif (ev.is_action_released("ui_jump")):
print("ui_jump off")

View file

@ -24,10 +24,10 @@
[ext_resource path="res://vaca_idle_3.tex" type="Texture" id=22]
[ext_resource path="res://vaca_idle_4.tex" type="Texture" id=23]
[sub_resource type="ConvexPolygonShape2D" id=1]
[sub_resource type="ConvexPolygonShape2D" id=4]
custom_solver_bias = 0.0
points = Vector2Array( -16.5903, -10.3465, 13.4341, -10.3403, 13.6042, 6.10309, 1.07087, 13.1015, -3.59432, 13.1015, -16.6847, 5.56475 )
points = Vector2Array( -13.2061, 7.63341, -13.1494, -10.328, 11.2943, -10.3627, 11.4077, 7.42536, 1.19923, 13.0773, -3.50803, 13.0773 )
[sub_resource type="RectangleShape2D" id=2]
@ -40,7 +40,7 @@ animations = [ {
"frames": [ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ) ],
"loop": true,
"name": "walk",
"speed": 20.0
"speed": 27.0
}, {
"frames": [ ExtResource( 20 ), ExtResource( 21 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 22 ), ExtResource( 21 ) ],
"loop": true,
@ -51,8 +51,9 @@ animations = [ {
[node name="Player" type="KinematicBody2D"]
transform/scale = Vector2( 1.8, 1.8 )
input/pickable = false
shapes/0/shape = SubResource( 1 )
z/relative = false
input/pickable = true
shapes/0/shape = SubResource( 4 )
shapes/0/transform = Matrix32( 1.89755, 0, 0, 3.10364, 2.93931, -4.91934 )
shapes/0/trigger = false
shapes/1/shape = SubResource( 2 )
@ -87,7 +88,7 @@ layer_mask = 30
transform/pos = Vector2( 2.93931, -4.91934 )
transform/scale = Vector2( 1.89755, 3.10364 )
build_mode = 0
polygon = Vector2Array( -16.6847, 5.56475, -3.59432, 13.1015, 1.07087, 13.1015, 13.6042, 6.10309, 13.4341, -10.3403, -16.5903, -10.3465 )
polygon = Vector2Array( -3.50803, 13.0773, 1.19923, 13.0773, 11.4077, 7.42536, 11.2943, -10.3627, -13.1494, -10.328, -13.2061, 7.63341 )
shape_range = Vector2( 0, 0 )
trigger = false
@ -102,8 +103,7 @@ _update_shape_index = 1
[node name="sprite" type="AnimatedSprite" parent="."]
frames = SubResource( 3 )
animation = "Idle"
frame = 2
animation = "walk"
playing = true
[node name="Camera2D" type="Camera2D" parent="sprite"]

View file

@ -56,7 +56,11 @@ damage = 10
transform/pos = Vector2( 0, -1 )
transform/scale = Vector2( 0.5, 0.5 )
z/z = 1
z/relative = false
config/lifetime = 0.25
config/emit_timeout = 0.0
params/initial_size = 1.5
[node name="Area2D" type="Area2D" parent="end"]
@ -91,7 +95,7 @@ texture = ExtResource( 4 )
centered = false
offset = Vector2( 0, -14.5 )
region = true
region_rect = Rect2( 0, 0, 100, 29 )
region_rect = Rect2( 0, 0, 0, 29 )
[connection signal="body_enter" from="end/Area2D" to="end/Area2D" method="_on_Area2D_body_enter"]

View file

@ -11,19 +11,22 @@ const MAX_DISTANCE = 10000
var distance = MAX_DISTANCE
func look_left():
middle.set_region_rect(Rect2(Vector2(0,0),Vector2(0,0)))
force_raycast_update()
distance = -MAX_DISTANCE
middle.set_rot(PI)
middle.set_region_rect(Rect2(Vector2(0,0),Vector2(0,0)))
middle.set_rot(PI)
func look_right():
middle.set_region_rect(Rect2(Vector2(0,0),Vector2(0,0)))
func look_right():
force_raycast_update()
distance = MAX_DISTANCE
middle.set_region_rect(Rect2(Vector2(0,0),Vector2(0,0)))
middle.set_rot(0)
func _ready():
set_fixed_process(true)
func enable():
force_raycast_update()
end.set_emitting(true)
enabled = true
@ -37,7 +40,7 @@ func calc_shoot():
set_cast_to(Vector2(distance, 0))
var end_point
if (is_colliding()):
end_point = Vector2 (abs(get_global_pos().x - get_collision_point().x), 29)
end_point = Vector2 ( get_global_pos().distance_to(get_collision_point()), 29)
else:
end_point = Vector2 (distance, 29)

View file

@ -1,10 +1,7 @@
extends Node2D
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
const BULLET = preload("res://bullet.tscn")
export var SHOOT_CADENCE = 0.5
export var SHOOT_CADENCE = 0.001
enum WEAPONS {
regular,
@ -12,55 +9,64 @@ enum WEAPONS {
}
var weapon = WEAPONS.laser
var shooting = false
var shoot = false
var recharge = false
onready var player = get_parent()
onready var instanced_ray = get_node("ray")
var shoot_dir = Vector2(500,-250)
func _ready():
set_fixed_process(true)
func shoot_regular ():
var instanced_bullet = BULLET.instance()
get_parent().get_parent().add_child(instanced_bullet)
instanced_bullet.set_global_pos(get_global_pos())
instanced_bullet.set_linear_velocity(shoot_dir + Vector2(rand_range(-100, 100) + get_parent().velocity.x, rand_range(-100, 100)))
set_process_input(true)
shooting = true
var t = Timer.new()
t.set_wait_time(SHOOT_CADENCE)
t.set_one_shot(true)
self.add_child(t)
t.start()
yield(t, "timeout")
shooting = false
player.decrease_milk(1)
func shoot_laser():
player.decrease_milk(0.5)
func _fixed_process(delta):
if (Input.is_action_pressed("ui_shoot") and !shooting and player.get_milk_level() > 0):
if (weapon == WEAPONS.regular):
shoot_regular()
elif (weapon == WEAPONS.laser):
instanced_ray.enable()
shoot_laser()
else:
func _input(ev):
# SHOOT
if (ev.is_action_pressed("ui_shoot") and check_can_shoot()):
set_fixed_process(true)
elif (ev.is_action_released("ui_shoot")):
instanced_ray.disable()
set_fixed_process(false)
if (Input.is_action_pressed("ui_change_weapon")):
# CHANGE WEAPON
if (ev.is_action_pressed("ui_change_weapon")):
if (weapon == WEAPONS.regular):
weapon = WEAPONS.laser
else:
weapon = WEAPONS.regular
Input.action_release("ui_change_weapon")
instanced_ray.disable()
func check_can_shoot():
return player.get_milk_level() > 0
func shoot_regular():
var instanced_bullet = BULLET.instance()
get_parent().get_parent().add_child(instanced_bullet)
instanced_bullet.set_global_pos(get_global_pos())
instanced_bullet.set_linear_velocity(shoot_dir + Vector2(rand_range(-100, 100) + get_parent().velocity.x, rand_range(-100, 100)))
recharge = true
var t = Timer.new()
t.set_wait_time(SHOOT_CADENCE)
self.add_child(t)
t.start()
yield(t, "timeout")
recharge = false
player.decrease_milk(1)
func shoot_laser():
player.decrease_milk(0.5)
func _fixed_process(delta):
if (weapon == WEAPONS.regular and !recharge):
shoot_regular()
elif (weapon == WEAPONS.laser):
instanced_ray.enable()
shoot_laser()
func _on_KinematicBody2D_looking_left():
shoot_dir = Vector2(-500,-250)
set_pos(Vector2(-21, 0))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After