This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/client/scripts/game/20-comp-Card.coffee

105 lines
1.9 KiB
CoffeeScript
Raw Normal View History

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
events:
2018-10-01 19:39:53 +00:00
# smooth placement
Place: (position) ->
@tween {
x: position.x
y: position.y
}, CONF.anim.time, CONF.anim.func
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
# 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
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'
# flipped 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-10-01 19:39:53 +00:00
required: 'Card'
2018-09-30 20:23:16 +00:00
# normally oriented 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