From 754e7d2c36d47cc33e10fec34d9c683f020d7944 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 15:43:10 -0400 Subject: [PATCH 01/13] custom controls module with array reduce functions --- assets/Controls (182)/draft.ts | 23 +++++++++++++++++++++++ assets/Controls (182)/script.ts | 23 +++++++++++++++++++++++ entries.json | 7 ++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 assets/Controls (182)/draft.ts create mode 100644 assets/Controls (182)/script.ts diff --git a/assets/Controls (182)/draft.ts b/assets/Controls (182)/draft.ts new file mode 100644 index 0000000..818d33d --- /dev/null +++ b/assets/Controls (182)/draft.ts @@ -0,0 +1,23 @@ +module Controls { + + export let keyboard = { + jump: [ "W", "UP", "SPACE" ], + moveLeft: [ "A", "LEFT" ], + moveDown: [ "S", "DOWN" ], + moveRight: [ "D", "RIGHT" ], + swap: [ "E", "SHIFsT", "Z" ], + use: [ "C", "ENTER" ], + }; + + export function pressed( action:string ):boolean { + return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.wasKeyJustPressed(key) ); + //return Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); + } + + export function held( action:string ):boolean { + return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.isKeyDown(key) ); + //return Sup.Input.isKeyDown( Controls.keyboard[action] ); + } + + +} \ No newline at end of file diff --git a/assets/Controls (182)/script.ts b/assets/Controls (182)/script.ts new file mode 100644 index 0000000..8e9a2ef --- /dev/null +++ b/assets/Controls (182)/script.ts @@ -0,0 +1,23 @@ +module Controls { + + export let keyboard = { + jump: [ "W", "UP", "SPACE" ], + moveLeft: [ "A", "LEFT" ], + moveDown: [ "S", "DOWN" ], + moveRight: [ "D", "RIGHT" ], + swap: [ "W", "UP" ], + use: [ "W", "UP" ], + }; + + export function pressed( action:string ):boolean { + return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.wasKeyJustPressed(key) ); + //return Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); + } + + export function held( action:string ):boolean { + return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.isKeyDown(key) ); + //return Sup.Input.isKeyDown( Controls.keyboard[action] ); + } + + +} \ No newline at end of file diff --git a/entries.json b/entries.json index fca49f5..2b39941 100644 --- a/entries.json +++ b/entries.json @@ -1,5 +1,5 @@ { - "nextEntryId": 182, + "nextEntryId": 183, "nodes": [ { "id": "128", @@ -717,6 +717,11 @@ "type": "script" } ] + }, + { + "id": "182", + "name": "Controls", + "type": "script" } ] } \ No newline at end of file From 7ae575fc3bb38fca6ac9cee9de1729959dfa8a6d Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 16:09:34 -0400 Subject: [PATCH 02/13] extracted reduce callbacks in Control module, integrated with Player behavior --- assets/Controls (182)/draft.ts | 23 -------- assets/Controls (182)/script.ts | 19 ++++--- .../Player (21)/PlayerBehavior (24)/script.ts | 53 +++++++++++++++++-- 3 files changed, 61 insertions(+), 34 deletions(-) delete mode 100644 assets/Controls (182)/draft.ts diff --git a/assets/Controls (182)/draft.ts b/assets/Controls (182)/draft.ts deleted file mode 100644 index 818d33d..0000000 --- a/assets/Controls (182)/draft.ts +++ /dev/null @@ -1,23 +0,0 @@ -module Controls { - - export let keyboard = { - jump: [ "W", "UP", "SPACE" ], - moveLeft: [ "A", "LEFT" ], - moveDown: [ "S", "DOWN" ], - moveRight: [ "D", "RIGHT" ], - swap: [ "E", "SHIFsT", "Z" ], - use: [ "C", "ENTER" ], - }; - - export function pressed( action:string ):boolean { - return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.wasKeyJustPressed(key) ); - //return Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); - } - - export function held( action:string ):boolean { - return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.isKeyDown(key) ); - //return Sup.Input.isKeyDown( Controls.keyboard[action] ); - } - - -} \ No newline at end of file diff --git a/assets/Controls (182)/script.ts b/assets/Controls (182)/script.ts index 8e9a2ef..33b237e 100644 --- a/assets/Controls (182)/script.ts +++ b/assets/Controls (182)/script.ts @@ -5,18 +5,25 @@ module Controls { moveLeft: [ "A", "LEFT" ], moveDown: [ "S", "DOWN" ], moveRight: [ "D", "RIGHT" ], - swap: [ "W", "UP" ], - use: [ "W", "UP" ], + swap: [ "Q", "SHIFT", "Z" ], + use: [ "E", "C", "ENTER" ], }; + let cbPressed = (acc, key) => acc || Sup.Input.wasKeyJustPressed(key); + let cbHeld = (acc, key) => acc || Sup.Input.isKeyDown(key); + export function pressed( action:string ):boolean { - return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.wasKeyJustPressed(key) ); - //return Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); + // let result = Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); + let result = Controls.keyboard[action].reduce( cbPressed, false ); + //Sup.log (result); + return result; } export function held( action:string ):boolean { - return Controls.keyboard[action].reduce( (acc, key) => acc || Sup.Input.isKeyDown(key) ); - //return Sup.Input.isKeyDown( Controls.keyboard[action] ); + //let result = Sup.Input.isKeyDown( Controls.keyboard[action] ); + let result = Controls.keyboard[action].reduce( cbHeld, false ); + //Sup.log (result); + return result; } diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index c543db5..8561534 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -8,15 +8,58 @@ class PlayerBehavior extends Sup.Behavior { private initialOffset; private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; + private controls; + awake() { this.initialSize = this.actor.arcadeBody2D.getSize(); this.initialOffset = this.actor.arcadeBody2D.getOffset(); + + // Platform bodies let platformBodies = Sup.getActor("Platforms").getChildren(); for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); + + // Init controls obj + this.controls = { + pressed: { + left: false, + right: false, + jump: false, + down: false, + swap: false, + use: false + }, + held: { + left: false, + right: false, + jump: false, + down: false, + swap: false, + use: false + } + }; } update() { + // Store controls status so we only have to reduce N per update + // Just Pressed + this.controls.pressed.left = Controls.pressed("moveLeft"); + this.controls.pressed.right = Controls.pressed("moveRight"); + this.controls.pressed.jump = Controls.pressed("jump"); + this.controls.pressed.down = Controls.pressed("moveDown"); + this.controls.pressed.swap = Controls.pressed("swap"); + this.controls.pressed.use = Controls.pressed("use"); + // Held + this.controls.held.left = Controls.held("moveLeft"); + this.controls.held.right = Controls.held("moveRight"); + this.controls.held.jump = Controls.held("jump"); + this.controls.held.down = Controls.held("moveDown"); + this.controls.held.swap = Controls.held("swap"); + this.controls.held.use = Controls.held("use"); + + // Test Keyboad controls module + //Sup.log(this.controls); + // Check collision with solid bodies (from tilemap) Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); //Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.ArcadePhysics2D.getAllBodies()); @@ -50,11 +93,11 @@ class PlayerBehavior extends Sup.Behavior { } // We override the `.x` component based on the player's input - if (Sup.Input.isKeyDown("LEFT") || Sup.Input.isKeyDown("A")) { + if ( this.controls.held.left ) { velocity.x = -this.speed; // When going left, we flip the sprite this.actor.spriteRenderer.setHorizontalFlip(true); - } else if (Sup.Input.isKeyDown("RIGHT") || Sup.Input.isKeyDown("D")) { + } else if ( this.controls.held.right ) { velocity.x = this.speed; // When going right, we clear the flip this.actor.spriteRenderer.setHorizontalFlip(false); @@ -65,11 +108,11 @@ class PlayerBehavior extends Sup.Behavior { //let touchBottom = this.actor.arcadeBody2D.getTouches().bottom; let touchBottom = touchSolids || touchPlatforms; if (touchBottom) { - if (Sup.Input.wasKeyJustPressed("UP") || Sup.Input.wasKeyJustPressed("W") || Sup.Input.wasKeyJustPressed("SPACE")) { + if ( this.controls.pressed.jump ) { velocity.y = this.jumpSpeed; this.actor.spriteRenderer.setAnimation("Jump"); // If isKeyDown("DOWN") and touchPlatforms to drop down from platform - } else if ( Sup.Input.wasKeyJustPressed("DOWN") || Sup.Input.wasKeyJustPressed("S") && touchPlatforms ) { + } else if ( this.controls.pressed.down && touchPlatforms ) { velocity.y = -this.speed; } else { // Here, we should play either "Idle" or "Run" depending on the horizontal speed @@ -83,7 +126,7 @@ class PlayerBehavior extends Sup.Behavior { } else { this.actor.spriteRenderer.setAnimation("Fall"); // If isKeyDown("DOWN") to add extra umph to the fall - if ( Sup.Input.isKeyDown("DOWN") || Sup.Input.isKeyDown("S") ) { + if ( this.controls.held.down ) { velocity.y = -Game.MAX_VELOCITY_Y; dampenFall = false; } From 3c3b880d5ff7b139048ed4664982ad5cee9cc784 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 16:26:21 -0400 Subject: [PATCH 03/13] typo enter/return; wasKeyPressed undefined to false; controls obj in player --- assets/Controls (182)/script.ts | 6 +++--- .../Actors (27)/Player (21)/PlayerBehavior (24)/script.ts | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/Controls (182)/script.ts b/assets/Controls (182)/script.ts index 33b237e..da6e0c9 100644 --- a/assets/Controls (182)/script.ts +++ b/assets/Controls (182)/script.ts @@ -6,17 +6,17 @@ module Controls { moveDown: [ "S", "DOWN" ], moveRight: [ "D", "RIGHT" ], swap: [ "Q", "SHIFT", "Z" ], - use: [ "E", "C", "ENTER" ], + use: [ "E", "C", "RETURN" ], }; - let cbPressed = (acc, key) => acc || Sup.Input.wasKeyJustPressed(key); + let cbPressed = (acc, key) => acc || ( Sup.Input.wasKeyJustPressed(key) ); let cbHeld = (acc, key) => acc || Sup.Input.isKeyDown(key); export function pressed( action:string ):boolean { // let result = Sup.Input.wasKeyJustPressed( Controls.keyboard[action] ); let result = Controls.keyboard[action].reduce( cbPressed, false ); //Sup.log (result); - return result; + return result != undefined; // For some reason wasKeyJustPressed returns undefined instead of false } export function held( action:string ):boolean { diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 8561534..4940684 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -57,8 +57,9 @@ class PlayerBehavior extends Sup.Behavior { this.controls.held.swap = Controls.held("swap"); this.controls.held.use = Controls.held("use"); - // Test Keyboad controls module - //Sup.log(this.controls); + // Check item interactions + if ( this.controls.pressed.swap ) Sup.log("Swapped item!"); + if ( this.controls.pressed.use ) Sup.log("Used item!"); // Check collision with solid bodies (from tilemap) Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); From 8225f8aa4c7d28924c70e3857756d6ff463c0859 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 18:30:44 -0400 Subject: [PATCH 04/13] enum and empty behaviors for items; extracted helper methods for player updates --- .../Player (21)/PlayerBehavior (24)/script.ts | 155 ++++++++++++------ .../Items (12)/ItemBehavior (183)/script.ts | 13 ++ .../WeaponBehavior (184)/script.ts | 12 ++ assets/Keep (129)/Game (131)/script.ts | 5 + entries.json | 12 +- resources/behaviorProperties/resource.json | 22 +++ 6 files changed, 170 insertions(+), 49 deletions(-) create mode 100644 assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts create mode 100644 assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/WeaponBehavior (184)/script.ts diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 4940684..42b303f 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -9,6 +9,7 @@ class PlayerBehavior extends Sup.Behavior { private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; private controls; + private equipment; awake() { this.initialSize = this.actor.arcadeBody2D.getSize(); @@ -18,6 +19,9 @@ class PlayerBehavior extends Sup.Behavior { let platformBodies = Sup.getActor("Platforms").getChildren(); for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); + // Equipment + let equipment = this.actor.getChild("Equipment"); + // Init controls obj this.controls = { pressed: { @@ -42,56 +46,15 @@ class PlayerBehavior extends Sup.Behavior { update() { // Store controls status so we only have to reduce N per update - // Just Pressed - this.controls.pressed.left = Controls.pressed("moveLeft"); - this.controls.pressed.right = Controls.pressed("moveRight"); - this.controls.pressed.jump = Controls.pressed("jump"); - this.controls.pressed.down = Controls.pressed("moveDown"); - this.controls.pressed.swap = Controls.pressed("swap"); - this.controls.pressed.use = Controls.pressed("use"); - // Held - this.controls.held.left = Controls.held("moveLeft"); - this.controls.held.right = Controls.held("moveRight"); - this.controls.held.jump = Controls.held("jump"); - this.controls.held.down = Controls.held("moveDown"); - this.controls.held.swap = Controls.held("swap"); - this.controls.held.use = Controls.held("use"); + this.updateControls(); - // Check item interactions - if ( this.controls.pressed.swap ) Sup.log("Swapped item!"); - if ( this.controls.pressed.use ) Sup.log("Used item!"); + // Handle interactions with items + this.processItems(); - // Check collision with solid bodies (from tilemap) - Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); - //Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.ArcadePhysics2D.getAllBodies()); - - let touchSolids = this.actor.arcadeBody2D.getTouches().bottom; - let velocity = this.actor.arcadeBody2D.getVelocity(); - let dampenFall = true; + // Handle solid body collisions + let {touchSolids, velocity, dampenFall, touchPlatforms } = this.updateSolidCollisions() ; - // If falling, check the semi-solid bodies - let touchPlatforms = false; - if ( velocity.y < 0 ) { - // We must change the size of the player body so only the feet are checked - // To do so, we reduce the height of the body and adapt the offset - //this.actor.arcadeBody2D.setSize(this.initialSize.x, 0.4); - //this.actor.arcadeBody2D.setOffset({ x: this.initialOffset.x, y: -0.8 }); - - // Now, we check with every (semi-solid) platform - // TODO: apply custom collision here so we can drop down - for (let platformBody of this.allPlatformBodies) { - Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); - if (this.actor.arcadeBody2D.getTouches().bottom) { - touchPlatforms = true; - velocity.y = 0; - break; - } - } - - // After the check, we have to reset the body to its normal size - //this.actor.arcadeBody2D.setSize(this.initialSize.x, this.initialSize.y); - //this.actor.arcadeBody2D.setOffset(this.initialOffset); - } + // Process player input for movement controls // We override the `.x` component based on the player's input if ( this.controls.held.left ) { @@ -106,7 +69,6 @@ class PlayerBehavior extends Sup.Behavior { // If the player is on the ground and wants to jump, // we update the `.y` component accordingly - //let touchBottom = this.actor.arcadeBody2D.getTouches().bottom; let touchBottom = touchSolids || touchPlatforms; if (touchBottom) { if ( this.controls.pressed.jump ) { @@ -141,5 +103,102 @@ class PlayerBehavior extends Sup.Behavior { // Finally, we apply the velocity back to the ArcadePhysics body this.actor.arcadeBody2D.setVelocity(velocity); } + + + // Helper functions + + private updateControls() { + // Just Pressed + this.controls.pressed.left = Controls.pressed("moveLeft"); + this.controls.pressed.right = Controls.pressed("moveRight"); + this.controls.pressed.jump = Controls.pressed("jump"); + this.controls.pressed.down = Controls.pressed("moveDown"); + this.controls.pressed.swap = Controls.pressed("swap"); + this.controls.pressed.use = Controls.pressed("use"); + // Held + this.controls.held.left = Controls.held("moveLeft"); + this.controls.held.right = Controls.held("moveRight"); + this.controls.held.jump = Controls.held("jump"); + this.controls.held.down = Controls.held("moveDown"); + this.controls.held.swap = Controls.held("swap"); + this.controls.held.use = Controls.held("use"); + } + + private processItems() { + if ( this.controls.pressed.swap ) Sup.log("Swapped item!"); + if ( this.controls.pressed.use ) Sup.log("Used item!"); + + // Check item actions + + if ( this.controls.pressed.use && this.equipment ) { + // Handle interactions + switch ( this.equipment.getBehavior(ItemBehavior).itemtype ) { + case Game.Item.Weapon: + if (Game.nearbyInteractives.length == 0) { + // TODO: Play default animation and sfx + } else { + // Handle differently based on weapon type + switch( this.equipment.getBehavior(WeaponBehavior).itemtype) { + case Game.Weapon.Axe: + // TODO: Check for treetrunk | chest in nearbyInteractives + break; + + case Game.Weapon.Spade: + // TODO: Check for dirt | chest in nearbyInteractives + break; + + case Game.Weapon.SquirtGun: + // TODO: Check for fruitspawner | chest in nearbyInteractives + break; + + case Game.Weapon.Sword: + default: + // TODO: Check for fruitspawner | chest in nearbyInteractives + break; + } + } + break; + + case Game.Item.Food: + // TODO: Play animation and sfx + // TODO: Restore health + break; + + case Game.Item.Gold: + // TODO: Play animation and sfx + // TODO: Attract nearby NPC or Dragon + break; + + default: + break; + } + } + } + + private updateSolidCollisions() { + // Check collision with solid bodies (from tilemap) + Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); + + let touchSolids = this.actor.arcadeBody2D.getTouches().bottom; + let velocity = this.actor.arcadeBody2D.getVelocity(); + let dampenFall = true; + + // If falling, check the semi-solid bodies + let touchPlatforms = false; + if ( velocity.y < 0 ) { + // TODO: apply custom collision here so we can drop down + for (let platformBody of this.allPlatformBodies) { + Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); + if (this.actor.arcadeBody2D.getTouches().bottom) { + touchPlatforms = true; + velocity.y = 0; + break; + } + } + } + + return {touchSolids, velocity, dampenFall, touchPlatforms}; + } + } Sup.registerBehavior(PlayerBehavior); diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts new file mode 100644 index 0000000..508c55c --- /dev/null +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -0,0 +1,13 @@ +class ItemBehavior extends Sup.Behavior { + itemtype: number; + + awake() { + + } + + update() { + + } + +} +Sup.registerBehavior(ItemBehavior); diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/WeaponBehavior (184)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/WeaponBehavior (184)/script.ts new file mode 100644 index 0000000..dbb9818 --- /dev/null +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/WeaponBehavior (184)/script.ts @@ -0,0 +1,12 @@ +class WeaponBehavior extends Sup.Behavior { + itemtype: number; + + awake() { + + } + + update() { + + } +} +Sup.registerBehavior(WeaponBehavior); diff --git a/assets/Keep (129)/Game (131)/script.ts b/assets/Keep (129)/Game (131)/script.ts index a80e474..9a99289 100644 --- a/assets/Keep (129)/Game (131)/script.ts +++ b/assets/Keep (129)/Game (131)/script.ts @@ -10,6 +10,8 @@ module Game { //export let allSolidBodies: Sup.ArcadePhysics2D.Body[] = []; //export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; + export let nearbyInteractives: Sup.Actor[] = []; + export let nearbyObjects: Sup.Actor[] = []; export enum Direction { Up, Left, Down, Right }; export enum Location { Top, Left, Bottom, Right }; @@ -18,6 +20,9 @@ module Game { export enum State { Init, Play, Done }; export let state: Game.State = Game.State.Init; + + export enum Item { Weapon, Food, Gold }; + export enum Weapon { Sword, Axe, Spade, SquirtGun }; export function init() { Game.state = Game.State.Init; diff --git a/entries.json b/entries.json index 2b39941..73e1028 100644 --- a/entries.json +++ b/entries.json @@ -1,5 +1,5 @@ { - "nextEntryId": 183, + "nextEntryId": 185, "nodes": [ { "id": "128", @@ -295,6 +295,11 @@ "type": "script" } ] + }, + { + "id": "184", + "name": "WeaponBehavior", + "type": "script" } ] }, @@ -370,6 +375,11 @@ "type": "script" } ] + }, + { + "id": "183", + "name": "ItemBehavior", + "type": "script" } ] }, diff --git a/resources/behaviorProperties/resource.json b/resources/behaviorProperties/resource.json index 83e3753..ca031e2 100644 --- a/resources/behaviorProperties/resource.json +++ b/resources/behaviorProperties/resource.json @@ -187,6 +187,28 @@ "line": 0, "parentBehavior": null, "properties": [] + }, + "ItemBehavior": { + "scriptId": "183", + "line": 0, + "parentBehavior": null, + "properties": [ + { + "name": "itemtype", + "type": "number" + } + ] + }, + "WeaponBehavior": { + "scriptId": "184", + "line": 0, + "parentBehavior": null, + "properties": [ + { + "name": "itemtype", + "type": "number" + } + ] } } } \ No newline at end of file From 45f8da937084e38d67aea8f3f8b274d893d58cad Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 19:49:55 -0400 Subject: [PATCH 05/13] filled in prefabs for bare minimum items --- .../Items (12)/Font (185)/asset.json | 13 ++ .../Items (12)/Font (185)/bitmap.dat | 0 .../Items (12)/Font (185)/font.dat | 0 .../Fruit (157)/Prefab (160)/scene.json | 172 ++++++++++++++++- .../Meat (158)/Prefab (159)/scene.json | 172 ++++++++++++++++- .../Gold (156)/Prefab (161)/scene.json | 172 ++++++++++++++++- .../SquirtGun (154)/Prefab (155)/scene.json | 180 +++++++++++++++++- .../Sword (152)/Prefab (153)/scene.json | 180 +++++++++++++++++- entries.json | 7 +- 9 files changed, 890 insertions(+), 6 deletions(-) create mode 100644 assets/Keep (129)/Entities (134)/Items (12)/Font (185)/asset.json create mode 100644 assets/Keep (129)/Entities (134)/Items (12)/Font (185)/bitmap.dat create mode 100644 assets/Keep (129)/Entities (134)/Items (12)/Font (185)/font.dat diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/asset.json b/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/asset.json new file mode 100644 index 0000000..4ad6e80 --- /dev/null +++ b/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/asset.json @@ -0,0 +1,13 @@ +{ + "formatVersion": 2, + "isBitmap": false, + "filtering": "pixelated", + "pixelsPerUnit": 20, + "size": 32, + "color": "ffffff", + "opacity": null, + "gridWidth": 16, + "gridHeight": 16, + "charset": null, + "charsetOffset": 32 +} \ No newline at end of file diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/bitmap.dat b/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/bitmap.dat new file mode 100644 index 0000000..e69de29 diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/font.dat b/assets/Keep (129)/Entities (134)/Items (12)/Font (185)/font.dat new file mode 100644 index 0000000..e69de29 diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json index 3d317b9..dd12c7e 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json @@ -1,4 +1,174 @@ { "formatVersion": 1, - "nodes": [] + "nodes": [ + { + "id": "0", + "name": "Fruit", + "children": [ + { + "id": "1", + "name": "Label", + "children": [], + "components": [ + { + "type": "TextRenderer", + "config": { + "formatVersion": 2, + "fontAssetId": "185", + "text": "fruit", + "alignment": "center", + "verticalAlignment": "center", + "size": 16, + "color": null, + "overrideOpacity": true, + "opacity": 0.9 + }, + "id": "0" + } + ], + "position": { + "x": 0, + "y": -2, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + }, + { + "id": "2", + "name": "Sprite", + "children": [], + "components": [ + { + "type": "SpriteRenderer", + "config": { + "formatVersion": 1, + "spriteAssetId": "48", + "animationId": null, + "horizontalFlip": false, + "verticalFlip": false, + "castShadow": false, + "receiveShadow": false, + "color": "ffffff", + "overrideOpacity": false, + "opacity": null, + "materialType": "basic", + "shaderAssetId": null + }, + "id": "0" + }, + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 1.5, + "height": 1.5, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ], + "components": [ + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 3, + "height": 3, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "0" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "ItemBehavior", + "propertyValues": { + "itemtype": { + "type": "number", + "value": 1 + } + } + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ] } \ No newline at end of file diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json index 3d317b9..6c2bc71 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json @@ -1,4 +1,174 @@ { "formatVersion": 1, - "nodes": [] + "nodes": [ + { + "id": "0", + "name": "Meat", + "children": [ + { + "id": "1", + "name": "Label", + "children": [], + "components": [ + { + "type": "TextRenderer", + "config": { + "formatVersion": 2, + "fontAssetId": "185", + "text": "meat", + "alignment": "center", + "verticalAlignment": "bottom", + "size": 16, + "color": null, + "overrideOpacity": true, + "opacity": 1 + }, + "id": "0" + } + ], + "position": { + "x": 0, + "y": -2, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + }, + { + "id": "2", + "name": "Sprite", + "children": [], + "components": [ + { + "type": "SpriteRenderer", + "config": { + "formatVersion": 1, + "spriteAssetId": "35", + "animationId": null, + "horizontalFlip": false, + "verticalFlip": false, + "castShadow": false, + "receiveShadow": false, + "color": "ffffff", + "overrideOpacity": false, + "opacity": null, + "materialType": "basic", + "shaderAssetId": null + }, + "id": "0" + }, + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 1, + "height": 1, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ], + "components": [ + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 3, + "height": 3, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "0" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "ItemBehavior", + "propertyValues": { + "itemtype": { + "type": "number", + "value": 1 + } + } + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ] } \ No newline at end of file diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json index 3d317b9..a16c5b2 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json @@ -1,4 +1,174 @@ { "formatVersion": 1, - "nodes": [] + "nodes": [ + { + "id": "0", + "name": "Gold", + "children": [ + { + "id": "1", + "name": "Label", + "children": [], + "components": [ + { + "type": "TextRenderer", + "config": { + "formatVersion": 2, + "fontAssetId": "185", + "text": "gold", + "alignment": "center", + "verticalAlignment": "bottom", + "size": 16, + "color": null, + "overrideOpacity": true, + "opacity": 0.9 + }, + "id": "0" + } + ], + "position": { + "x": 0, + "y": -2, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + }, + { + "id": "2", + "name": "Sprite", + "children": [], + "components": [ + { + "type": "SpriteRenderer", + "config": { + "formatVersion": 1, + "spriteAssetId": "46", + "animationId": null, + "horizontalFlip": false, + "verticalFlip": false, + "castShadow": false, + "receiveShadow": false, + "color": "ffffff", + "overrideOpacity": false, + "opacity": null, + "materialType": "basic", + "shaderAssetId": null + }, + "id": "0" + }, + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 1, + "height": 1, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ], + "components": [ + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 3, + "height": 3, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "0" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "ItemBehavior", + "propertyValues": { + "itemtype": { + "type": "number", + "value": 2 + } + } + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ] } \ No newline at end of file diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json index 3d317b9..e96dcc4 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json @@ -1,4 +1,182 @@ { "formatVersion": 1, - "nodes": [] + "nodes": [ + { + "id": "0", + "name": "SquirtGun", + "children": [ + { + "id": "1", + "name": "Label", + "children": [], + "components": [ + { + "type": "TextRenderer", + "config": { + "formatVersion": 2, + "fontAssetId": "185", + "text": "squirt gun", + "alignment": "center", + "verticalAlignment": "bottom", + "size": 16, + "color": null, + "overrideOpacity": true, + "opacity": 0.9 + }, + "id": "0" + } + ], + "position": { + "x": 0, + "y": -2, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + }, + { + "id": "2", + "name": "Sprite", + "children": [], + "components": [ + { + "type": "SpriteRenderer", + "config": { + "formatVersion": 1, + "spriteAssetId": "45", + "animationId": null, + "horizontalFlip": false, + "verticalFlip": false, + "castShadow": false, + "receiveShadow": false, + "color": "ffffff", + "overrideOpacity": false, + "opacity": null, + "materialType": "basic", + "shaderAssetId": null + }, + "id": "0" + }, + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 1, + "height": 1, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ], + "components": [ + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 3, + "height": 3, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "0" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "ItemBehavior", + "propertyValues": {} + }, + "id": "1" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "WeaponBehavior", + "propertyValues": { + "itemtype": { + "type": "number", + "value": 3 + } + } + }, + "id": "2" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ] } \ No newline at end of file diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json index 3d317b9..469caa6 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json @@ -1,4 +1,182 @@ { "formatVersion": 1, - "nodes": [] + "nodes": [ + { + "id": "0", + "name": "Sword", + "children": [ + { + "id": "4", + "name": "Label", + "children": [], + "components": [ + { + "type": "TextRenderer", + "config": { + "formatVersion": 2, + "fontAssetId": "185", + "text": "sword", + "alignment": "center", + "verticalAlignment": "bottom", + "size": 16, + "color": null, + "overrideOpacity": true, + "opacity": 0.9 + }, + "id": "0" + } + ], + "position": { + "x": 0, + "y": -2, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + }, + { + "id": "5", + "name": "Sprite", + "children": [], + "components": [ + { + "type": "SpriteRenderer", + "config": { + "formatVersion": 1, + "spriteAssetId": "31", + "animationId": null, + "horizontalFlip": true, + "verticalFlip": false, + "castShadow": false, + "receiveShadow": false, + "color": "ffffff", + "overrideOpacity": false, + "opacity": null, + "materialType": "basic", + "shaderAssetId": null + }, + "id": "0" + }, + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 0.5, + "height": 1.2, + "offset": { + "x": 0.05, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "1" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": -0.3826834323650898, + "w": 0.9238795325112867 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ], + "components": [ + { + "type": "ArcadeBody2D", + "config": { + "formatVersion": 2, + "type": "box", + "movable": true, + "width": 3, + "height": 3, + "offset": { + "x": 0, + "y": 0 + }, + "bounce": { + "x": 0, + "y": 0 + }, + "tileMapAssetId": null, + "tileSetPropertyName": null, + "layersIndex": null + }, + "id": "2" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "ItemBehavior", + "propertyValues": {} + }, + "id": "3" + }, + { + "type": "Behavior", + "config": { + "behaviorName": "WeaponBehavior", + "propertyValues": { + "itemtype": { + "type": "number", + "value": 0 + } + } + }, + "id": "4" + } + ], + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": null + } + ] } \ No newline at end of file diff --git a/entries.json b/entries.json index 73e1028..26808a1 100644 --- a/entries.json +++ b/entries.json @@ -1,5 +1,5 @@ { - "nextEntryId": 185, + "nextEntryId": 186, "nodes": [ { "id": "128", @@ -247,6 +247,11 @@ "name": "Items", "type": null, "children": [ + { + "id": "185", + "name": "Font", + "type": "font" + }, { "id": "13", "name": "Weapons", From 65459373dfa13922868580b77da9468363fae082 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 19:55:57 -0400 Subject: [PATCH 06/13] set all item labels invisible by default; equipped hero/player with sword --- .../Hero (20)/Prefab (162)/scene.json | 30 ++++++++++++++++++- .../Player (21)/Prefab (163)/scene.json | 30 ++++++++++++++++++- .../Fruit (157)/Prefab (160)/scene.json | 2 +- .../Meat (158)/Prefab (159)/scene.json | 2 +- .../Gold (156)/Prefab (161)/scene.json | 2 +- .../SquirtGun (154)/Prefab (155)/scene.json | 2 +- 6 files changed, 62 insertions(+), 6 deletions(-) diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Hero (20)/Prefab (162)/scene.json b/assets/Keep (129)/Entities (134)/Actors (27)/Hero (20)/Prefab (162)/scene.json index 624ed8c..1b3d650 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Hero (20)/Prefab (162)/scene.json +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Hero (20)/Prefab (162)/scene.json @@ -4,7 +4,35 @@ { "id": "0", "name": "Hero", - "children": [], + "children": [ + { + "id": "1", + "name": "Equipment", + "children": [], + "components": [], + "position": { + "x": 1, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": { + "sceneAssetId": "153" + } + } + ], "components": [ { "type": "SpriteRenderer", diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/Prefab (163)/scene.json b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/Prefab (163)/scene.json index 9d7b0ca..549de53 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/Prefab (163)/scene.json +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/Prefab (163)/scene.json @@ -4,7 +4,35 @@ { "id": "0", "name": "Player", - "children": [], + "children": [ + { + "id": "2", + "name": "Equipment", + "children": [], + "components": [], + "position": { + "x": 1, + "y": 0, + "z": 0 + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + }, + "visible": true, + "layer": 0, + "prefab": { + "sceneAssetId": "153" + } + } + ], "components": [ { "type": "SpriteRenderer", diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json index dd12c7e..656c48e 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Fruit (157)/Prefab (160)/scene.json @@ -42,7 +42,7 @@ "y": 1, "z": 1 }, - "visible": true, + "visible": false, "layer": 0, "prefab": null }, diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json index 6c2bc71..c833f9a 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Food (14)/Meat (158)/Prefab (159)/scene.json @@ -42,7 +42,7 @@ "y": 1, "z": 1 }, - "visible": true, + "visible": false, "layer": 0, "prefab": null }, diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json index a16c5b2..01fbd64 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Gold (156)/Prefab (161)/scene.json @@ -42,7 +42,7 @@ "y": 1, "z": 1 }, - "visible": true, + "visible": false, "layer": 0, "prefab": null }, diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json index e96dcc4..90aac76 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/SquirtGun (154)/Prefab (155)/scene.json @@ -42,7 +42,7 @@ "y": 1, "z": 1 }, - "visible": true, + "visible": false, "layer": 0, "prefab": null }, From e3983979b70c639697abd1223588b0c4faf6f33c Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Fri, 31 Mar 2017 21:20:55 -0400 Subject: [PATCH 07/13] equipped items flip along with the player --- .../Player (21)/PlayerBehavior (24)/script.ts | 20 +++++++--- .../Items (12)/ItemBehavior (183)/script.ts | 40 ++++++++++++++++++- .../Sword (152)/Prefab (153)/scene.json | 13 ++++-- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 42b303f..00f333f 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -9,7 +9,8 @@ class PlayerBehavior extends Sup.Behavior { private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; private controls; - private equipment; + private equipment: Sup.Actor; + private equipmentBehavior: ItemBehavior; awake() { this.initialSize = this.actor.arcadeBody2D.getSize(); @@ -20,7 +21,8 @@ class PlayerBehavior extends Sup.Behavior { for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); // Equipment - let equipment = this.actor.getChild("Equipment"); + this.equipment = this.actor.getChild("Equipment"); + this.equipmentBehavior = this.equipment.getBehavior(ItemBehavior); // Init controls obj this.controls = { @@ -59,12 +61,12 @@ class PlayerBehavior extends Sup.Behavior { // We override the `.x` component based on the player's input if ( this.controls.held.left ) { velocity.x = -this.speed; - // When going left, we flip the sprite - this.actor.spriteRenderer.setHorizontalFlip(true); + // When going left, we flip the sprite= + this.setFlip(true); } else if ( this.controls.held.right ) { velocity.x = this.speed; // When going right, we clear the flip - this.actor.spriteRenderer.setHorizontalFlip(false); + this.setFlip(false); } else velocity.x = 0; // If the player is on the ground and wants to jump, @@ -106,6 +108,12 @@ class PlayerBehavior extends Sup.Behavior { // Helper functions + private setFlip( v:boolean ):void { + // If we aren't flipped yet, flip the equipment as well + if ( this.actor.spriteRenderer.getHorizontalFlip() != v ) this.equipmentBehavior.flip(); + // Set whether or not we are flipped + this.actor.spriteRenderer.setHorizontalFlip(v); + } private updateControls() { // Just Pressed @@ -132,7 +140,7 @@ class PlayerBehavior extends Sup.Behavior { if ( this.controls.pressed.use && this.equipment ) { // Handle interactions - switch ( this.equipment.getBehavior(ItemBehavior).itemtype ) { + switch ( this.equipmentBehavior.itemtype ) { case Game.Item.Weapon: if (Game.nearbyInteractives.length == 0) { // TODO: Play default animation and sfx diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index 508c55c..fd3508d 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -1,13 +1,51 @@ class ItemBehavior extends Sup.Behavior { itemtype: number; - awake() { + /* An item is comprised of: + * Parent actor (this) with an arcadeBody2D for detecting proximity to player via Collision2D + * Label actor with a text renderer for showing item name when close to player + * Sprite actor with a sprite renderer of animations and an arcadeBody2D for collisions with nearby objects/actors + */ + + private label: Sup.Actor; + private sprite: Sup.Actor; + + private isEquipped; + awake() { + this.label = this.actor.getChild("Label"); + this.sprite = this.actor.getChild("Sprite"); + this.isEquipped = ( this.actor.getParent().getName() == "Player" ); } update() { } + // Handle transition from equipped to dropped + + // Dropped: yes movement; collide with tileset solids; label visibility based on player collision with near box + onDropped():void { + if (!this.isEquipped) return; // it's already dropped! do nothing. + this.isEquipped = false; + } + + // Equipped: no movement; follow player position on updates; no label visibility + onEquipped():void { + if (this.isEquipped) return; // it's already equipped! do nothing. + this.isEquipped = true; + } + + // When player changes directions, so should this item, if it's equipped + flip():void { + if (!this.isEquipped) return; // it's not equipped! do nothing. + // Flip sprite + this.sprite.spriteRenderer.setHorizontalFlip(!this.sprite.spriteRenderer.getHorizontalFlip()); + // Flip sprite rotation + this.sprite.setLocalEulerZ( this.sprite.getLocalEulerZ() * -1 ); + // Adjust actor position + this.actor.setLocalPosition( { x: (-1 * this.actor.getLocalX()), y: this.actor.getLocalY() } ); + } + } Sup.registerBehavior(ItemBehavior); diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json index 469caa6..c2b9d42 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json @@ -42,7 +42,7 @@ "y": 1, "z": 1 }, - "visible": true, + "visible": false, "layer": 0, "prefab": null }, @@ -74,7 +74,7 @@ "config": { "formatVersion": 2, "type": "box", - "movable": true, + "movable": false, "width": 0.5, "height": 1.2, "offset": { @@ -119,7 +119,7 @@ "config": { "formatVersion": 2, "type": "box", - "movable": true, + "movable": false, "width": 3, "height": 3, "offset": { @@ -140,7 +140,12 @@ "type": "Behavior", "config": { "behaviorName": "ItemBehavior", - "propertyValues": {} + "propertyValues": { + "heldPosOffset": { + "type": "number", + "value": 1 + } + } }, "id": "3" }, From e87f4640911c0be706ae6ff749fa954c59acbf00 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 00:07:39 -0400 Subject: [PATCH 08/13] implemented drop item --- .../{ => Keep (129)}/Controls (182)/script.ts | 0 .../Player (21)/PlayerBehavior (24)/script.ts | 37 ++++++++-- .../Items (12)/ItemBehavior (183)/script.ts | 68 ++++++++++++++++++- .../Sword (152)/Prefab (153)/scene.json | 2 +- entries.json | 20 +++--- resources/behaviorProperties/resource.json | 16 +++++ 6 files changed, 125 insertions(+), 18 deletions(-) rename assets/{ => Keep (129)}/Controls (182)/script.ts (100%) diff --git a/assets/Controls (182)/script.ts b/assets/Keep (129)/Controls (182)/script.ts similarity index 100% rename from assets/Controls (182)/script.ts rename to assets/Keep (129)/Controls (182)/script.ts diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 00f333f..0998e5e 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -50,8 +50,9 @@ class PlayerBehavior extends Sup.Behavior { // Store controls status so we only have to reduce N per update this.updateControls(); - // Handle interactions with items - this.processItems(); + // Handle interactions with items + this.processUseItem(); + this.processSwapItem(); // Handle solid body collisions let {touchSolids, velocity, dampenFall, touchPlatforms } = this.updateSolidCollisions() ; @@ -110,7 +111,7 @@ class PlayerBehavior extends Sup.Behavior { // Helper functions private setFlip( v:boolean ):void { // If we aren't flipped yet, flip the equipment as well - if ( this.actor.spriteRenderer.getHorizontalFlip() != v ) this.equipmentBehavior.flip(); + if ( this.equipmentBehavior && this.actor.spriteRenderer.getHorizontalFlip() != v ) this.equipmentBehavior.flip(); // Set whether or not we are flipped this.actor.spriteRenderer.setHorizontalFlip(v); } @@ -132,8 +133,34 @@ class PlayerBehavior extends Sup.Behavior { this.controls.held.use = Controls.held("use"); } - private processItems() { - if ( this.controls.pressed.swap ) Sup.log("Swapped item!"); + private processSwapItem() { + // If user is using an item, don't do anything here! + if ( this.controls.held.use && this.equipment ) return; + if ( !this.controls.pressed.swap ) return; + + // If user is near an item, + if ( Game.nearbyObjects.length > 0 ) { + if ( this.equipmentBehavior ) this.equipmentBehavior.onDropped(); // Drop current equipment + + // Get closest object and swap + // TODO: Get nearest object + //this.equipment = nearestObj; + //this.equipmentBehavior = nearestObj.getBehavior(ItemBehavior); + //this.equipmentBehavior.onEquipped(); + + } else { + // Otherwise just drop it, assuming we have an item + if ( this.equipment ) { + // Drop it + this.equipmentBehavior.onDropped(); + // Set our references to null + this.equipment = null; + this.equipmentBehavior = null; + } + } + } + + private processUseItem() { if ( this.controls.pressed.use ) Sup.log("Used item!"); // Check item actions diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index fd3508d..bb76e7c 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -1,5 +1,9 @@ class ItemBehavior extends Sup.Behavior { - itemtype: number; + itemtype: number = 0; + groupName: string = "Weapons"; + name: string = "Sword"; + heldPositionX: number = 0; + heldPositionY: number = 0; /* An item is comprised of: * Parent actor (this) with an arcadeBody2D for detecting proximity to player via Collision2D @@ -9,17 +13,41 @@ class ItemBehavior extends Sup.Behavior { private label: Sup.Actor; private sprite: Sup.Actor; + private groupActor: Sup.Actor; - private isEquipped; + private isEquipped: boolean; + private isFlipped: boolean; awake() { this.label = this.actor.getChild("Label"); this.sprite = this.actor.getChild("Sprite"); + this.groupActor = Sup.getActor(this.groupName); this.isEquipped = ( this.actor.getParent().getName() == "Player" ); + this.isFlipped = false; } update() { + if (!this.isEquipped) { + // Collide with solid tiles + Sup.ArcadePhysics2D.collides( this.sprite.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); + // Parent should follow the sprite + this.actor.arcadeBody2D.warpPosition(this.sprite.getPosition()); + + // Check if nearbox collides with player + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, Sup.getActor("Player").arcadeBody2D) ) { + // set visibility + this.label.setVisible(true); + // TODO: add to nearby objects if not already + + } else { + // no longer close to player so disable visibility + this.label.setVisible(false); + // TODO: remove from nearby objects if not already + + } + } + } // Handle transition from equipped to dropped @@ -28,12 +56,46 @@ class ItemBehavior extends Sup.Behavior { onDropped():void { if (!this.isEquipped) return; // it's already dropped! do nothing. this.isEquipped = false; + + // Reparent object to Items actor in appropriate child + this.actor.setParent( this.groupActor ); + // Rename object to what it is + this.actor.setName( this.name ); + + // Set sprite movement + this.sprite.arcadeBody2D.setMovable(true); + // Set visibility + this.label.setVisible(true); + + // Set local position + //this.actor.setLocalX(0); + //this.actor.setLocalY(0); + + // Set global position of sprite + this.sprite.arcadeBody2D.warpPosition( Sup.getActor("Player").getPosition() ); + + Sup.log("Dropped item! " + this.name); } // Equipped: no movement; follow player position on updates; no label visibility onEquipped():void { if (this.isEquipped) return; // it's already equipped! do nothing. this.isEquipped = true; + + // Reparent object to Player + this.actor.setParent( Sup.getActor("Player") ); + // Rename object to Equipment + this.actor.setName( "Equipment" ); + + // Disable sprite movement + this.sprite.arcadeBody2D.setMovable(false); + // Disable visibility + this.label.setVisible(false); + + // Set local position + //this.actor.setLocalX(this.heldPositionX); + //this.actor.setLocalY(this.heldPositionY); + Sup.log("Equipped item! " + this.name); } // When player changes directions, so should this item, if it's equipped @@ -45,6 +107,8 @@ class ItemBehavior extends Sup.Behavior { this.sprite.setLocalEulerZ( this.sprite.getLocalEulerZ() * -1 ); // Adjust actor position this.actor.setLocalPosition( { x: (-1 * this.actor.getLocalX()), y: this.actor.getLocalY() } ); + + this.isFlipped = !this.isFlipped; } } diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json index c2b9d42..bf2da42 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json @@ -29,7 +29,7 @@ "position": { "x": 0, "y": -2, - "z": 0 + "z": 1 }, "orientation": { "x": 0, diff --git a/entries.json b/entries.json index 26808a1..f1d7a0b 100644 --- a/entries.json +++ b/entries.json @@ -129,16 +129,16 @@ "name": "Keep", "type": null, "children": [ - { - "id": "130", - "name": "Scene", - "type": "scene" - }, { "id": "178", "name": "Collision2D", "type": "script" }, + { + "id": "182", + "name": "Controls", + "type": "script" + }, { "id": "61", "name": "CameraBehavior", @@ -726,17 +726,17 @@ "name": "TestScene", "type": "scene" }, + { + "id": "130", + "name": "Scene", + "type": "scene" + }, { "id": "131", "name": "Game", "type": "script" } ] - }, - { - "id": "182", - "name": "Controls", - "type": "script" } ] } \ No newline at end of file diff --git a/resources/behaviorProperties/resource.json b/resources/behaviorProperties/resource.json index ca031e2..9f77f09 100644 --- a/resources/behaviorProperties/resource.json +++ b/resources/behaviorProperties/resource.json @@ -196,6 +196,22 @@ { "name": "itemtype", "type": "number" + }, + { + "name": "groupName", + "type": "string" + }, + { + "name": "name", + "type": "string" + }, + { + "name": "heldPositionX", + "type": "number" + }, + { + "name": "heldPositionY", + "type": "number" } ] }, From 681c90dac0ec81c41bf9159e440a13318ac0c72d Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 01:57:19 -0400 Subject: [PATCH 09/13] swap item works but flipping gets mixed up --- .../Player (21)/PlayerBehavior (24)/script.ts | 65 +++++++++++++++++-- .../Items (12)/ItemBehavior (183)/script.ts | 18 +++-- .../Sword (152)/Prefab (153)/scene.json | 8 +++ assets/Keep (129)/Game (131)/script.ts | 2 - 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 0998e5e..85393ed 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -12,6 +12,12 @@ class PlayerBehavior extends Sup.Behavior { private equipment: Sup.Actor; private equipmentBehavior: ItemBehavior; + private nearbyItems: Sup.Actor[] = []; + private nearbyWeapons: Sup.Actor[] = []; + private nearbyFood: Sup.Actor[] = []; + private nearbyGold: Sup.Actor[] = []; + private nearbyInteractives: Sup.Actor[] = []; + awake() { this.initialSize = this.actor.arcadeBody2D.getSize(); this.initialOffset = this.actor.arcadeBody2D.getOffset(); @@ -50,6 +56,9 @@ class PlayerBehavior extends Sup.Behavior { // Store controls status so we only have to reduce N per update this.updateControls(); + // Store nearby object status for quick access + if (this.controls.pressed.swap || this.controls.pressed.use) this.updateNearbyObjects(); + // Handle interactions with items this.processUseItem(); this.processSwapItem(); @@ -105,6 +114,12 @@ class PlayerBehavior extends Sup.Behavior { // Finally, we apply the velocity back to the ArcadePhysics body this.actor.arcadeBody2D.setVelocity(velocity); + + this.nearbyItems = []; + this.nearbyWeapons = []; + this.nearbyFood = []; + this.nearbyGold = []; + this.nearbyInteractives = []; } @@ -133,20 +148,58 @@ class PlayerBehavior extends Sup.Behavior { this.controls.held.use = Controls.held("use"); } + private updateNearbyObjects() { + for ( let item of Sup.getActor("Weapons") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyWeapons.push(item); + this.nearbyItems.push(item); + } + } + for ( let item of Sup.getActor("Food") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyFood.push(item); + this.nearbyItems.push(item); + } + } + for ( let item of Sup.getActor("Gold") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyGold.push(item); + this.nearbyItems.push(item); + } + } + /*for ( let item of Sup.getActor("Interactive") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyInteractives.push(item); + this.nearbyItems.push(item); + } + }*/ + } + + private getNearestObject() { + return this.nearbyItems.reduce( function(acc,item) { + let distance = Sup.getActor("Player").getPosition().distanceTo(item.getPosition()); + if (distance < acc.d) return { a:item, d:distance } + return acc; + }, {a:this.actor,d:Infinity} ); + } + private processSwapItem() { // If user is using an item, don't do anything here! if ( this.controls.held.use && this.equipment ) return; if ( !this.controls.pressed.swap ) return; // If user is near an item, - if ( Game.nearbyObjects.length > 0 ) { + if ( this.nearbyItems.length > 0 ) { if ( this.equipmentBehavior ) this.equipmentBehavior.onDropped(); // Drop current equipment // Get closest object and swap - // TODO: Get nearest object - //this.equipment = nearestObj; - //this.equipmentBehavior = nearestObj.getBehavior(ItemBehavior); - //this.equipmentBehavior.onEquipped(); + let {a, d} = this.getNearestObject(); + Sup.log(a); + if (a && d < Infinity && a != this.equipment) { + this.equipment = a; + this.equipmentBehavior = a.getBehavior(ItemBehavior); + this.equipmentBehavior.onEquipped(); + } } else { // Otherwise just drop it, assuming we have an item @@ -169,7 +222,7 @@ class PlayerBehavior extends Sup.Behavior { // Handle interactions switch ( this.equipmentBehavior.itemtype ) { case Game.Item.Weapon: - if (Game.nearbyInteractives.length == 0) { + if (this.nearbyInteractives.length == 0) { // TODO: Play default animation and sfx } else { // Handle differently based on weapon type diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index bb76e7c..16ae122 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -60,7 +60,7 @@ class ItemBehavior extends Sup.Behavior { // Reparent object to Items actor in appropriate child this.actor.setParent( this.groupActor ); // Rename object to what it is - this.actor.setName( this.name ); + this.actor.setName( this.name + this.groupActor.getChildren().length ); // Set sprite movement this.sprite.arcadeBody2D.setMovable(true); @@ -68,13 +68,16 @@ class ItemBehavior extends Sup.Behavior { this.label.setVisible(true); // Set local position - //this.actor.setLocalX(0); - //this.actor.setLocalY(0); + this.actor.setLocalX(0); + this.actor.setLocalY(0); // Set global position of sprite this.sprite.arcadeBody2D.warpPosition( Sup.getActor("Player").getPosition() ); - Sup.log("Dropped item! " + this.name); + // Reset Flip + if (this.isFlipped) this.flip(); + + Sup.log("Dropped item! " + this.actor.getName()); } // Equipped: no movement; follow player position on updates; no label visibility @@ -93,9 +96,10 @@ class ItemBehavior extends Sup.Behavior { this.label.setVisible(false); // Set local position - //this.actor.setLocalX(this.heldPositionX); - //this.actor.setLocalY(this.heldPositionY); - Sup.log("Equipped item! " + this.name); + this.actor.setLocalX(this.heldPositionX); + this.actor.setLocalY(this.heldPositionY); + + Sup.log("Equipped item! " + this.actor.getName()); } // When player changes directions, so should this item, if it's equipped diff --git a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json index bf2da42..1e82fbf 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json +++ b/assets/Keep (129)/Entities (134)/Items (12)/Weapons (13)/Sword (152)/Prefab (153)/scene.json @@ -144,6 +144,14 @@ "heldPosOffset": { "type": "number", "value": 1 + }, + "name": { + "type": "string", + "value": "Sword" + }, + "heldPositionX": { + "type": "number", + "value": 1 } } }, diff --git a/assets/Keep (129)/Game (131)/script.ts b/assets/Keep (129)/Game (131)/script.ts index 9a99289..743d074 100644 --- a/assets/Keep (129)/Game (131)/script.ts +++ b/assets/Keep (129)/Game (131)/script.ts @@ -10,8 +10,6 @@ module Game { //export let allSolidBodies: Sup.ArcadePhysics2D.Body[] = []; //export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; - export let nearbyInteractives: Sup.Actor[] = []; - export let nearbyObjects: Sup.Actor[] = []; export enum Direction { Up, Left, Down, Right }; export enum Location { Top, Left, Bottom, Right }; From 5d44003151f9bcf1e0843dba942aecd204eef9d4 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 02:26:41 -0400 Subject: [PATCH 10/13] corrected flip bug when swapping --- .../Player (21)/PlayerBehavior (24)/script.ts | 2 +- .../Items (12)/ItemBehavior (183)/script.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 85393ed..2cf30ed 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -194,7 +194,7 @@ class PlayerBehavior extends Sup.Behavior { // Get closest object and swap let {a, d} = this.getNearestObject(); - Sup.log(a); + if (a && d < Infinity && a != this.equipment) { this.equipment = a; this.equipmentBehavior = a.getBehavior(ItemBehavior); diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index 16ae122..b8849a3 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -74,10 +74,7 @@ class ItemBehavior extends Sup.Behavior { // Set global position of sprite this.sprite.arcadeBody2D.warpPosition( Sup.getActor("Player").getPosition() ); - // Reset Flip - if (this.isFlipped) this.flip(); - - Sup.log("Dropped item! " + this.actor.getName()); + //Sup.log("Dropped item! " + this.actor.getName()); } // Equipped: no movement; follow player position on updates; no label visibility @@ -99,7 +96,13 @@ class ItemBehavior extends Sup.Behavior { this.actor.setLocalX(this.heldPositionX); this.actor.setLocalY(this.heldPositionY); - Sup.log("Equipped item! " + this.actor.getName()); + // Re-adjust position if flipped + if (this.isFlipped) this.actor.setLocalX(-1 * this.heldPositionX); + + // Set flip according to player + if (Sup.getActor("Player").spriteRenderer.getHorizontalFlip() != this.isFlipped) this.flip(); + + //Sup.log("Equipped item! " + this.actor.getName()); } // When player changes directions, so should this item, if it's equipped @@ -116,4 +119,4 @@ class ItemBehavior extends Sup.Behavior { } } -Sup.registerBehavior(ItemBehavior); +Sup.registerBehavior(ItemBehavior \ No newline at end of file From 0d50cf780d19c528ebc2890e59be796370a36d28 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 02:29:45 -0400 Subject: [PATCH 11/13] moved allPlatBodies to Game to be accessed by all --- .../Player (21)/PlayerBehavior (24)/draft.ts | 292 ++++++++++++++++++ .../Items (12)/ItemBehavior (183)/script.ts | 2 +- assets/Keep (129)/Game (131)/draft.ts | 59 ++++ 3 files changed, 352 insertions(+), 1 deletion(-) create mode 100644 assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts create mode 100644 assets/Keep (129)/Game (131)/draft.ts diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts new file mode 100644 index 0000000..150fc70 --- /dev/null +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts @@ -0,0 +1,292 @@ +//Sup.ArcadePhysics2D.setGravity(0, -0.02); + +class PlayerBehavior extends Sup.Behavior { + speed:number = 0.2; + jumpSpeed:number = 0.42; + + private initialSize; + private initialOffset; + private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; + + private controls; + private equipment: Sup.Actor; + private equipmentBehavior: ItemBehavior; + + private nearbyItems: Sup.Actor[] = []; + private nearbyWeapons: Sup.Actor[] = []; + private nearbyFood: Sup.Actor[] = []; + private nearbyGold: Sup.Actor[] = []; + private nearbyInteractives: Sup.Actor[] = []; + + awake() { + this.initialSize = this.actor.arcadeBody2D.getSize(); + this.initialOffset = this.actor.arcadeBody2D.getOffset(); + + // Platform bodies + let platformBodies = Sup.getActor("Platforms").getChildren(); + for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); + + // Equipment + this.equipment = this.actor.getChild("Equipment"); + this.equipmentBehavior = this.equipment.getBehavior(ItemBehavior); + + // Init controls obj + this.controls = { + pressed: { + left: false, + right: false, + jump: false, + down: false, + swap: false, + use: false + }, + held: { + left: false, + right: false, + jump: false, + down: false, + swap: false, + use: false + } + }; + } + + update() { + + // Store controls status so we only have to reduce N per update + this.updateControls(); + + // Store nearby object status for quick access + if (this.controls.pressed.swap || this.controls.pressed.use) this.updateNearbyObjects(); + + // Handle interactions with items + this.processUseItem(); + this.processSwapItem(); + + // Handle solid body collisions + let {touchSolids, velocity, dampenFall, touchPlatforms } = this.updateSolidCollisions() ; + + // Process player input for movement controls + + // We override the `.x` component based on the player's input + if ( this.controls.held.left ) { + velocity.x = -this.speed; + // When going left, we flip the sprite= + this.setFlip(true); + } else if ( this.controls.held.right ) { + velocity.x = this.speed; + // When going right, we clear the flip + this.setFlip(false); + } else velocity.x = 0; + + // If the player is on the ground and wants to jump, + // we update the `.y` component accordingly + let touchBottom = touchSolids || touchPlatforms; + if (touchBottom) { + if ( this.controls.pressed.jump ) { + velocity.y = this.jumpSpeed; + this.actor.spriteRenderer.setAnimation("Jump"); + // If isKeyDown("DOWN") and touchPlatforms to drop down from platform + } else if ( this.controls.pressed.down && touchPlatforms ) { + velocity.y = -this.speed; + } else { + // Here, we should play either "Idle" or "Run" depending on the horizontal speed + if (velocity.x === 0) this.actor.spriteRenderer.setAnimation("Idle"); + else this.actor.spriteRenderer.setAnimation("Move"); + } + } else { + // Here, we should play either "Jump" or "Fall" depending on the vertical speed + if (velocity.y >= 0) { + this.actor.spriteRenderer.setAnimation("Jump"); + } else { + this.actor.spriteRenderer.setAnimation("Fall"); + // If isKeyDown("DOWN") to add extra umph to the fall + if ( this.controls.held.down ) { + velocity.y = -Game.MAX_VELOCITY_Y; + dampenFall = false; + } + } + } + + // Cap the velocity to avoid going crazy in falls + velocity.x = Sup.Math.clamp(velocity.x, -Game.MAX_VELOCITY_X, Game.MAX_VELOCITY_X); + if (dampenFall) velocity.y = Sup.Math.clamp(velocity.y, -Game.MAX_VELOCITY_Y/2, Game.MAX_VELOCITY_Y); + + // Finally, we apply the velocity back to the ArcadePhysics body + this.actor.arcadeBody2D.setVelocity(velocity); + + this.nearbyItems = []; + this.nearbyWeapons = []; + this.nearbyFood = []; + this.nearbyGold = []; + this.nearbyInteractives = []; + } + + + // Helper functions + private setFlip( v:boolean ):void { + // If we aren't flipped yet, flip the equipment as well + if ( this.equipmentBehavior && this.actor.spriteRenderer.getHorizontalFlip() != v ) this.equipmentBehavior.flip(); + // Set whether or not we are flipped + this.actor.spriteRenderer.setHorizontalFlip(v); + } + + private updateControls() { + // Just Pressed + this.controls.pressed.left = Controls.pressed("moveLeft"); + this.controls.pressed.right = Controls.pressed("moveRight"); + this.controls.pressed.jump = Controls.pressed("jump"); + this.controls.pressed.down = Controls.pressed("moveDown"); + this.controls.pressed.swap = Controls.pressed("swap"); + this.controls.pressed.use = Controls.pressed("use"); + // Held + this.controls.held.left = Controls.held("moveLeft"); + this.controls.held.right = Controls.held("moveRight"); + this.controls.held.jump = Controls.held("jump"); + this.controls.held.down = Controls.held("moveDown"); + this.controls.held.swap = Controls.held("swap"); + this.controls.held.use = Controls.held("use"); + } + + private updateNearbyObjects() { + for ( let item of Sup.getActor("Weapons") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyWeapons.push(item); + this.nearbyItems.push(item); + } + } + for ( let item of Sup.getActor("Food") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyFood.push(item); + this.nearbyItems.push(item); + } + } + for ( let item of Sup.getActor("Gold") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyGold.push(item); + this.nearbyItems.push(item); + } + } + /*for ( let item of Sup.getActor("Interactive") .getChildren()) { + if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { + this.nearbyInteractives.push(item); + this.nearbyItems.push(item); + } + }*/ + } + + private getNearestObject() { + return this.nearbyItems.reduce( function(acc,item) { + let distance = Sup.getActor("Player").getPosition().distanceTo(item.getPosition()); + if (distance < acc.d) return { a:item, d:distance } + return acc; + }, {a:this.actor,d:Infinity} ); + } + + private processSwapItem() { + // If user is using an item, don't do anything here! + if ( this.controls.held.use && this.equipment ) return; + if ( !this.controls.pressed.swap ) return; + + // If user is near an item, + if ( this.nearbyItems.length > 0 ) { + if ( this.equipmentBehavior ) this.equipmentBehavior.onDropped(); // Drop current equipment + + // Get closest object and swap + let {a, d} = this.getNearestObject(); + + if (a && d < Infinity && a != this.equipment) { + this.equipment = a; + this.equipmentBehavior = a.getBehavior(ItemBehavior); + this.equipmentBehavior.onEquipped(); + } + + } else { + // Otherwise just drop it, assuming we have an item + if ( this.equipment ) { + // Drop it + this.equipmentBehavior.onDropped(); + // Set our references to null + this.equipment = null; + this.equipmentBehavior = null; + } + } + } + + private processUseItem() { + if ( this.controls.pressed.use ) Sup.log("Used item!"); + + // Check item actions + + if ( this.controls.pressed.use && this.equipment ) { + // Handle interactions + switch ( this.equipmentBehavior.itemtype ) { + case Game.Item.Weapon: + if (this.nearbyInteractives.length == 0) { + // TODO: Play default animation and sfx + } else { + // Handle differently based on weapon type + switch( this.equipment.getBehavior(WeaponBehavior).itemtype) { + case Game.Weapon.Axe: + // TODO: Check for treetrunk | chest in nearbyInteractives + break; + + case Game.Weapon.Spade: + // TODO: Check for dirt | chest in nearbyInteractives + break; + + case Game.Weapon.SquirtGun: + // TODO: Check for fruitspawner | chest in nearbyInteractives + break; + + case Game.Weapon.Sword: + default: + // TODO: Check for fruitspawner | chest in nearbyInteractives + break; + } + } + break; + + case Game.Item.Food: + // TODO: Play animation and sfx + // TODO: Restore health + break; + + case Game.Item.Gold: + // TODO: Play animation and sfx + // TODO: Attract nearby NPC or Dragon + break; + + default: + break; + } + } + } + + private updateSolidCollisions() { + // Check collision with solid bodies (from tilemap) + Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); + + let touchSolids = this.actor.arcadeBody2D.getTouches().bottom; + let velocity = this.actor.arcadeBody2D.getVelocity(); + let dampenFall = true; + + // If falling, check the semi-solid bodies + let touchPlatforms = false; + if ( velocity.y < 0 ) { + // TODO: apply custom collision here so we can drop down + for (let platformBody of G.allPlatformBodies) { + Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); + if (this.actor.arcadeBody2D.getTouches().bottom) { + touchPlatforms = true; + velocity.y = 0; + break; + } + } + } + + return {touchSolids, velocity, dampenFall, touchPlatforms}; + } + +} +Sup.registerBehavior(PlayerBehavior); diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index b8849a3..1c6f3c3 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -119,4 +119,4 @@ class ItemBehavior extends Sup.Behavior { } } -Sup.registerBehavior(ItemBehavior \ No newline at end of file +Sup.registerBehavior(ItemBehavior); diff --git a/assets/Keep (129)/Game (131)/draft.ts b/assets/Keep (129)/Game (131)/draft.ts new file mode 100644 index 0000000..8f41e61 --- /dev/null +++ b/assets/Keep (129)/Game (131)/draft.ts @@ -0,0 +1,59 @@ +module Game { + + export let MAX_VELOCITY_X: number = 0.8; + export let MAX_VELOCITY_Y: number = 0.5; + + export let map: Sup.TileMap; + export let playerActor: Sup.Actor; + + export let musicPlayer: Sup.Audio.SoundPlayer; + + //export let allSolidBodies: Sup.ArcadePhysics2D.Body[] = []; + //export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; + + + export enum Direction { Up, Left, Down, Right }; + export enum Location { Top, Left, Bottom, Right }; + export let stringLocation: string[] = ["top", "left", "bottom", "right"]; + export let opposingLocation: string[] = ["bottom", "right", "top", "left"]; + + export enum State { Init, Play, Done }; + export let state: Game.State = Game.State.Init; + + export enum Item { Weapon, Food, Gold }; + export enum Weapon { Sword, Axe, Spade, SquirtGun }; + + export function init() { + Game.state = Game.State.Init; + + // Play Music + Game.musicPlayer = new Sup.Audio.SoundPlayer("Keep/Music/Pyre", 0.25, { loop: true }); + musicPlayer.play(); + + // NOTE: this only works if the scene is loaded, but for some reason not in a timeout callback + // Store solid bodies in a list separate from semi-solid bodies + //let platformBodies = Sup.getActor("Platforms").getChildren(); + //for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); + //let solidBodies = Sup.getActor("Solids").getChildren(); + //for (let solidBody of solidBodies) this.allSolidBodies.push(solidBody.arcadeBody2D); + + Sup.setTimeout(1000, startGame); + } + + export function startGame() { + + // NOTE: Behavior classes won't be recognized at runtime unless this script is the very last in the hierarchy + // Load scene + Sup.loadScene("Keep/Scene"); + Game.playerActor = Sup.getActor("Player"); + + // Set Gamestate + Game.state = Game.State.Play; + + // Set Gravity + Sup.ArcadePhysics2D.setGravity(0, -0.02); + } + +} + +Game.init(); From 21e60cf8936c0c396e9426f81a9169a92dd82f40 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 02:32:24 -0400 Subject: [PATCH 12/13] items collide with platforms now --- .../Player (21)/PlayerBehavior (24)/draft.ts | 292 ------------------ .../Player (21)/PlayerBehavior (24)/script.ts | 5 +- .../Items (12)/ItemBehavior (183)/script.ts | 2 + assets/Keep (129)/Game (131)/draft.ts | 59 ---- assets/Keep (129)/Game (131)/script.ts | 1 + 5 files changed, 5 insertions(+), 354 deletions(-) delete mode 100644 assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts delete mode 100644 assets/Keep (129)/Game (131)/draft.ts diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts deleted file mode 100644 index 150fc70..0000000 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/draft.ts +++ /dev/null @@ -1,292 +0,0 @@ -//Sup.ArcadePhysics2D.setGravity(0, -0.02); - -class PlayerBehavior extends Sup.Behavior { - speed:number = 0.2; - jumpSpeed:number = 0.42; - - private initialSize; - private initialOffset; - private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; - - private controls; - private equipment: Sup.Actor; - private equipmentBehavior: ItemBehavior; - - private nearbyItems: Sup.Actor[] = []; - private nearbyWeapons: Sup.Actor[] = []; - private nearbyFood: Sup.Actor[] = []; - private nearbyGold: Sup.Actor[] = []; - private nearbyInteractives: Sup.Actor[] = []; - - awake() { - this.initialSize = this.actor.arcadeBody2D.getSize(); - this.initialOffset = this.actor.arcadeBody2D.getOffset(); - - // Platform bodies - let platformBodies = Sup.getActor("Platforms").getChildren(); - for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); - - // Equipment - this.equipment = this.actor.getChild("Equipment"); - this.equipmentBehavior = this.equipment.getBehavior(ItemBehavior); - - // Init controls obj - this.controls = { - pressed: { - left: false, - right: false, - jump: false, - down: false, - swap: false, - use: false - }, - held: { - left: false, - right: false, - jump: false, - down: false, - swap: false, - use: false - } - }; - } - - update() { - - // Store controls status so we only have to reduce N per update - this.updateControls(); - - // Store nearby object status for quick access - if (this.controls.pressed.swap || this.controls.pressed.use) this.updateNearbyObjects(); - - // Handle interactions with items - this.processUseItem(); - this.processSwapItem(); - - // Handle solid body collisions - let {touchSolids, velocity, dampenFall, touchPlatforms } = this.updateSolidCollisions() ; - - // Process player input for movement controls - - // We override the `.x` component based on the player's input - if ( this.controls.held.left ) { - velocity.x = -this.speed; - // When going left, we flip the sprite= - this.setFlip(true); - } else if ( this.controls.held.right ) { - velocity.x = this.speed; - // When going right, we clear the flip - this.setFlip(false); - } else velocity.x = 0; - - // If the player is on the ground and wants to jump, - // we update the `.y` component accordingly - let touchBottom = touchSolids || touchPlatforms; - if (touchBottom) { - if ( this.controls.pressed.jump ) { - velocity.y = this.jumpSpeed; - this.actor.spriteRenderer.setAnimation("Jump"); - // If isKeyDown("DOWN") and touchPlatforms to drop down from platform - } else if ( this.controls.pressed.down && touchPlatforms ) { - velocity.y = -this.speed; - } else { - // Here, we should play either "Idle" or "Run" depending on the horizontal speed - if (velocity.x === 0) this.actor.spriteRenderer.setAnimation("Idle"); - else this.actor.spriteRenderer.setAnimation("Move"); - } - } else { - // Here, we should play either "Jump" or "Fall" depending on the vertical speed - if (velocity.y >= 0) { - this.actor.spriteRenderer.setAnimation("Jump"); - } else { - this.actor.spriteRenderer.setAnimation("Fall"); - // If isKeyDown("DOWN") to add extra umph to the fall - if ( this.controls.held.down ) { - velocity.y = -Game.MAX_VELOCITY_Y; - dampenFall = false; - } - } - } - - // Cap the velocity to avoid going crazy in falls - velocity.x = Sup.Math.clamp(velocity.x, -Game.MAX_VELOCITY_X, Game.MAX_VELOCITY_X); - if (dampenFall) velocity.y = Sup.Math.clamp(velocity.y, -Game.MAX_VELOCITY_Y/2, Game.MAX_VELOCITY_Y); - - // Finally, we apply the velocity back to the ArcadePhysics body - this.actor.arcadeBody2D.setVelocity(velocity); - - this.nearbyItems = []; - this.nearbyWeapons = []; - this.nearbyFood = []; - this.nearbyGold = []; - this.nearbyInteractives = []; - } - - - // Helper functions - private setFlip( v:boolean ):void { - // If we aren't flipped yet, flip the equipment as well - if ( this.equipmentBehavior && this.actor.spriteRenderer.getHorizontalFlip() != v ) this.equipmentBehavior.flip(); - // Set whether or not we are flipped - this.actor.spriteRenderer.setHorizontalFlip(v); - } - - private updateControls() { - // Just Pressed - this.controls.pressed.left = Controls.pressed("moveLeft"); - this.controls.pressed.right = Controls.pressed("moveRight"); - this.controls.pressed.jump = Controls.pressed("jump"); - this.controls.pressed.down = Controls.pressed("moveDown"); - this.controls.pressed.swap = Controls.pressed("swap"); - this.controls.pressed.use = Controls.pressed("use"); - // Held - this.controls.held.left = Controls.held("moveLeft"); - this.controls.held.right = Controls.held("moveRight"); - this.controls.held.jump = Controls.held("jump"); - this.controls.held.down = Controls.held("moveDown"); - this.controls.held.swap = Controls.held("swap"); - this.controls.held.use = Controls.held("use"); - } - - private updateNearbyObjects() { - for ( let item of Sup.getActor("Weapons") .getChildren()) { - if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { - this.nearbyWeapons.push(item); - this.nearbyItems.push(item); - } - } - for ( let item of Sup.getActor("Food") .getChildren()) { - if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { - this.nearbyFood.push(item); - this.nearbyItems.push(item); - } - } - for ( let item of Sup.getActor("Gold") .getChildren()) { - if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { - this.nearbyGold.push(item); - this.nearbyItems.push(item); - } - } - /*for ( let item of Sup.getActor("Interactive") .getChildren()) { - if ( Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, item.arcadeBody2D) ) { - this.nearbyInteractives.push(item); - this.nearbyItems.push(item); - } - }*/ - } - - private getNearestObject() { - return this.nearbyItems.reduce( function(acc,item) { - let distance = Sup.getActor("Player").getPosition().distanceTo(item.getPosition()); - if (distance < acc.d) return { a:item, d:distance } - return acc; - }, {a:this.actor,d:Infinity} ); - } - - private processSwapItem() { - // If user is using an item, don't do anything here! - if ( this.controls.held.use && this.equipment ) return; - if ( !this.controls.pressed.swap ) return; - - // If user is near an item, - if ( this.nearbyItems.length > 0 ) { - if ( this.equipmentBehavior ) this.equipmentBehavior.onDropped(); // Drop current equipment - - // Get closest object and swap - let {a, d} = this.getNearestObject(); - - if (a && d < Infinity && a != this.equipment) { - this.equipment = a; - this.equipmentBehavior = a.getBehavior(ItemBehavior); - this.equipmentBehavior.onEquipped(); - } - - } else { - // Otherwise just drop it, assuming we have an item - if ( this.equipment ) { - // Drop it - this.equipmentBehavior.onDropped(); - // Set our references to null - this.equipment = null; - this.equipmentBehavior = null; - } - } - } - - private processUseItem() { - if ( this.controls.pressed.use ) Sup.log("Used item!"); - - // Check item actions - - if ( this.controls.pressed.use && this.equipment ) { - // Handle interactions - switch ( this.equipmentBehavior.itemtype ) { - case Game.Item.Weapon: - if (this.nearbyInteractives.length == 0) { - // TODO: Play default animation and sfx - } else { - // Handle differently based on weapon type - switch( this.equipment.getBehavior(WeaponBehavior).itemtype) { - case Game.Weapon.Axe: - // TODO: Check for treetrunk | chest in nearbyInteractives - break; - - case Game.Weapon.Spade: - // TODO: Check for dirt | chest in nearbyInteractives - break; - - case Game.Weapon.SquirtGun: - // TODO: Check for fruitspawner | chest in nearbyInteractives - break; - - case Game.Weapon.Sword: - default: - // TODO: Check for fruitspawner | chest in nearbyInteractives - break; - } - } - break; - - case Game.Item.Food: - // TODO: Play animation and sfx - // TODO: Restore health - break; - - case Game.Item.Gold: - // TODO: Play animation and sfx - // TODO: Attract nearby NPC or Dragon - break; - - default: - break; - } - } - } - - private updateSolidCollisions() { - // Check collision with solid bodies (from tilemap) - Sup.ArcadePhysics2D.collides( this.actor.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); - - let touchSolids = this.actor.arcadeBody2D.getTouches().bottom; - let velocity = this.actor.arcadeBody2D.getVelocity(); - let dampenFall = true; - - // If falling, check the semi-solid bodies - let touchPlatforms = false; - if ( velocity.y < 0 ) { - // TODO: apply custom collision here so we can drop down - for (let platformBody of G.allPlatformBodies) { - Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); - if (this.actor.arcadeBody2D.getTouches().bottom) { - touchPlatforms = true; - velocity.y = 0; - break; - } - } - } - - return {touchSolids, velocity, dampenFall, touchPlatforms}; - } - -} -Sup.registerBehavior(PlayerBehavior); diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 2cf30ed..7aa48a6 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -6,7 +6,6 @@ class PlayerBehavior extends Sup.Behavior { private initialSize; private initialOffset; - private allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; private controls; private equipment: Sup.Actor; @@ -24,7 +23,7 @@ class PlayerBehavior extends Sup.Behavior { // Platform bodies let platformBodies = Sup.getActor("Platforms").getChildren(); - for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); + for (let platBody of platformBodies) Game.allPlatformBodies.push(platBody.arcadeBody2D); // Equipment this.equipment = this.actor.getChild("Equipment"); @@ -275,7 +274,7 @@ class PlayerBehavior extends Sup.Behavior { let touchPlatforms = false; if ( velocity.y < 0 ) { // TODO: apply custom collision here so we can drop down - for (let platformBody of this.allPlatformBodies) { + for (let platformBody of Game.allPlatformBodies) { Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); if (this.actor.arcadeBody2D.getTouches().bottom) { touchPlatforms = true; diff --git a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts index 1c6f3c3..d941897 100644 --- a/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts +++ b/assets/Keep (129)/Entities (134)/Items (12)/ItemBehavior (183)/script.ts @@ -31,6 +31,8 @@ class ItemBehavior extends Sup.Behavior { if (!this.isEquipped) { // Collide with solid tiles Sup.ArcadePhysics2D.collides( this.sprite.arcadeBody2D, Sup.getActor("Map").arcadeBody2D ); + // Collide with platforms + Sup.ArcadePhysics2D.collides( this.sprite.arcadeBody2D, Game.allPlatformBodies ); // Parent should follow the sprite this.actor.arcadeBody2D.warpPosition(this.sprite.getPosition()); diff --git a/assets/Keep (129)/Game (131)/draft.ts b/assets/Keep (129)/Game (131)/draft.ts deleted file mode 100644 index 8f41e61..0000000 --- a/assets/Keep (129)/Game (131)/draft.ts +++ /dev/null @@ -1,59 +0,0 @@ -module Game { - - export let MAX_VELOCITY_X: number = 0.8; - export let MAX_VELOCITY_Y: number = 0.5; - - export let map: Sup.TileMap; - export let playerActor: Sup.Actor; - - export let musicPlayer: Sup.Audio.SoundPlayer; - - //export let allSolidBodies: Sup.ArcadePhysics2D.Body[] = []; - //export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; - - - export enum Direction { Up, Left, Down, Right }; - export enum Location { Top, Left, Bottom, Right }; - export let stringLocation: string[] = ["top", "left", "bottom", "right"]; - export let opposingLocation: string[] = ["bottom", "right", "top", "left"]; - - export enum State { Init, Play, Done }; - export let state: Game.State = Game.State.Init; - - export enum Item { Weapon, Food, Gold }; - export enum Weapon { Sword, Axe, Spade, SquirtGun }; - - export function init() { - Game.state = Game.State.Init; - - // Play Music - Game.musicPlayer = new Sup.Audio.SoundPlayer("Keep/Music/Pyre", 0.25, { loop: true }); - musicPlayer.play(); - - // NOTE: this only works if the scene is loaded, but for some reason not in a timeout callback - // Store solid bodies in a list separate from semi-solid bodies - //let platformBodies = Sup.getActor("Platforms").getChildren(); - //for (let platBody of platformBodies) this.allPlatformBodies.push(platBody.arcadeBody2D); - //let solidBodies = Sup.getActor("Solids").getChildren(); - //for (let solidBody of solidBodies) this.allSolidBodies.push(solidBody.arcadeBody2D); - - Sup.setTimeout(1000, startGame); - } - - export function startGame() { - - // NOTE: Behavior classes won't be recognized at runtime unless this script is the very last in the hierarchy - // Load scene - Sup.loadScene("Keep/Scene"); - Game.playerActor = Sup.getActor("Player"); - - // Set Gamestate - Game.state = Game.State.Play; - - // Set Gravity - Sup.ArcadePhysics2D.setGravity(0, -0.02); - } - -} - -Game.init(); diff --git a/assets/Keep (129)/Game (131)/script.ts b/assets/Keep (129)/Game (131)/script.ts index 743d074..92c1597 100644 --- a/assets/Keep (129)/Game (131)/script.ts +++ b/assets/Keep (129)/Game (131)/script.ts @@ -10,6 +10,7 @@ module Game { //export let allSolidBodies: Sup.ArcadePhysics2D.Body[] = []; //export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; + export let allPlatformBodies: Sup.ArcadePhysics2D.Body[] = []; export enum Direction { Up, Left, Down, Right }; export enum Location { Top, Left, Bottom, Right }; From e93c5861e1c34e1578ba7e797d49643533cadd82 Mon Sep 17 00:00:00 2001 From: Flying Katsu Date: Sat, 1 Apr 2017 02:47:16 -0400 Subject: [PATCH 13/13] jump down from platforms works! --- .../Player (21)/PlayerBehavior (24)/script.ts | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts index 7aa48a6..db63811 100644 --- a/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts +++ b/assets/Keep (129)/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts @@ -17,6 +17,8 @@ class PlayerBehavior extends Sup.Behavior { private nearbyGold: Sup.Actor[] = []; private nearbyInteractives: Sup.Actor[] = []; + private dropFromPlatform: boolean = false; + awake() { this.initialSize = this.actor.arcadeBody2D.getSize(); this.initialOffset = this.actor.arcadeBody2D.getOffset(); @@ -88,6 +90,7 @@ class PlayerBehavior extends Sup.Behavior { // If isKeyDown("DOWN") and touchPlatforms to drop down from platform } else if ( this.controls.pressed.down && touchPlatforms ) { velocity.y = -this.speed; + this.dropFromPlatform = true; } else { // Here, we should play either "Idle" or "Run" depending on the horizontal speed if (velocity.x === 0) this.actor.spriteRenderer.setAnimation("Idle"); @@ -114,6 +117,7 @@ class PlayerBehavior extends Sup.Behavior { // Finally, we apply the velocity back to the ArcadePhysics body this.actor.arcadeBody2D.setVelocity(velocity); + // Empty storage this.nearbyItems = []; this.nearbyWeapons = []; this.nearbyFood = []; @@ -269,21 +273,33 @@ class PlayerBehavior extends Sup.Behavior { let touchSolids = this.actor.arcadeBody2D.getTouches().bottom; let velocity = this.actor.arcadeBody2D.getVelocity(); let dampenFall = true; + let intersectsPlatform = false; // If falling, check the semi-solid bodies let touchPlatforms = false; if ( velocity.y < 0 ) { - // TODO: apply custom collision here so we can drop down - for (let platformBody of Game.allPlatformBodies) { - Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); - if (this.actor.arcadeBody2D.getTouches().bottom) { - touchPlatforms = true; - velocity.y = 0; - break; + + if (this.dropFromPlatform) { + for (let platformBody of Game.allPlatformBodies) { + if (Sup.ArcadePhysics2D.intersects(this.actor.arcadeBody2D, platformBody)) { + intersectsPlatform = true; + } + } + } else { + for (let platformBody of Game.allPlatformBodies) { + Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, platformBody); + if (this.actor.arcadeBody2D.getTouches().bottom) { + touchPlatforms = true; + velocity.y = 0; + break; + } } } + } + if (!intersectsPlatform && this.dropFromPlatform) this.dropFromPlatform = false; + return {touchSolids, velocity, dampenFall, touchPlatforms}; }