Skip to content

Commit

Permalink
Merge pull request #15 from worldsowisdom/cyanrealm
Browse files Browse the repository at this point in the history
Cyanrealm updates
  • Loading branch information
eaglegamma committed Mar 27, 2017
2 parents 2704c8a + 4ed13cf commit 4fe9e06
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Data/AI/Circle.gd
@@ -1,9 +1,11 @@

var body

func _ready():

pass

func update():

set_fixed_process()
pass
87 changes: 87 additions & 0 deletions Data/AI/DefaultAIScript.gd
@@ -0,0 +1,87 @@
extends Node

#Default AI
#Behavior: moving random

var maxSpeedValue = 2

var speedDirection = Vector2(0,1)
var speedValue = 2
var speedVector = Vector2(0,0)


var des
var tmp

#State 0: wandering - 1:moving to destination
var state = 0

func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass

func update( body):

if state == 0:
wanderRandomly(body)
if state == 1:
moveToTarget(des, body)

pass

func unhandled_input(ev):

#change state
state = 1
#Set destination
des = ev

pass

func moveToTarget(des, body):

tmp = des - body.get_global_pos()
#Set speed
speedValue = maxSpeedValue

#Calculate distance
if tmp.length() <= speedValue || des ==null: #If des reached, back to wandering mode
print("STOPPP")
state = 0
speedValue = 0
des = null
return
#Calculate direction
speedDirection = tmp.normalized()
#Move target to des
speedVector = speedDirection * speedValue
body.set_global_pos( body.get_global_pos() + speedVector)
pass

func wanderRandomly(body):
#random change direction
tmp = rand_range(0, 999)

#Calculate action
if 0 <tmp && tmp < 2:
#Change direction
speedDirection = speedDirection.rotated(rand_range(0, 314) /100)
print("Directino change")
if 10 < tmp && tmp< 20 :
#Change speed
speedValue = maxSpeedValue
print("Speed change")

if 30< tmp && tmp <50 :
#Stop
speedValue = 0

if 50< tmp && tmp < 100:
#No change
pass

#Moving body
speedVector = speedDirection * speedValue
body.set_global_pos( body.get_global_pos() + speedVector)
pass
12 changes: 12 additions & 0 deletions Data/CommonScns/AI.tscn
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=1]

[sub_resource type="GDScript" id=1]

resource/name = "AI"
script/source = "var data\nvar body\n\n\n\nvar AIScript\nvar defaultAIScript = \"res://Data/AI/DefaultAIScript.gd\"\n\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\t#Get the body node\n\tbody = get_node(\"..\")\n\t\n\t#Init AI system for the body\n\tsetAI(body)\n\t\n\tset_fixed_process(true)\n\tset_process_unhandled_input(true)\n\tpass\n\nfunc _fixed_process(delta):\n\t\n\tAIScript.update(body)\n\t\n\tpass\n\nfunc setAI(bd):\n\t\n\tif \"AIScript\" in body:\n\t\t#IF body carry AI script info, use that info\n\t\tAIScript = load(body.AIScript).new()\n\telse:\n\t\t#If not, use the default AI script\n\t\tAIScript = load(defaultAIScript).new()\n\t\t\n\t\tpass \n\t\n\tif AIScript == null:# if AI script is null, use default AI script\n\t\tAIScript = load(defaultAIScript).new()\n\t\tpass\n\t\n\tpass\n\nfunc _unhandled_input( ev ):\n\t#If input is not mouse click -> return\n\tif (ev.type!=InputEvent.MOUSE_BUTTON ):\n\t\treturn\n\t#Make sure event only occur at click point once\n\tif !(ev.button_index == BUTTON_LEFT and ev.pressed):\n\t\treturn\n\t#If it not play mode, do nothing\n\tif data.controlMode != data.CONTROLMODE.idle:\n\t\t\n\t\treturn\n\t\n\t#Calculate real ev position\n\tev = ev.global_pos + data.activeCamera.get_global_pos() - (get_viewport().get_rect().size/2)\n\t\n\tAIScript.unhandled_input(ev)\n\t\n\tpass\n\nfunc update():\n\t\n\tpass"

[node name="Node2D" type="Node2D"]

script/script = SubResource( 1 )


4 changes: 3 additions & 1 deletion Data/CommonScns/Canvas.tscn
Expand Up @@ -6,13 +6,15 @@
[sub_resource type="GDScript" id=1]

resource/name = "Canvas"
script/source = "\nvar data\n\nvar HUD\n\nvar tmp\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\tHUD = get_node(\"HUD\")\n\t\n\tset_process_unhandled_input(true)\n\tpass\n\n\n# Listen to input\nfunc _unhandled_input( ev ):\n\t#If input is not mouse click -> return\n\tif (ev.type!=InputEvent.MOUSE_BUTTON ):\n\t\treturn\n\t#Make sure event only occur at click point once\n\tif !(ev.button_index == BUTTON_LEFT and ev.pressed):\n\t\treturn\n\t\n\t#If the controll mode is not create new mode -> return\n\tif data.controlMode !=data.CONTROLMODE.new:\n\t\treturn\n\t#If no object selected yet -> return\n\tif data.selectedObject == null:\n\t\treturn\n\t\n\tvar newObj = data.selectedObject.instance()\n\t\n\tadd_child(newObj)\n\t\n\tnewObj.set_pos(ev.global_pos + HUD.get_global_pos() - (get_viewport().get_rect().size/2))\n\t#Add button to select object\n\tvar selectionBtn = load(\"res://Data/CommonScns/HUD/ObjectSelectionBtn.tscn\").instance()\n\tnewObj.add_child(selectionBtn)\n\t\n\tprint(\"Mouse Click/Unclick at: \",ev.pos)\n\t\n\tpass"
script/source = "\nvar data\n\nvar HUD\n\nvar des\nvar tmp\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\tHUD = get_node(\"HUD\")\n\t\n\tset_process_unhandled_input(true)\n\tpass\n\n\n# Listen to input\nfunc _unhandled_input( ev ):\n\t#If input is not mouse click -> return\n\tif (ev.type!=InputEvent.MOUSE_BUTTON ):\n\t\treturn\n\t#Make sure event only occur at click point once\n\tif !(ev.button_index == BUTTON_LEFT and ev.pressed):\n\t\treturn\n\t\n\t#If the controll mode is not create new mode -> return\n\tif data.controlMode !=data.CONTROLMODE.new:\n\t\treturn\n\t#If no object selected yet -> return\n\tif data.selectedObject == null:\n\t\treturn\n\t\n\tvar newObj = data.selectedObject.instance()\n\t\n\t#Calculate the click position based on ev position\n\tdes = ev.global_pos + HUD.get_global_pos() - (get_viewport().get_rect().size/2)\n\t\n\tget_node(\"Field\").add_child(newObj)\n\t\n\t\n\tnewObj.set_pos(des)\n\t#Add AI to the object\n\tvar newAI = data.AIObject.instance()\n\tnewObj.add_child(newAI)\n\t#Add button to select object\n\tvar selectionBtn = load(\"res://Data/CommonScns/HUD/ObjectSelectionBtn.tscn\").instance()\n\tnewObj.add_child(selectionBtn)\n\t\n\tprint(\"Mouse Click/Unclick at: \",ev.pos)\n\t\n\tpass"

[node name="Canvas" type="Sprite"]

texture = ExtResource( 1 )
script/script = SubResource( 1 )

[node name="Field" type="Node2D" parent="."]

[node name="HUD" parent="." instance=ExtResource( 2 )]


2 changes: 1 addition & 1 deletion Data/CommonScns/Data.tscn
Expand Up @@ -3,7 +3,7 @@
[sub_resource type="GDScript" id=1]

resource/name = "Data"
script/source = "\nvar selectedObject\nvar selectedGroupObject = []\n\nvar controlMode = 3\nvar CONTROLMODE = {\n\tnew = 0,\n\tremove = 1,\n\tedit = 2,\n\tinspect = 3\n\n}\n\nvar objectPath = \"res://Data/Objects/\"\nvar objectsList = [\n]\n\nvar AITYPE = {\n\tsquare = \"res://Data/AI/Circle.gd\",\n\tcircle = 1,\n\ttriangle = 2\n}\n\nvar tmp\n\nfunc _ready():\n\t\n\tloadObject()\n\t\n\tpass\n\n# load all object file name in objectPath to objectList \nfunc loadObject():\n\tvar objectDir = Directory.new()\n\tobjectDir.open(objectPath)\n\tobjectDir.list_dir_begin()\n\t\n\t\n\twhile true:\n\t\tvar file = objectDir.get_next()\n\t\t\n\t\tif file == \"\":\n\t\t\tbreak\n\t\telif not file.begins_with(\".\"):\n\t\t\tobjectsList.append(file)\n\t\t\t\n\t\n\t\n\tpass"
script/source = "\nvar activeCamera\n\nvar selectedObject\nvar selectedGroupObject = []\n\nvar controlMode = 3\nvar CONTROLMODE = {\n\tidle = -1,\n\tnew = 0,\n\tremove = 1,\n\tedit = 2,\n\tinspect = 3\n\n}\n\nvar objectPath = \"res://Data/Objects/\"\nvar objectsList = [\n]\n\nvar AIObjectPath = \"res://Data/CommonScns/AI.tscn\"\nvar AIObject\n\nvar AITYPE = {\n\tsquare = \"res://Data/AI/Circle.gd\",\n\tcircle = 1,\n\ttriangle = 2\n}\n\nvar tmp\n\nfunc _ready():\n\tloadCommonObject()\n\tloadObject()\n\t\n\tpass\n\n#\nfunc loadCommonObject():\n\t\n\tAIObject= load(AIObjectPath)\n\tpass\n\n# load all object file name in objectPath to objectList \nfunc loadObject():\n\tvar objectDir = Directory.new()\n\tobjectDir.open(objectPath)\n\tobjectDir.list_dir_begin()\n\t\n\t\n\twhile true:\n\t\tvar file = objectDir.get_next()\n\t\t\n\t\tif file == \"\":\n\t\t\tbreak\n\t\telif not file.begins_with(\".\"):\n\t\t\tobjectsList.append(file)\n\t\t\t\n\t\n\t\n\tpass"

[node name="Data" type="Node2D"]

Expand Down
6 changes: 3 additions & 3 deletions Data/CommonScns/HUD/HUD.tscn
Expand Up @@ -10,16 +10,16 @@
[sub_resource type="GDScript" id=1]

resource/name = "HUD"
script/source = "\nvar data\n\n\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\t\n\t\n\tupdate()\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\t#Check ObjectPanel condition\n\tif data.controlMode == data.CONTROLMODE.new:\n\t\tget_node(\"ObjectPanel\").show()\n\telse:\n\t\tget_node(\"ObjectPanel\").hide()\n\t\n\t\n\tpass\n\nfunc update():\n\tupdateObjectPanel()\n\tpass\n\nfunc updateObjectPanel():\n\t\n\tget_node(\"ObjectPanel\").update()\n\t\n\tpass"
script/source = "\nvar data\n\n\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\t\n\t#Regist this to data\n\tdata.activeCamera = self\n\t\n\tupdate()\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\t#Check ObjectPanel condition\n\tif data.controlMode == data.CONTROLMODE.new:\n\t\tget_node(\"ObjectPanel\").show()\n\telse:\n\t\tget_node(\"ObjectPanel\").hide()\n\t\n\t\n\tpass\n\nfunc update():\n\tupdateObjectPanel()\n\tpass\n\nfunc updateObjectPanel():\n\t\n\tget_node(\"ObjectPanel\").update()\n\t\n\tpass"

[sub_resource type="GDScript" id=2]

resource/name = "NewBtn"
script/source = "\nvar disabledTexture = \"\"\nvar activatedTexture = \"\"\n\nfunc _ready():\n\tdisabledTexture = load(\"res://Data/Textures/HUD/NewBtn.png\")\n\tactivatedTexture = load(\"res://Data/Textures/HUD/NewBtn1.png\")\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\tupdate()\n\tpass\n\nfunc update():\n\t\n\tif get_node(\"/root/Data\").controlMode == get_node(\"/root/Data\").CONTROLMODE.new:\n\t\tset_normal_texture(activatedTexture)\n\telse:\n\t\tset_normal_texture(disabledTexture)\n\t\n\tpass\n\nfunc _on_NewBtn_pressed():\n\t\n\tget_node(\"/root/Data\").controlMode = get_node(\"/root/Data\").CONTROLMODE.new\n\t\n\tpass # replace with function body\n\n"
script/source = "\nvar disabledTexture = \"\"\nvar activatedTexture = \"\"\n\nfunc _ready():\n\tdisabledTexture = load(\"res://Data/Textures/HUD/NewBtn.png\")\n\tactivatedTexture = load(\"res://Data/Textures/HUD/NewBtn1.png\")\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\tupdate()\n\tpass\n\nfunc update():\n\t\n\tif get_node(\"/root/Data\").controlMode == get_node(\"/root/Data\").CONTROLMODE.new:\n\t\tset_normal_texture(activatedTexture)\n\telse:\n\t\tset_normal_texture(disabledTexture)\n\t\n\tpass\n\nfunc _on_NewBtn_pressed():\n\t\n\tif get_node(\"/root/Data\").controlMode != get_node(\"/root/Data\").CONTROLMODE.new:\n\t\t#If game mode is not current in new mode -> set it in new mode\n\t\tget_node(\"/root/Data\").controlMode = get_node(\"/root/Data\").CONTROLMODE.new\n\telse:\n\t\t#If game mode is current in new mode -> set it in idle mode\n\t\tget_node(\"/root/Data\").controlMode = get_node(\"/root/Data\").CONTROLMODE.idle\n\t\tpass\n\t\n\tpass # replace with function body\n\n"

[sub_resource type="GDScript" id=3]

script/source = "var data\n\nvar tmp = \"\"\n\nfunc _ready():\n\tdata = get_node(\"/root/Data\")\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\t\n\tif data.controlMode == data.CONTROLMODE.new:\n\t\ttmp = \"Create new\"\n\t\n\tif data.controlMode == data.CONTROLMODE.remove:\n\t\ttmp = \"Remove\"\n\t\n\tif data.controlMode == data.CONTROLMODE.edit:\n\t\ttmp = \"Edit\"\n\t\n\tif data.controlMode == data.CONTROLMODE.inspect:\n\t\ttmp = \"Inspect\"\n\t\n\tset_text(tmp)\n\tpass"
script/source = "var data\n\nvar tmp = \"\"\n\nfunc _ready():\n\tdata = get_node(\"/root/Data\")\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process(delta):\n\t\n\tif data.controlMode == data.CONTROLMODE.idle:\n\t\ttmp = \"Play mode\"\n\t\n\tif data.controlMode == data.CONTROLMODE.new:\n\t\ttmp = \"Create new\"\n\t\n\tif data.controlMode == data.CONTROLMODE.remove:\n\t\ttmp = \"Remove\"\n\t\n\tif data.controlMode == data.CONTROLMODE.edit:\n\t\ttmp = \"Edit\"\n\t\n\tif data.controlMode == data.CONTROLMODE.inspect:\n\t\ttmp = \"Inspect\"\n\t\n\tset_text(tmp)\n\tpass"

[sub_resource type="GDScript" id=4]

Expand Down
19 changes: 9 additions & 10 deletions Data/Objects/Object1.tscn
Expand Up @@ -2,25 +2,24 @@

[ext_resource path="res://Data/Textures/Objects/Circle.png" type="Texture" id=1]

[sub_resource type="CircleShape2D" id=3]
[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
radius = 10.0

[sub_resource type="GDScript" id=1]
[sub_resource type="GDScript" id=2]

resource/name = "Object"
script/source = "var name\nvar shape\nvar color\nvar AItype\n\nvar moveSpeed = 3\n\nvar moveVector = Vector2(0,0)\n\nvar targetList = []\n\nvar objCode = 0\n\nvar data\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\t\n\tAItype = load(data.AITYPE.circle).new()\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process():\n\t\n\tpass\n\nfunc update():\n\t\n\tAItype.updateBehavior(self)\n\t\n\tpass\n\n\nfunc _on_Area2D_body_enter( body ):\n\t\n\tif body == self:\n\t\treturn\n\t\n\tif \"objCode\" in body:\n\t\t\n\t\tprint(\"FOUND IT\")\n\t\n\tpass # replace with function body\n"
script/source = "var name\nvar shape\nvar color\nvar AItype\n\nvar moveSpeed = 3\n\nvar moveVector = Vector2(0,0)\n\nvar targetList = []\n\nvar objCode = 0\n\nvar data\n\nfunc _ready():\n\t\n\tdata = get_node(\"/root/Data\")\n\t\n\t\n\t\n\tset_fixed_process(true)\n\tpass\n\nfunc _fixed_process():\n\t\n\tpass\n\nfunc update():\n\t\n\tAItype.updateBehavior(self)\n\t\n\tpass\n\n\nfunc _on_Area2D_body_enter( body ):\n\t\n\tif body == self:\n\t\treturn\n\t\n\tif \"objCode\" in body:\n\t\t\n\t\tprint(\"FOUND IT\")\n\t\n\tpass # replace with function body\n"

[sub_resource type="CircleShape2D" id=2]
[sub_resource type="CircleShape2D" id=3]

custom_solver_bias = 0.0
radius = 10.0

[node name="Object" type="RigidBody2D"]

input/pickable = false
shapes/0/shape = SubResource( 3 )
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 4.64775, 0, 0, 4.64775, -5.21225, -0.906581 )
shapes/0/trigger = false
collision/layers = 1
Expand All @@ -40,7 +39,7 @@ velocity/linear = Vector2( 0, 0 )
velocity/angular = 0.0
damp_override/linear = -1.0
damp_override/angular = -1.0
script/script = SubResource( 1 )
script/script = SubResource( 2 )

[node name="Sprite" type="Sprite" parent="."]

Expand All @@ -49,7 +48,7 @@ texture = ExtResource( 1 )
[node name="Area2D" type="Area2D" parent="."]

input/pickable = true
shapes/0/shape = SubResource( 2 )
shapes/0/shape = SubResource( 3 )
shapes/0/transform = Matrix32( 15.3894, 0, 0, 14.4274, 1.00009, 5.38725 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
Expand All @@ -61,15 +60,15 @@ angular_damp = 1.0

transform/pos = Vector2( 1.00009, 5.38725 )
transform/scale = Vector2( 15.3894, 14.4274 )
shape = SubResource( 2 )
shape = SubResource( 3 )
trigger = false
_update_shape_index = 0

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

transform/pos = Vector2( -5.21225, -0.906581 )
transform/scale = Vector2( 4.64775, 4.64775 )
shape = SubResource( 3 )
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

Expand Down
16 changes: 16 additions & 0 deletions Data/Objects/stat.gd
@@ -0,0 +1,16 @@

var name = "Default" #(user-given during Create/Edit)
var shape #(square/rect, circle/oval, etc)
var color
var personality #/behavior (#10)
var id #unique identifying number
var location #(x and y coordinates)
var age #(time since creation)
var origin #(objected created by)



func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass

0 comments on commit 4fe9e06

Please sign in to comment.