Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-kickball
Project
Project
Details
Activity
Releases
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
wildfirecode13
scilla-kickball
Commits
28f9308b
Commit
28f9308b
authored
Apr 25, 2019
by
wildfirecode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
42d0ce01
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
43 deletions
+118
-43
BallItem.ts
assets/scripts/scenes/BallItem.ts
+3
-1
ScenePlay.ts
assets/scripts/scenes/ScenePlay.ts
+54
-16
gameconst.ts
assets/scripts/scenes/gameconst.ts
+1
-1
transform.ts
assets/scripts/transform.ts
+1
-0
bundle.js
debug/bundle.js
+58
-24
bundle.js.map
debug/bundle.js.map
+1
-1
No files found.
assets/scripts/scenes/BallItem.ts
View file @
28f9308b
...
...
@@ -6,10 +6,11 @@ import { TextRenderer } from 'scilla-components/src';
export
default
class
BallItem
extends
Body
{
score
=
0
;
scoreTxt
:
Entity
;
isBig
=
true
;
constructor
()
{
super
();
this
.
gravity
=
gravityY
;
this
.
rotationSpeed
=
0.5
*
2
;
this
.
rotationSpeed
=
0.5
;
}
onAwake
()
{
...
...
@@ -22,6 +23,7 @@ export default class BallItem extends Body {
if
(
this
.
score
<
0
)
this
.
score
=
0
;
this
.
updateScoreTxt
();
return
this
.
score
;
}
updateScoreTxt
()
{
...
...
assets/scripts/scenes/ScenePlay.ts
View file @
28f9308b
...
...
@@ -74,16 +74,28 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
super
.
onAwake
();
this
.
ballList
=
[];
this
.
bodys
=
[];
this
.
toRmoveBallList
=
[];
}
onUpdate
()
{
for
(
let
i
=
0
;
i
<
this
.
toRmoveBallList
.
length
;
i
++
)
{
const
element
=
this
.
toRmoveBallList
[
i
];
const
bc
=
element
.
getComponent
(
BallItem
);
this
.
toRmoveBallList
.
splice
(
i
,
1
);
i
--
;
this
.
removeBall
(
element
);
if
(
bc
.
isBig
)
{
this
.
onBallSplit
(
element
);
}
}
//所有的刚体检查,包括子弹、掉落
for
(
let
i
=
0
;
i
<
this
.
bodys
.
length
;
i
++
)
{
const
body
=
this
.
bodys
[
i
];
const
{
position
}
=
body
.
getComponent
(
Transform
);
const
pic
=
body
.
getChildrenByName
(
'pic'
)[
0
];
const
{
height
,
width
}
=
pic
.
getComponent
(
Transform
);
const
r
=
height
/
2
;
//刚体的半径
const
{
height
,
width
,
scale
}
=
pic
.
getComponent
(
Transform
);
const
r
=
height
/
2
*
scale
.
y
;
//刚体的半径
if
(
position
.
y
+
r
>
GROUND_Y
)
{
position
.
y
=
GROUND_Y
-
r
;
body
.
getComponent
(
Body
).
revertY
();
...
...
@@ -121,24 +133,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
i
--
;
}
else
{
//子弹和ball处理
// console.log(body.getComponent(Transform))
try
{
for
(
const
ball
of
this
.
ballList
)
{
const
x0
=
Math
.
abs
(
getX
(
body
)
-
getX
(
ball
));
const
y0
=
Math
.
abs
(
getY
(
body
)
-
getY
(
ball
));
const
ballT
=
ball
.
getComponent
(
Transform
);
const
{
height
:
ballH
}
=
ball
.
getChildrenByName
(
'pic'
)[
0
].
getComponent
(
Transform
);
const
x1
=
width
/
2
+
ballH
/
2
;
const
y1
=
height
/
2
+
ballH
/
2
;
const
x1
=
width
/
2
+
ballH
/
2
*
ballT
.
scale
.
x
;
const
y1
=
height
/
2
+
ballH
/
2
*
ballT
.
scale
.
x
;
// console.log(ballT.scale.x)
if
(
x0
<
x1
&&
y0
<
y1
)
{
//子弹和球碰撞了
this
.
removeBullet
(
body
);
i
--
;
if
(
ball
.
getComponent
(
BallItem
).
reduceScore
()
==
0
)
{
//破裂
this
.
toRmoveBallList
.
push
(
ball
);
}
}
}
}
catch
(
error
)
{
}
}
}
}
}
toRmoveBallList
:
Entity
[];
removeBullet
(
body
:
Entity
)
{
console
.
log
(
this
.
bodys
.
length
)
//
console.log(this.bodys.length)
body
.
removeAllComponents
();
const
index
=
this
.
bodys
.
indexOf
(
body
);
if
(
index
==
-
1
)
return
;
...
...
@@ -166,10 +190,24 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
onBallSplit
(
body
:
Entity
)
{
//球分裂
const
ball1
=
this
.
getBallItem
(
100
);
// const ball2 = this.getBallItem(
);
const
ball1
=
this
.
createSmallBalls
(
body
);
const
ball2
=
this
.
createSmallBalls
(
body
);
setXY
(
ball1
,
getX
(
body
),
getY
(
body
));
ball1
.
getComponent
(
Body
).
velocityY
=
-
45
;
setXY
(
ball2
,
getX
(
body
),
getY
(
body
));
ball1
.
getComponent
(
Body
).
velocityY
=
-
10
;
ball1
.
getComponent
(
Body
).
velocityX
=
-
5
;
ball2
.
getComponent
(
Body
).
velocityY
=
-
10
;
ball2
.
getComponent
(
Body
).
velocityX
=
5
;
}
createSmallBalls
(
parentBall
:
Entity
)
{
const
ball
=
this
.
getBallItem
(
10
);
const
ballc
=
ball
.
getComponent
(
BallItem
);
const
tras
=
ball
.
getComponent
(
Transform
);
tras
.
scale
.
x
=
0.6
;
tras
.
scale
.
y
=
0.6
;
ballc
.
isBig
=
false
;
return
ball
;
}
async
onCarCollideDrops
(
body
:
Entity
)
{
...
...
@@ -187,7 +225,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
async
createBigBall
()
{
const
ball
=
this
.
getBallItem
(
10
0
);
const
ball
=
this
.
getBallItem
(
2
0
);
setXY
(
ball
,
-
375
,
-
400
);
const
body
=
ball
.
getComponent
(
Body
);
body
.
enabled
=
false
;
...
...
assets/scripts/scenes/gameconst.ts
View file @
28f9308b
export
const
gravityY
=
.
7
;
\ No newline at end of file
export
const
gravityY
=
.
5
;
\ No newline at end of file
assets/scripts/transform.ts
View file @
28f9308b
...
...
@@ -8,6 +8,7 @@ export const setY = (entity: Entity, y) => {
entity
.
getComponent
(
Transform
).
position
.
y
=
y
;
}
export
const
getX
=
(
entity
:
Entity
)
=>
{
// if(!entity.getComponent(Transform))debugger
return
entity
.
getComponent
(
Transform
).
position
.
x
}
export
const
getY
=
(
entity
:
Entity
)
=>
{
...
...
debug/bundle.js
View file @
28f9308b
...
...
@@ -7019,15 +7019,16 @@
return
Body
;
}(
ScillaComponent
));
var
gravityY
=
.
7
;
var
gravityY
=
.
5
;
var
BallItem
=
(
function
(
_super
)
{
__extends
(
BallItem
,
_super
);
function
BallItem
()
{
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
score
=
0
;
_this
.
isBig
=
true
;
_this
.
gravity
=
gravityY
;
_this
.
rotationSpeed
=
0.5
*
2
;
_this
.
rotationSpeed
=
0.5
;
return
_this
;
}
BallItem
.
prototype
.
onAwake
=
function
()
{
...
...
@@ -7039,6 +7040,7 @@
if
(
this
.
score
<
0
)
this
.
score
=
0
;
this
.
updateScoreTxt
();
return
this
.
score
;
};
BallItem
.
prototype
.
updateScoreTxt
=
function
()
{
var
tr
=
this
.
scoreTxt
.
getComponent
(
TextRenderer
);
...
...
@@ -7125,15 +7127,26 @@
_super
.
prototype
.
onAwake
.
call
(
this
);
this
.
ballList
=
[];
this
.
bodys
=
[];
this
.
toRmoveBallList
=
[];
};
ScenePlay
.
prototype
.
onUpdate
=
function
()
{
var
e_1
,
_a
;
for
(
var
i
=
0
;
i
<
this
.
toRmoveBallList
.
length
;
i
++
)
{
var
element
=
this
.
toRmoveBallList
[
i
];
var
bc
=
element
.
getComponent
(
BallItem
);
this
.
toRmoveBallList
.
splice
(
i
,
1
);
i
--
;
this
.
removeBall
(
element
);
if
(
bc
.
isBig
)
{
this
.
onBallSplit
(
element
);
}
}
for
(
var
i
=
0
;
i
<
this
.
bodys
.
length
;
i
++
)
{
var
body
=
this
.
bodys
[
i
];
var
position
=
body
.
getComponent
(
Transform
).
position
;
var
pic
=
body
.
getChildrenByName
(
'pic'
)[
0
];
var
_b
=
pic
.
getComponent
(
Transform
),
height
=
_b
.
height
,
width
=
_b
.
width
;
var
r
=
height
/
2
;
var
_b
=
pic
.
getComponent
(
Transform
),
height
=
_b
.
height
,
width
=
_b
.
width
,
scale
=
_b
.
scale
;
var
r
=
height
/
2
*
scale
.
y
;
if
(
position
.
y
+
r
>
GROUND_Y
)
{
position
.
y
=
GROUND_Y
-
r
;
body
.
getComponent
(
Body
).
revertY
();
...
...
@@ -7165,17 +7178,22 @@
i
--
;
}
else
{
try
{
try
{
for
(
var
_d
=
__values
(
this
.
ballList
),
_e
=
_d
.
next
();
!
_e
.
done
;
_e
=
_d
.
next
())
{
var
ball
=
_e
.
value
;
var
x0_1
=
Math
.
abs
(
getX
(
body
)
-
getX
(
ball
));
var
y0_1
=
Math
.
abs
(
getY
(
body
)
-
getY
(
ball
));
var
ballT
=
ball
.
getComponent
(
Transform
);
var
ballH
=
ball
.
getChildrenByName
(
'pic'
)[
0
].
getComponent
(
Transform
).
height
;
var
x1_1
=
width
/
2
+
ballH
/
2
;
var
y1_1
=
height
/
2
+
ballH
/
2
;
var
x1_1
=
width
/
2
+
ballH
/
2
*
ballT
.
scale
.
x
;
var
y1_1
=
height
/
2
+
ballH
/
2
*
ballT
.
scale
.
x
;
if
(
x0_1
<
x1_1
&&
y0_1
<
y1_1
)
{
this
.
removeBullet
(
body
);
i
--
;
if
(
ball
.
getComponent
(
BallItem
).
reduceScore
()
==
0
)
{
this
.
toRmoveBallList
.
push
(
ball
);
}
}
}
}
...
...
@@ -7187,11 +7205,13 @@
finally
{
if
(
e_1
)
throw
e_1
.
error
;
}
}
}
catch
(
error
)
{
}
}
}
}
};
ScenePlay
.
prototype
.
removeBullet
=
function
(
body
)
{
console
.
log
(
this
.
bodys
.
length
);
body
.
removeAllComponents
();
var
index
=
this
.
bodys
.
indexOf
(
body
);
if
(
index
==
-
1
)
...
...
@@ -7217,9 +7237,23 @@
this
.
entity
.
removeChild
(
body
);
};
ScenePlay
.
prototype
.
onBallSplit
=
function
(
body
)
{
var
ball1
=
this
.
getBallItem
(
100
);
var
ball1
=
this
.
createSmallBalls
(
body
);
var
ball2
=
this
.
createSmallBalls
(
body
);
setXY
(
ball1
,
getX
(
body
),
getY
(
body
));
ball1
.
getComponent
(
Body
).
velocityY
=
-
45
;
setXY
(
ball2
,
getX
(
body
),
getY
(
body
));
ball1
.
getComponent
(
Body
).
velocityY
=
-
10
;
ball1
.
getComponent
(
Body
).
velocityX
=
-
5
;
ball2
.
getComponent
(
Body
).
velocityY
=
-
10
;
ball2
.
getComponent
(
Body
).
velocityX
=
5
;
};
ScenePlay
.
prototype
.
createSmallBalls
=
function
(
parentBall
)
{
var
ball
=
this
.
getBallItem
(
10
);
var
ballc
=
ball
.
getComponent
(
BallItem
);
var
tras
=
ball
.
getComponent
(
Transform
);
tras
.
scale
.
x
=
0.6
;
tras
.
scale
.
y
=
0.6
;
ballc
.
isBig
=
false
;
return
ball
;
};
ScenePlay
.
prototype
.
onCarCollideDrops
=
function
(
body
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
...
...
@@ -7262,7 +7296,7 @@
return
__generator
(
this
,
function
(
_a
)
{
switch
(
_a
.
label
)
{
case
0
:
ball
=
this
.
getBallItem
(
10
0
);
ball
=
this
.
getBallItem
(
2
0
);
setXY
(
ball
,
-
375
,
-
400
);
body
=
ball
.
getComponent
(
Body
);
body
.
enabled
=
false
;
...
...
debug/bundle.js.map
View file @
28f9308b
This diff is collapsed.
Click to expand it.
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