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
41450b46
Commit
41450b46
authored
Aug 27, 2020
by
Jacky Chen
Browse files
Options
Downloads
Patches
Plain Diff
updated game, gun
parent
592939f4
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/gun.js
+16
-22
16 additions, 22 deletions
homepage_html/classes/gun.js
homepage_html/game.js
+115
-8
115 additions, 8 deletions
homepage_html/game.js
with
131 additions
and
30 deletions
homepage_html/classes/gun.js
+
16
−
22
View file @
41450b46
...
...
@@ -9,6 +9,7 @@ let g;
let
gunAnim
=
{};
class
gun
{
constructor
(
x
,
y
,
weapon
,
f_ammo
,
t_ammo
,
dmg
){
this
.
x
=
x
;
...
...
@@ -22,6 +23,8 @@ class gun{
create_gun
(
app
){
app
.
loader
.
add
(
"
default
"
,
"
../art/Player/Gun/pistol_sheet.png
"
);
app
.
loader
.
add
(
"
awpGun
"
,
"
../art/Player/Gun/Awp.png
"
);
app
.
loader
.
add
(
"
smgGun
"
,
"
../art/Player/Gun/smg.png
"
);
g
=
this
;
c_amt
=
this
.
f_ammo
;
...
...
@@ -35,7 +38,7 @@ class gun{
}
start
(){
if
(
!
wep
.
playing
){
if
(
!
wep
.
playing
&&
g
.
weapon
===
"
Pistol
"
){
wep
.
textures
=
gunAnim
.
fire
;
wep
.
play
();
}
...
...
@@ -59,9 +62,6 @@ class gun{
}
//Make boolean variable to detect whether to shoot or reload, if ammo enough, bool=true,
//pass createBullet function
//if false, boolean=false, wait 3 seconds, boolean=true, pass createBullet func.
fireBullet
(
e
){
let
create_bullet
=
g
.
createBullet
();
create_bullet
.
direction
=
bullet_angle
;
...
...
@@ -69,23 +69,6 @@ class gun{
bullets
.
push
(
create_bullet
);
c_amt
--
;
if
(
c_amt
===
0
&&
g
.
weapon
===
"
Pistol
"
){
c_amt
=
g
.
f_ammo
;
console
.
log
(
c_amt
);
}
else
if
(
c_amt
===
0
){
g
.
t_ammo
-=
g
.
f_ammo
;
console
.
log
(
g
.
t_ammo
);
c_amt
=
g
.
f_ammo
;
console
.
log
(
c_amt
);
console
.
log
(
"
Reloaded
"
);
}
else
if
(
g
.
t_ammo
===
0
){
console
.
log
(
"
Omae wa Shindeiru!
"
);
//Placeholder for when total ammo is gone
}
}
bullet_loop
(
delta
){
...
...
@@ -167,6 +150,8 @@ class gun{
createSheet
(){
let
gun_sheet
=
new
PIXI
.
BaseTexture
.
from
(
app
.
loader
.
resources
[
"
default
"
].
url
);
let
awp_sheet
=
new
PIXI
.
BaseTexture
.
from
(
app
.
loader
.
resources
[
"
awpGun
"
].
url
);
let
smg_sheet
=
new
PIXI
.
BaseTexture
.
from
(
app
.
loader
.
resources
[
"
smgGun
"
].
url
);
let
width
=
64
;
let
height
=
64
;
...
...
@@ -178,9 +163,18 @@ class gun{
];
gunAnim
[
"
idle
"
]
=
[
new
PIXI
.
Texture
(
gun_sheet
,
new
PIXI
.
Rectangle
(
3
*
width
,
0
,
width
,
height
)),
new
PIXI
.
Texture
(
gun_sheet
,
new
PIXI
.
Rectangle
(
3
*
width
,
0
,
width
,
height
))
];
gunAnim
[
"
awp
"
]
=
[
new
PIXI
.
Texture
(
awp_sheet
,
new
PIXI
.
Rectangle
(
0
*
96
,
0
,
96
,
64
))
];
gunAnim
[
"
smg
"
]
=
[
new
PIXI
.
Texture
(
smg_sheet
,
new
PIXI
.
Rectangle
(
0
*
width
,
0
,
width
,
height
))
]
}
}
...
...
This diff is collapsed.
Click to expand it.
homepage_html/game.js
+
115
−
8
View file @
41450b46
...
...
@@ -46,7 +46,7 @@ let p1 = new player("Bob", app.view.width/2, app.view.height/2, 5, "Pistol");
p1
.
create_p1
(
app
);
console
.
log
(
p1
);
let
g1
=
new
gun
(
p1
.
x
-
40
,
p1
.
y
-
5
,
p1
.
weapon
,
10
,
50
,
10
);
let
g1
=
new
gun
(
p1
.
x
-
40
,
p1
.
y
-
5
,
p1
.
weapon
,
10
,
Infinity
,
0.79
);
g1
.
create_gun
(
app
,
animatedObjects
);
console
.
log
(
g1
);
...
...
@@ -73,6 +73,7 @@ function randomlySpawnMobs(numMobs) {
enemies
.
push
(
mob
);
mob
.
addToObjectsList
(
animatedObjects
);
}
enemies
[
0
].
lootbox
=
true
;
}
//Making Enemy Bullets
function
make_bullet
(){
...
...
@@ -148,7 +149,7 @@ function mobTurn(){
let
bounds
=
map
.
currentRoom
.
getColliders
(
app
);
let
enemies
=
[];
randomlySpawnMobs
(
5
);
randomlySpawnMobs
(
3
);
loadSprites
();
let
playerCollided
;
...
...
@@ -160,6 +161,7 @@ let rightPressed = false;
let
leftPressed
=
false
;
let
upPressed
=
false
;
let
downPressed
=
false
;
let
fPressed
=
false
;
document
.
addEventListener
(
"
keydown
"
,
keyDownHandler
,
false
);
document
.
addEventListener
(
"
keyup
"
,
keyUpHandler
,
false
);
app
.
view
.
setAttribute
(
"
onmousemove
"
,
"
angle(event)
"
);
...
...
@@ -179,6 +181,9 @@ function keyDownHandler(e) {
case
"
s
"
:
downPressed
=
true
;
break
;
case
"
f
"
:
fPressed
=
true
;
break
;
}
}
...
...
@@ -196,6 +201,9 @@ function keyUpHandler(e) {
case
"
s
"
:
downPressed
=
false
;
break
;
case
"
f
"
:
fPressed
=
false
;
break
;
}
}
...
...
@@ -267,7 +275,7 @@ function map_loop(delta) {
emptyList
.
push
(
emptyTile
);
let
c
=
p1
.
hp
*
48
;
emptyTile
.
x
=
c
;
emptyTile
.
y
=
4
0
emptyTile
.
y
=
1
0
app
.
stage
.
addChild
(
emptyTile
);
}
p1
.
hp
-=
1
;
...
...
@@ -329,10 +337,14 @@ function bulletCollider(delta){
bullets
[
x
].
y
+
10
>
enemies
[
j
].
y
-
enemies
[
j
].
height
/
2
&&
bullets
[
x
].
y
-
10
<
enemies
[
j
].
y
-
enemies
[
j
].
height
/
2
+
enemies
[
j
].
height
)
{
bullets
[
x
].
gone
=
true
;
enemies
[
j
].
hp
-=
1
;
enemies
[
j
].
hp
-=
g1
.
dmg
;
if
(
enemies
[
j
].
hp
<=
0
)
{
if
(
enemies
[
j
].
lootbox
){
createBox
();
}
app
.
stage
.
removeChild
(
enemies
[
j
].
sprite
)
enemies
.
splice
(
j
,
1
)
enemies
.
splice
(
j
,
1
);
}
}
}
...
...
@@ -377,7 +389,7 @@ function enemyBulletCollider(delta){
emptyList
.
push
(
emptyTile
);
let
c
=
p1
.
hp
*
48
;
emptyTile
.
x
=
c
;
emptyTile
.
y
=
4
0
emptyTile
.
y
=
1
0
app
.
stage
.
addChild
(
emptyTile
);
}
p1
.
hp
-=
1
;
...
...
@@ -414,12 +426,106 @@ function healthBar(){
heartList
.
push
(
heartTile
);
let
c
=
i
*
48
;
heartTile
.
x
=
c
;
heartTile
.
y
=
4
0
;
heartTile
.
y
=
1
0
;
app
.
stage
.
addChild
(
heartTile
);
}
}
//Reload Gun
function
reload
(){
if
(
c_amt
===
0
&&
g1
.
weapon
===
"
Pistol
"
){
c_amt
=
g1
.
f_ammo
;
app
.
stage
.
interactive
=
false
;
let
pistolReload
=
setTimeout
(
reload_timer
,
1000
);
}
else
if
(
c_amt
===
0
&&
g1
.
weapon
===
"
Awp
"
){
app
.
stage
.
interactive
=
false
;
let
reloadTime
=
setTimeout
(
reload_timer
,
4500
);
g1
.
t_ammo
-=
g1
.
f_ammo
;
console
.
log
(
"
Total Ammo Left
"
,
g1
.
t_ammo
);
c_amt
=
g1
.
f_ammo
;
console
.
log
(
"
Current Ammo
"
,
c_amt
);
}
else
if
(
g1
.
t_ammo
<=
0
){
g1
.
weapon
=
"
Pistol
"
;
g1
.
t_ammo
=
Infinity
;
g1
.
f_ammo
=
10
;
wep
.
textures
=
gunAnim
.
idle
;
wep
.
play
();
}
}
//Reload Timer
function
reload_timer
(){
app
.
stage
.
interactive
=
true
;
}
let
gunList
=
[
"
Awp
"
,
"
smg
"
];
//Drop Gun
let
box
;
function
createBox
(){
box
=
new
PIXI
.
Sprite
.
from
(
"
../art/Player/Gun/box2.png
"
);
box
.
anchor
.
set
(
0.5
);
box
.
x
=
enemies
[
0
].
x
;
box
.
y
=
enemies
[
0
].
y
;
box
.
height
=
64
;
box
.
width
=
64
;
app
.
stage
.
addChild
(
box
);
}
console
.
log
(
gunList
);
//Pickup Gun
function
pickup
(){
if
(
box
===
undefined
){
return
;
}
if
(
nextX
+
23
>
box
.
x
-
box
.
width
/
2
&&
nextX
-
23
<
box
.
x
-
box
.
width
/
2
+
box
.
width
&&
nextY
+
23
>
box
.
y
-
box
.
height
/
2
&&
nextY
-
23
<
box
.
y
-
box
.
height
/
2
+
box
.
height
){
if
(
fPressed
){
randomGun
();
if
(
g1
.
weapon
===
"
Awp
"
){
g1
.
weapon
==
"
Awp
"
;
g1
.
t_ammo
=
20
;
g1
.
f_ammo
=
5
;
g1
.
dmg
=
2
;
wep
.
textures
=
gunAnim
.
awp
;
wep
.
play
();
app
.
stage
.
removeChild
(
box
);
}
else
if
(
g1
.
weapon
===
"
smg
"
){
g1
.
weapon
==
"
smg
"
;
g1
.
t_ammo
=
150
;
g1
.
f_ammo
=
25
;
g1
.
dmg
=
0.94
;
wep
.
textures
=
gunAnim
.
smg
;
wep
.
play
();
app
.
stage
.
removeChild
(
box
);
}
}
}
}
function
randomGun
(){
let
randLoot
=
Math
.
floor
(
Math
.
random
()
*
gunList
.
length
);
let
gunNum
=
randLoot
;
g1
.
weapon
=
gunList
[
gunNum
];
}
function
delayTicker
(){
app
.
ticker
.
add
(
update_bullet
);
}
...
...
@@ -428,6 +534,7 @@ app.ticker.add(map_loop);
app
.
ticker
.
add
(
bulletCollider
);
app
.
ticker
.
add
(
mobTurn
);
app
.
ticker
.
add
(
enemyBulletCollider
);
app
.
ticker
.
add
(
reload
);
app
.
ticker
.
add
(
pickup
);
//Enemy bullet don't start shooting until 3 seconds later
let
timeout
=
setTimeout
(
delayTicker
,
3000
);
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