Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-website
Commits
8ebe1f89
Commit
8ebe1f89
authored
May 04, 2018
by
Hubert Denkmair
Browse files
make SnakeSegment independent from Snake
parent
14b41de5
Changes
2
Hide whitespace changes
Inline
Side-by-side
visualization/static/visualization/Snake.js
View file @
8ebe1f89
...
...
@@ -29,16 +29,6 @@ function Snake(headTexture, bodyTexture, name, colorScheme, world_size_x, world_
this
.
Container
.
addChild
(
this
.
_nameSprite
);
}
Snake
.
prototype
.
GetBodyTexture
=
function
()
{
return
this
.
_bodyTexture
;
};
Snake
.
prototype
.
GetCurrentSnakeScale
=
function
()
{
return
this
.
spriteScale
;
};
Snake
.
prototype
.
SetData
=
function
(
data
)
{
this
.
heading
=
data
.
heading
;
...
...
@@ -70,12 +60,14 @@ Snake.prototype.SetLength = function(newLength)
for
(
let
i
=
this
.
GetLength
();
i
<
newLength
;
i
++
)
{
let
segment
=
new
SnakeSegment
(
this
);
let
segment
=
new
SnakeSegment
(
this
.
_bodyTexture
);
if
(
this
.
_segments
.
length
>
0
)
{
segment
.
ClonePosition
(
this
.
_segments
[
this
.
_segments
.
length
-
1
]);
}
segment
.
SetTint
(
this
.
_colorScheme
[
i
%
this
.
_colorScheme
.
length
]);
segment
.
SetScale
(
this
.
spriteScale
);
this
.
_segmentContainer
.
addChildAt
(
segment
.
GetSprite
(),
0
);
this
.
_segments
.
push
(
segment
);
}
...
...
visualization/static/visualization/SnakeSegment.js
View file @
8ebe1f89
"
use strict
"
;
function
SnakeSegment
(
snak
e
)
function
SnakeSegment
(
textur
e
)
{
this
.
x
=
0
;
this
.
y
=
0
;
this
.
_sprite
=
new
PIXI
.
Sprite
(
snake
.
GetBodyT
exture
()
);
this
.
_sprite
=
new
PIXI
.
Sprite
(
t
exture
);
this
.
_sprite
.
anchor
.
set
(
0.5
);
this
.
_sprite
.
alpha
=
0.8
;
this
.
SetScale
(
snake
.
GetCurrentSnakeScale
());
}
SnakeSegment
.
prototype
.
GetSprite
=
function
()
...
...
@@ -45,14 +44,6 @@ SnakeSegment.prototype.MoveDirection = function(direction, length)
);
};
SnakeSegment
.
prototype
.
MoveRelative
=
function
(
dx
,
dy
)
{
this
.
SetPosition
(
this
.
x
+
dx
,
this
.
y
+
dy
);
};
SnakeSegment
.
prototype
.
UpdateSprites
=
function
()
{
this
.
_sprite
.
x
=
this
.
x
;
...
...
Write
Preview
Supports
Markdown
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