77 lines
1.1 KiB
CoffeeScript
77 lines
1.1 KiB
CoffeeScript
|
Crafty.c 'Card',
|
||
|
required: '2D, Canvas, Mouse, Tween'
|
||
|
|
||
|
init: ->
|
||
|
@attr {
|
||
|
w: 1 * CONF.card.w
|
||
|
h: 1 * CONF.card.h
|
||
|
tapped: false
|
||
|
}
|
||
|
@origin 'center'
|
||
|
return
|
||
|
|
||
|
remove: ->
|
||
|
Crafty.log 'Card was removed!'
|
||
|
return
|
||
|
|
||
|
place: (px, py) ->
|
||
|
@tween {
|
||
|
x: px
|
||
|
y: py
|
||
|
}, CONF.anim.time, CONF.anim.func
|
||
|
|
||
|
events:
|
||
|
Tap: (newState) ->
|
||
|
@tapped = !!newState
|
||
|
_rotation = @baseRot + 90 * @tapped
|
||
|
|
||
|
@tween {
|
||
|
rotation: _rotation
|
||
|
}, CONF.anim.time, CONF.anim.func
|
||
|
return
|
||
|
|
||
|
ToggleTap: ->
|
||
|
@trigger 'Tap', !@tapped
|
||
|
return
|
||
|
|
||
|
MouseOver: ->
|
||
|
@z_old = @_z
|
||
|
@z = 1
|
||
|
return
|
||
|
|
||
|
MouseOut: ->
|
||
|
@z = @z_old
|
||
|
delete @z_old
|
||
|
return
|
||
|
|
||
|
|
||
|
Crafty.c 'EnemyCard',
|
||
|
required: 'Card'
|
||
|
|
||
|
init: ->
|
||
|
@baseRot = 180
|
||
|
@rotation = @baseRot
|
||
|
return
|
||
|
|
||
|
|
||
|
Crafty.c 'AllyCard',
|
||
|
required: 'Card, Draggable'
|
||
|
|
||
|
init: ->
|
||
|
@baseRot = 0
|
||
|
@rotation = @baseRot
|
||
|
return
|
||
|
|
||
|
events:
|
||
|
DoubleClick: ->
|
||
|
@trigger 'ToggleTap'
|
||
|
return
|
||
|
|
||
|
StopDrag: ->
|
||
|
|
||
|
round100 = (v) ->
|
||
|
Math.round(v / 100) * 100
|
||
|
|
||
|
@place round100(@_x), round100(@_y)
|
||
|
return
|