Skip to content

Commit

Permalink
Part 13 - terrain and smoke effects
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed Jan 16, 2019
1 parent 7b81d76 commit 2edccf4
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 9 deletions.
104 changes: 104 additions & 0 deletions effects/Smoke.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[gd_scene load_steps=8 format=2]

[sub_resource type="Gradient" id=1]

offsets = PoolRealArray( 0, 0.207101, 1 )
colors = PoolColorArray( 0.945312, 0.420152, 0.0369263, 1, 0.542969, 0.538727, 0.538727, 1, 0, 0, 0, 0 )

[sub_resource type="GradientTexture" id=2]

flags = 4
gradient = SubResource( 1 )
width = 2048

[sub_resource type="Curve" id=4]

min_value = 0.0
max_value = 1.0
bake_resolution = 100
_data = [ Vector2( 0, 0.5 ), 0.0, 3.92898, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]

[sub_resource type="CurveTexture" id=5]

flags = 4
width = 2048
curve = SubResource( 4 )

[sub_resource type="Curve" id=6]

min_value = -200.0
max_value = 200.0
bake_resolution = 100
_data = [ Vector2( 0, -141.797 ), 0.0, 0.0, 0, 0, Vector2( 1, 200 ), -62.6108, 0.0, 0, 0 ]

[sub_resource type="CurveTexture" id=7]

flags = 4
width = 2048
curve = SubResource( 6 )

[sub_resource type="ParticlesMaterial" id=3]

render_priority = 0
trail_divisor = 1
emission_shape = 2
emission_box_extents = Vector3( 5, 12, 1 )
flag_align_y = false
flag_rotate_y = false
flag_disable_z = true
spread = 15.0
flatness = 0.0
gravity = Vector3( 0, 0, 0 )
initial_velocity = 40.0
initial_velocity_random = 1.0
angular_velocity = 0.0
angular_velocity_random = 0.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
linear_accel = 0.0
linear_accel_random = 0.0
radial_accel = 0.0
radial_accel_random = 0.0
tangential_accel = 50.0
tangential_accel_random = 0.0
tangential_accel_curve = SubResource( 7 )
damping = 0.0
damping_random = 0.0
angle = 0.0
angle_random = 0.0
scale = 20.0
scale_random = 0.0
scale_curve = SubResource( 5 )
color_ramp = SubResource( 2 )
hue_variation = 0.0
hue_variation_random = 0.0
anim_speed = 0.0
anim_speed_random = 0.0
anim_offset = 0.0
anim_offset_random = 0.0
anim_loop = false
_sections_unfolded = [ "Color", "Emission Shape", "Gravity", "Initial Velocity", "Scale", "Spread", "Tangential Accel" ]

[node name="Smoke" type="Particles2D"]

emitting = true
amount = 50
lifetime = 0.75
one_shot = false
preprocess = 0.0
speed_scale = 1.0
explosiveness = 0.0
randomness = 0.0
fixed_fps = 0
fract_delta = true
visibility_rect = Rect2( -100, -100, 200, 200 )
local_coords = false
draw_order = 0
process_material = SubResource( 3 )
texture = null
normal_map = null
h_frames = 1
v_frames = 1
_sections_unfolded = [ "Drawing", "Process Material", "Time", "Transform" ]


3 changes: 3 additions & 0 deletions globals.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends Node

var slow_terrain = [0, 10, 20, 30, 7, 8, 17, 18]
1 change: 1 addition & 0 deletions maps/Map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends Node2D
func _ready():
set_camera_limits()
Input.set_custom_mouse_cursor(load("res://assets/UI/crossair_black.png"), Input.CURSOR_ARROW, Vector2(16, 16))
$Player.map = $Ground

func set_camera_limits():
var map_limits = $Ground.get_used_rect()
Expand Down
5 changes: 4 additions & 1 deletion maps/Map01.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ __meta__ = {

[node name="Player" parent="." index="2" instance=ExtResource( 4 )]

position = Vector2( 2420.48, 1359.13 )
position = Vector2( 2445.23, 1352.53 )

[node name="Paths" type="Node2D" parent="." index="3"]

Expand All @@ -80,6 +80,7 @@ lookahead = 4.0

[node name="EnemyTank" parent="Paths/Path2D/PathFollow2D" index="0" instance=ExtResource( 5 )]

_sections_unfolded = [ "Collision", "Transform", "collision" ]
Bullet = ExtResource( 6 )
max_speed = 175
gun_shots = 3
Expand All @@ -105,6 +106,7 @@ lookahead = 4.0

[node name="EnemyTank" parent="Paths/Path2D2/PathFollow2D" index="0" instance=ExtResource( 5 )]

_sections_unfolded = [ "Collision", "Transform", "collision" ]
max_speed = 150
rotation_speed = 0.0
turret_speed = 3.0
Expand All @@ -113,6 +115,7 @@ detect_radius = 450
[node name="GunTurret" parent="." index="4" instance=ExtResource( 7 )]

position = Vector2( 2308.93, 396.547 )
offroad_friction = null

[node name="Obstacles" type="Node2D" parent="." index="5"]

Expand Down
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ config_version=3
config/name="Top-down Tank Battle"
config/icon="res://icon.png"

[autoload]

GLOBALS="*res://globals.gd"

[display]

window/stretch/mode="2d"
Expand Down
2 changes: 1 addition & 1 deletion tanks/EnemyTank.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _sections_unfolded = [ "Transform" ]
position = Vector2( 55, 0 )
offset = Vector2( 23, 0 )
region_rect = Rect2( 644, 94, 50, 40 )
_sections_unfolded = [ "Offset", "Region", "Transform", "Visibility" ]
_sections_unfolded = [ "Offset", "Region", "Transform", "Visibility", "Z Index" ]

[node name="DetectRadius" type="Area2D" parent="." index="4"]

Expand Down
2 changes: 1 addition & 1 deletion tanks/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ position = Vector2( 741.177, 459.959 )
collision_layer = 2
collision_mask = 5
script = ExtResource( 2 )
_sections_unfolded = [ "Collision", "collision" ]
_sections_unfolded = [ "Collision", "Transform", "collision" ]
Bullet = ExtResource( 3 )
max_speed = 200
rotation_speed = 1.0
Expand Down
11 changes: 11 additions & 0 deletions tanks/Tank.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export (int) var max_speed
export (float) var rotation_speed
export (float) var gun_cooldown
export (int) var max_health
export (float) var offroad_friction

export (int) var gun_shots = 1
export (float, 0, 1.5) var gun_spread = 0.2
Expand All @@ -20,9 +21,11 @@ var velocity = Vector2()
var can_shoot = true
var alive = true
var health
var map

func _ready():
health = max_health
$Smoke.emitting = false
emit_signal('health_changed', health * 100/max_health)
emit_signal('ammo_changed', ammo * 100/max_ammo)
$GunTimer.wait_time = gun_cooldown
Expand All @@ -48,18 +51,26 @@ func _physics_process(delta):
if not alive:
return
control(delta)
if map:
var tile = map.get_cellv(map.world_to_map(position))
if tile in GLOBALS.slow_terrain:
velocity *= offroad_friction
move_and_slide(velocity)

func take_damage(amount):
health -= amount
emit_signal('health_changed', health * 100/max_health)
if health < max_health / 2:
$Smoke.emitting = true
if health <= 0:
explode()

func heal(amount):
health += amount
health = clamp(health, 0, max_health)
emit_signal('health_changed', health * 100/max_health)
if health >= max_health / 2:
$Smoke.emitting = false

func explode():
$CollisionShape2D.disabled = true
Expand Down
21 changes: 15 additions & 6 deletions tanks/Tank.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://tanks/Tank.gd" type="Script" id=1]
[ext_resource path="res://assets/onlyObjects_retina_rotated.png" type="Texture" id=2]
[ext_resource path="res://effects/Explosion.tscn" type="PackedScene" id=3]
[ext_resource path="res://effects/Smoke.tscn" type="PackedScene" id=3]
[ext_resource path="res://effects/Explosion.tscn" type="PackedScene" id=4]

[sub_resource type="Animation" id=1]

Expand Down Expand Up @@ -61,11 +62,13 @@ collision_layer = 1
collision_mask = 1
collision/safe_margin = 0.08
script = ExtResource( 1 )
_sections_unfolded = [ "Transform" ]
Bullet = null
max_speed = null
rotation_speed = null
gun_cooldown = null
max_health = null
offroad_friction = 0.75
gun_shots = 1
gun_spread = 0.2
max_ammo = 20
Expand All @@ -79,7 +82,13 @@ _sections_unfolded = [ "Region" ]

[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]

[node name="Turret" type="Sprite" parent="." index="2"]
[node name="Smoke" parent="." index="2" instance=ExtResource( 3 )]

position = Vector2( -25, 0 )
rotation = -3.14159
draw_order = 1

[node name="Turret" type="Sprite" parent="." index="3"]

texture = ExtResource( 2 )
region_enabled = true
Expand All @@ -95,14 +104,14 @@ texture = ExtResource( 2 )
region_enabled = true
_sections_unfolded = [ "Region", "Transform", "Visibility", "Z Index" ]

[node name="GunTimer" type="Timer" parent="." index="3"]
[node name="GunTimer" type="Timer" parent="." index="4"]

process_mode = 1
wait_time = 1.0
one_shot = false
autostart = false

[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="4"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="5"]

root_node = NodePath("..")
autoplay = "init"
Expand All @@ -113,7 +122,7 @@ anims/init = SubResource( 1 )
anims/muzzle_flash = SubResource( 2 )
blend_times = [ ]

[node name="Explosion" parent="." index="5" instance=ExtResource( 3 )]
[node name="Explosion" parent="." index="6" instance=ExtResource( 4 )]

visible = false

Expand Down

0 comments on commit 2edccf4

Please sign in to comment.