Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crazyflirt
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shawn Wang
crazyflirt
Commits
3563970a
Commit
3563970a
authored
May 05, 2018
by
Nick An
Browse files
Options
Browse Files
Download
Plain Diff
mg
parents
2e7e59be
15ec9eca
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
310 additions
and
11 deletions
+310
-11
.gitignore
.gitignore
+5
-2
Controller.ts
fe/src/Controller.ts
+66
-0
Main.ts
fe/src/Main.ts
+63
-6
Platform.ts
fe/src/Platform.ts
+38
-0
SceneManager.ts
fe/src/SceneManager.ts
+1
-1
Store.ts
fe/src/Store.ts
+20
-0
GameScene.ts
fe/src/scenes/GameScene.ts
+5
-1
README.md
fe/src/scenes/README.md
+33
-0
native_require.js
fe/template/runtime/native_require.js
+13
-1
platform.js
fe_wxgame/platform.js
+66
-0
No files found.
.gitignore
View file @
3563970a
node_modules/
.wing/
fe_wxgame/
\ No newline at end of file
fe_wxgame/*
!fe_wxgame/platform.js
\ No newline at end of file
fe/src/Controller.ts
0 → 100644
View file @
3563970a
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
fe/src/Main.ts
View file @
3563970a
...
...
@@ -55,19 +55,63 @@ class Main extends egret.DisplayObjectContainer {
this
.
runGame
().
catch
(
e
=>
{
console
.
log
(
e
);
})
}
private
async
runGame
()
{
await
this
.
loadResource
()
var
stage
=
egret
.
MainContext
.
instance
.
stage
;
stage
.
setContentSize
(
1334
,
750
);
this
.
createGameScene
();
const
result
=
await
RES
.
getResAsync
(
"description_json"
)
await
platform
.
login
();
const
userInfo
=
await
platform
.
getUserInfo
();
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
()
{
...
...
@@ -83,6 +127,9 @@ class Main extends egret.DisplayObjectContainer {
}
}
private
textfield
:
egret
.
TextField
;
private
myPosition
=
new
egret
.
Point
(
0
,
0
)
/**
* 创建游戏场景
* Create a game scene
...
...
@@ -90,5 +137,16 @@ class Main extends egret.DisplayObjectContainer {
private
createGameScene
()
{
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
}
fe/src/Platform.ts
View file @
3563970a
...
...
@@ -10,15 +10,53 @@ declare interface Platform {
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
{
async
getUserInfo
()
{
return
{
nickName
:
"username"
}
}
async
login
()
{
}
showToast
(
title
){
}
connectSocket
(
options
){
}
onSocketOpen
(
callback
){
}
onSocketClose
(
callback
){
}
onSocketMessage
(
options
){
}
onSocketError
(
callback
){
}
sendSocketMessage
(
callback
){
}
request
(){
}
}
...
...
fe/src/SceneManager.ts
View file @
3563970a
...
...
@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this
.
roomScene
=
new
RoomScene
();
this
.
gameScene
=
new
GameScene
();
// 默认添加开始场景
this
.
addChild
(
this
.
room
Scene
);
this
.
addChild
(
this
.
game
Scene
);
}
// 实例化单例获取方法
public
static
getInstance
():
SceneManager
{
...
...
fe/src/Store.ts
0 → 100644
View file @
3563970a
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
fe/src/scenes/GameScene.ts
View file @
3563970a
class
GameScene
extends
egret
.
Sprite
{
private
controller
public
constructor
()
{
super
();
this
.
init
()
}
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
// put display object to this scene
this
.
controller
=
new
Controller
()
this
.
addChild
(
this
.
controller
)
}
public
release
()
{
...
...
fe/src/scenes/README.md
0 → 100644
View file @
3563970a
{
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
fe/template/runtime/native_require.js
View file @
3563970a
...
...
@@ -31,7 +31,19 @@ egret_native.egretStart = function () {
//以下为自动修改,请勿修改
//The following is automatically modified, please do not modify
//----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
;
...
...
fe_wxgame/platform.js
0 → 100644
View file @
3563970a
/**
* 请在白鹭引擎的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
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment