-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timer to get rid of bullets. Recognize when objects are hit. Still issue with show and hide of Tanks.
- Loading branch information
Showing
4 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://bullet.png" type="Texture" id=1] | ||
[ext_resource path="res://Bullet.gd" type="Script" id=2] | ||
[ext_resource path="res://Bullet_rigid.gd" type="Script" id=3] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 1.02081, 1.02438 ) | ||
|
||
[node name="Bullet" type="KinematicBody2D"] | ||
script = ExtResource( 2 ) | ||
__meta__ = { | ||
"_edit_group_": true | ||
} | ||
[node name="Bullet_Rigid" type="RigidBody2D"] | ||
gravity_scale = 0.0 | ||
contacts_reported = 1 | ||
contact_monitor = true | ||
script = ExtResource( 3 ) | ||
|
||
[node name="bullet" type="Sprite" parent="."] | ||
position = Vector2( 0.0633631, -0.0659924 ) | ||
texture = ExtResource( 1 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2( -0.0633631, 0.0659924 ) | ||
shape = SubResource( 1 ) | ||
[connection signal="body_entered" from="." to="." method="_on_Bullet_Rigid_body_entered"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
extends Area2D | ||
|
||
# Max speeds | ||
const BULLET_SPEED = 40 | ||
|
||
# Global Vars | ||
var velocity = Vector2.ZERO | ||
var heading = 0 | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass | ||
|
||
func set_velocity(new_velocity): | ||
velocity = new_velocity | ||
|
||
func set_heading(new_heading): | ||
heading = new_heading | ||
|
||
func _physics_process(delta): | ||
|
||
#velocity.x = delta * BULLET_SPEED * cos(heading * (PI/180)) | ||
#velocity.y = delta * BULLET_SPEED * sin(heading * (PI/180)) | ||
#move_and_collide(velocity) | ||
|
||
#if position.y < 10: | ||
# queue_free() | ||
|
||
move_and_collide(velocity * delta) | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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) | ||
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_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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters