Commit 3563970a by Nick An

mg

parents 2e7e59be 15ec9eca
node_modules/ node_modules/
.wing/ .wing/
fe_wxgame/
\ No newline at end of file
fe_wxgame/*
!fe_wxgame/platform.js
\ No newline at end of file
class Controller extends egret.Sprite {
public constructor() {
super();
this.init()
}
private speed = 10
private speedX = 0
private speedY = 0
private p1:egret.Point = new egret.Point();
private p2:egret.Point = new egret.Point();
private control = new egret.Shape();
private pointtt = new egret.Shape();
private controlCenter = new egret.Point(1100, 450)
// 初始化(给开始按钮绑定点击事件)
private init() {
this.control.graphics.beginFill( 0xFF3866, 1);
this.control.graphics.drawCircle(1100, 450, 90);
this.control.graphics.endFill();
this.addChild( this.control );
this.pointtt.graphics.beginFill(0xFF0000, 1)
this.pointtt.graphics.drawCircle(1100, 450, 10)
this.pointtt.graphics.endFill()
this.addChild(this.pointtt)
this.touchEnabled = true
this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.controlTouchMove, this)
this.addEventListener(egret.TouchEvent.TOUCH_END, this.controlTouchEnd, this)
this.addEventListener(egret.Event.ENTER_FRAME,this.onEnterFrame,this)
}
private onEnterFrame(e: egret.Event){
if(this.touchEnd){
return
}
this.pointtt.x += this.speedX
this.pointtt.y += this.speedY
}
private touchEnd = false
private controlTouchBegin(e: egret.TouchEvent){
this.touchEnd = false
}
private controlTouchMove(e: egret.TouchEvent){
var angle = Math.atan2(e.stageY - this.controlCenter.y, e.stageX - this.controlCenter.x )
// console.error(e)
this.speedX = Math.cos(angle)*this.speed;
this.speedY = Math.sin(angle)*this.speed;
// console.error(this.speedX)
// console.error(e.stageX)
}
private controlTouchEnd(e: egret.TouchEvent){
this.touchEnd = true
// this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
}
public release() {
// 移除事件
}
}
\ No newline at end of file
...@@ -55,19 +55,63 @@ class Main extends egret.DisplayObjectContainer { ...@@ -55,19 +55,63 @@ class Main extends egret.DisplayObjectContainer {
this.runGame().catch(e => { this.runGame().catch(e => {
console.log(e); console.log(e);
}) })
} }
private async runGame() { private async runGame() {
await this.loadResource() await this.loadResource()
var stage = egret.MainContext.instance.stage;
stage.setContentSize(1334, 750);
this.createGameScene(); this.createGameScene();
const result = await RES.getResAsync("description_json")
await platform.login(); await platform.login();
const userInfo = await platform.getUserInfo(); const userInfo = await platform.getUserInfo();
console.log(userInfo); console.log(userInfo);
platform.connectSocket({
url: "ws://192.168.50.118:9090",
header: {
'content-type': 'application/json'
},
method: "GET",
success: (...args) => {
console.error("success")
console.error(args)
},
fail: (...args) => {
console.error("fail")
console.error(args)
}
})
platform.onSocketOpen(() => {
platform.sendSocketMessage({
data: JSON.stringify({
cid: "asnbduawh",
seq: "moving",
x: 100,
y: 123
}),
success: () => {
console.error("sendSocketMessage success")
},
fail: () => {
console.error("sendSocketMessage fail")
}
})
})
platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(res.data)
})
platform.onSocketError((e) => {
console.error("onSocketError")
console.error(e)
})
platform.onSocketClose((e) => {
console.error("onSocketClose")
console.error(e)
})
} }
private async loadResource() { private async loadResource() {
...@@ -83,6 +127,9 @@ class Main extends egret.DisplayObjectContainer { ...@@ -83,6 +127,9 @@ class Main extends egret.DisplayObjectContainer {
} }
} }
private textfield: egret.TextField;
private myPosition = new egret.Point(0, 0)
/** /**
* 创建游戏场景 * 创建游戏场景
* Create a game scene * Create a game scene
...@@ -90,5 +137,16 @@ class Main extends egret.DisplayObjectContainer { ...@@ -90,5 +137,16 @@ class Main extends egret.DisplayObjectContainer {
private createGameScene() { private createGameScene() {
this.addChild(SceneManager.getInstance()); this.addChild(SceneManager.getInstance());
} }
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
private createBitmapByName(name: string) {
let result = new egret.Bitmap();
let texture: egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
} }
\ No newline at end of file
...@@ -10,15 +10,53 @@ declare interface Platform { ...@@ -10,15 +10,53 @@ declare interface Platform {
login(): Promise<any> login(): Promise<any>
connectSocket(options): void
onSocketOpen(callback): void
onSocketClose(callback): void
onSocketMessage(callback): void
onSocketError(callback): void
sendSocketMessage(callback): void
request(options): void
} }
class DebugPlatform implements Platform { class DebugPlatform implements Platform {
async getUserInfo() { async getUserInfo() {
return { nickName: "username" } return { nickName: "username" }
} }
async login() { async login() {
}
showToast(title){
}
connectSocket(options){
}
onSocketOpen(callback){
}
onSocketClose(callback){
} }
onSocketMessage(options){
}
onSocketError(callback){
}
sendSocketMessage(callback){
}
request(){
}
} }
......
...@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer { ...@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this.roomScene = new RoomScene(); this.roomScene = new RoomScene();
this.gameScene = new GameScene(); this.gameScene = new GameScene();
// 默认添加开始场景 // 默认添加开始场景
this.addChild(this.roomScene); this.addChild(this.gameScene);
} }
// 实例化单例获取方法 // 实例化单例获取方法
public static getInstance(): SceneManager { public static getInstance(): SceneManager {
......
const _state = {}
class Store {
static getState() {
return _state
}
static onMessage(message) {
switch (message.type) {
case 'start':
_state = {
}
break;
default:
break;
}
return _state
}
}
\ No newline at end of file
class GameScene extends egret.Sprite { class GameScene extends egret.Sprite {
private controller
public constructor() { public constructor() {
super(); super();
this.init() this.init()
} }
// 初始化(给开始按钮绑定点击事件) // 初始化(给开始按钮绑定点击事件)
private init() { private init() {
// put display object to this scene // put display object to this scene
this.controller = new Controller()
this.addChild(this.controller)
} }
public release() { public release() {
......
{
type: 'moving', # 'start' , 'entry', 'clicking'
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
x: 1,
y: 4
}
}
{
type: 'game_ready',
cid: 'abcdefg',
room_id: 'asdfadfaf',
payload: {
open_id: 'asdfasdfa',
picture: 'https://xxx.com',
role: 'ghost', # runner
}
}
GameScene
RunnerList
if isRunner
Controller
Map
if isCatcher
Map.mask = touchArea
\ No newline at end of file
...@@ -31,7 +31,19 @@ egret_native.egretStart = function () { ...@@ -31,7 +31,19 @@ egret_native.egretStart = function () {
//以下为自动修改,请勿修改 //以下为自动修改,请勿修改
//The following is automatically modified, please do not modify //The following is automatically modified, please do not modify
//----auto option start---- //----auto option start----
//----auto option end---- entryClassName: "Main",
frameRate: 30,
scaleMode: "fixedWidth",
contentWidth: 640,
contentHeight: 1136,
showPaintRect: false,
showFPS: false,
fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9",
showLog: false,
logFilter: "",
maxTouches: 2,
textureScaleFactor: 1
//----auto option end----
}; };
egret.native.NativePlayer.option = option; egret.native.NativePlayer.option = option;
......
/**
* 请在白鹭引擎的Main.ts中调用 platform.login() 方法调用至此处。
*/
class WxgamePlatform {
name = 'wxgame'
login() {
return new Promise((resolve, reject) => {
wx.login({
success: (res) => {
resolve(res)
}
})
})
}
getUserInfo() {
return new Promise((resolve, reject) => {
wx.getUserInfo({
withCredentials: true,
success: function (res) {
var userInfo = res.userInfo
var nickName = userInfo.nickName
var avatarUrl = userInfo.avatarUrl
var gender = userInfo.gender //性别 0:未知、1:男、2:女
var province = userInfo.province
var city = userInfo.city
var country = userInfo.country
resolve(userInfo);
}
})
})
}
connectSocket(options){
wx.connectSocket(options)
}
onSocketOpen(callback){
wx.onSocketOpen(callback)
}
onSocketClose(callback){
wx.onSocketClose(callback)
}
onSocketMessage(callback){
wx.onSocketMessage(callback)
}
onSocketError(callback){
wx.onSocketError(callback)
}
sendSocketMessage(options){
wx.sendSocketMessage(options)
}
request(options){
wx.request(options)
}
}
window.platform = new WxgamePlatform();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment