Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sae-2023-groupeH-Bouin-Belguebli-Decoster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Julien Bouin
sae-2023-groupeH-Bouin-Belguebli-Decoster
Commits
ecba4f84
Commit
ecba4f84
authored
1 year ago
by
Rayane Belguebli
Browse files
Options
Downloads
Patches
Plain Diff
refactor synchro time et apparition enemis
parent
ea4ad61c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
client/public/index.html
+1
-1
1 addition, 1 deletion
client/public/index.html
client/src/main.js
+98
-65
98 additions, 65 deletions
client/src/main.js
client/src/scoreboard.json
+17
-0
17 additions, 0 deletions
client/src/scoreboard.json
server/index.js
+40
-25
40 additions, 25 deletions
server/index.js
with
156 additions
and
91 deletions
client/public/index.html
+
1
−
1
View file @
ecba4f84
...
...
@@ -21,7 +21,7 @@
<div
class=
"divMain"
>
<h1>
ça geek
</h1>
<button
class=
"buttonStart"
>
Play
</button>
<button
class=
"
S
coreBoard"
>
ScoreBoard
</button>
<button
class=
"
s
coreBoard"
>
ScoreBoard
</button>
<button
class=
"credits"
>
Credits
</button>
</section>
</div>
...
...
This diff is collapsed.
Click to expand it.
client/src/main.js
+
98
−
65
View file @
ecba4f84
...
...
@@ -47,6 +47,37 @@ setInterval(function () {
document
.
querySelector
(
'
.buttonStart
'
).
addEventListener
(
'
click
'
,
startGame
);
document
.
querySelector
(
'
.credits
'
).
addEventListener
(
'
click
'
,
afficherCredits
);
/*document
.querySelector('.scoreBoard')
.addEventListener('click', afficherScoreboard);
let scoreBoard = '';
fetch('./scoreboard.json')
.then(response => {
if (!response.ok) {
throw new Error('Erreur lors de la récupération du fichier JSON');
}
return response.json();
})
.then(data => {
const score = data.results;
score.forEach(element => {
scoreBoard += 'Nom: ' + element.nom;
scoreBoard += ' Score: ' + element.score;
scoreBoard += '</br></br>';
});
})
.catch(error => {
scoreBoard += error.message;
});
function afficherScoreboard(event) {
event.preventDefault();
document.querySelector('.divMain').innerHTML = scoreBoard;
const retour = document.querySelector('.retourMenu');
retour.addEventListener('click', afficherMenu);
}*/
function
afficherCredits
(
event
)
{
event
.
preventDefault
();
document
.
querySelector
(
'
.divMain
'
).
innerHTML
=
setHtml
.
credits
();
...
...
@@ -116,40 +147,33 @@ let newBonus = [];
function
render
()
{
context
.
clearRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
);
context
.
drawImage
(
background
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
context
.
font
=
'
40pt New Super Mario Font U
'
;
for
(
let
i
=
1
;
i
<
avatars
.
length
;
i
++
)
{
if
(
avatars
[
i
]
!=
undefined
)
{
context
.
fillStyle
=
colors
[
i
-
1
];
const
x
=
10
+
i
*
100
;
if
(
avatars
[
i
].
score
!=
undefined
)
{
context
.
fillText
(
avatars
[
i
].
score
,
x
,
50
);
}
imageCoeur
.
src
=
`/images/heart
${
i
}
.webp`
;
console
.
log
(
imageCoeur
.
src
);
for
(
let
j
=
0
;
j
<
avatars
[
i
].
vies
;
j
++
)
{
context
.
drawImage
(
imageCoeur
,
avatars
[
i
].
x
+
(
avatars
[
i
].
vies
-
j
)
*
20
-
15
,
avatars
[
i
].
y
+
imageMortier
.
height
,
20
,
20
);
if
(
gameStarted
)
{
context
.
font
=
'
40pt New Super Mario Font U
'
;
for
(
let
i
=
1
;
i
<
avatars
.
length
;
i
++
)
{
if
(
avatars
[
i
]
!=
undefined
)
{
context
.
fillStyle
=
colors
[
i
-
1
];
const
x
=
10
+
i
*
100
;
if
(
avatars
[
i
].
score
!=
undefined
)
{
context
.
fillText
(
avatars
[
i
].
score
,
x
,
50
);
}
imageCoeur
.
src
=
`/images/heart
${
i
}
.webp`
;
console
.
log
(
imageCoeur
.
src
);
for
(
let
j
=
0
;
j
<
avatars
[
i
].
vies
;
j
++
)
{
context
.
drawImage
(
imageCoeur
,
avatars
[
i
].
x
+
(
avatars
[
i
].
vies
-
j
)
*
20
-
15
,
avatars
[
i
].
y
+
imageMortier
.
height
,
20
,
20
);
}
}
}
}
context
.
fillStyle
=
'
blue
'
;
context
.
fillStyle
=
'
blue
'
;
context
.
fillText
(
0
+
'
:
'
+
min
+
'
:
'
+
sec
,
canvas
.
width
/
2
,
50
);
context
.
fillText
(
0
+
'
:
'
+
min
+
'
:
'
+
sec
,
canvas
.
width
/
2
,
50
);
for
(
let
avatarId
in
avatars
)
{
Render
.
renderProjectile
(
context
,
avatar
,
avatars
,
avatarId
,
imageProjectile
);
for
(
let
avatarId
in
avatars
)
{
Render
.
renderProjectile
(
context
,
...
...
@@ -158,43 +182,52 @@ function render() {
avatarId
,
imageProjectile
);
for
(
let
avatarId
in
avatars
)
{
Render
.
renderProjectile
(
context
,
avatar
,
avatars
,
avatarId
,
imageProjectile
);
}
socket
.
on
(
'
bonusArray
'
,
data
=>
{
newBonus
=
data
;
});
newBonus
.
forEach
(
bonus
=>
{
let
img
=
new
Image
();
img
.
src
=
bonusImages
[
bonus
.
choix
];
img
.
width
=
75
;
img
.
height
=
75
;
draw
(
canvas
,
context
,
img
,
bonus
.
x
,
bonus
.
y
);
});
socket
.
on
(
'
enemis
'
,
data
=>
{
newEnemis
=
data
;
});
newEnemis
.
forEach
(
enemi
=>
{
Render
.
renderEnnemi
(
canvas
,
context
,
imageEnemi
,
imageEnemi2
,
enemi
.
x
,
enemi
.
y
,
enemi
);
});
socket
.
on
(
'
bonusArray
'
,
data
=>
{
newBonus
=
data
;
});
newBonus
.
forEach
(
bonus
=>
{
Render
.
renderBonus
(
canvas
,
context
,
bonusImages
[
bonus
.
choix
],
bonus
.
x
,
bonus
.
y
);
});
}
socket
.
on
(
'
bonusArray
'
,
data
=>
{
newBonus
=
data
;
});
newBonus
.
forEach
(
bonus
=>
{
let
img
=
new
Image
();
img
.
src
=
bonusImages
[
bonus
.
choix
];
img
.
width
=
75
;
img
.
height
=
75
;
draw
(
canvas
,
context
,
img
,
bonus
.
x
,
bonus
.
y
);
});
socket
.
on
(
'
enemis
'
,
data
=>
{
newEnemis
=
data
;
});
newEnemis
.
forEach
(
enemi
=>
{
Render
.
renderEnnemi
(
canvas
,
context
,
imageEnemi
,
imageEnemi2
,
enemi
.
x
,
enemi
.
y
,
enemi
);
});
socket
.
on
(
'
bonusArray
'
,
data
=>
{
newBonus
=
data
;
});
newBonus
.
forEach
(
bonus
=>
{
Render
.
renderBonus
(
canvas
,
context
,
bonusImages
[
bonus
.
choix
],
bonus
.
x
,
bonus
.
y
);
});
}
requestAnimationFrame
(
render
);
...
...
This diff is collapsed.
Click to expand it.
client/src/scoreboard.json
0 → 100644
+
17
−
0
View file @
ecba4f84
{
"results"
:
[
{
"nom"
:
"Joueur 1"
,
"score"
:
100
},
{
"nom"
:
"Joueur 2"
,
"score"
:
200
},
{
"nom"
:
"Joueur 3"
,
"score"
:
150
}
]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/index.js
+
40
−
25
View file @
ecba4f84
...
...
@@ -15,6 +15,7 @@ let canvasSize = new Coordinate(1920, 1261);
let
canLostLifeAvatar
=
true
;
let
canLostLifeEnemi
=
true
;
let
gameStarted
=
false
;
let
t
=
new
timer
();
...
...
@@ -32,8 +33,12 @@ httpServer.listen(port, () => {
});
setInterval
(
function
()
{
t
.
addTime
();
io
.
emit
(
'
timer
'
,
t
.
getMin
(),
t
.
getSec
());
if
(
gameStarted
)
{
t
.
addTime
();
io
.
emit
(
'
timer
'
,
t
.
getMin
(),
t
.
getSec
());
}
else
{
t
=
new
timer
();
}
},
1000
);
const
avatars
=
[];
...
...
@@ -63,6 +68,14 @@ io.on('connection', socket => {
console
.
log
(
`Déconnexion du client
${
socket
.
id
}
`
);
});
socket
.
on
(
'
start
'
,
s
=>
{
if
(
s
==
true
&&
cpt
!=
0
)
{
gameStarted
=
s
;
}
else
if
(
cpt
==
0
)
{
gameStarted
=
false
;
}
});
socket
.
on
(
'
clickEvent
'
,
clickEvent
=>
{
const
playerAvatar
=
avatars
.
find
(
avatar
=>
avatar
.
nom
===
clickEvent
.
id
);
if
(
playerAvatar
)
{
...
...
@@ -96,43 +109,45 @@ io.on('connection', socket => {
});
let
spawnIntervalLV1
=
setInterval
(()
=>
{
if
(
t
.
getSec
()
>=
10
)
{
LVL2start
=
true
;
}
if
(
gameStarted
)
{
if
(
t
.
getMin
()
>=
1
)
{
LVL2start
=
true
;
}
let
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
do
{
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
}
while
(
randomY
>
canvasSize
.
height
-
57
);
const
newEnemy
=
new
enemi
(
canvasSize
.
width
,
randomY
,
0
,
1
);
enemis
.
push
(
newEnemy
);
let
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
do
{
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
}
while
(
randomY
>
canvasSize
.
height
-
57
);
const
newEnemy
=
new
enemi
(
canvasSize
.
width
,
randomY
,
0
,
1
);
enemis
.
push
(
newEnemy
);
}
},
1000
);
let
spawnIntervalLV2
=
setInterval
(()
=>
{
if
(
LVL2start
)
{
if
(
LVL2start
&&
gameStarted
)
{
let
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
do
{
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
}
while
(
randomY
>
canvasSize
.
height
-
100
);
const
newEnemy
=
new
enemi
(
canvasSize
.
width
-
100
,
randomY
,
1
,
2
);
newEnemy
.
setVx
(
10
);
newEnemy
.
setVy
(
4
);
enemis
.
push
(
newEnemy
);
}
},
800
);
let
spawnBonusInterval
=
setInterval
(()
=>
{
let
randomX
;
let
randomY
;
const
choix
=
Math
.
floor
(
Math
.
random
()
*
bonusNoms
.
length
);
do
{
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
}
while
(
randomY
>
canvasSize
.
height
-
75
);
do
{
randomX
=
Math
.
random
()
*
(
canvasSize
.
width
-
0
)
+
0
;
}
while
(
randomX
>
canvasSize
.
width
-
75
);
const
bonus
=
new
Bonus
(
choix
,
1
,
randomX
,
randomY
,
t
.
getTotalTime
());
bonusArray
.
push
(
bonus
);
if
(
gameStarted
)
{
let
randomX
;
let
randomY
;
const
choix
=
Math
.
floor
(
Math
.
random
()
*
bonusNoms
.
length
);
do
{
randomY
=
Math
.
random
()
*
(
canvasSize
.
height
-
0
)
+
0
;
}
while
(
randomY
>
canvasSize
.
height
-
75
);
do
{
randomX
=
Math
.
random
()
*
(
canvasSize
.
width
-
0
)
+
0
;
}
while
(
randomX
>
canvasSize
.
width
-
75
);
const
bonus
=
new
Bonus
(
choix
,
1
,
randomX
,
randomY
,
t
.
getTotalTime
());
bonusArray
.
push
(
bonus
);
}
},
15000
);
setInterval
(()
=>
{
...
...
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