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
a4d93e06
Commit
a4d93e06
authored
4 years ago
by
ah3472
Browse files
Options
Downloads
Patches
Plain Diff
added levels and difficulty scaling
parent
9fba1fef
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
homepage_html/classes/map.js
+9
-7
9 additions, 7 deletions
homepage_html/classes/map.js
homepage_html/game.js
+100
-9
100 additions, 9 deletions
homepage_html/game.js
with
109 additions
and
16 deletions
homepage_html/classes/map.js
+
9
−
7
View file @
a4d93e06
...
...
@@ -2,13 +2,12 @@ class Map {
constructor
(
numRooms
,
currentRoom
=
null
)
{
this
.
numOfRooms
=
numRooms
;
this
.
currentRoom
=
currentRoom
;
this
.
listOf
Rooms
=
[]
;
this
.
notEmpty
Rooms
=
0
;
}
generateStartRoom
()
{
let
numOfEnemies
=
Math
.
floor
(
Math
.
random
()
*
(
10
-
4
))
+
4
let
start
=
new
Room
(
lvl1TileMaps
[
1
],
1
)
this
.
currentRoom
=
start
let
start
=
new
Room
(
lvl1TileMaps
[
1
],
0
)
this
.
currentRoom
=
start
;
}
copyTileMap
(
tileMap
)
{
...
...
@@ -22,7 +21,7 @@ class Map {
return
newTileMap
}
generateRandomMap
()
{
generateRandomMap
(
minEnemies
,
maxEnemies
)
{
let
room
=
this
.
currentRoom
let
roomsLeft
=
this
.
numOfRooms
while
(
roomsLeft
>
0
)
{
...
...
@@ -31,13 +30,14 @@ class Map {
return
arr
.
slice
()
})
//var tileMap = this.copyTileMap(lvl1TileMaps[1])
let
numOfEnemies
=
Math
.
floor
(
Math
.
random
()
*
(
10
-
4
))
+
4
let
numOfEnemies
=
Math
.
floor
(
Math
.
random
()
*
(
maxEnemies
-
minEnemies
))
+
minEnemies
;
let
newRoom
=
new
Room
(
tileMap
,
numOfEnemies
)
switch
(
num
)
{
case
0
:
if
(
room
.
top
==
null
)
{
this
.
addRoomTop
(
room
,
newRoom
);
roomsLeft
--
;
this
.
notEmptyRooms
++
;
}
else
{
room
=
room
.
top
;
...
...
@@ -47,6 +47,7 @@ class Map {
if
(
room
.
bottom
==
null
)
{
this
.
addRoomBottom
(
room
,
newRoom
);
roomsLeft
--
;
this
.
notEmptyRooms
++
;
}
else
{
room
=
room
.
bottom
;
...
...
@@ -56,6 +57,7 @@ class Map {
if
(
room
.
left
==
null
)
{
this
.
addRoomLeft
(
room
,
newRoom
);
roomsLeft
--
;
this
.
notEmptyRooms
++
;
}
else
{
room
=
room
.
left
;
...
...
@@ -65,12 +67,12 @@ class Map {
if
(
room
.
right
==
null
)
{
this
.
addRoomRight
(
room
,
newRoom
);
roomsLeft
--
;
this
.
notEmptyRooms
++
;
}
else
{
room
=
room
.
right
;
}
}
this
.
listOfRooms
.
push
(
newRoom
)
}
}
...
...
This diff is collapsed.
Click to expand it.
homepage_html/game.js
+
100
−
9
View file @
a4d93e06
...
...
@@ -8,9 +8,10 @@ restartButton.addEventListener("click", function() {
overlay
.
style
.
display
=
"
none
"
;
app
.
stage
.
removeChildren
();
app
.
ticker
.
stop
();
score
=
0
lvl
=
1
;
score
=
0
;
startUpGame
();
app
.
ticker
.
start
()
app
.
ticker
.
start
()
;
})
let
logOutButton
=
document
.
getElementById
(
"
logout
"
)
...
...
@@ -54,9 +55,17 @@ let mobList = [];
let
bounds
;
let
playerCollided
;
let
lvl
=
1
;
let
lvlText
;
let
score
=
0
;
let
scoreTxt
;
let
difficulty
=
{
numOfRooms
:
3
,
minEnemies
:
2
,
maxEnemies
:
4
,
}
let
nextX
;
let
nextY
;
...
...
@@ -67,16 +76,15 @@ let downPressed = false;
let
fPressed
=
false
;
function
startUpGame
()
{
map
=
new
Map
(
5
);
map
=
new
Map
(
difficulty
.
numOfRooms
);
map
.
generateStartRoom
();
map
.
generateRandomMap
();
console
.
log
(
map
.
listOfRooms
)
map
.
generateRandomMap
(
difficulty
.
minEnemies
,
difficulty
.
maxEnemies
);
map
.
currentRoom
.
drawRoom
(
app
)
map
.
currentRoom
.
firstTimeInRoom
=
false
;
roomDoors
=
map
.
currentRoom
.
getRoomDoorColliders
()
p1
=
new
player
(
"
Bob
"
,
app
.
view
.
width
/
2
,
app
.
view
.
height
/
2
,
5
,
"
Pistol
"
);
p1
=
new
player
(
"
Bob
"
,
app
.
view
.
width
/
2
,
app
.
view
.
height
/
2
,
10
,
"
Pistol
"
);
nextX
=
p1
.
x
;
nextY
=
p1
.
y
;
p1
.
create_p1
(
app
);
...
...
@@ -86,10 +94,10 @@ function startUpGame() {
bounds
=
map
.
currentRoom
.
getColliders
(
app
);
randomlySpawnMobs
(
map
.
currentRoom
.
numOfEnemies
);
loadSprites
();
healthBar
();
createLevelLabel
();
createScoreBoard
();
app
.
ticker
.
add
(
map_loop
);
...
...
@@ -100,11 +108,18 @@ function createScoreBoard() {
scoreTxt
=
new
PIXI
.
Text
(
something
,{
fontFamily
:
"
Arial
"
,
fontSize
:
25
,
fill
:
"
#FFFFFF
"
});
scoreTxt
.
anchor
.
set
(
0.5
);
scoreTxt
.
x
=
app
.
view
.
width
/
2
;
scoreTxt
.
y
=
30
;
//app.view.height / 4;
scoreTxt
.
anchor
.
set
=
0.5
;
scoreTxt
.
y
=
50
;
app
.
stage
.
addChild
(
scoreTxt
);
}
function
createLevelLabel
()
{
lvlText
=
new
PIXI
.
Text
(
"
Level
"
+
lvl
,
{
fontFamily
:
"
Arial
"
,
fontSize
:
30
,
fill
:
"
#FFFFFF
"
});
lvlText
.
anchor
.
set
(
0.5
);
lvlText
.
x
=
app
.
view
.
width
/
2
;
lvlText
.
y
=
20
;
app
.
stage
.
addChild
(
lvlText
);
}
function
checkDoorCollision
()
{
if
(
nextX
-
23
<
roomDoors
.
minX
)
{
p1
.
x
=
app
.
view
.
width
/
2
+
64
*
9.5
...
...
@@ -138,6 +153,7 @@ function ChangeRooms(nextRoom) {
app
.
ticker
.
stop
()
map
.
currentRoom
=
nextRoom
map
.
currentRoom
.
drawRoom
(
app
)
createLevelLabel
()
createScoreBoard
()
bounds
=
map
.
currentRoom
.
getColliders
(
app
)
if
(
map
.
currentRoom
.
firstTimeInRoom
)
{
...
...
@@ -349,6 +365,73 @@ function calculateNextXY() {
}
}
function
scaleDifficulty
()
{
let
multipler
=
1
+
lvl
/
4
if
(
difficulty
.
maxEnemies
<
8
)
{
difficulty
.
maxEnemies
=
Math
.
floor
(
4
*
multipler
);
}
else
{
difficulty
.
maxEnemies
=
8
}
if
(
difficulty
.
minEnemies
<
8
)
{
difficulty
.
minEnemies
=
Math
.
floor
(
2
*
multipler
);
}
else
{
difficulty
.
minEnemies
=
5
;
}
if
(
difficulty
.
numOfRooms
<
9
)
{
difficulty
.
numOfRooms
=
Math
.
floor
(
3
*
multipler
);
}
else
{
difficulty
.
numOfRooms
=
9
;
}
}
function
createNextLvl
()
{
lvl
++
;
scaleDifficulty
();
app
.
stage
.
removeChildren
();
app
.
ticker
.
stop
();
map
=
new
Map
(
difficulty
.
numOfRooms
)
map
.
generateStartRoom
();
map
.
generateRandomMap
(
difficulty
.
minEnemies
,
difficulty
.
maxEnemies
);
p1
.
x
=
app
.
view
.
width
/
2
;
p1
.
y
=
app
.
view
.
height
/
2
;
g1
.
x
=
p1
.
x
-
40
g1
.
y
=
p1
.
y
-
5
map
.
currentRoom
.
drawRoom
(
app
)
map
.
currentRoom
.
firstTimeInRoom
=
false
;
roomDoors
=
map
.
currentRoom
.
getRoomDoorColliders
()
bounds
=
map
.
currentRoom
.
getColliders
(
app
);
healthBar
();
createLevelLabel
();
createScoreBoard
();
loadSprites
();
if
(
g1
.
weapon
===
"
Awp
"
){
wep
.
textures
=
gunAnim
.
awp
;
wep
.
play
();
}
else
if
(
g1
.
weapon
===
"
smg
"
){
wep
.
textures
=
gunAnim
.
smg
;
wep
.
play
();
}
else
{
wep
.
textures
=
gunAnim
.
idle
;
wep
.
play
();
}
app
.
ticker
.
start
();
}
function
map_loop
(
delta
)
{
calculateNextXY
()
...
...
@@ -383,6 +466,11 @@ function map_loop(delta) {
}
}
console
.
log
(
map
.
notEmptyRooms
)
if
(
map
.
notEmptyRooms
===
0
)
{
createNextLvl
()
}
checkDoorCollision
()
movePlayer
()
...
...
@@ -449,6 +537,9 @@ function bulletCollider(delta){
map
.
currentRoom
.
enemies
.
splice
(
j
,
1
);
score
+=
100
;
scoreTxt
.
text
=
"
Score:
"
+
score
;
if
(
map
.
currentRoom
.
numOfEnemies
===
0
)
{
map
.
notEmptyRooms
--
;
}
}
}
}
...
...
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