################ # Card ################ Crafty.c 'Card', # Mouse interactivity, Tween (animation smooth) required: '2D, Canvas, Mouse, Tween' # initialize card init: -> @attr { 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 y: py }, 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 # animate to new rotation, @tapped has "int" value 0 or 1 @tween { rotation: @baseRot + 90 * @tapped }, CONF.anim.time, CONF.anim.func return ToggleTap: -> @trigger 'Tap', !@tapped return # bring card to focus layer and back MouseOver: -> @z = CONF.layer.focus return MouseOut: -> @z = CONF.layer.cards return # show big version Enlarge: -> Crafty 'BigCard' .each -> @trigger 'Fade' return Crafty.e 'BigCard, Color' .color 'black' .trigger 'Copy', @ .trigger 'Enlarge' return MouseUp: (e) -> if e.mouseButton == Crafty.mouseButtons.RIGHT @trigger 'Enlarge' return ################ # EnemyCard ################ Crafty.c 'EnemyCard', # is a card required: 'Card' # flipped by default init: -> @baseRot = 180 @rotation = @baseRot return ################ # AllyCard ################ Crafty.c 'AllyCard', # is a card required: 'Card, Draggable' # normally oriented by default init: -> @baseRot = 0 @rotation = @baseRot return events: # un-/tappable DoubleClick: -> @trigger 'ToggleTap' return # snap to 100×100 grid (TODO) StopDrag: -> round100 = (v) -> Math.round(v / 100) * 100 @place round100(@_x), round100(@_y) return