-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to pickup/add to inventory icons
- Loading branch information
Showing
9 changed files
with
201 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var getItemsWithingRange = function (iconFactory, player) { | ||
|
||
var icon = iconFactory.getHead(); | ||
var range = 40 * 48; | ||
var foundItems = []; | ||
while (icon) { | ||
|
||
//no one is holding it | ||
if (icon.owner == null) { | ||
if (icon.x > (player.offset.x - range) | ||
&& icon.x < (player.offset.x + range) | ||
&& icon.y > (player.offset.y - range) | ||
&& icon.y < (player.offset.y + range) | ||
) { | ||
foundItems.push(icon) | ||
} | ||
} | ||
icon = icon.next; | ||
} | ||
return foundItems | ||
}; | ||
|
||
export const drawItems = (game, iconTiles) => { | ||
|
||
|
||
var offTileX = Math.floor(game.player.offset.x % 32); | ||
var offTileY = Math.floor(game.player.offset.y % 32); | ||
|
||
|
||
if (game.forceDraw) { | ||
iconTiles.clear(); | ||
|
||
var foundItems = getItemsWithingRange(game.iconFactory, game.player); | ||
foundItems.forEach((icon, index) => { | ||
console.log(game.player.offset.x - icon.x); | ||
var tmpText = new PIXI.Texture( | ||
game.textures['imageItems'].baseTexture, | ||
new PIXI.Rectangle(icon.type * 32, 0, 32, 32) | ||
); | ||
iconTiles.addFrame(tmpText, icon.x - game.player.offset.x + offTileX, icon.y - game.player.offset.y + offTileY); | ||
}); | ||
|
||
iconTiles.position.set(game.player.defaultOffset.x + game.player.offset.x - offTileX, game.player.defaultOffset.y + game.player.offset.y - offTileY); | ||
} | ||
|
||
iconTiles.pivot.set(game.player.offset.x, game.player.offset.y); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
class IconFactory { | ||
|
||
constructor(game) { | ||
this.game = game; | ||
this.iconListHead = null; | ||
} | ||
|
||
cycle() { | ||
} | ||
|
||
newIcon(owner, x, y, type) { | ||
|
||
var icon = { | ||
"owner": owner, | ||
"x": x, | ||
"y": y, | ||
"type": type, | ||
"next": null, | ||
"previous": null | ||
|
||
}; | ||
|
||
|
||
if (this.iconListHead) { | ||
this.iconListHead.previous = building; | ||
icon.next = this.iconListHead | ||
} | ||
|
||
|
||
this.iconListHead = icon; | ||
return icon; | ||
} | ||
|
||
|
||
pickupIcon() { | ||
var icon = this.findIconByLocation(); | ||
if (icon) { | ||
icon.owner = this.game.player.id; | ||
this.game.forceDraw = true; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param selectedIcon | ||
*/ | ||
toggleSelected(selectedIcon) { | ||
selectedIcon.selected = !selectedIcon.selected; | ||
|
||
var icon = this.getHead(); | ||
while (icon) { | ||
if (icon.owner == selectedIcon.owner && icon != selectedIcon) { | ||
console.log("setting other icons selected to false"); | ||
icon.selected = false; | ||
} | ||
icon = icon.next; | ||
} | ||
} | ||
|
||
findIconByLocation() { | ||
|
||
var icon = this.getHead(); | ||
var range = 24; | ||
|
||
while (icon) { | ||
|
||
if (icon.x >= (this.game.player.offset.x - range) | ||
&& icon.x <= (this.game.player.offset.x + range) | ||
&& icon.y >= (this.game.player.offset.y - range) | ||
&& icon.y <= (this.game.player.offset.y + range) | ||
) { | ||
return icon; | ||
} | ||
|
||
icon = icon.next; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
deleteIcon(icon) { | ||
var returnIcon = icon.next; | ||
|
||
if (icon.next) { | ||
icon.next.previous = icon.previous; | ||
} | ||
|
||
if (icon.previous) { | ||
icon.previous.next = icon.next | ||
} else { | ||
this.iconListHead = icon.next; | ||
} | ||
|
||
return returnIcon; | ||
} | ||
|
||
|
||
getHead() { | ||
return this.iconListHead; | ||
} | ||
} | ||
|
||
|
||
export default IconFactory; |
Oops, something went wrong.