Skip to content

Commit 1756db6

Browse files
author
Joe Dytrych
committed
Start on new Entity system with kittenbox
1 parent d5260c4 commit 1756db6

File tree

15 files changed

+46
-10
lines changed

15 files changed

+46
-10
lines changed

app/assets/common/bundle.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"/audio/effects/*",
33
"/content/common/**/*.*",
44
"/content/particles/*",
5-
"/content/sprites/*"
5+
"/content/sprites/*",
6+
"/entities/kitten-box/**/*.*"
67
]

app/scripts/game/actors/KittenBox.ls renamed to app/entities/kitten-box/KittenBox.ls

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ random-kitten-el = ->
1616
..add-class 'kitten-anim'
1717

1818
box-burst-sprite = (av, x, y) ->
19-
sprite = new SpriteSheet '/content/sprites/kitten-box-burst', 48, 52, x - 24, y - 26, {
19+
sprite = new SpriteSheet '/entities/kitten-box/sprites/kitten-box-burst', 48, 52, x - 24, y - 26, {
2020
speed: 30
2121
loop-times: 1
2222
state: \paused
2323
}
2424

2525
blink-sprite = (av, x, y) ->
26-
sprite = new SpriteSheet '/content/sprites/kitten-box-blink', 48, 52, x - 24, y - 26, {
26+
sprite = new SpriteSheet '/entities/kitten-box/sprites/kitten-box-blink', 48, 52, x - 24, y - 26, {
2727
speed: 30
2828
delay: [0.1, 6]
2929
}
3030

31-
module.exports = class KittenBox extends Actor
31+
class KittenBox extends Actor
3232
@from-el = ($el, [x, y, kitten-id], offset = {x: 0, y: 0}, save-level, area-view) ->
3333
new KittenBox {
3434
x: offset.x + parse-float x
@@ -103,3 +103,5 @@ module.exports = class KittenBox extends Actor
103103
@$el
104104
..empty!
105105
..remove!
106+
107+
eak.register-actor KittenBox

app/scripts/App.ls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require! {
66
'game/event-loop'
77
'game/load'
88
'game/pauser'
9+
'game/actors'
910
'lib/channels'
1011
'lib/parse'
1112
'loader/LoaderView'
@@ -82,6 +83,9 @@ module.exports = class App
8283
@start-state-machine!
8384
@on 'transition' (leave, enter) -> console.log "[transition] #leave -> #enter"
8485

86+
# Expose stuff:
87+
@register-actor = actors.register-actor
88+
8589
Promise
8690
.all [
8791
assets.load-bundle 'common' .then -> effects.load!

app/scripts/assets.ls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function load-bundle name, progress
3333
.then (bundle) ->
3434
for name, file of bundle
3535
asset-cache[name] = debundle file
36+
if name.match /\.js$/ then add-js asset-cache[name].default
3637

3738
export function debundle file
3839
if typeof file is \string then file = data: file, type: \string
@@ -57,3 +58,6 @@ export function debundle file
5758
default: url, url: url, buffer: data.buffer, image: tag
5859
default
5960
throw new TypeError "Unknown file type #{file.type}"
61+
62+
function add-js js
63+
eval js

app/scripts/game/actors/index.ls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ module.exports.from-el = (el, offset, level-store, area-view) ->
1515
a = actors[actor].from-el $el, args, offset, level-store, area-view
1616
$el.data 'actor', a
1717
a
18+
19+
module.exports.register-actor = (ctor) ->
20+
name = dasherize ctor.display-name
21+
console.log "[actors] Registered actor #name"
22+
actors[name] = ctor

app/scripts/user/Game.ls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = class Game extends Backbone.DeepModel
9191
'game.state.kittenCount': 1 + (@get \game.state.kittenCount or 0)
9292
}, silent: true
9393

94-
@store.levels.save-kitten @id, level-id, kitten
94+
@store.levels.save-kitten @id, level-id, kitten: kitten
9595

9696
patch-stage-state: (patch, value) ->
9797
if typeof patch is \string then patch = {"#patch": value}

0 commit comments

Comments
 (0)