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/30-scene-game.coffee

80 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2018-09-30 21:23:43 +00:00
# free viewport
2018-09-30 20:23:16 +00:00
Crafty.viewport.clampToEntities = false
2018-09-30 21:23:43 +00:00
# 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')
2018-09-30 20:23:16 +00:00
)
2018-09-30 21:23:43 +00:00
# scale viewport automatically (show that new entity)
2018-09-30 20:23:16 +00:00
Crafty.bind 'ViewportResize', ->
2018-09-30 21:23:43 +00:00
sX = @viewport._width / (1 * CONF.playmat.w)
sY = @viewport._height / (2 * CONF.playmat.h)
2018-09-30 20:23:16 +00:00
@viewport.scale Math.min(sX, sY)
return
2018-09-30 21:23:43 +00:00
# force scale adjustment
2018-09-30 20:23:16 +00:00
Crafty.trigger 'ViewportResize'
# Testing playmat
# custom playmats at https://imgur.com/a/VSosu#cwGQdAS
Crafty.sprite 997, 582, '//i.imgur.com/cwGQdAS.png',
playmat: [
0
0
]
Crafty.e('playmat, 2D, Canvas')
.attr {
x: 0
y: 900
w: 1600
h: 900
}
Crafty.e('playmat, 2D, Canvas')
.attr {
x: 0
y: 900
w: 1600
h: 900
}
.origin('top middle')
.attr {
rotation: 180
}
# Testing some entities
Crafty.sprite 480, 670, '//www.fftcgmognet.com/images/cards/hd/1/1/107.jpg',
shantotto: [
0
0
]
card = Crafty.e('shantotto, AllyCard')
.attr {
x: 0
y: 0
}
.bind 'DoubleClick', ->
@destroy()
return
Crafty.e('shantotto, AllyCard')
.place 300, 0
Crafty.e('shantotto, AllyCard')
.place 600, 0
Crafty.e('shantotto, EnemyCard')
.place 900, 0
# Crafty.e("shantotto, AllyCard")
# .attr({ x: 0, y: 0, w: 1200, h: 1675 });