Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented fire method #77

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions scenes/ammo/ammo.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends KinematicBody2D

var velocity = Vector2(0.0, 0.0)
var acceleration = Vector2(0.0, 0.0)
var direction
var hit

func _ready():
hit = false
acceleration = Vector2(1.0, 1.0)


func _process(delta):
velocity += acceleration
direction = get_parent().shot_direction

var dynamics = move_and_collide(velocity * direction * delta)

if dynamics :
if dynamics.collider.is_in_group("enemies") :
hit = true
hide()
queue_free() #remove scene from the tree after the strike
29 changes: 29 additions & 0 deletions scenes/ammo/missile/missile.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://scenes/ammo/missile/missile_sprite.png" type="Texture" id=1]
[ext_resource path="res://scenes/ammo/ammo.gd" type="Script" id=2]
[ext_resource path="res://scenes/ammo/missile/smoke_cloud_sprite.png" type="Texture" id=3]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8.71297, 22.9291 )

[node name="missile" type="KinematicBody2D"]
script = ExtResource( 2 )

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

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

[node name="CPUParticles2D" type="CPUParticles2D" parent="."]
modulate = Color( 1, 1, 1, 0.25098 )
show_behind_parent = true
position = Vector2( 0, 20 )
scale = Vector2( 0.16, 0.2 )
amount = 4
lifetime = 1.3
randomness = 0.56
lifetime_randomness = 0.35
texture = ExtResource( 3 )
Binary file added scenes/ammo/missile/missile_sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions scenes/ammo/missile/missile_sprite.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/missile_sprite.png-5276ce11471be67e12af183ae11d6d0b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/ammo/missile/missile_sprite.png"
dest_files=[ "res://.import/missile_sprite.png-5276ce11471be67e12af183ae11d6d0b.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added scenes/ammo/missile/smoke_cloud_sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions scenes/ammo/missile/smoke_cloud_sprite.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/smoke_cloud_sprite.png-e4d79bdaa0d020a361cf278abc42258d.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/ammo/missile/smoke_cloud_sprite.png"
dest_files=[ "res://.import/smoke_cloud_sprite.png-e4d79bdaa0d020a361cf278abc42258d.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
1 change: 1 addition & 0 deletions scenes/credits.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var contributors = [
"davtur19",
"mRuggi",
"m0rp30",
"Iranon",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

]

onready var labels_container = $LabelsContainer
Expand Down
2 changes: 1 addition & 1 deletion scenes/enemy/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://scenes/enemy/enemy.gd" type="Script" id=1]
[ext_resource path="res://assets/sprites/tower-defense-top-down/png/tower-defense_tile245.png" type="Texture" id=2]
[ext_resource path="res://assets/sprites/ui/png/green_button06.png" type="Texture" id=2]
[ext_resource path="res://scenes/enemy/enemy-types/aircraft-elite.tres" type="Resource" id=3]

[sub_resource type="RectangleShape2D" id=1]
Expand Down
24 changes: 22 additions & 2 deletions scenes/tower/tower.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var alpha_area_hide : float = 0
var alpha_area = alpha_area_hide

var target
var shot_direction

enum TOWER_STATES {
PREVIEW,
Expand All @@ -26,6 +27,9 @@ var state = TOWER_STATES.PREVIEW
func initialise(_resource: Resource):
tower_resource = _resource

#Preload missle scene
onready var missile_scene = preload("res://scenes/ammo/missile/missile.tscn")


func _ready() -> void:
load_resource_data(tower_resource)
Expand Down Expand Up @@ -85,5 +89,21 @@ func load_resource_data(tower_resource : Tower_Resource):


func fire():
print("firing")
# add fire method
#print("firing")
#searching for closest target
var enemies = get_tree().get_nodes_in_group("enemies")
var nearest
var near_pos
var min_dist = INF
for enemy in enemies :
var enemy_pos = enemy.get_global_position()
var distance = enemy_pos.distance_squared_to(self.get_global_position())
if distance < min_dist :
min_dist = distance
nearest = enemy #storing closest enemy
near_pos = nearest.get_global_position()
shot_direction = self.get_global_position().direction_to(near_pos)
var ammo = missile_scene.instance()
ammo.set_position(self.position)
ammo.set_rotation(self.rotation) #tower should rotate
add_child(ammo)