Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from worldsowisdom/cyanrealm
Cyanrealm updates
- Loading branch information
Showing
8 changed files
with
133 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
|
||
var body | ||
|
||
func _ready(): | ||
|
||
pass | ||
|
||
func update(): | ||
|
||
set_fixed_process() | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |