Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS375_Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ah3472
CS375_Project
Commits
e095af22
Commit
e095af22
authored
Aug 30, 2020
by
ah3472
Browse files
Options
Downloads
Patches
Plain Diff
more database stuff
parent
1cee6787
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
homepage_html/game.js
+36
-8
36 additions, 8 deletions
homepage_html/game.js
homepage_html/login.js
+1
-1
1 addition, 1 deletion
homepage_html/login.js
homepage_html/register.js
+1
-1
1 addition, 1 deletion
homepage_html/register.js
server.js
+57
-8
57 additions, 8 deletions
server.js
with
95 additions
and
18 deletions
homepage_html/game.js
+
36
−
8
View file @
e095af22
...
...
@@ -7,7 +7,6 @@ restartButton.addEventListener("click", function() {
let
overlay
=
document
.
getElementById
(
"
overlay
"
);
overlay
.
style
.
display
=
"
none
"
;
app
.
stage
.
removeChildren
();
app
.
ticker
.
stop
();
lvl
=
1
;
score
=
0
;
startUpGame
();
...
...
@@ -22,13 +21,35 @@ logOutButton.addEventListener("click", function() {
document
.
addEventListener
(
"
keydown
"
,
keyDownHandler
,
false
);
document
.
addEventListener
(
"
keyup
"
,
keyUpHandler
,
false
);
function
checkCurrentUser
()
{
fetch
(
'
/getCurrentUser
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
}).
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
console
.
log
(
data
)
if
(
data
===
null
)
{
window
.
location
.
href
=
"
/login.html
"
;
}
else
{
userId
=
data
.
userId
;
email
=
data
.
email
;
}
})
.
catch
((
error
)
=>
{
console
.
log
(
'
Error:
'
,
error
);
})
}
function
updateDatabase
()
{
fetch
(
'
/updateDatabase
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
body
:
JSON
.
stringify
({
userId
:
"
9rIvzwdIi1fnPg1dUozbfsnhYxo1
"
,
email
:
"
alexh4949@gmail.com
"
,
score
:
score
}),
body
:
JSON
.
stringify
({
userId
:
userId
,
email
:
email
,
score
:
score
}),
}).
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
console
.
log
(
data
);
...
...
@@ -56,6 +77,9 @@ app.loader.add("pistolR", "../art/Player/Gun/reload_sprite.png");
app
.
view
.
setAttribute
(
"
onmousemove
"
,
"
angle(event)
"
);
let
userId
;
let
email
;
let
map
;
let
roomDoors
;
let
animatedObjects
=
[];
...
...
@@ -490,6 +514,7 @@ function map_loop(delta) {
movePlayer
()
playerCollided
=
false
updateStatus
();
}
...
...
@@ -607,16 +632,16 @@ function enemyBulletCollider(delta){
}
}
updateStatus
();
}
//Dead
function
updateStatus
(){
if
(
p1
.
hp
<=
0
)
{
app
.
stage
.
removeChild
(
wep
);
for
(
let
x
=
0
;
x
<
map
.
currentRoom
.
enemies
.
length
;
x
++
){
app
.
stage
.
removeChild
(
map
.
currentRoom
.
enemies
[
x
].
sprite
);
map
.
currentRoom
.
enemies
.
splice
(
x
,
1
);
app
.
stage
.
interactive
=
false
;
app
.
stage
.
removeChild
(
wep
);
while
(
map
.
currentRoom
.
enemies
.
length
>
0
)
{
app
.
stage
.
removeChild
(
map
.
currentRoom
.
enemies
[
0
].
sprite
);
map
.
currentRoom
.
enemies
.
splice
(
0
,
1
);
}
if
(
anim_player
.
playing
){
...
...
@@ -625,6 +650,7 @@ function updateStatus(){
anim_player
.
textures
=
playerAnim
.
death
;
anim_player
.
play
();
}
setTimeout
(
function
()
{
let
scoreLabel
=
document
.
getElementById
(
"
score
"
);
scoreLabel
.
textContent
=
"
Score:
"
+
score
...
...
@@ -633,6 +659,7 @@ function updateStatus(){
let
overlay
=
document
.
getElementById
(
"
overlay
"
);
overlay
.
style
.
display
=
"
block
"
;
updateDatabase
()
app
.
ticker
.
stop
();
},
2000
)
}
}
...
...
@@ -754,6 +781,7 @@ function delayTicker(){
}
checkCurrentUser
()
startUpGame
()
app
.
ticker
.
add
(
bulletCollider
);
...
...
This diff is collapsed.
Click to expand it.
homepage_html/login.js
+
1
−
1
View file @
e095af22
...
...
@@ -22,7 +22,7 @@ function assign_info(){
}).
then
(
function
(
response
){
return
response
.
json
();
}).
then
(
function
(
data
){
if
(
data
!==
null
){
if
(
data
.
userId
!==
null
&&
data
.
email
!==
null
){
userId
=
data
.
userId
userEmail
=
data
.
email
window
.
location
.
href
=
"
/game.html
"
;
...
...
This diff is collapsed.
Click to expand it.
homepage_html/register.js
+
1
−
1
View file @
e095af22
...
...
@@ -19,7 +19,7 @@ function sendEmailAndPassword() {
}).
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
console
.
log
(
data
);
if
(
data
===
"
Success
"
)
{
if
(
data
.
userId
!==
null
&&
data
.
email
!==
null
)
{
window
.
location
.
href
=
"
/game.html
"
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
server.js
+
57
−
8
View file @
e095af22
...
...
@@ -20,7 +20,14 @@ app.post("/createUser", function(req, res) {
let
email
=
req
.
body
[
"
email
"
];
let
password
=
req
.
body
[
"
password
"
];
firebase
.
auth
().
createUserWithEmailAndPassword
(
email
,
password
).
then
(
function
()
{
res
.
status
(
200
).
json
(
"
Success
"
)
firebase
.
auth
().
onAuthStateChanged
(
function
(
user
){
if
(
user
){
res
.
status
(
200
).
json
({
userId
:
user
.
uid
,
email
:
user
.
email
});
}
else
{
console
.
log
(
"
User is signed out
"
);
}
});
}).
catch
(
function
(
error
)
{
console
.
log
(
error
.
code
);
console
.
log
(
error
.
message
);
...
...
@@ -32,6 +39,7 @@ app.post("/createUser", function(req, res) {
app
.
post
(
"
/login
"
,
function
(
req
,
res
){
let
email
=
req
.
body
.
email
;
let
pass
=
req
.
body
.
pass
;
firebase
.
auth
().
signInWithEmailAndPassword
(
email
,
pass
).
then
(
function
(){
firebase
.
auth
().
onAuthStateChanged
(
function
(
user
){
if
(
user
){
...
...
@@ -47,20 +55,61 @@ app.post("/login", function(req, res){
console
.
log
(
error
.
message
);
res
.
json
(
error
.
code
);
});
/*firebase.auth().setPersistence(firebase.auth.Auth.Persistence.NONE).then(function() {
return firebase.auth().signInWithEmailAndPassword(email, pass).then(function(){
firebase.auth().onAuthStateChanged(function(user){
if(user){
res.status(200).json({userId: user.uid, email: user.email});
}
else{
console.log("User is signed out");
}
});
}).catch(function(error){
console.log(error.code);
console.log(error.message);
res.json(error.code);
});
}).catch(function(error) {
console.log(error.code);
console.log(error.message);
});*/
});
app
.
post
(
"
/updateDatabase
"
,
function
(
req
,
res
)
{
let
userId
=
req
.
body
.
userId
;
let
email
=
req
.
body
.
email
;
let
score
=
req
.
body
.
score
;
firebase
.
database
().
ref
(
'
users/
'
+
userId
).
set
({
email
:
email
,
score
:
score
}).
catch
(
function
(
error
)
{
firebase
.
database
().
ref
(
'
users/
'
+
userId
).
once
(
'
value
'
).
then
(
function
(
snapshot
)
{
if
(
snapshot
.
val
()
===
null
)
{
firebase
.
database
().
ref
(
'
users/
'
+
userId
).
set
({
email
:
email
,
score
:
score
}).
catch
(
function
(
error
)
{
console
.
log
(
error
);
res
.
json
(
error
);
});
}
else
{
if
(
score
>
snapshot
.
val
().
score
)
{
firebase
.
database
().
ref
(
'
users/
'
+
userId
+
'
/score
'
).
set
(
score
).
catch
(
function
(
error
)
{
console
.
log
(
error
);
res
.
json
(
error
);
});
}
}
})
});
app
.
post
(
"
/getCurrentUser
"
,
function
(
req
,
res
)
{
var
user
=
firebase
.
auth
().
currentUser
;
if
(
user
!==
null
)
{
res
.
status
(
200
).
json
({
userId
:
user
.
uid
,
email
:
user
.
email
});
}
else
{
res
.
status
(
200
).
json
(
null
);
}
})
app
.
listen
(
port
,
hostname
,
()
=>
{
console
.
log
(
"
Link Start!
"
);
...
...
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
sign in
to comment