This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inside onKeyPressed() | |
case cc.KEY.space: | |
const barrelPosition = cannon.barrel.getPosition() // 1 | |
const angle = cannon.barrel.rotation | |
const barrelLength = cannon.barrel.height | |
barrelPosition.x += barrelLength * sind(angle) | |
barrelPosition.y += barrelLength * cosd(angle) | |
const barrelTipWorldSpace = cannon.node.convertToWorldSpaceAR(barrelPosition) // 2 | |
const bulletPosition = cannon.game.node.convertToNodeSpaceAR(barrelTipWorld) // 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ccclass, property} = cc._decorator; | |
@ccclass | |
export default class Meteor extends cc.Component { | |
timeToLive = 10000 | |
timeAlive = 0 | |
update(dt) { | |
if (!cc.isValid(this.node)) return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ccclass | |
export default class Game extends cc.Component { | |
@property(cc.Prefab) | |
meteor: cc.Prefab = null | |
start() { | |
this.scheduleCreateMeteor() | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collider callbacks | |
onBeginContact(contact, selfCollider, otherCollider) { | |
if (otherCollider.node.name === "bullet") { | |
selfCollider.node.destroy() | |
otherCollider.node.destroy() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@property (cc.Prefab) | |
explosion: cc.Prefab = null | |
createExplosion(position: cc.Vec2) { | |
const explosion = cc.instantiate(this.explosion) | |
explosion.setPosition(position) | |
this.node.addChild(explosion) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ccclass, property} = cc._decorator; | |
import Game from './Game' | |
@ccclass | |
export default class Meteor extends cc.Component { | |
game: Game | |
timeToLive = 10000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create(duration: number, type: Types, creationProp: Properties): Config { | |
return { | |
duration, | |
create: { | |
type, | |
property: creationProp, | |
}, | |
update: { | |
type, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Config = { | |
duration: number, | |
create?: Anim, | |
update?: Anim, | |
delete?: Anim, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Anim = { | |
duration?: number, | |
delay?: number, | |
springDamping?: number, | |
initialVelocity?: number, | |
type?: $Enum<typeof TypesEnum>, | |
property?: $Enum<typeof PropertiesEnum>, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TypesEnum = { | |
spring: true, | |
linear: true, | |
easeInEaseOut: true, | |
easeIn: true, | |
easeOut: true, | |
keyboard: true, | |
}; | |
const Types = keyMirror(TypesEnum); |