mirror of https://github.com/profan/ld-39-jam.git
boolet impacts
This commit is contained in:
parent
efbcd5cf22
commit
dcdc9171cd
12
Asteroid.gd
12
Asteroid.gd
|
@ -30,9 +30,12 @@ func wrap(v, v_min, v_max):
|
|||
else:
|
||||
return v
|
||||
|
||||
func explode():
|
||||
func on_explode():
|
||||
queue_free()
|
||||
|
||||
func do_damage(v):
|
||||
health -= v
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
# var cur_pos = get_pos()
|
||||
|
@ -40,13 +43,8 @@ func _fixed_process(delta):
|
|||
# cur_pos.y = wrap(cur_pos.y, 1, get_viewport().get_rect().size.y)
|
||||
# set_pos(cur_pos)
|
||||
|
||||
if is_colliding():
|
||||
var e = get_collider()
|
||||
if e.type() == "Bullet":
|
||||
health -= 25
|
||||
|
||||
if health <= 0:
|
||||
explode()
|
||||
on_explode()
|
||||
|
||||
self.move(velocity)
|
||||
self.rotate(rot_vel)
|
||||
|
|
23
Bullet.gd
23
Bullet.gd
|
@ -1,8 +1,12 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
var BulletImpact = load("res://BulletImpact.tscn")
|
||||
|
||||
var velocity = Vector2(1, 0)
|
||||
var lifetime = 16 # seconds
|
||||
|
||||
var bullet_dmg = 0.25
|
||||
|
||||
onready var sprite = get_node("Sprite")
|
||||
|
||||
func _ready():
|
||||
|
@ -15,6 +19,23 @@ func fire(delta, vel, dir, speed):
|
|||
func type():
|
||||
return "Bullet"
|
||||
|
||||
func on_impact(e):
|
||||
|
||||
# create bullet impact
|
||||
var new_bi = BulletImpact.instance()
|
||||
e.add_child(new_bi)
|
||||
# get_tree().get_root().add_child(new_bi)
|
||||
new_bi.set_global_pos(get_collision_pos() + velocity/2)
|
||||
|
||||
# align along "hit normal, the lazy way"
|
||||
new_bi.set_global_rot((-get_collision_normal()).angle())
|
||||
|
||||
# new_bi.rotate(deg2rad(180))
|
||||
|
||||
# damage and free
|
||||
e.do_damage(bullet_dmg)
|
||||
queue_free()
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
move(velocity)
|
||||
|
@ -22,6 +43,8 @@ func _fixed_process(delta):
|
|||
|
||||
if is_colliding():
|
||||
var e = get_collider()
|
||||
if e.type() == "Asteroid":
|
||||
on_impact(e)
|
||||
|
||||
if lifetime <= 0:
|
||||
queue_free()
|
|
@ -11,7 +11,6 @@ extents = Vector2( 0.99762, 3.98857 )
|
|||
[node name="Bullet" type="KinematicBody2D"]
|
||||
|
||||
transform/rot = 180.0
|
||||
transform/scale = Vector2( 2, 2 )
|
||||
input/pickable = false
|
||||
shapes/0/shape = SubResource( 1 )
|
||||
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
extends Sprite
|
||||
|
||||
var current_time = 0
|
||||
var frames_per_second = 0.05
|
||||
|
||||
func _ready():
|
||||
set_process(true)
|
||||
|
||||
func _process(delta):
|
||||
|
||||
if int(current_time / frames_per_second) >= get_hframes() - 1:
|
||||
queue_free()
|
||||
|
||||
set_frame(int(current_time / frames_per_second))
|
||||
|
||||
current_time += delta
|
|
@ -0,0 +1,14 @@
|
|||
[gd_scene load_steps=3 format=1]
|
||||
|
||||
[ext_resource path="res://raw/bullet_impact.png" type="Texture" id=1]
|
||||
[ext_resource path="res://BulletImpact.gd" type="Script" id=2]
|
||||
|
||||
[node name="BulletImpact" type="Sprite"]
|
||||
|
||||
transform/scale = Vector2( 0.25, 0.25 )
|
||||
texture = ExtResource( 1 )
|
||||
hframes = 5
|
||||
region_rect = Rect2( 0, 0, 32, 48 )
|
||||
script/script = ExtResource( 2 )
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=1]
|
||||
[gd_scene load_steps=9 format=1]
|
||||
|
||||
[ext_resource path="res://Game.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Minimap.tscn" type="PackedScene" id=2]
|
||||
|
@ -7,6 +7,7 @@
|
|||
[ext_resource path="res://Player.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://raw/space.png" type="Texture" id=6]
|
||||
[ext_resource path="res://EnemyGrunt.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://BulletImpact.tscn" type="PackedScene" id=8]
|
||||
|
||||
[node name="Game" type="Node"]
|
||||
|
||||
|
@ -71,4 +72,8 @@ region_rect = Rect2( 0, 0, 8192, 8192 )
|
|||
transform/pos = Vector2( 127.878, -20.3627 )
|
||||
transform/scale = Vector2( 1.5, 1.5 )
|
||||
|
||||
[node name="BulletImpact" parent="." instance=ExtResource( 8 )]
|
||||
|
||||
transform/pos = Vector2( 53.4955, -25.9372 )
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,2 @@
|
|||
filter=false
|
||||
gen_mipmaps=false
|
Loading…
Reference in New Issue