Skip to content

Commit

Permalink
Add propulsion of hosts that show symptoms, Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Apr 4, 2020
1 parent 6db257b commit 740abda
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 17 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
![CI](https://github.com/h4de5/godot-wusely/workflows/CI/badge.svg)

# wusely
A godot game simulation about swarming dots


Run Simulation on [github Pages](https://h4de5.github.io/godot-wusely/)

![pjEkZ15k3Z](https://user-images.githubusercontent.com/6115324/77979782-e7404100-7305-11ea-9c49-8130dd3b2c0a.gif)


4 changes: 4 additions & 0 deletions src/autoloads/effects.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func play(sound, position = null, parent = null):
player.stream = load(sound)
else:
player.stream = sound

# randomize pitch - credits to CW
player.pitch_scale = randf() * 0.2 + 0.9

# play the sound
player.play()

Expand Down
17 changes: 16 additions & 1 deletion src/city.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const host = preload("res://src/host.tscn")

### city attributes
export var movement_speed = 100
export var citizens = 120
export var citizens = 100
export var hospital_beds = 20
export var social_distance = 150

# Called when the node enters the scene tree for the first time.
func _ready():
Expand All @@ -26,7 +27,21 @@ func create_hosts():
for i in range(citizens):
citizen = host.instance()
citizen.birth(self)
# citizen.position = Vector2((i+1) * 100,(i+1) * 100)
# citizen.direction = Vector2(i%2,i%2)
get_node("hosts").add_child(citizen)
# citizen = host.instance()
# citizen.birth(self)
# citizen.position = Vector2(-200, 105)
# citizen.direction = Vector2(1,0)
# get_node("hosts").add_child(citizen)
#
# citizen = host.instance()
# citizen.birth(self)
# citizen.position = Vector2(200, 100)
# citizen.direction = Vector2(-1,0)
# get_node("hosts").add_child(citizen)

outbreak()

# set the virus free
Expand Down
63 changes: 53 additions & 10 deletions src/host.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const COLOR_DEATH = Color.black

# TODO - get each host a randomize name
onready var sprite = get_node("Sprite")
onready var area = get_node("Area")
onready var area_shape = get_node("Area/Shape")
onready var infections = get_node("Infections")

### host attributes
Expand Down Expand Up @@ -116,29 +118,68 @@ func _ready():
var boundary : Rect2 = city.get_boundaries()
var x = boundary.size.x
var y = boundary.size.y

randomize()
position = Vector2(randf() * x*2 - x, randf() * y*2 -y)
# start direction
direction = Vector2(randf() * 2 -1, randf() * 2 -1)

movement_speed = city.movement_speed
area_shape.shape.radius = city.social_distance

add_to_group("HOST")

func birth(city):
self.city = city
movement_speed = city.movement_speed

func _process(delta: float) -> void:
# Get velocity
var velocity = movement_speed * direction
func _physics_process(delta: float) -> void:


# if host is dead - slowing down until stopping
if is_dead:
movement_speed *= 0.98
# if host show symptoms, drop movement speed
#if get_symptoms():
if self.is_symptoms:
velocity /= 2
movement_speed *= 0.99
direction *= 0.99

elif self.is_symptoms:
if !has_sound():
# if symptoms are shown - make some noise
Effects.cough(self)

# check which hosts are nearby
var nearby_hosts = area.get_overlapping_areas()
if len(nearby_hosts) > 0:
for nearby_host in nearby_hosts:
# print("found host: ", nearby_host)
# print("direction: ", (nearby_host.position - self.position))
# print("normalized: ", (nearby_host.position - self.position).normalized())
# print("length: ", (nearby_host.position - self.position).length())
# print("distance: ", (nearby_host.position - self.position).length())
# print("#####")
# direction = ( (self.position - ).normalized()).normalized()
# direction = self.position.reflect((nearby_host.position - self.position).normalized())
var collision_vector = nearby_host.global_position - self.position
var normalized_direction = collision_vector.normalized()
var inverse_distance = area_shape.shape.radius*2 - collision_vector.length()
# var inverse_distance_lerped = 1 - inverse_lerp(0, area_shape.shape.radius*2, collision_vector.length())
var inverse_distance_lerped = 1 - inverse_lerp(0, pow(area_shape.shape.radius*2, 2), pow(collision_vector.length(),2) )
#
# print("positions: ", nearby_host.position, " self: ", self.position)
# print("area_shape.shape.radius: ", area_shape.shape.radius)
# print("collision_vector: ", collision_vector)
# print("vector_length: ", collision_vector.length())
# print("normalized_direction: ", normalized_direction)
# print("inverse_distance: ", inverse_distance)
# print("inverse_distance_lerped: ", inverse_distance_lerped)
# print("#####")

# direction = direction - (inverse_distance_lerped * normalized_direction * delta) / (len(nearby_hosts))
nearby_host.owner.direction = nearby_host.owner.direction + (inverse_distance_lerped * normalized_direction * delta) / (len(nearby_hosts))

# Get velocity
var velocity = movement_speed * direction

# if host show symptoms, drop movement speed
if self.is_symptoms:
velocity /= 1.5

move_and_slide(velocity)
# check if there is a collision:
Expand All @@ -150,6 +191,8 @@ func _process(delta: float) -> void:
if collision.collider.get_script() == load("res://src/host.gd"):
# if 2 hosts meet
meet(collision.collider)
else: # only if no collision was registered
pass

func has_sound():
return has_node("sound")
Expand Down
6 changes: 3 additions & 3 deletions src/host.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
radius = 4.97443

[sub_resource type="CircleShape2D" id=2]
radius = 20.0
radius = 50.0

[node name="host" type="KinematicBody2D"]
script = ExtResource( 2 )
Expand All @@ -21,7 +21,7 @@ texture = ExtResource( 1 )

[node name="Infections" type="Node" parent="."]

[node name="Area2D" type="Area2D" parent="."]
[node name="Area" type="Area2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="Shape" type="CollisionShape2D" parent="Area"]
shape = SubResource( 2 )
11 changes: 11 additions & 0 deletions src/main.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
extends Node2D

var tmp = 0

func _ready():

pass

func _physics_process(delta: float) -> void:
var sum_speed = 0
for host in get_tree().get_nodes_in_group("HOST"):
sum_speed += host.direction.length()

tmp += delta
if tmp > 3:
tmp = 0
# print("sum speed: ",sum_speed)
6 changes: 3 additions & 3 deletions src/virus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const time_to_contagion = 20
# how long does it take for someone to see symptoms
const time_to_symptoms = 50
# how long does it take to get cured (once in hospitality)
const time_to_cure = 100
const time_to_cure = 150
# how long does it take until you die
const time_to_death = 200
const time_to_death = 250

# TODO - missing time variations
# when does cure start? - immediatly after infection
Expand All @@ -22,7 +22,7 @@ const time_to_death = 200
#

# how likely it is to infect other people
const chance_of_infection : float = 0.8
const chance_of_infection : float = 0.95
# how likely it is to show symptoms
const chance_of_contagion : float = 1.0
# how likely it is to show symptoms
Expand Down

0 comments on commit 740abda

Please sign in to comment.