Skip to content

Commit

Permalink
Shooting correctly now.
Browse files Browse the repository at this point in the history
Recognize when hit.
  • Loading branch information
bblodget committed Aug 1, 2020
1 parent 8db95ec commit 8cef594
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
8 changes: 8 additions & 0 deletions Bullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -0.0633631, 0.0659924 )
shape = SubResource( 1 )

[node name="TimerBullet" type="Timer" parent="."]
wait_time = 0.9
one_shot = true
autostart = true

[node name="TimerHidden" type="Timer" parent="."]
[connection signal="body_entered" from="." to="." method="_on_Bullet_Rigid_body_entered"]
[connection signal="timeout" from="TimerBullet" to="." method="_on_TimerBullet_timeout"]
32 changes: 9 additions & 23 deletions Bullet_rigid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,21 @@ extends RigidBody2D

# Global Vars
var projectile_speed = 400
var life_time = 0.9
var deadTimer


# Called when the node enters the scene tree for the first time.
func _ready():
deadTimer = Timer.new()
deadTimer.set_wait_time(1.0)
add_child(deadTimer)
func _ready():
apply_impulse(Vector2(), Vector2(projectile_speed, 0).rotated(rotation))
SelfDestruct()

func SelfDestruct():
yield(get_tree().create_timer(life_time),"timeout")
queue_free()


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_TimerBullet_timeout():
queue_free()


func _on_Bullet_Rigid_body_entered(body):
#print("body: ", body.name)
#self.hide()
if body.name == "Tank1" or body.name == "Tank2":
body.hide()
deadTimer.start()
yield(deadTimer, "timeout")
deadTimer.stop()
body.show()

self.hide()
if (body.name=="Tank1"):
get_parent().get_node("Tank1").hit()
if (body.name=="Tank2"):
get_parent().get_node("Tank2").hit()

9 changes: 8 additions & 1 deletion TankPlayer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,12 @@ func shoot():
#bullet.transform = world.transform
#add_child_below_node(world, bullet)

func hit():
print("I'm hit: ",self.name)
self.hide()
$TimerHidden.start()



func _on_TimerHidden_timeout():
$TimerHidden.stop()
self.show()
4 changes: 4 additions & 0 deletions TankPlayer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ __meta__ = {
}

[node name="tank" type="Sprite" parent="."]
scale = Vector2( 2, 2 )
texture = ExtResource( 2 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="TimerHidden" type="Timer" parent="."]
[connection signal="timeout" from="TimerHidden" to="." method="_on_TimerHidden_timeout"]
10 changes: 6 additions & 4 deletions World.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_scene load_steps=26 format=2]

[ext_resource path="res://orange_tank.png" type="Texture" id=1]
[ext_resource path="res://boat_guy_still.png" type="Texture" id=1]
[ext_resource path="res://border_tiles.png" type="Texture" id=2]
[ext_resource path="res://dg_tank.png" type="Texture" id=3]
[ext_resource path="res://boat_guy_still2.png" type="Texture" id=3]
[ext_resource path="res://TankPlayer.tscn" type="PackedScene" id=4]

[sub_resource type="ConvexPolygonShape2D" id=1]
Expand Down Expand Up @@ -221,18 +221,20 @@ tile_data = PoolIntArray( -1, 0, 131073, -65536, 0, 131076, -65535, 0, 131076, -

[node name="Tank1" parent="." instance=ExtResource( 4 )]
position = Vector2( 299.694, 95.3571 )
tank_sprite = ExtResource( 3 )
tank_sprite = ExtResource( 1 )
ui_left = "ui_p1_left"
ui_right = "ui_p1_right"
ui_up = "ui_p1_up"
ui_down = "ui_p1_down"
ui_fire = "ui_p1_fire"
initial_heading = 90.0

[node name="Tank2" parent="." instance=ExtResource( 4 )]
position = Vector2( 14.3036, 98.4222 )
tank_sprite = ExtResource( 1 )
tank_sprite = ExtResource( 3 )
ui_left = "ui_p2_left"
ui_right = "ui_p2_right"
ui_up = "ui_p2_up"
ui_down = "ui_p2_down"
ui_fire = "ui_p2_fire"
initial_heading = 90.0
Binary file modified boat_guy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified boat_guy_still.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8cef594

Please sign in to comment.