Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TTOS0700
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nikon Projektikansio
TTOS0700
Commits
a53bb873
Commit
a53bb873
authored
6 years ago
by
Niko Kaski
Browse files
Options
Downloads
Patches
Plain Diff
last step
parent
1e31e5a0
No related branches found
No related tags found
1 merge request
!2
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
First Game/index.html
+162
-105
162 additions, 105 deletions
First Game/index.html
with
162 additions
and
105 deletions
First Game/index.html
+
162
−
105
View file @
a53bb873
...
...
@@ -14,135 +14,192 @@
<script
type=
"text/javascript"
>
var
config
=
{
type
:
Phaser
.
AUTO
,
width
:
800
,
height
:
600
,
physics
:
{
default
:
'
arcade
'
,
arcade
:
{
gravity
:
{
y
:
300
},
debug
:
false
}
},
scene
:
{
preload
:
preload
,
create
:
create
,
update
:
update
var
config
=
{
type
:
Phaser
.
AUTO
,
width
:
800
,
height
:
600
,
physics
:
{
default
:
'
arcade
'
,
arcade
:
{
gravity
:
{
y
:
300
},
debug
:
false
}
};
var
player
;
var
stars
;
var
platforms
;
var
cursors
;
var
score
=
0
;
var
scoreText
;
var
game
=
new
Phaser
.
Game
(
config
);
function
preload
()
},
scene
:
{
preload
:
preload
,
create
:
create
,
update
:
update
}
};
var
player
;
var
stars
;
var
bombs
;
var
platforms
;
var
cursors
;
var
score
=
0
;
var
gameOver
=
false
;
var
scoreText
;
var
game
=
new
Phaser
.
Game
(
config
);
function
preload
()
{
this
.
load
.
image
(
'
sky
'
,
'
assets/sky.png
'
);
this
.
load
.
image
(
'
ground
'
,
'
assets/platform.png
'
);
this
.
load
.
image
(
'
star
'
,
'
assets/star.png
'
);
this
.
load
.
image
(
'
bomb
'
,
'
assets/bomb.png
'
);
this
.
load
.
spritesheet
(
'
dude
'
,
'
assets/dude.png
'
,
{
frameWidth
:
32
,
frameHeight
:
48
});
}
function
create
()
{
// A simple background for our game
this
.
add
.
image
(
400
,
300
,
'
sky
'
);
// The platforms group contains the ground and the 2 ledges we can jump on
platforms
=
this
.
physics
.
add
.
staticGroup
();
// Here we create the ground.
// Scale it to fit the width of the game (the original sprite is 400x32 in size)
platforms
.
create
(
400
,
568
,
'
ground
'
).
setScale
(
2
).
refreshBody
();
// Now let's create some ledges
platforms
.
create
(
600
,
400
,
'
ground
'
);
platforms
.
create
(
50
,
250
,
'
ground
'
);
platforms
.
create
(
750
,
220
,
'
ground
'
);
// The player and its settings
player
=
this
.
physics
.
add
.
sprite
(
100
,
450
,
'
dude
'
);
// Player physics properties. Give the little guy a slight bounce.
player
.
setBounce
(
0.2
);
player
.
setCollideWorldBounds
(
true
);
// Our player animations, turning, walking left and walking right.
this
.
anims
.
create
({
key
:
'
left
'
,
frames
:
this
.
anims
.
generateFrameNumbers
(
'
dude
'
,
{
start
:
0
,
end
:
3
}),
frameRate
:
10
,
repeat
:
-
1
});
this
.
anims
.
create
({
key
:
'
turn
'
,
frames
:
[
{
key
:
'
dude
'
,
frame
:
4
}
],
frameRate
:
20
});
this
.
anims
.
create
({
key
:
'
right
'
,
frames
:
this
.
anims
.
generateFrameNumbers
(
'
dude
'
,
{
start
:
5
,
end
:
8
}),
frameRate
:
10
,
repeat
:
-
1
});
// Input Events
cursors
=
this
.
input
.
keyboard
.
createCursorKeys
();
// Some stars to collect, 12 in total, evenly spaced 70 pixels apart along the x axis
stars
=
this
.
physics
.
add
.
group
({
key
:
'
star
'
,
repeat
:
11
,
setXY
:
{
x
:
12
,
y
:
0
,
stepX
:
70
}
});
stars
.
children
.
iterate
(
function
(
child
)
{
// Give each star a slightly different bounce
child
.
setBounceY
(
Phaser
.
Math
.
FloatBetween
(
0.4
,
0.8
));
});
bombs
=
this
.
physics
.
add
.
group
();
// The score
scoreText
=
this
.
add
.
text
(
16
,
16
,
'
score: 0
'
,
{
fontSize
:
'
32px
'
,
fill
:
'
#000
'
});
// Collide the player and the stars with the platforms
this
.
physics
.
add
.
collider
(
player
,
platforms
);
this
.
physics
.
add
.
collider
(
stars
,
platforms
);
this
.
physics
.
add
.
collider
(
bombs
,
platforms
);
// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this
.
physics
.
add
.
overlap
(
player
,
stars
,
collectStar
,
null
,
this
);
this
.
physics
.
add
.
collider
(
player
,
bombs
,
hitBomb
,
null
,
this
);
}
function
update
()
{
if
(
gameOver
)
{
this
.
load
.
image
(
'
sky
'
,
'
assets/sky.png
'
);
this
.
load
.
image
(
'
ground
'
,
'
assets/platform.png
'
);
this
.
load
.
image
(
'
star
'
,
'
assets/star.png
'
);
this
.
load
.
image
(
'
bomb
'
,
'
assets/bomb.png
'
);
this
.
load
.
spritesheet
(
'
dude
'
,
'
assets/dude.png
'
,
{
frameWidth
:
32
,
frameHeight
:
48
});
return
;
}
function
create
(
)
if
(
cursors
.
left
.
isDown
)
{
this
.
add
.
image
(
400
,
300
,
'
sky
'
);
platforms
=
this
.
physics
.
add
.
staticGroup
();
platforms
.
create
(
400
,
568
,
'
ground
'
).
setScale
(
2
).
refreshBody
();
platforms
.
create
(
600
,
400
,
'
ground
'
);
platforms
.
create
(
50
,
250
,
'
ground
'
);
platforms
.
create
(
750
,
220
,
'
ground
'
);
player
=
this
.
physics
.
add
.
sprite
(
100
,
450
,
'
dude
'
);
player
.
setVelocityX
(
-
160
);
player
.
setBounce
(
0.2
);
player
.
setCollideWorldBounds
(
true
);
player
.
anims
.
play
(
'
left
'
,
true
);
}
else
if
(
cursors
.
right
.
isDown
)
{
player
.
setVelocityX
(
160
);
this
.
anims
.
create
({
key
:
'
left
'
,
frames
:
this
.
anims
.
generateFrameNumbers
(
'
dude
'
,
{
start
:
0
,
end
:
3
}),
frameRate
:
10
,
repeat
:
-
1
});
player
.
anims
.
play
(
'
right
'
,
true
);
}
else
{
player
.
setVelocityX
(
0
);
this
.
anims
.
create
({
key
:
'
turn
'
,
frames
:
[
{
key
:
'
dude
'
,
frame
:
4
}
],
frameRate
:
20
});
player
.
anims
.
play
(
'
turn
'
);
}
this
.
anims
.
create
({
key
:
'
right
'
,
frames
:
this
.
anims
.
generateFrameNumbers
(
'
dude
'
,
{
start
:
5
,
end
:
8
}),
frameRate
:
10
,
repeat
:
-
1
});
if
(
cursors
.
up
.
isDown
&&
player
.
body
.
touching
.
down
)
{
player
.
setVelocityY
(
-
330
);
}
}
cursors
=
this
.
input
.
keyboard
.
createCursorKeys
();
function
collectStar
(
player
,
star
)
{
star
.
disableBody
(
true
,
true
);
stars
=
this
.
physics
.
add
.
group
({
key
:
'
star
'
,
repeat
:
11
,
setXY
:
{
x
:
12
,
y
:
0
,
stepX
:
70
}
});
// Add and update the score
score
+=
10
;
scoreText
.
setText
(
'
Score:
'
+
score
);
if
(
stars
.
countActive
(
true
)
===
0
)
{
// A new batch of stars to collect
stars
.
children
.
iterate
(
function
(
child
)
{
child
.
setBounceY
(
Phaser
.
Math
.
FloatBetween
(
0.4
,
0.8
)
);
child
.
enableBody
(
true
,
child
.
x
,
0
,
true
,
true
);
});
scoreText
=
this
.
add
.
text
(
16
,
16
,
'
score: 0
'
,
{
fontSize
:
'
32px
'
,
fill
:
'
#000
'
}
);
var
x
=
(
player
.
x
<
400
)
?
Phaser
.
Math
.
Between
(
400
,
800
)
:
Phaser
.
Math
.
Between
(
0
,
400
);
this
.
physics
.
add
.
collider
(
player
,
platforms
);
this
.
physics
.
add
.
collider
(
stars
,
platforms
);
var
bomb
=
bombs
.
create
(
x
,
16
,
'
bomb
'
);
bomb
.
setBounce
(
1
);
bomb
.
setCollideWorldBounds
(
true
);
bomb
.
setVelocity
(
Phaser
.
Math
.
Between
(
-
200
,
200
),
20
);
bomb
.
allowGravity
=
false
;
this
.
physics
.
add
.
overlap
(
player
,
stars
,
collectStar
,
null
,
this
);
}
}
function
update
()
{
if
(
cursors
.
left
.
isDown
)
{
player
.
setVelocityX
(
-
160
);
function
hitBomb
(
player
,
bomb
)
{
this
.
physics
.
pause
();
player
.
anims
.
play
(
'
left
'
,
true
);
}
else
if
(
cursors
.
right
.
isDown
)
{
player
.
setVelocityX
(
160
);
player
.
setTint
(
0xff0000
);
player
.
anims
.
play
(
'
right
'
,
true
);
}
else
{
player
.
setVelocityX
(
0
);
player
.
anims
.
play
(
'
turn
'
);
player
.
anims
.
play
(
'
turn
'
);
}
if
(
cursors
.
up
.
isDown
&&
player
.
body
.
touching
.
down
)
{
player
.
setVelocityY
(
-
330
);
}
}
function
collectStar
(
player
,
star
)
{
star
.
disableBody
(
true
,
true
);
score
+=
10
;
scoreText
.
setText
(
'
Score:
'
+
score
);
}
gameOver
=
true
;
}
</script>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment