properties: {
startprefab:{default:null,type:cc.Prefab},
bulletprefab:{default:null,type:cc.Prefab},
scorelable:{default:null,type:cc.Label},
player:{default:null,type:cc.Node},
background:{default:null,type:cc.Node},
bullett_num:0,
bullett_speed:0,
},
mousegetposition()
{
this.node.on(cc.Node.EventType.TOUCH_START,function(event){
var touch =event.getTouches()[0];
var position = touch.getLocation();
var localPosition = this.node.convertToNodeSpaceAR(position);
this.shoot(localPosition);
// this.node.on(cc.node.EventType.TOUCH_START,function(event)
// {
// var touch=event.getTouches()[0];
// var position=touch.getLocation();
// var localposition=this.Node.place(position);//修改过
// this.shoot(localposition);
},this);
},
newstar()
{
if(this.happen!=null)
{
this.happen.destroy();
}
var happen=cc.instantiate(this.startprefab);
this.node.addChild(happen);
happen.position=this.randomPosition();
this.happen=happen;
},
randomPosition()
{
var x=this.node.width/2*cc.randomMinus1To1();
var y=320*cc.random0To1();
return cc.p(x,y);
},
shoot(normalposition)
{
if(0<this.bullett_num)
{
var fire=cc.instantiate(this.bulletprefab);
this.node.addChild(fire);
fire.position=this.player.position;
let bulletthaverb=fire.getComponent("rigidBody");
normalposition=cc.pNormalize(cc.pSub(normalposition,fire.position));
fire.getComponent(cc.RigidBody).linearVelocity=cc.pMult(normalposition,this.bullett_speed);
this. bullett_num--;
}
},
scoreAdd()
{
this.count++;
this.scorelable.string="Scroce:"+this.count;
},
onLoad()
{
cc.director.getPhysicsManager().enabled=true;
cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit;
this.mousegetposition();
this.count=0;
this.happen=null;
this.newstar();
startprefab:{default:null,type:cc.Prefab},
bulletprefab:{default:null,type:cc.Prefab},
scorelable:{default:null,type:cc.Label},
player:{default:null,type:cc.Node},
background:{default:null,type:cc.Node},
bullett_num:0,
bullett_speed:0,
},
mousegetposition()
{
this.node.on(cc.Node.EventType.TOUCH_START,function(event){
var touch =event.getTouches()[0];
var position = touch.getLocation();
var localPosition = this.node.convertToNodeSpaceAR(position);
this.shoot(localPosition);
// this.node.on(cc.node.EventType.TOUCH_START,function(event)
// {
// var touch=event.getTouches()[0];
// var position=touch.getLocation();
// var localposition=this.Node.place(position);//修改过
// this.shoot(localposition);
},this);
},
newstar()
{
if(this.happen!=null)
{
this.happen.destroy();
}
var happen=cc.instantiate(this.startprefab);
this.node.addChild(happen);
happen.position=this.randomPosition();
this.happen=happen;
},
randomPosition()
{
var x=this.node.width/2*cc.randomMinus1To1();
var y=320*cc.random0To1();
return cc.p(x,y);
},
shoot(normalposition)
{
if(0<this.bullett_num)
{
var fire=cc.instantiate(this.bulletprefab);
this.node.addChild(fire);
fire.position=this.player.position;
let bulletthaverb=fire.getComponent("rigidBody");
normalposition=cc.pNormalize(cc.pSub(normalposition,fire.position));
fire.getComponent(cc.RigidBody).linearVelocity=cc.pMult(normalposition,this.bullett_speed);
this. bullett_num--;
}
},
scoreAdd()
{
this.count++;
this.scorelable.string="Scroce:"+this.count;
},
onLoad()
{
cc.director.getPhysicsManager().enabled=true;
cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit;
this.mousegetposition();
this.count=0;
this.happen=null;
this.newstar();
},
star.........
cc.Class({
extends: cc.Component,
properties: {
},
onBeginContact(contact,thisColider,otherColider)
{
if(otherColider.node.name=="star")
{
console.log("star");
otherColider.node.parent.getComponent("game").newstar();
otherColider.node.parent.getComponent("game").scoreAdd();
}
this.node.parent.getComponent("game").bullett_num++;
this.node.destroy();
console.log("1000000000");
},
onLoad () {},
start () {
},
// update (dt) {},
});