diff --git a/client/scripts/10-config.coffee b/client/scripts/10-config.coffee index ac296d5..3046e37 100644 --- a/client/scripts/10-config.coffee +++ b/client/scripts/10-config.coffee @@ -11,3 +11,9 @@ CONF = anim: time: 300 func: 'smootherStep' + + layer: + background: 0 + playmats: 1 + cards: 2 + focus: 3 diff --git a/client/scripts/20-component-card.coffee b/client/scripts/20-component-card.coffee index 9795dbd..99db182 100644 --- a/client/scripts/20-component-card.coffee +++ b/client/scripts/20-component-card.coffee @@ -1,19 +1,26 @@ +################ +# component name Crafty.c 'Card', + # Mouse interactivity, Tween (animation smooth) required: '2D, Canvas, Mouse, Tween' + # initialize card init: -> @attr { - w: 1 * CONF.card.w - h: 1 * CONF.card.h + z: CONF.layer.cards + w: CONF.card.w + h: CONF.card.h tapped: false } @origin 'center' return + # on destroy (TODO/example) remove: -> Crafty.log 'Card was removed!' return + # smooth placement place: (px, py) -> @tween { x: px @@ -21,12 +28,14 @@ Crafty.c 'Card', }, CONF.anim.time, CONF.anim.func events: + # Tap or untap, pass true iff you want to tap Tap: (newState) -> + # store new state in property as boolean value @tapped = !!newState - _rotation = @baseRot + 90 * @tapped + # animate to new rotation, @tapped has "int" value 0 or 1 @tween { - rotation: _rotation + rotation: @baseRot + 90 * @tapped }, CONF.anim.time, CONF.anim.func return @@ -34,39 +43,46 @@ Crafty.c 'Card', @trigger 'Tap', !@tapped return + # bring card to focus layer and back MouseOver: -> - @z_old = @_z - @z = 1 + @z = CONF.layer.focus return MouseOut: -> - @z = @z_old - delete @z_old + @z = CONF.layer.cards return - +################ +# component name Crafty.c 'EnemyCard', + # is a card required: 'Card' + # turned by default init: -> @baseRot = 180 @rotation = @baseRot return - +################ +# component name Crafty.c 'AllyCard', + # is a card required: 'Card, Draggable' + # straight by default init: -> @baseRot = 0 @rotation = @baseRot return events: + # un-/tappable DoubleClick: -> @trigger 'ToggleTap' return + # snap to 100×100 grid (TODO) StopDrag: -> round100 = (v) -> diff --git a/client/scripts/30-scene-game.coffee b/client/scripts/30-scene-game.coffee index 9bf7888..30a70f9 100644 --- a/client/scripts/30-scene-game.coffee +++ b/client/scripts/30-scene-game.coffee @@ -1,22 +1,25 @@ +# free viewport Crafty.viewport.clampToEntities = false -Crafty.viewport.follow(Crafty.e('2D, Canvas') - .attr { - x: 0 - y: 0 - w: 1 * CONF.playmat.w - h: 2 * CONF.playmat.h - } - .origin('center') +# attach viewport to an entity twice as big as a playmat +Crafty.viewport.follow( + Crafty.e('2D, Canvas') + .attr { + w: 1 * CONF.playmat.w + h: 2 * CONF.playmat.h + } + .origin('center') ) +# scale viewport automatically (show that new entity) Crafty.bind 'ViewportResize', -> - sX = @viewport._width / 1600 - sY = @viewport._height / 1800 + sX = @viewport._width / (1 * CONF.playmat.w) + sY = @viewport._height / (2 * CONF.playmat.h) @viewport.scale Math.min(sX, sY) return +# force scale adjustment Crafty.trigger 'ViewportResize' # Testing playmat