├── Sources
└── found
│ ├── data
│ ├── DataPatcher.hx
│ ├── Project.hx
│ ├── Wasm.hx
│ ├── SpriteData.hx
│ ├── Creator.hx
│ ├── DataLoader.hx
│ ├── SceneFormat.hx
│ └── Data.hx
│ ├── import.hx
│ ├── node
│ ├── NullNode.hx
│ ├── MultiEventNode.hx
│ ├── IsTrueNode.hx
│ ├── InitNode.hx
│ ├── IsFalseNode.hx
│ ├── OnAddNode.hx
│ ├── PlaySfxNode.hx
│ ├── BranchNode.hx
│ ├── UpdateNode.hx
│ ├── FloatToIntNode.hx
│ ├── ParseIntNode.hx
│ ├── PrintNode.hx
│ ├── DegToRadNode.hx
│ ├── RadToDegNode.hx
│ ├── ParseFloatNode.hx
│ ├── GetCenterNode.hx
│ ├── PlayMusicNode.hx
│ ├── RandFNode.hx
│ ├── GetRotationNode.hx
│ ├── JoinVec2Node.hx
│ ├── RandINode.hx
│ ├── AddVec2Node.hx
│ ├── MultiplyVec2Node.hx
│ ├── MultiplyVec2sNode.hx
│ ├── WhileNode.hx
│ ├── DestroyObjectNode.hx
│ ├── SplitVec2Node.hx
│ ├── GetWidthHeightNode.hx
│ ├── SendEventNode.hx
│ ├── GetPositionNode.hx
│ ├── FloatNode.hx
│ ├── GetRandomObjectNode.hx
│ ├── IntegerNode.hx
│ ├── StringNode.hx
│ ├── BooleanNode.hx
│ ├── SetCameraFollowTargetNode.hx
│ ├── EveryXNode.hx
│ ├── CooldownNode.hx
│ ├── MathNode.hx
│ ├── IsObjectOutsideViewNode.hx
│ ├── LogicTree.hx
│ ├── data
│ │ ├── NodeCreator.hx
│ │ ├── StdNode.hx
│ │ ├── MathNode.hx
│ │ ├── LogicNode.hx
│ │ └── VariableNode.hx
│ ├── EventListenNode.hx
│ ├── RotateTowardPositionNode.hx
│ ├── MouseCoordNode.hx
│ ├── Vector2Node.hx
│ ├── ApplyForceToRigidbodyNode.hx
│ ├── DestroyObjectOutsideViewNode.hx
│ ├── GetObjectNode.hx
│ ├── PlayAnimationNode.hx
│ ├── TranslateObjectNode.hx
│ ├── ApplyImpulseToRigidbodyNode.hx
│ ├── SetCameraTargetPositionNode.hx
│ ├── GetForwardNode.hx
│ ├── SetObjectLocationNode.hx
│ ├── BulletMovementNode.hx
│ ├── OnGamepadAxisInputNode.hx
│ ├── OnMouseNode.hx
│ ├── SetPropNode.hx
│ ├── OnKeyboardNode.hx
│ ├── OnGamepadButtonInputNode.hx
│ ├── GetPropNode.hx
│ ├── GateNode.hx
│ ├── FlipSpriteNode.hx
│ ├── Platformer2DControllerNode.hx
│ ├── SpawnObjectNode.hx
│ ├── LogicNode.hx
│ ├── OnCollisionNode.hx
│ ├── TopDownControllerNode.hx
│ └── Logic.hx
│ ├── Timer.hx
│ ├── object
│ ├── Collidable.hx
│ ├── Action.hx
│ ├── Camera.hx
│ └── Executor.hx
│ ├── tool
│ ├── Loop.hx
│ ├── OneOf.hx
│ ├── UUID.hx
│ ├── Runner.hx
│ ├── Follower.hx
│ ├── Pool.hx
│ └── Log.hx
│ ├── particle
│ ├── Particle.hx
│ └── Emitter.hx
│ ├── trait
│ ├── TestScript.hx
│ └── internal
│ │ ├── CameraMovement.hx
│ │ ├── LoadingScript.hx
│ │ ├── Arrows.hx
│ │ └── CanvasScript.hx
│ ├── math
│ ├── Vec2.hx
│ └── Util.hx
│ ├── audio
│ ├── Music.hx
│ └── Sfx.hx
│ ├── tween
│ ├── Tween.hx
│ └── Ease.hx
│ ├── Url.hx
│ ├── Event.hx
│ ├── anim
│ ├── Animation.hx
│ ├── Tile.hx
│ ├── Sprite.hx
│ └── Tilemap.hx
│ ├── glsl
│ └── Shader.hx
│ ├── State.hx
│ ├── Trait.hx
│ ├── Found.hx
│ └── App.hx
├── defaults
├── loading.png
├── tilesheet.png
├── font_default.ttf
├── foundry_icon.png
├── platformerPack_character.png
├── temp.txt
├── loading.json
└── default.json
├── .github
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── ask_question.md
│ ├── feature_request.md
│ └── bug_report.md
└── FUNDING.yml
├── README.md
├── khafile.js
├── License.md
└── OtherLicenses.md
/Sources/found/data/DataPatcher.hx:
--------------------------------------------------------------------------------
1 | package found.data;
2 |
3 | class DataPatcher {
4 |
5 | }
--------------------------------------------------------------------------------
/defaults/loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Foundry3D/foundry2d/HEAD/defaults/loading.png
--------------------------------------------------------------------------------
/defaults/tilesheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Foundry3D/foundry2d/HEAD/defaults/tilesheet.png
--------------------------------------------------------------------------------
/defaults/font_default.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Foundry3D/foundry2d/HEAD/defaults/font_default.ttf
--------------------------------------------------------------------------------
/defaults/foundry_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Foundry3D/foundry2d/HEAD/defaults/foundry_icon.png
--------------------------------------------------------------------------------
/defaults/platformerPack_character.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Foundry3D/foundry2d/HEAD/defaults/platformerPack_character.png
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | # Disallow blank issues to make sure people follow one of the templates.
2 | blank_issues_enabled: false
3 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [foundry2D]
4 | custom: ['https://www.patreon.com/user?u=11154829']
5 |
--------------------------------------------------------------------------------
/Sources/found/import.hx:
--------------------------------------------------------------------------------
1 | package found;
2 | // Global imports
3 |
4 | #if (!macro)
5 | import found.tool.Log.warn;
6 | import found.tool.Log.error;
7 | #end
--------------------------------------------------------------------------------
/Sources/found/node/NullNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class NullNode extends LogicNode {
5 |
6 | public function new(tree: LogicTree) {
7 | super(tree);
8 | }
9 |
10 | override function get(from: Int): Dynamic { return null; }
11 | }
12 |
--------------------------------------------------------------------------------
/Sources/found/node/MultiEventNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 |
4 |
5 | class MultiEventNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function run(from:Int) {
12 | runOutput(0);
13 | }
14 | }
--------------------------------------------------------------------------------
/defaults/temp.txt:
--------------------------------------------------------------------------------
1 | https://www.flaticon.com/free-icon/loading_189792#term=loading&page=1&position=7
2 |
3 |
--------------------------------------------------------------------------------
/Sources/found/node/IsTrueNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class IsTrueNode extends LogicNode{
4 |
5 | public function new(tree: LogicTree){
6 | super(tree);
7 | }
8 |
9 | override function run(from: Int){
10 | var bool: Bool = inputs[1].get();
11 | if(bool) runOutput(0);
12 | }
13 | }
--------------------------------------------------------------------------------
/Sources/found/node/InitNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | @:access(found.Trait)
5 | class InitNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnInit(init);
10 | }
11 |
12 | function init() {
13 | runOutput(0);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/IsFalseNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class IsFalseNode extends LogicNode{
4 |
5 | public function new(tree: LogicTree){
6 | super(tree);
7 | }
8 |
9 | override function run(from: Int){
10 | var bool: Bool = inputs[1].get();
11 | if(!bool) runOutput(0);
12 | }
13 | }
--------------------------------------------------------------------------------
/Sources/found/node/OnAddNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | @:access(found.Trait)
5 | class OnAddNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnAdd(add);
10 | }
11 |
12 | function add() {
13 | runOutput(0);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/Timer.hx:
--------------------------------------------------------------------------------
1 | package found;
2 |
3 | import kha.Scheduler;
4 |
5 | class Timer {
6 | public static var delta:Float;
7 | static var current:Float;
8 |
9 | public static function update() {
10 | delta = Scheduler.time() -current;
11 | current = Scheduler.time();
12 | }
13 | }
--------------------------------------------------------------------------------
/Sources/found/node/PlaySfxNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.audio.Sfx;
4 |
5 | @:keep
6 | class PlaySfxNode extends LogicNode {
7 | public var volume:Float;
8 |
9 | override function run(from:Int) {
10 | var name:String = inputs[1].get();
11 | Sfx.play(name,volume);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Sources/found/node/BranchNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class BranchNode extends LogicNode{
4 |
5 | public function new(tree: LogicTree){
6 | super(tree);
7 | }
8 |
9 | override function run(from: Int){
10 | var bool: Bool = inputs[1].get();
11 | bool ? runOutput(0) : runOutput(1);
12 | }
13 |
14 | }
--------------------------------------------------------------------------------
/Sources/found/node/UpdateNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | @:access(found.Trait)
5 | class UpdateNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnUpdate(update);
10 | }
11 |
12 | function update(dt:Float) {
13 | runOutput(0);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/ask_question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Ask a question
3 | about: Post a question about Foundry2D
4 | title: ''
5 | labels: question
6 | assignees: ''
7 | ---
8 |
9 |
12 |
--------------------------------------------------------------------------------
/Sources/found/data/Project.hx:
--------------------------------------------------------------------------------
1 | package found.data;
2 |
3 | typedef TProject = {
4 | var name:String;
5 | var dataVersion:Float;
6 | var path:String;
7 | var scenes:Array;//path
8 | var type:Project.Type;
9 | }
10 | enum abstract Type(Int) from Int to Int {
11 | var twoD = 0;
12 | var threeD = 1;
13 | }
--------------------------------------------------------------------------------
/Sources/found/node/FloatToIntNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class FloatToIntNode extends LogicNode {
4 |
5 | public function new(tree: LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 |
11 | var float: Float = inputs[0].get();
12 |
13 | return Math.round(float);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/ParseIntNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class ParseIntNode extends LogicNode {
4 |
5 | public function new(tree: LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 |
11 | var string: String = inputs[0].get();
12 |
13 | return Std.parseInt(string);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/PrintNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class PrintNode extends LogicNode {
5 |
6 | public function new(tree:LogicTree) {
7 | super(tree);
8 | }
9 |
10 | override function run(from:Int) {
11 | var value:Dynamic = inputs[1].get();
12 |
13 | trace(value);
14 |
15 | runOutput(0);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Sources/found/node/DegToRadNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class DegToRadNode extends LogicNode {
4 |
5 | public function new(tree: LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 |
11 | var degree: Float = inputs[0].get();
12 |
13 | return degree * Math.PI / 180;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/RadToDegNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class RadToDegNode extends LogicNode {
4 |
5 | public function new(tree: LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 |
11 | var radian: Float = inputs[0].get();
12 |
13 | return radian * 180 / Math.PI;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/ParseFloatNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class ParseFloatNode extends LogicNode {
4 |
5 | public function new(tree: LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 |
11 | var string: String = inputs[0].get();
12 |
13 | return Std.parseFloat(string);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/GetCenterNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class GetCenterNode extends LogicNode {
6 | override function get(from:Int):Dynamic {
7 | if (inputs[0].node == null) {
8 | return tree.object.center;
9 | } else {
10 | var object:Object = cast(inputs[0].get());
11 | return object.center;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Sources/found/node/PlayMusicNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.audio.Music;
4 |
5 | @:keep
6 | class PlayMusicNode extends LogicNode {
7 | public var loop:Bool = false;
8 | public var volume:Float = 1.0;
9 |
10 | override function run(from:Int) {
11 | var name:String = inputs[1].get();
12 | Music.play(name,volume,loop);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Create a feature request
4 | title: ''
5 | labels: feature request
6 | assignees: ''
7 | ---
8 |
9 |
12 |
--------------------------------------------------------------------------------
/Sources/found/node/RandFNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class RandFNode extends LogicNode {
5 |
6 | public function new(tree: LogicTree) {
7 | super(tree);
8 | }
9 |
10 | override function get(from: Int): Dynamic {
11 | var min: Float = inputs[0].get();
12 | var max: Float = inputs[1].get();
13 | return Math.random() * (max - min) + min;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/object/Collidable.hx:
--------------------------------------------------------------------------------
1 | package found.object;
2 |
3 | import echo.data.Data.CollisionData;
4 | import echo.Body;
5 |
6 | interface Collidable {
7 | private function onEnter(me:Body,other:Body, data:Array):Void;
8 | private function onStay(me:Body,other:Body, data:Array):Void;
9 | private function onExit(me:Body,other:Body):Void;
10 | }
--------------------------------------------------------------------------------
/Sources/found/node/GetRotationNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class GetRotationNode extends LogicNode {
6 | override function get(from:Int):Dynamic {
7 | if (inputs[0].node == null) {
8 | return tree.object.rotation.z;
9 | } else {
10 | var object:Object = cast(inputs[0].get());
11 | return object.rotation.z;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Sources/found/node/JoinVec2Node.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class JoinVec2Node extends LogicNode {
4 |
5 | public function new(tree:LogicTree) {
6 | super(tree);
7 | }
8 |
9 | override function get(from: Int): Dynamic {
10 | var x:Float = inputs[0].get();
11 | var y:Float = inputs[1].get();
12 |
13 | return new kha.math.FastVector2(x, y);
14 | }
15 | }
--------------------------------------------------------------------------------
/Sources/found/node/RandINode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class RandINode extends LogicNode {
5 |
6 | public function new(tree: LogicTree) {
7 | super(tree);
8 | }
9 |
10 | override function get(from: Int): Dynamic {
11 | var min: Int = inputs[0].get();
12 | var max: Int = inputs[1].get();
13 | return Math.round( Math.random() * (max - min) + min);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Sources/found/node/AddVec2Node.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 |
5 | class AddVec2Node extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function get(from: Int): Dynamic {
12 | var one:Vector2 = inputs[0].get();
13 | var two:Vector2 = inputs[1].get();
14 |
15 | return one.add(two);
16 | }
17 | }
--------------------------------------------------------------------------------
/Sources/found/node/MultiplyVec2Node.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 |
5 | class MultiplyVec2Node extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function get(from: Int): Dynamic {
12 | var one:Vector2 = inputs[0].get();
13 | var two:Float = inputs[1].get();
14 |
15 | return one.mult(two);
16 | }
17 | }
--------------------------------------------------------------------------------
/Sources/found/tool/Loop.hx:
--------------------------------------------------------------------------------
1 | package found.tool;
2 |
3 | class Loop {
4 | private var _start:Int;
5 | private var _end:Int;
6 | private var _step:Int;
7 |
8 | public function new(start:Int, end:Int, step:Int){
9 | this._start = start;
10 | this._end = end;
11 | this._step = step;
12 | }
13 |
14 | public inline function hasNext() return _start < _end;
15 | public inline function next() return (_start += _step) - _step;
16 | }
--------------------------------------------------------------------------------
/Sources/found/node/MultiplyVec2sNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 |
5 | class MultiplyVec2sNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function get(from: Int): Dynamic {
12 | var one:Vector2 = inputs[0].get();
13 | var two:Vector2 = inputs[1].get();
14 |
15 | return new Vector2(one.x * two.x, two.y * one.y);
16 | }
17 | }
--------------------------------------------------------------------------------
/Sources/found/node/WhileNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class WhileNode extends LogicNode{
4 |
5 | public function new(tree: LogicTree){
6 | super(tree);
7 | }
8 |
9 | override function run(from: Int){
10 | var bool: Bool = inputs[1].get();
11 |
12 | while(bool){
13 | runOutput(0);
14 |
15 | if(tree.loopBreak){
16 | tree.loopBreak = false;
17 | break;
18 | }
19 | }
20 |
21 | runOutput(1);
22 | }
23 | }
--------------------------------------------------------------------------------
/Sources/found/node/DestroyObjectNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class DestroyObjectNode extends LogicNode {
6 | override function run(from:Int) {
7 | var objectToDestroy:Object;
8 |
9 | if (inputs[1].node != null) {
10 | objectToDestroy = cast(inputs[1].get());
11 | } else {
12 | objectToDestroy = tree.object;
13 | }
14 |
15 | found.State.active.remove(objectToDestroy);
16 |
17 | runOutput(0);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/found/node/SplitVec2Node.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.FastVector2;
4 |
5 | class SplitVec2Node extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function get(from: Int): Dynamic {
12 | var vec2:FastVector2 = inputs[0].get();
13 |
14 | if(from == 0){
15 | return vec2.x;
16 | }else{
17 | return vec2.y;
18 | }
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/Sources/found/node/GetWidthHeightNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 | import found.object.Object;
5 |
6 | class GetWidthHeightNode extends LogicNode {
7 | override function get(from:Int):Dynamic {
8 |
9 | if (inputs[0].node == null) {
10 | return new Vector2(tree.object.width,tree.object.height);
11 | } else {
12 | var object:Object = cast(inputs[0].get());
13 | return new Vector2(object.width,object.height);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Sources/found/node/SendEventNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | @:keep
6 | @:access(found.Trait)
7 | class SendEventNode extends LogicNode {
8 |
9 | public function new(tree:LogicTree) {
10 | super(tree);
11 |
12 | }
13 | override function run(from:Int) {
14 | var eventName:String = inputs[1].get();
15 | var object:Object = inputs[2].get();
16 | var mask = object != null ? object.uid: -1;
17 | Event.send(eventName,mask);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/found/node/GetPositionNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 | import found.object.Object;
5 |
6 | class GetPositionNode extends LogicNode {
7 | override function get(from:Int):Dynamic {
8 |
9 | if (inputs[0].node == null) {
10 | return new Vector2(tree.object.position.x,tree.object.position.y);
11 | } else {
12 | var object:Object = cast(inputs[0].get());
13 | return new Vector2(object.position.x,object.position.y);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Sources/found/object/Action.hx:
--------------------------------------------------------------------------------
1 | package found.object;
2 |
3 | import kha.Worker;
4 |
5 | class Action {
6 | public static function main():Void {
7 | #if kha_kore
8 | kha.Worker.notifyWorker(function(message:Dynamic){
9 | var actions:Array = message.actions;
10 | for(i in 0...actions.length){
11 | kha.Worker.postFromWorker({out: message.actions[i](message.datas[i]), uid: message.uids[i],set: message.sets[i]});
12 | }
13 | });
14 | #end
15 | }
16 | }
--------------------------------------------------------------------------------
/Sources/found/node/FloatNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class FloatNode extends LogicNode {
5 |
6 | public var value: Float;
7 |
8 | public function new(tree: LogicTree, value = 0.0) {
9 | super(tree);
10 | this.value = value;
11 | }
12 |
13 | override function get(from: Int): Dynamic {
14 | if (inputs.length > 0) return inputs[0].get();
15 | return value;
16 | }
17 |
18 | override function set(value: Dynamic) {
19 | if (inputs.length > 0) inputs[0].set(value);
20 | else this.value = value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/found/node/GetRandomObjectNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.math.Util;
4 |
5 | @:keep
6 | class GetRandomObjectNode extends LogicNode {
7 | public var listOfObjects:Array;
8 |
9 |
10 | public function new(tree:LogicTree) {
11 | super(tree);
12 | }
13 |
14 | override function get(from:Int):Dynamic {
15 | var names:Array = State.active.getObjectNames();
16 | var choice:Int = listOfObjects[Util.randomInt(listOfObjects.length)];
17 | return State.active.getObject(names[choice]);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/found/node/IntegerNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class IntegerNode extends LogicNode {
5 |
6 | public var value: Int;
7 |
8 | public function new(tree: LogicTree, value = 0) {
9 | super(tree);
10 | this.value = value;
11 | }
12 |
13 | override function get(from: Int): Dynamic {
14 | if (inputs.length > 0) return inputs[0].get();
15 | return value;
16 | }
17 |
18 | override function set(value: Dynamic) {
19 | if (inputs.length > 0) inputs[0].set(value);
20 | else this.value = value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/found/node/StringNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class StringNode extends LogicNode {
5 |
6 | public var value:String;
7 |
8 | public function new(tree:LogicTree, value = "") {
9 | super(tree);
10 | this.value = value;
11 | }
12 |
13 | override function get(from:Int):Dynamic {
14 | if (inputs.length > 0) return inputs[0].get();
15 | return value;
16 | }
17 |
18 | override function set(value:Dynamic) {
19 | if (inputs.length > 0) inputs[0].set(value);
20 | else this.value = value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/found/node/BooleanNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class BooleanNode extends LogicNode {
5 |
6 | public var value: Bool;
7 |
8 | public function new(tree: LogicTree, value = false) {
9 | super(tree);
10 | this.value = value;
11 | }
12 |
13 | override function get(from: Int): Dynamic {
14 | if (inputs.length > 0) return inputs[0].get();
15 | return value;
16 | }
17 |
18 | override function set(value: Dynamic) {
19 | if (inputs.length > 0) inputs[0].set(value);
20 | else this.value = value;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/found/node/SetCameraFollowTargetNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class SetCameraFollowTargetNode extends LogicNode {
6 | public function new(tree:LogicTree) {
7 | super(tree);
8 | }
9 |
10 | override function run(from:Int) {
11 | if (inputs[1].node == null) {
12 | State.active.cam.setCameraFollowTarget(tree.object);
13 | } else {
14 | var objectToFollow:Object = cast(inputs[1].get());
15 | State.active.cam.setCameraFollowTarget(objectToFollow);
16 | }
17 |
18 | runOutput(0);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Sources/found/node/EveryXNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.Scheduler;
4 |
5 | class EveryXNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnInit(init);
10 | tree.notifyOnUpdate(update);
11 | }
12 | function init(){
13 | everyX = inputs[0].get();
14 | }
15 | var everyX:Float;
16 | var lastTime:Float;
17 | function update(dt:Float) {
18 | var dif = Scheduler.time() - lastTime;
19 | if(dif >= everyX){
20 | lastTime = Scheduler.time();
21 | runOutput(0);
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/found/node/CooldownNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.Scheduler;
4 |
5 | class CooldownNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnInit(init);
10 | }
11 | function init(){
12 | cooldown = inputs[1].get();
13 | lastTime = Scheduler.time();
14 | }
15 | var cooldown:Float;
16 | var lastTime:Float;
17 | override function run(from:Int) {
18 | var dif = Scheduler.time() - lastTime;
19 | if(dif >= cooldown){
20 | lastTime = Scheduler.time();
21 | runOutput(0);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Sources/found/node/MathNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class MathNode extends LogicNode {
5 |
6 | public var operations: String;
7 |
8 | public function new(tree: LogicTree) {
9 | super(tree);
10 | }
11 |
12 | override function get(from: Int): Dynamic {
13 |
14 | var v1: Float = inputs[0].get();
15 | var v2: Float = inputs[1].get();
16 | var f = 0.0;
17 |
18 | switch (operations) {
19 | case "Add": f = v1 + v2;
20 | case "Subtract": f = v1 - v2;
21 | case "Multiply": f = v1 * v2;
22 | case "Divide": f = v1 / v2;
23 | }
24 |
25 | return f;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Sources/found/tool/OneOf.hx:
--------------------------------------------------------------------------------
1 | package found.tool;
2 |
3 | import haxe.ds.Either;
4 |
5 | abstract OneOf(Either) from Either to Either {
6 | @:from inline static function fromA(a:A):OneOf {
7 | return Left(a);
8 | }
9 | @:from inline static function fromB(b:B):OneOf {
10 | return Right(b);
11 | }
12 |
13 | @:to inline function toA():Null return switch(this) {
14 | case Left(a): a;
15 | default: null;
16 | }
17 | @:to inline function toB():Null return switch(this) {
18 | case Right(b): b;
19 | default: null;
20 | }
21 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Foundry2D
2 |
3 | 
4 |
5 | Foundry is a real-time and all in one game engine. The goal is performance, ease of use and portability.
6 |
7 | - [docs](https://github.com/foundry2D/foundry2d/wiki)
8 | - For building locally and engine developement have a look at the [Empty project repository](https://github.com/foundry2D/Empty).
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Sources/found/particle/Particle.hx:
--------------------------------------------------------------------------------
1 | package found.particle;
2 |
3 |
4 | import kha.Canvas;
5 | import kha.Color;
6 |
7 | import found.object.Object;
8 |
9 | class Particle extends Object {
10 |
11 | public function new(?x:Float, ?y:Float, ?width:Float, ?height:Float){
12 | super(x, y, width, height);
13 | }
14 |
15 | override public function update(dt:Float){
16 | super.update(dt);
17 |
18 | // velocity.y -= acceleration;
19 | }
20 |
21 | override public function render(canvas:Canvas){
22 | super.render(canvas);
23 | canvas.g2.color = Color.White;
24 | canvas.g2.fillRect(position.x, position.y, width, height);
25 | }
26 | }
--------------------------------------------------------------------------------
/Sources/found/node/IsObjectOutsideViewNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class IsObjectOutsideViewNode extends LogicNode {
6 | public function new(tree:LogicTree) {
7 | super(tree);
8 |
9 | tree.notifyOnUpdate(update);
10 | }
11 |
12 | function update(dt:Float) {
13 | var object:Object;
14 | var maxViewOffset:Int = inputs[1].get();
15 |
16 | if (inputs[0].node != null) {
17 | object = cast(inputs[0].get());
18 | } else {
19 | object = tree.object;
20 | }
21 |
22 | if (!object.isVisible(maxViewOffset, found.State.active.getCameraView())) {
23 | runOutput(0);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/found/node/LogicTree.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | class LogicTree extends found.Trait {
5 |
6 | public var loopBreak = false; // Trigger break from loop nodes
7 |
8 | public function new() {
9 | super();
10 | }
11 |
12 | public function add() {}
13 |
14 | var paused = false;
15 |
16 | public function pause() {
17 | if (paused) return;
18 | paused = true;
19 |
20 | if (_update != null) for (f in _update) found.App.removeUpdate(f);
21 | }
22 |
23 | public function resume() {
24 | if (!paused) return;
25 | paused = false;
26 |
27 | if (_update != null) for (f in _update) found.App.notifyOnUpdate(f);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Sources/found/node/data/NodeCreator.hx:
--------------------------------------------------------------------------------
1 | package found.node.data;
2 |
3 | import haxe.Json;
4 | import zui.Nodes;
5 | import zui.Nodes.TNode;
6 |
7 | class NodeCreator {
8 |
9 | public static function createNode(node: TNode, nodes: Nodes, nodeCanvas: TNodeCanvas):TNode {
10 | var node:TNode = Json.parse(Json.stringify(node));
11 | node.id = nodes.getNodeId(nodeCanvas.nodes);
12 | for (soc in node.inputs) {
13 | soc.id = nodes.getSocketId(nodeCanvas.nodes);
14 | soc.node_id = node.id;
15 | }
16 | for (soc in node.outputs) {
17 | soc.id = nodes.getSocketId(nodeCanvas.nodes);
18 | soc.node_id = node.id;
19 | }
20 | return node;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/found/node/EventListenNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | @:keep
4 | @:access(found.Trait)
5 | class EventListenNode extends LogicNode {
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | tree.notifyOnRemove(removeEvent);
10 | }
11 | override function run(from:Int) {
12 | addEvent();
13 | }
14 | var eventName:String;
15 | function addEvent() {
16 | eventName = inputs[1].get();
17 | if(eventName != "" && eventName != null){
18 | Event.add(eventName,onEvent,tree.object.uid);
19 | }
20 | }
21 | function removeEvent(){
22 | if(eventName != null)
23 | Event.remove(eventName);
24 | }
25 | function onEvent(){
26 | runOutput(0);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Sources/found/trait/TestScript.hx:
--------------------------------------------------------------------------------
1 | package found.trait;
2 |
3 | import found.object.Object.RotateData;
4 | import found.object.Object.MoveData;
5 |
6 | class TestScript extends found.Trait {
7 | public function new(){
8 | super();
9 | notifyOnInit(function(){
10 | this.object.onCollision({tileId: 70,objectName: "Tilemap",onEnter:onCollisionEnter });
11 | });
12 | }
13 | function onCollisionEnter(body:echo.Body,otherBody:echo.Body,data:Array){
14 | if(body == this.object.body){
15 | trace(body.x +" "+body.y+ "x Y from current Object");
16 | }
17 | trace("Collided on spikes");
18 | }
19 | }
--------------------------------------------------------------------------------
/Sources/found/node/RotateTowardPositionNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 | import kha.math.FastVector2;
5 | import found.object.Object;
6 |
7 | class RotateTowardPositionNode extends LogicNode {
8 | override function run(from:Int) {
9 | var fastTargetPosition:FastVector2 = inputs[2].get();
10 | var targetPosition:Vector2 = new Vector2(fastTargetPosition.x, fastTargetPosition.y);
11 |
12 | var objectToRotate:Object;
13 | if (inputs[1].node == null) {
14 | objectToRotate = tree.object;
15 | } else {
16 | objectToRotate = cast(inputs[1].get());
17 | }
18 |
19 | objectToRotate.rotateTowardPosition(targetPosition);
20 |
21 | runOutput(0);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Sources/found/node/MouseCoordNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class MouseCoordNode extends LogicNode {
4 | var coords = new kha.math.FastVector2();
5 | var move = new kha.math.FastVector2();
6 |
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function get(from:Int):Dynamic {
12 | var mouse = Input.getMouse();
13 |
14 | if (from == 0) {
15 | coords.x = mouse.x+State.active.cam.position.x;
16 | coords.y = mouse.y+State.active.cam.position.y;
17 | return coords;
18 | } else if (from == 1) {
19 | move.x = mouse.movementX;
20 | move.y = mouse.movementY;
21 | return move;
22 | } else {
23 | return mouse.wheelDelta;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/found/node/Vector2Node.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class Vector2Node extends LogicNode {
4 | var value = new kha.math.FastVector2();
5 |
6 | public function new(tree:LogicTree, x:Null = null, y:Null = null) {
7 | super(tree);
8 | }
9 |
10 | override function get(from:Int):Dynamic {
11 | if(inputs[0] != null && inputs[1] != null){
12 | value.x = inputs[0].get();
13 | value.y = inputs[1].get();
14 |
15 | if (from == 0) {
16 | return value;
17 | }
18 |
19 | return value.normalized();
20 | }
21 | else {
22 | return null;
23 | }
24 |
25 | }
26 |
27 | override function set(value:Dynamic) {
28 | inputs[0].set(value.x);
29 | inputs[1].set(value.y);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Sources/found/node/ApplyForceToRigidbodyNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 | import kha.math.FastVector2;
5 |
6 | class ApplyForceToRigidbodyNode extends LogicNode {
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function run(from:Int) {
12 | var force:FastVector2 = inputs[2].get();
13 |
14 | if (inputs[1].node == null) {
15 | if (tree.object.body != null) {
16 | tree.object.body.push(force.x, force.y);
17 | }
18 | } else {
19 | var objectToApplyForceTo:Object = cast(inputs[1].get());
20 | if (objectToApplyForceTo.body != null) {
21 | objectToApplyForceTo.body.push(force.x, force.y);
22 | }
23 | }
24 |
25 | runOutput(0);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Sources/found/tool/UUID.hx:
--------------------------------------------------------------------------------
1 | package found.tool;
2 |
3 | class UUID {
4 |
5 | static public function get(?val:Null):String {
6 | // https://web.archive.org/web/20190318040344/http://www.anotherchris.net/csharp/friendly-unique-id-generation-part-2/#base62
7 |
8 | if(val == null) val = Std.random(0x7fffffff);
9 |
10 | function toChar(value:Int):String {
11 | if (value > 9) {
12 | var ascii = (65 + (value - 10));
13 | if (ascii > 90) { ascii += 6; }
14 | return String.fromCharCode(ascii);
15 | } else {
16 | return Std.string(value).charAt(0);
17 | }
18 | }
19 |
20 | var r = Std.int(val % 62);
21 | var q = Std.int(val / 62);
22 | return q > 0 ? get(q) + toChar(r) : Std.string(toChar(r));
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/Sources/found/node/DestroyObjectOutsideViewNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | class DestroyObjectOutsideViewNode extends LogicNode {
6 | public function new(tree:LogicTree) {
7 | super(tree);
8 |
9 | tree.notifyOnUpdate(update);
10 | }
11 |
12 | function update(dt:Float) {
13 | var objectToDestroy:Object;
14 | var viewOffsetToDestroyAt:Int = inputs[1].get();
15 |
16 | if (inputs[0].node != null) {
17 | objectToDestroy = cast(inputs[0].get());
18 | } else {
19 | objectToDestroy = tree.object;
20 | }
21 |
22 | if (!objectToDestroy.isVisible(viewOffsetToDestroyAt, found.State.active.getCameraView())) {
23 | found.State.active.remove(objectToDestroy);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/found/node/GetObjectNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | @:keep
6 | class GetObjectNode extends LogicNode {
7 | public var selectedObjectName:String = "";
8 |
9 | var lastSelectedObjectName:String = "";
10 | var selectedObject:Object = null;
11 |
12 | public function new(tree:LogicTree) {
13 | super(tree);
14 | }
15 |
16 | override function run(from:Int) {
17 | get(0);
18 | runOutput(0);
19 | }
20 |
21 | override function get(from:Int):Dynamic {
22 | if (selectedObject == null || lastSelectedObjectName != selectedObjectName) {
23 | lastSelectedObjectName = selectedObjectName;
24 | selectedObject = State.active.getObject(selectedObjectName);
25 | }
26 | return selectedObject;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Sources/found/node/PlayAnimationNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 |
5 | @:keep
6 | class PlayAnimationNode extends LogicNode {
7 | override function run(from:Int) {
8 | var selectedObject:Object = null;
9 | if (inputs[2].node == null) {
10 | selectedObject = tree.object;
11 | } else {
12 | selectedObject = cast(inputs[2].get());
13 | }
14 |
15 | if (selectedObject.raw.type == "sprite_object" && inputs[1].get() != "") {
16 | var curSprite:found.anim.Sprite = cast(selectedObject);
17 | curSprite.setAnimationByName(inputs[1].get());
18 | } else {
19 | if (selectedObject.raw.type != "sprite_object") {
20 | error("\"Play Animation\" node needs to be associated to a sprite_object");
21 | }
22 | }
23 |
24 | runOutput(0);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/found/node/TranslateObjectNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 | import kha.math.FastVector2;
5 |
6 | class TranslateObjectNode extends LogicNode {
7 | var direction:FastVector2 = new FastVector2();
8 | var speed:Float = 0;
9 |
10 | override function run(from:Int) {
11 | direction = inputs[2].get();
12 | speed = inputs[3].get();
13 |
14 | if (inputs[1].node == null) {
15 | tree.object.translate(translateObject);
16 | } else {
17 | var objectToTranslate:Object = cast(inputs[1].get());
18 | objectToTranslate.translate(translateObject);
19 | }
20 |
21 | runOutput(0);
22 | }
23 |
24 | function translateObject(data:MoveData) {
25 | data._positions.x += direction.x * speed;
26 | data._positions.y += direction.y * speed;
27 | return data;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Sources/found/node/ApplyImpulseToRigidbodyNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 | import kha.math.FastVector2;
5 |
6 | class ApplyImpulseToRigidbodyNode extends LogicNode {
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 | }
10 |
11 | override function run(from:Int) {
12 | var force:FastVector2 = inputs[2].get();
13 |
14 | if (inputs[1].node == null) {
15 | if (tree.object.body != null) {
16 | tree.object.body.velocity.x = force.x;
17 | tree.object.body.velocity.y = force.y;
18 | }
19 | } else {
20 | var objectToApplyImpulseTo:Object = cast(inputs[1].get());
21 | if (objectToApplyImpulseTo.body != null) {
22 | objectToApplyImpulseTo.body.velocity.x = force.x;
23 | objectToApplyImpulseTo.body.velocity.y = force.y;
24 | }
25 | }
26 |
27 | runOutput(0);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a bug report
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 |
13 |
14 | **Foundry2D version:**
15 |
16 |
17 |
18 | **OS/device including version:**
19 |
20 |
21 | **Browser:**
22 |
23 |
24 | **Issue description:**
25 |
26 |
27 |
28 | **Steps to reproduce:**
29 |
30 |
--------------------------------------------------------------------------------
/Sources/found/node/SetCameraTargetPositionNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2;
4 |
5 | class SetCameraTargetPositionNode extends LogicNode {
6 | public function new(tree:LogicTree) {
7 | super(tree);
8 | }
9 | //@TODO: We should test this; I doubt it works.
10 | override function run(from:Int) {
11 | var position:Vector2 = inputs[1].get();
12 | var camPos = State.active.cam.position;
13 | var direction = position.sub(camPos).normalized();
14 | var move= new Vector2();
15 | if(direction.x > 0)
16 | {
17 | move.x = position.x - camPos.x;
18 | }
19 | else
20 | {
21 | move.x = camPos.x - position.x;
22 | }
23 | if(direction.y > 0)
24 | {
25 | move.y = position.y - camPos.y;
26 | }
27 | else
28 | {
29 | move.y = camPos.y - position.y;
30 | }
31 | State.active.cam.move(move);
32 |
33 | runOutput(0);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Sources/found/node/GetForwardNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.math.Util;
4 | import kha.math.Vector2;
5 | import found.object.Object;
6 |
7 | class GetForwardNode extends LogicNode {
8 | #if debug_nodes
9 | public function new(tree:LogicTree) {
10 | super(tree);
11 | tree.notifyOnRender2D(debugDraw);
12 | }
13 | function debugDraw(g2:kha.graphics2.Graphics){
14 | var pos:Vector2 = tree.object.center;
15 | var forward:Vector2 = this.get(0);
16 | forward = forward.mult(50);
17 | g2.color = 0xaa0000ff;
18 | g2.fillRect(pos.x + forward.x,pos.y + forward.y,10,10);
19 | g2.color = 0xffffffff;
20 | }
21 | #end
22 | override function get(from:Int):Dynamic {
23 |
24 | var angle = Util.degToRad(inputs[0].node == null ?
25 | tree.object.rotation.z:
26 | cast(inputs[0].get(),Object).rotation.z);
27 | return new Vector2(Math.cos(angle),Math.sin(angle));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Sources/found/node/SetObjectLocationNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.object.Object;
4 | import found.object.Object.MoveData;
5 | import kha.math.FastVector2;
6 |
7 | class SetObjectLocationNode extends LogicNode {
8 | var newPositionVector:FastVector2 = new FastVector2();
9 |
10 | public function new(tree:LogicTree) {
11 | super(tree);
12 | }
13 |
14 | override function run(from:Int) {
15 | newPositionVector = inputs[2].get();
16 |
17 | if (inputs[1].node == null) {
18 | tree.object.translate(setObjectLocation);
19 | } else {
20 | var objectToSetLocation:Object = cast(inputs[1].get());
21 | objectToSetLocation.translate(setObjectLocation);
22 | }
23 |
24 | runOutput(0);
25 | }
26 |
27 | function setObjectLocation(data:MoveData) {
28 | data._positions.x = newPositionVector.x;
29 | data._positions.y = newPositionVector.y;
30 | return data;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/khafile.js:
--------------------------------------------------------------------------------
1 | let project = new Project('found');
2 | project.addAssets('defaults/**');
3 | project.addSources('Sources');
4 | project.addDefine("found");
5 | project.addDefine("zui_translate");
6 | project.addParameter('found.trait');
7 | project.addParameter("--macro keep('found.trait')");
8 | project.addParameter('found.node');
9 | project.addParameter("--macro keep('found.node')");
10 | project.addParameter('--macro echo.Macros.add_data("object", "found.object.Object")');
11 | // @TODO: Fix strict null safety issues by enabling this and fixing the compile issues
12 | // project.addParameter('--macro nullSafety("found", Strict)');
13 |
14 | // To enable debug code for nodes:
15 | // project.addDefine("debug_nodes");
16 |
17 | project.addLibrary('Libraries/foundsdk/hxmath');
18 | project.addLibrary('Libraries/foundsdk/echo');
19 | project.addLibrary('Libraries/foundsdk/zui');
20 | resolve(project);
--------------------------------------------------------------------------------
/Sources/found/node/BulletMovementNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.math.Util;
4 | import kha.math.Vector2;
5 |
6 | class BulletMovementNode extends LogicNode {
7 | public function new(tree:LogicTree) {
8 | super(tree);
9 |
10 | tree.notifyOnInit(setVelocity);
11 | }
12 | function setVelocity() {
13 | if (tree.object.body != null) {
14 | var speed:Float = inputs[1].get();
15 | var angle:Float = tree.object.rotation.z;
16 |
17 | var newVelocity:Vector2 = new Vector2();
18 | var rotationInRadians:Float = Util.degToRad(angle);
19 | newVelocity.x = Math.cos(rotationInRadians) * speed;
20 | newVelocity.y = Math.sin(rotationInRadians) * speed;
21 |
22 | tree.object.body.velocity = newVelocity;
23 | }
24 | #if debug
25 | else {
26 | error("Bullet Movement node needs the object to have a Rigidbody");
27 | }
28 | #end
29 | }
30 | override function run(from:Int) {
31 | setVelocity();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2020 the Foundry2d Development Team
2 |
3 | This software is provided 'as-is', without any express or implied
4 | warranty. In no event will the authors be held liable for any damages
5 | arising from the use of this software.
6 |
7 | Permission is granted to anyone to use this software for any purpose,
8 | including commercial applications, and to alter it and redistribute it
9 | freely, subject to the following restrictions:
10 |
11 | 1. The origin of this software must not be misrepresented; you must not
12 | claim that you wrote the original software. If you use this software
13 | in a product, an acknowledgment in the product documentation would be
14 | appreciated but is not required.
15 |
16 | 2. Altered source versions must be plainly marked as such, and must not be
17 | misrepresented as being the original software.
18 |
19 | 3. This notice may not be removed or altered from any source distribution.
20 |
--------------------------------------------------------------------------------
/Sources/found/node/OnGamepadAxisInputNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.Input.Gamepad;
4 |
5 | class OnGamepadAxisInputNode extends LogicNode {
6 | public var selectedAxisName:String;
7 |
8 | var deadZone = 0.1;
9 | var selectedAxisValue:Float = 0;
10 |
11 | public function new(tree:LogicTree) {
12 | super(tree);
13 |
14 | tree.notifyOnUpdate(update);
15 | }
16 |
17 | function update(dt:Float) {
18 | var gamepadIndex:Int = inputs[0].get();
19 | var gamepad:Gamepad = Input.getGamepad(gamepadIndex);
20 |
21 | if (gamepad == null)
22 | return;
23 |
24 | selectedAxisValue = gamepad.getAxisInformation(selectedAxisName).value;
25 | if (selectedAxisValue < deadZone && selectedAxisValue > -deadZone) {
26 | selectedAxisValue = 0;
27 | }
28 |
29 | if (gamepad.getAxisInformation(selectedAxisName).moved) {
30 | runOutput(0);
31 | }
32 | }
33 |
34 | override function get(from:Int):Dynamic {
35 | return selectedAxisValue;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Sources/found/node/OnMouseNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class OnMouseNode extends LogicNode {
4 | public var mouseEventType:String;
5 | public var mouseButton:String;
6 |
7 | static var mouseEventTypes:Array = ["Pressed", "Down", "Released", "Moved"];
8 |
9 | public static function getMouseButtonEventTypes() {
10 | return mouseEventTypes;
11 | }
12 |
13 | public function new(tree:LogicTree) {
14 | super(tree);
15 |
16 | tree.notifyOnUpdate(update);
17 | }
18 |
19 | function update(dt:Float) {
20 | var mouse = Input.getMouse();
21 | var mouseEventOccured:Bool = false;
22 |
23 | switch (mouseEventType) {
24 | case "Pressed":
25 | mouseEventOccured = mouse.started(mouseButton);
26 | case "Down":
27 | mouseEventOccured = mouse.down(mouseButton);
28 | case "Released":
29 | mouseEventOccured = mouse.released(mouseButton);
30 | case "Moved":
31 | mouseEventOccured = mouse.moved;
32 | }
33 |
34 | if (mouseEventOccured) runOutput(0);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Sources/found/tool/Runner.hx:
--------------------------------------------------------------------------------
1 | package found.tool;
2 |
3 | import found.object.Entity;
4 |
5 | class Runner {
6 | public var speed = 0.6;
7 | public var range = 200.00;
8 | private var _rate = 1.0;
9 | private var _x:Float = 0;
10 | private var _y:Float = 0;
11 |
12 | public function new(){}
13 |
14 | public function update(entity01:Entity, entity02:Entity){
15 | var distanceX:Float = entity01.position.x - entity02.position.x;
16 | var distanceY:Float = entity01.position.y - entity02.position.y;
17 |
18 | var total = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
19 |
20 | if (total <= range){
21 | distanceX = _rate * distanceX / total;
22 | distanceY = _rate * distanceY / total;
23 |
24 | _x -= distanceX;
25 | _y -= distanceY;
26 |
27 | var totalDistance = Math.sqrt(_x * _x + _y * _y);
28 |
29 | _x = speed * _x / totalDistance;
30 | _y = speed * _y / totalDistance;
31 |
32 | entity02.position.x += _x;
33 | entity02.position.y += _y;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Sources/found/tool/Follower.hx:
--------------------------------------------------------------------------------
1 | package found.tool;
2 |
3 | import found.object.Entity;
4 |
5 | class Follower {
6 | public var speed = 0.6;
7 | public var range = 200.00;
8 | private var _rate = 1.0;
9 | private var _x:Float = 0;
10 | private var _y:Float = 0;
11 |
12 | public function new(){}
13 |
14 | public function update(entity01:Entity, entity02:Entity){
15 | var distanceX:Float = entity01.position.x - entity02.position.x;
16 | var distanceY:Float = entity01.position.y - entity02.position.y;
17 |
18 | var total = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
19 |
20 | if (total <= range){
21 | distanceX = _rate * distanceX / total;
22 | distanceY = _rate * distanceY / total;
23 |
24 | _x += distanceX;
25 | _y += distanceY;
26 |
27 | var totalDistance = Math.sqrt(_x * _x + _y * _y);
28 |
29 | _x = speed * _x / totalDistance;
30 | _y = speed * _y / totalDistance;
31 |
32 | entity02.position.x += _x;
33 | entity02.position.y += _y;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Sources/found/math/Vec2.hx:
--------------------------------------------------------------------------------
1 | package found.math;
2 |
3 | import kha.math.FastVector2;
4 |
5 | // @:TODO Investigate using import kha.simd.Float32x4;
6 | // We could store scale and or center vector;
7 | // We actually need to determine which of them will be used often for calculations
8 |
9 | @:forward(dot,normalized,angle,toString,x,y)
10 | abstract Vec2(FastVector2) from FastVector2 to FastVector2 {
11 | inline public function new(x= 0.0,y=0.0) {
12 | this = new FastVector2(x,y);
13 | }
14 |
15 | @:op(A + B)
16 | public function addition(other:Vec2):Vec2 {
17 | return inline this.add(other);
18 | }
19 |
20 | @:op(A - B)
21 | public function subtract(other:Vec2):Vec2 {
22 | return inline this.sub(other);
23 | }
24 |
25 | @:op(A * B)
26 | public function multiply(f:Float):Vec2 {
27 | return inline this.mult(f);
28 | }
29 |
30 | @:op(A / B)
31 | public function divide(f:Float):Vec2 {
32 | return inline this.div(f);
33 | }
34 | }
--------------------------------------------------------------------------------
/Sources/found/node/SetPropNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.data.SceneFormat.TTrait;
4 |
5 | class SetPropNode extends LogicNode {
6 |
7 | public var classname:String;
8 | public var propertyName:String;
9 |
10 | public function new(tree: LogicTree) {
11 | super(tree);
12 | tree.notifyOnRemove(reset);
13 | }
14 | @:access(found.Trait)
15 | function reset(){
16 | for(t in tree.object.raw.traits){
17 | if(t.classname == classname && t.props != null){
18 | Trait.props.set(classname+tree.object.uid,t.props);
19 | }
20 | }
21 | }
22 | @:access(found.Trait)
23 | override function run(from:Int) {
24 | var props = Trait.getProps(classname+tree.object.uid);
25 | var i = 0;
26 | for(p in props){
27 | if(StringTools.contains(p,propertyName)){
28 | var prop = p.split("~");
29 | prop.pop();
30 | var newValue = inputs[1].get();
31 | prop.push('$newValue');
32 | props[i] = prop.join('~');
33 | Trait.props.set(classname+tree.object.uid,props);
34 | break;
35 | }
36 | i++;
37 | }
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Sources/found/audio/Music.hx:
--------------------------------------------------------------------------------
1 | package found.audio;
2 |
3 | import found.data.Data;
4 |
5 | import kha.audio2.AudioChannel;
6 | import kha.audio1.Audio;
7 |
8 | class Music {
9 | static var musicChannels:Map = new Map();
10 | public static function play(name:String, ?volume:Float = 0.3, ?loop:Bool= false ) {
11 | Data.getSound(name,function(snd:kha.Sound){
12 | var chan:AudioChannel = cast(Audio.stream(snd,loop));
13 | chan.volume = volume;
14 | musicChannels.set(name,chan);
15 |
16 | });
17 | }
18 | public static function setVolume(name:String,volume:Float){
19 | var chan = musicChannels.get(name);
20 | if(chan != null && !chan.finished){
21 | chan.volume = volume;
22 | }
23 | #if debug
24 | else if(chan == null){
25 | warn('Can\'t set volume, no music with name $name exists');
26 | }
27 | #end
28 | }
29 |
30 | public static function stopAll() {
31 | for(chan in musicChannels){
32 | chan.stop();
33 | }
34 | musicChannels.clear();
35 | }
36 | }
--------------------------------------------------------------------------------
/Sources/found/tween/Tween.hx:
--------------------------------------------------------------------------------
1 | package found.tween;
2 |
3 | class Tween {
4 | private var _from:Float;
5 | private var _to:Float;
6 | private var _time:Float;
7 | private var _duration:Float;
8 | private var _set:Float->Float->Void;
9 | private var _ease:Float->Float;
10 | private var _finished:Bool;
11 | private var _onCompleteFunc:NullVoid>;
12 |
13 | public function new(from:Float, to:Float, duration:Float, ease:Float->Float, set:Float->Float->Void){
14 | this._from = from;
15 | this._to = to - from;
16 | this._duration = duration;
17 | this._set = set;
18 | this._ease = ease;
19 | _time = 0;
20 | _finished = false;
21 | }
22 |
23 | public function update(){
24 | if (_finished) return;
25 |
26 | _time += 1 / 60;
27 | if (_time >= _duration){
28 | _set(1, _from + _to);
29 | _finished = true;
30 | finish();
31 | } else {
32 | var t = _time / _duration;
33 | _set(t, _from + _ease(t) * _to);
34 | }
35 | }
36 |
37 | function finish(){
38 | if (_onCompleteFunc!= null) _onCompleteFunc();
39 | }
40 |
41 | public function onComplete(func:Void->Void){
42 | _onCompleteFunc = func;
43 | return this;
44 | }
45 | }
--------------------------------------------------------------------------------
/Sources/found/Url.hx:
--------------------------------------------------------------------------------
1 | package found;
2 |
3 | import haxe.io.Bytes;
4 |
5 | class Url {
6 |
7 | public static function explorer(url: String) {
8 | #if krom_windows
9 | Krom.sysCommand('explorer "' + url + '"');
10 | #elseif krom_linux
11 | Krom.sysCommand('xdg-open "' + url + '"');
12 | #elseif (krom_android || krom_ios)
13 | Krom.loadUrl(url);
14 | #elseif krom
15 | Krom.sysCommand('open "' + url + '"');
16 | #else
17 | kha.System.loadUrl(url);
18 | #end
19 | }
20 |
21 | public static function download(url: String, dstPath: String) {
22 | #if krom_windows
23 | Krom.sysCommand('powershell -c "Invoke-WebRequest -Uri ' + url + " -OutFile '" + dstPath + "'");
24 | #elseif krom
25 | Krom.sysCommand("curl " + url + " -o " + dstPath);
26 | #end
27 | }
28 |
29 | public static function downloadBytes(url: String): Bytes {
30 | #if krom
31 | var save = Path.data() + Path.sep + "download.bin";
32 | download(url, save);
33 | try {
34 | return Bytes.ofData(Krom.loadBlob(save));
35 | }
36 | catch (e: Dynamic) {
37 | return null;
38 | }
39 | #else
40 | return null;
41 | #end
42 | }
43 | }
--------------------------------------------------------------------------------
/Sources/found/trait/internal/CameraMovement.hx:
--------------------------------------------------------------------------------
1 | package found.trait.internal;
2 |
3 | import kha.math.Vector2;
4 | import found.object.Camera;
5 | import found.math.Util;
6 |
7 | @:access(found.object.Camera)
8 | class CameraMovement extends found.Trait {
9 | var camera:Camera;
10 | public var considerRotation:Bool = false;
11 | public function new(){
12 | super();
13 | this.notifyOnInit(function(){
14 | this.camera = cast(this.object,Camera);
15 | });
16 | notifyOnUpdate(update);
17 | }
18 | function update(dt:Float){
19 | if (camera.target != null){
20 | var pos = camera.target.center.mult(camera.zoom);
21 | var center = camera.origin;
22 | var lpos = new Vector2(camera.position.x,camera.position.y);
23 | if (camera.offsetX < Math.abs(Math.abs(camera.position.x - center.x) - pos.x)) {
24 | lpos.x = Util.lerp(camera.position.x, pos.x - center.x, camera.camSpeedX * Timer.delta);
25 | }
26 | if (camera.offsetY < Math.abs(Math.abs(camera.position.y - center.y) - pos.y)) {
27 | lpos.y = Util.lerp(camera.position.y, pos.y - center.y, camera.camSpeedY * Timer.delta);
28 | }
29 | camera.move(lpos.sub(camera.position),considerRotation);
30 |
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/defaults/loading.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "loading",
3 | "_entities":[
4 | {
5 | "name": "load-icon",
6 | "type": "sprite_object",
7 | "position":{ "x": 0.0, "y": 0.0},
8 | "rotation": { "x": 0.0, "y": 0.0,"z": 0.0},
9 | "width": 666.0,
10 | "height": 555.0,
11 | "center":{ "x": 0.0, "y": 0.0},
12 | "scale":{ "x": 0.5, "y": 0.5},
13 | "depth": 0.0,
14 | "active": true,
15 | "imagePath": "loading",
16 | "anims": [],
17 | "traits":[
18 | {
19 | "type": "Script",
20 | "classname": "found.trait.internal.LoadingScript"
21 | }
22 | ],
23 | "rigidBody":{
24 | "kinematic": true,
25 | "mass": 9.8,
26 | "shapes": [ {
27 | "type": 0,
28 | "solid":true,
29 | "width": 333.0,
30 | "height": 277.5
31 | }]
32 | }
33 | }
34 | ],
35 | "physicsWorld": {
36 | "width": 1280.0,
37 | "height": 720.0,
38 | "x": 0.0,
39 | "y": 0.0,
40 | "gravity_y": 20.0,
41 | "iterations": 5
42 | }
43 | }
--------------------------------------------------------------------------------
/Sources/found/Event.hx:
--------------------------------------------------------------------------------
1 | package found;
2 |
3 | import found.tool.OneOf;
4 | import haxe.ds.Either;
5 |
6 | class Event {
7 |
8 | static var events = new Map>();
9 |
10 | public static function send(name: String, mask = -1) {
11 | var entries = get(name);
12 | if (entries != null)
13 | for (e in entries)
14 | if (mask == -1 || mask == e.mask )
15 | switch(e.onEvent){
16 | case Left(v):
17 | v();
18 | case Right(v):
19 | v([name,mask]);
20 | }
21 | }
22 |
23 | public static function get(name: String): Array {
24 | return events.get(name);
25 | }
26 |
27 | public static function add(name: String, onEvent:OneOfVoid,Array->Void>, mask = -1): TEvent {
28 | var e: TEvent = { name: name, onEvent: onEvent, mask: mask };
29 | var entries = events.get(name);
30 | if (entries != null) entries.push(e);
31 | else events.set(name, [e]);
32 | return e;
33 | }
34 |
35 | public static function remove(name: String) {
36 | events.remove(name);
37 | }
38 |
39 | public static function removeListener(event: TEvent) {
40 | var entries = events.get(event.name);
41 | if (entries != null) entries.remove(event);
42 | }
43 | }
44 |
45 | typedef TEvent = {
46 | var name: String;
47 | var onEvent:OneOfVoid,Array->Void>;
48 | var mask: Int;
49 | }
50 |
--------------------------------------------------------------------------------
/Sources/found/node/OnKeyboardNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.input.KeyCode;
4 | import found.Input.Keyboard;
5 |
6 | class OnKeyboardNode extends LogicNode {
7 | public var keyboardEventType:String;
8 | public var keyCode:KeyCode;
9 |
10 | static var keyboardEventTypes:Array = ["Pressed", "Down", "Released"];
11 | var isDown:Bool = false;
12 | public static function getKeyboardEventTypes() {
13 | return keyboardEventTypes;
14 | }
15 |
16 | public function new(tree:LogicTree) {
17 | super(tree);
18 |
19 | tree.notifyOnUpdate(update);
20 | }
21 | var lastKey:KeyCode;
22 | var keyName:String;
23 | function update(dt:Float) {
24 | var keyboard:Keyboard = Input.getKeyboard();
25 | var keyboardEventOccured:Bool = false;
26 |
27 | if(lastKey != keyCode){
28 | keyName = Input.Keyboard.keyCode(keyCode);
29 | lastKey = keyCode;
30 | }
31 |
32 | switch (keyboardEventType) {
33 | case "Pressed":
34 | keyboardEventOccured = keyboard.started(keyName);
35 | case "Down":
36 | keyboardEventOccured = keyboard.down(keyName);
37 | case "Released":
38 | keyboardEventOccured = keyboard.released(keyName);
39 | }
40 |
41 | isDown = keyboardEventOccured;
42 |
43 | if (keyboardEventOccured)
44 | runOutput(0);
45 | }
46 | override function get(from:Int):Dynamic {
47 | return isDown;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Sources/found/node/OnGamepadButtonInputNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.Input.Gamepad;
4 |
5 | class OnGamepadButtonInputNode extends LogicNode {
6 | static var buttonEventTypes:Array = ["Pressed", "Down", "Released"];
7 |
8 | public var selectedButtonEventType:String;
9 | public var selectedButtonName:String;
10 |
11 | var selectedButtonValue:Int = 0;
12 |
13 | public static function getButtonEventTypes() {
14 | return buttonEventTypes;
15 | }
16 |
17 | public function new(tree:LogicTree) {
18 | super(tree);
19 |
20 | tree.notifyOnUpdate(update);
21 | }
22 |
23 | function update(dt:Float) {
24 | var gamepadIndex:Int = inputs[0].get();
25 | var gamepad:Gamepad = Input.getGamepad(gamepadIndex);
26 | var gamepadEventOccured:Bool = false;
27 |
28 | if (gamepad == null)
29 | return;
30 |
31 | switch (selectedButtonEventType) {
32 | case "Pressed":
33 | gamepadEventOccured = gamepad.started(selectedButtonName);
34 | case "Down":
35 | gamepadEventOccured = gamepad.down(selectedButtonName) > 0.0;
36 | case "Released":
37 | gamepadEventOccured = gamepad.released(selectedButtonName);
38 | }
39 |
40 | if (gamepadEventOccured) {
41 | selectedButtonValue = 1;
42 | runOutput(0);
43 | } else {
44 | selectedButtonValue = 0;
45 | }
46 | }
47 |
48 | override function get(from:Int):Dynamic {
49 | return selectedButtonValue;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Sources/found/trait/internal/LoadingScript.hx:
--------------------------------------------------------------------------------
1 | package found.trait.internal;
2 |
3 | import found.object.Object.RotateData;
4 | import found.object.Object.MoveData;
5 |
6 | class LoadingScript extends found.Trait {
7 | public function new(){
8 | super();
9 | notifyOnInit(doStuff);
10 | notifyOnInit(function (){
11 | this.object.translate(center);
12 | // this.object.rotate(function (data:RotateData){
13 | // data._rotations.z+= 10*data.dt;
14 | // return data;
15 | // },1.0);
16 | });
17 | notifyOnUpdate(function(dt:Float){
18 | // this.object.rotate(function (data:RotateData){
19 | // data._rotations.z+= 10*data.dt;
20 | // return data;
21 | // },dt);
22 | // State.active.cam.x-=1.0;
23 | // this.object.translate(move,dt);
24 | // this.object.rotation+= 10*dt;
25 | });
26 | }
27 | function doStuff(){
28 | trace("Hello World !");
29 | }
30 | function center(data:MoveData){
31 | data._positions.x = (Found.WIDTH*0.5-(this.object.width)*0.5);
32 | data._positions.y = (Found.HEIGHT*0.5-(this.object.height)*0.5);
33 | return data;
34 | }
35 | function move(data:MoveData){
36 | var speed = 25.0;
37 | data._positions.x += speed*data.dt;
38 | return data;
39 | }
40 | }
--------------------------------------------------------------------------------
/Sources/found/node/GetPropNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import kha.math.Vector2i;
4 |
5 | class GetPropNode extends LogicNode {
6 | public var classname:String;
7 | public var propertyName:String;
8 | override function get(from:Int):Dynamic {
9 | var value:Null = null;
10 | for(t in tree.object.raw.traits){
11 | if(t.classname == classname && t.props != null){
12 | var props = Trait.getProps(classname+tree.object.uid);
13 | for(p in props){
14 | if(StringTools.contains(p,propertyName)){
15 | var prop = p.split("~");
16 | var type = Std.parseInt(prop[1]);
17 | value = toType(type,prop[2]);
18 | break;
19 | }
20 | }
21 | }
22 | }
23 | return value;
24 | }
25 | function toType(type:Trait.PropertyType,text:String){
26 | var value:Any;
27 | switch(type){
28 | case int:
29 | value = Std.parseInt(text);
30 | case bool:
31 | value = text == "1" ? true : false;
32 | case float:
33 | value = Std.parseFloat(text);
34 | case string:
35 | value = text;
36 | case vector2i:
37 | var values:Array = text.split("|");
38 | value = new Vector2i(toType(int,values[0]),toType(int,values[1]));
39 | case vector2b:
40 | var values:Array = text.split("|");
41 | value = new Vector2i(toType(int,values[0]),toType(int,values[1]));
42 | case vector2:
43 | var values:Array = text.split("|");
44 | value = new Vector2i(toType(float,values[0]),toType(float,values[1]));
45 | }
46 | return value;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Sources/found/node/GateNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | class GateNode extends LogicNode {
4 |
5 | public var operations: String;
6 |
7 | public function new(tree: LogicTree) {
8 | super(tree);
9 | }
10 | static var operationsNames:Array = ["Or","And","Equal","Less", "Less Equal","Greater", "Greater Equal"];
11 | public static function getOperationsNames() {
12 | return operationsNames;
13 | }
14 | override function get(from:Int):Dynamic {
15 | var v1: Dynamic = inputs[0].get();
16 | var v2: Dynamic = inputs[1].get();
17 | var cond = false;
18 |
19 | switch (operations) {
20 | case "Equal":
21 | cond = v1 == v2;
22 | case "Greater":
23 | cond = v1 > v2;
24 | case "Greater Equal":
25 | cond = v1 >= v2;
26 | case "Less":
27 | cond = v1 < v2;
28 | case "Less Equal":
29 | cond = v1 <= v2;
30 | case "Or":
31 | for (i in 0...inputs.length) {
32 | if (inputs[i].get()) {
33 | cond = true;
34 | break;
35 | }
36 | }
37 | case "And":
38 | cond = true;
39 | for (i in 0...inputs.length) {
40 | if (!inputs[i].get()) {
41 | cond = false;
42 | break;
43 | }
44 | }
45 | }
46 |
47 | return cond;
48 | }
49 | }
--------------------------------------------------------------------------------
/Sources/found/node/FlipSpriteNode.hx:
--------------------------------------------------------------------------------
1 | package found.node;
2 |
3 | import found.anim.Sprite;
4 | import found.object.Object;
5 |
6 | @:keep
7 | class FlipSpriteNode extends LogicNode {
8 | public var selectedSpriteName:String = "";
9 |
10 | public var value: Bool;
11 | var lastselectedSpriteName:String = "";
12 | var selectedSprite:Sprite = null;
13 |
14 | public function new(tree:LogicTree) {
15 | super(tree);
16 | }
17 |
18 | override function run(from:Int) {
19 | var sprite:Null