-
Notifications
You must be signed in to change notification settings - Fork 6
/
CardImage.ts
72 lines (55 loc) · 2.68 KB
/
CardImage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Phaser from "phaser"
import ImageKey from "../ImageKey"
import { CARD_HEIGHT, CARD_WIDTH, } from "../constants"
class CardImage extends Phaser.GameObjects.Container {
cardImage: Phaser.GameObjects.Image
interactiveZone: Phaser.GameObjects.Rectangle
blueGlow: Phaser.GameObjects.Image
orangeGlow: Phaser.GameObjects.Image
greenGlow: Phaser.GameObjects.Image
maverick: Phaser.GameObjects.Image
maverickHouse: Phaser.GameObjects.Image
constructor(scene: Phaser.Scene, x: number, y: number, public id: string, public house: string, public isMaverick: boolean, public back: string = "cardback", public faceup: boolean = true) {
super(scene, x, y)
this.cardImage = new Phaser.GameObjects.Image(scene, 0, 0, id)
this.interactiveZone = new Phaser.GameObjects.Rectangle(scene, 0, 0, CARD_WIDTH, CARD_HEIGHT)
this.interactiveZone.setInteractive({ cursor: "pointer" })
this.scene.input.setDraggable(this.interactiveZone)
this.orangeGlow = new Phaser.GameObjects.Image(this.scene, 0, 0, ImageKey.ORANGE_CARD_GLOW)
this.orangeGlow.setDisplaySize(CARD_WIDTH * 1.2, CARD_HEIGHT + CARD_WIDTH * 0.2)
this.greenGlow = new Phaser.GameObjects.Image(this.scene, 0, 0, ImageKey.GREEN_CARD_GLOW)
this.greenGlow.setDisplaySize(CARD_WIDTH * 1.2, CARD_HEIGHT + CARD_WIDTH * 0.2)
this.blueGlow = new Phaser.GameObjects.Image(this.scene, 0, 0, ImageKey.BLUE_CARD_GLOW)
this.blueGlow.setDisplaySize(CARD_WIDTH * 1.2, CARD_HEIGHT + CARD_WIDTH * 0.2)
this.maverick = new Phaser.GameObjects.Image(this.scene, 0, 0, ImageKey.MAVERICK)
this.maverick.setDisplaySize(CARD_WIDTH, CARD_HEIGHT)
scene.load.image(house, require(`../../images/maverick/${house}.png`))
this.maverickHouse = new Phaser.GameObjects.Image(this.scene, 0, 0, house)
this.maverickHouse.setDisplaySize(CARD_WIDTH, CARD_HEIGHT)
}
render() {
if (!this.faceup) {
this.cardImage.setTexture(this.back)
}
this.orangeGlow.setAlpha(0)
this.add(this.orangeGlow)
this.greenGlow.setAlpha(0)
this.add(this.greenGlow)
this.blueGlow.setAlpha(0)
this.add(this.blueGlow)
this.cardImage.setDisplaySize(CARD_WIDTH, CARD_HEIGHT)
this.add(this.cardImage)
if (this.isMaverick) {
this.add(this.maverickHouse)
this.add(this.maverick)
}
this.interactiveZone.setPosition(0, 0)
this.interactiveZone.setSize(CARD_WIDTH, CARD_HEIGHT)
this.add(this.interactiveZone)
}
destroy() {
this.cardImage.destroy()
this.interactiveZone.destroy()
}
}
export default CardImage