init
This commit is contained in:
77
assets/src/UIMain.ts
Normal file
77
assets/src/UIMain.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { _decorator, Component, Node, input, Input, EventTouch, Animation } from 'cc';
|
||||
import { gameManager } from './gameManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('UIMain')
|
||||
export class UIMain extends Component {
|
||||
|
||||
@property(gameManager)
|
||||
public gm:gameManager = null;
|
||||
|
||||
@property(Node)
|
||||
public bg1:Node = null;
|
||||
|
||||
@property(Node)
|
||||
public bg2:Node = null;
|
||||
|
||||
@property(Node)
|
||||
public plane:Node = null;
|
||||
|
||||
//背景滚动速度
|
||||
public bg_sd:number = 1;
|
||||
|
||||
//背景滚动最大距离
|
||||
public bg_max:number = 10;
|
||||
|
||||
//plane移动速度
|
||||
@property
|
||||
public p_speed:number = 1;
|
||||
|
||||
//plane移动动画
|
||||
@property(Animation)
|
||||
public p_an:Animation = null;
|
||||
|
||||
start() {
|
||||
|
||||
//背景
|
||||
this.bg1.setPosition(0,0,0);
|
||||
this.bg2.setPosition(0,0,-this.bg_max);
|
||||
|
||||
//plane
|
||||
this.node.on(Input.EventType.TOUCH_MOVE,this.onmove,this);
|
||||
this.node.on(Input.EventType.TOUCH_START,this.onmoves,this);
|
||||
this.node.on(Input.EventType.TOUCH_END,this.onmovee,this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
//背景
|
||||
this.bg1.setPosition(0,0,this.bg1.position.z+deltaTime*this.bg_sd);
|
||||
this.bg2.setPosition(0,0,this.bg2.position.z+deltaTime*this.bg_sd);
|
||||
if(this.bg1.position.z>this.bg_max) this.bg1.setPosition(0,0,this.bg2.position.z-this.bg_max);
|
||||
else if(this.bg2.position.z>this.bg_max) this.bg2.setPosition(0,0,this.bg1.position.z-this.bg_max);
|
||||
|
||||
|
||||
}
|
||||
|
||||
onmove(event:EventTouch){
|
||||
const delat = event.touch.getDelta();
|
||||
const pos = this.plane.position;
|
||||
this.plane.setPosition(pos.x + 0.01 * this.p_speed * delat.x, pos.y, pos.z - 0.01 * this.p_speed * delat.y);
|
||||
}
|
||||
|
||||
onmoves(event:EventTouch){
|
||||
this.p_an.crossFade('p_an', .5);
|
||||
this.gm.isTouch(true);
|
||||
//this.plane.setPosition(event.touch.getLocationX(),this.plane.position.y,event.touch.getLocationY());
|
||||
}
|
||||
|
||||
onmovee(event:EventTouch){
|
||||
this.p_an.stop();
|
||||
this.gm.isTouch(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/src/UIMain.ts.meta
Normal file
9
assets/src/UIMain.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9f13340b-a236-4f6a-94da-6d69735fa52f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
59
assets/src/gameManager.ts
Normal file
59
assets/src/gameManager.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { _decorator, Component, Node, Prefab, instantiate } from 'cc';
|
||||
import { zd } from './zd';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('gameManager')
|
||||
export class gameManager extends Component {
|
||||
|
||||
@property(Node)
|
||||
public plant:Node = null;
|
||||
|
||||
@property(Node)
|
||||
public zdOut:Node = null;
|
||||
|
||||
@property(Prefab)
|
||||
public zd1:Prefab = null;
|
||||
|
||||
/**子弹移动速度*/
|
||||
@property
|
||||
public zd_speed:number = 0.2;
|
||||
|
||||
/**发射子弹的间隔*/
|
||||
@property
|
||||
public new_zd_time = 0.3;
|
||||
|
||||
/**当前发射子弹的间隔*/
|
||||
@property
|
||||
public _new_zd_time = 0;
|
||||
|
||||
private _isTouch:boolean = false;
|
||||
|
||||
start() {
|
||||
this._new_zd_time = this.new_zd_time;
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
this._new_zd_time += deltaTime;
|
||||
if(this._isTouch && this._new_zd_time > this.new_zd_time){
|
||||
this.createZd();
|
||||
this._new_zd_time = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public createZd(){
|
||||
const zd01 = instantiate(this.zd1);
|
||||
zd01.setParent(this.zdOut);
|
||||
const ppos = this.plant.position;
|
||||
zd01.setPosition(ppos.x, ppos.y, ppos.z - 1);
|
||||
const zdcop = zd01.getComponent(zd);
|
||||
console.log(this.zd_speed);
|
||||
zdcop.z_speed = this.zd_speed;
|
||||
}
|
||||
|
||||
isTouch(val:boolean){
|
||||
this._isTouch = val;
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/src/gameManager.ts.meta
Normal file
9
assets/src/gameManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7dcc9246-3519-47f8-909c-f7c5fce852c3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
28
assets/src/zd.ts
Normal file
28
assets/src/zd.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
const OUTMOVE = -10;
|
||||
|
||||
@ccclass('zd')
|
||||
export class zd extends Component {
|
||||
|
||||
@property
|
||||
public z_speed:number = 0;
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
const pos = this.node.position;
|
||||
const moveLength = pos.z - this.z_speed;
|
||||
this.node.setPosition(pos.x, pos.y, moveLength);
|
||||
|
||||
if(moveLength < OUTMOVE){
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/src/zd.ts.meta
Normal file
9
assets/src/zd.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e6210d16-2ce8-4552-a41e-dd2b582c988e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user