2018-09-30 21:23:43 +00:00
|
|
|
|
################
|
2018-09-30 21:48:24 +00:00
|
|
|
|
# Card
|
|
|
|
|
################
|
2018-09-30 20:23:16 +00:00
|
|
|
|
Crafty.c 'Card',
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# Mouse interactivity, Tween (animation smooth)
|
2018-09-30 20:23:16 +00:00
|
|
|
|
required: '2D, Canvas, Mouse, Tween'
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# initialize card
|
2018-09-30 20:23:16 +00:00
|
|
|
|
init: ->
|
|
|
|
|
@attr {
|
2018-09-30 21:23:43 +00:00
|
|
|
|
z: CONF.layer.cards
|
|
|
|
|
w: CONF.card.w
|
|
|
|
|
h: CONF.card.h
|
2018-09-30 20:23:16 +00:00
|
|
|
|
tapped: false
|
|
|
|
|
}
|
|
|
|
|
@origin 'center'
|
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# on destroy (TODO/example)
|
2018-09-30 20:23:16 +00:00
|
|
|
|
remove: ->
|
|
|
|
|
Crafty.log 'Card was removed!'
|
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# smooth placement
|
2018-09-30 20:23:16 +00:00
|
|
|
|
place: (px, py) ->
|
|
|
|
|
@tween {
|
|
|
|
|
x: px
|
|
|
|
|
y: py
|
|
|
|
|
}, CONF.anim.time, CONF.anim.func
|
|
|
|
|
|
|
|
|
|
events:
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# Tap or untap, pass true iff you want to tap
|
2018-09-30 20:23:16 +00:00
|
|
|
|
Tap: (newState) ->
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# store new state in property as boolean value
|
2018-09-30 20:23:16 +00:00
|
|
|
|
@tapped = !!newState
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# animate to new rotation, @tapped has "int" value 0 or 1
|
2018-09-30 20:23:16 +00:00
|
|
|
|
@tween {
|
2018-09-30 21:23:43 +00:00
|
|
|
|
rotation: @baseRot + 90 * @tapped
|
2018-09-30 20:23:16 +00:00
|
|
|
|
}, CONF.anim.time, CONF.anim.func
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
ToggleTap: ->
|
|
|
|
|
@trigger 'Tap', !@tapped
|
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# bring card to focus layer and back
|
2018-09-30 20:23:16 +00:00
|
|
|
|
MouseOver: ->
|
2018-09-30 21:23:43 +00:00
|
|
|
|
@z = CONF.layer.focus
|
2018-09-30 20:23:16 +00:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
MouseOut: ->
|
2018-09-30 21:23:43 +00:00
|
|
|
|
@z = CONF.layer.cards
|
2018-09-30 20:23:16 +00:00
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
################
|
2018-09-30 21:48:24 +00:00
|
|
|
|
# EnemyCard
|
|
|
|
|
################
|
2018-09-30 20:23:16 +00:00
|
|
|
|
Crafty.c 'EnemyCard',
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# is a card
|
2018-09-30 20:23:16 +00:00
|
|
|
|
required: 'Card'
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# turned by default
|
2018-09-30 20:23:16 +00:00
|
|
|
|
init: ->
|
|
|
|
|
@baseRot = 180
|
|
|
|
|
@rotation = @baseRot
|
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
################
|
2018-09-30 21:48:24 +00:00
|
|
|
|
# AllyCard
|
|
|
|
|
################
|
2018-09-30 20:23:16 +00:00
|
|
|
|
Crafty.c 'AllyCard',
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# is a card
|
2018-09-30 20:23:16 +00:00
|
|
|
|
required: 'Card, Draggable'
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# straight by default
|
2018-09-30 20:23:16 +00:00
|
|
|
|
init: ->
|
|
|
|
|
@baseRot = 0
|
|
|
|
|
@rotation = @baseRot
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
events:
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# un-/tappable
|
2018-09-30 20:23:16 +00:00
|
|
|
|
DoubleClick: ->
|
|
|
|
|
@trigger 'ToggleTap'
|
|
|
|
|
return
|
|
|
|
|
|
2018-09-30 21:23:43 +00:00
|
|
|
|
# snap to 100×100 grid (TODO)
|
2018-09-30 20:23:16 +00:00
|
|
|
|
StopDrag: ->
|
|
|
|
|
|
|
|
|
|
round100 = (v) ->
|
|
|
|
|
Math.round(v / 100) * 100
|
|
|
|
|
|
|
|
|
|
@place round100(@_x), round100(@_y)
|
|
|
|
|
return
|