Browse Source

Color Hero 1 walls according to friendliness!

master
Luna 7 years ago
parent
commit
251c7c6735
4 changed files with 37 additions and 8 deletions
  1. +4
    -1
      scenes/wall.tscn
  2. +20
    -0
      scripts/heroes/0-wall.gd
  3. +9
    -2
      scripts/heroes/1.gd
  4. +4
    -5
      scripts/player.gd

+ 4
- 1
scenes/wall.tscn View File

@ -1,4 +1,6 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://scripts/heroes/0-wall.gd" type="Script" id=1]
[sub_resource type="CubeMesh" id=1] [sub_resource type="CubeMesh" id=1]
@ -21,6 +23,7 @@ friction = 1.0
bounce = 0.0 bounce = 0.0
constant_linear_velocity = Vector3( 0, 0, 0 ) constant_linear_velocity = Vector3( 0, 0, 0 )
constant_angular_velocity = Vector3( 0, 0, 0 ) constant_angular_velocity = Vector3( 0, 0, 0 )
script = ExtResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="." index="0"] [node name="MeshInstance" type="MeshInstance" parent="." index="0"]


+ 20
- 0
scripts/heroes/0-wall.gd View File

@ -0,0 +1,20 @@
extends StaticBody
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass
func set_color(color):
var mat = SpatialMaterial.new()
mat.albedo_color = color
get_node("MeshInstance").set_surface_material(0, mat)
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass

+ 9
- 2
scripts/heroes/1.gd View File

@ -8,7 +8,7 @@ const max_walls = 7
func _process(delta): func _process(delta):
if is_network_master(): if is_network_master():
if Input.is_action_just_pressed("hero_1_place_wall"): if Input.is_action_just_pressed("hero_1_place_wall"):
# Press button twice to cancel # Press button twice to cancel
if is_placing_wall: if is_placing_wall:
@ -36,6 +36,10 @@ func _process(delta):
placing_wall_node = null placing_wall_node = null
is_placing_wall = false is_placing_wall = false
func _exit_tree():
for wall in walls:
wall.queue_free()
slave func slave_place_wall(tf): slave func slave_place_wall(tf):
var wall = add_wall() var wall = add_wall()
finalize_wall(wall, tf) finalize_wall(wall, tf)
@ -43,6 +47,9 @@ slave func slave_place_wall(tf):
# Creates wall, adds to world, and returns the node # Creates wall, adds to world, and returns the node
func add_wall(): func add_wall():
var wall = preload("res://scenes/wall.tscn").instance() var wall = preload("res://scenes/wall.tscn").instance()
var friendly = player_info.is_right_team == master_player.player_info.is_right_team
var color = friend_color if friendly else enemy_color
wall.set_color(color)
get_node("/root/Level").add_child(wall) get_node("/root/Level").add_child(wall)
return wall return wall
@ -60,4 +67,4 @@ func check_wall_count():
# If we've made max_walls, remove the first we made # If we've made max_walls, remove the first we made
if walls.size() > max_walls: if walls.size() > max_walls:
walls[0].queue_free() walls[0].queue_free()
walls.pop_front()
walls.pop_front()

+ 4
- 5
scripts/player.gd View File

@ -32,6 +32,8 @@ var tp_camera = "TPCamera"
var master_only = "MasterOnly" var master_only = "MasterOnly"
var master_player var master_player
var friend_color = Color("#073a98") # Blue
var enemy_color = Color("#62071a") # Red
var ai_instanced = false var ai_instanced = false
@ -104,9 +106,9 @@ func begin():
# Set color to blue (teammate) or red (enemy) # Set color to blue (teammate) or red (enemy)
var color var color
if master_player.player_info.is_right_team == player_info.is_right_team: if master_player.player_info.is_right_team == player_info.is_right_team:
color = Color("#073a98") # Blue for friendly
color = friend_color
else: else:
color = Color("#62071a") # Red for enemy
color = enemy_color
var mat = SpatialMaterial.new() var mat = SpatialMaterial.new()
mat.albedo_color = color mat.albedo_color = color
get_node("Yaw/MainMesh").set_surface_material(0, mat) get_node("Yaw/MainMesh").set_surface_material(0, mat)
@ -256,9 +258,6 @@ sync func switch_hero(hero):
new_hero.call_deferred("set_status", get_status()) new_hero.call_deferred("set_status", get_status())
queue_free() queue_free()
func _exit_scene():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _exit_tree(): func _exit_tree():
if "record" in player_info: if "record" in player_info:
write_recording() write_recording()


Loading…
Cancel
Save