Skip to content
Snippets Groups Projects
Commit a861774f authored by ah3472's avatar ah3472
Browse files

Merge branch 'develop' of gitlab.cci.drexel.edu:ah3472/cs375_project into map_stuff

something
parents 83462c6c 626a745d
No related branches found
No related tags found
No related merge requests found
...@@ -13,13 +13,13 @@ class Enemy { ...@@ -13,13 +13,13 @@ class Enemy {
} }
addToObjectsList(objectList) { addToObjectsList(objectList) {
objectList.push(this) objectList.push(this);
} }
animate() { animate() {
this.sprite = new PIXI.AnimatedSprite(animations.basic); this.sprite = new PIXI.AnimatedSprite(animations.basic);
this.sprite.anchor.set(0.5); this.sprite.anchor.set(0.5);
this.sprite.animationSpeed = 0.15; this.sprite.animationSpeed = 0.50;
this.sprite.loop = true; this.sprite.loop = true;
this.sprite.x = this.x; this.sprite.x = this.x;
this.sprite.y = this.y; this.sprite.y = this.y;
...@@ -27,6 +27,7 @@ class Enemy { ...@@ -27,6 +27,7 @@ class Enemy {
this.sprite.height = 128; this.sprite.height = 128;
app.stage.addChild(this.sprite); app.stage.addChild(this.sprite);
this.sprite.play(); this.sprite.play();
} }
getColliders() { getColliders() {
...@@ -61,7 +62,12 @@ class Enemy { ...@@ -61,7 +62,12 @@ class Enemy {
new PIXI.Texture(sheet, new PIXI.Rectangle(11 * width, 0, width, height)), new PIXI.Texture(sheet, new PIXI.Rectangle(11 * width, 0, width, height)),
new PIXI.Texture(sheet, new PIXI.Rectangle(12 * width, 0, width, height)), new PIXI.Texture(sheet, new PIXI.Rectangle(12 * width, 0, width, height)),
new PIXI.Texture(sheet, new PIXI.Rectangle(13 * width, 0, width, height)), new PIXI.Texture(sheet, new PIXI.Rectangle(13 * width, 0, width, height)),
new PIXI.Texture(sheet, new PIXI.Rectangle(14 * width, 0, width, height)), new PIXI.Texture(sheet, new PIXI.Rectangle(14 * width, 0, width, height))
] ]
} }
} }
\ No newline at end of file
let e_bulletAnim = {};
class E_bullet {
constructor(x, y){
this.x = x;
this.y = y;
this.width = 64;
this.height = 64;
this.sprite = null;
this.speed = 10;
this.rotation = null;
}
addToObjectsList(objectList) {
objectList.push(this);
}
animate(){
this.sprite = new PIXI.AnimatedSprite(e_bulletAnim.enemy_shoot);
this.sprite.anchor.set(0.5);
this.sprite.animationSpeed = 1;
this.sprite.loop = true;
this.sprite.x = this.x;
this.sprite.y = this.y;
this.sprite.width = 48;
this.sprite.height = 48;
this.sprite.speed = this.speed;
app.stage.addChild(this.sprite);
this.sprite.play();
return this;
}
createSheet(){
let bullet_sheet = new PIXI.BaseTexture.from(app.loader.resources["enemy_bullet"].url);
let width = 64;
let height = 64;
e_bulletAnim["enemy_shoot"] = [
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(0 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(1 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(2 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(3 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(4 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(5 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(6 * width, 0, width, height)),
new PIXI.Texture(bullet_sheet, new PIXI.Rectangle(7 * width, 0, width, height))
];
}
}
\ No newline at end of file
...@@ -31,7 +31,7 @@ class gun{ ...@@ -31,7 +31,7 @@ class gun{
app.ticker.add(this.bullet_loop); app.ticker.add(this.bullet_loop);
window.addEventListener("click", this.start); app.stage.on("pointerdown", this.start);
} }
start(){ start(){
...@@ -115,7 +115,6 @@ class gun{ ...@@ -115,7 +115,6 @@ class gun{
for(let x = 0; x < bullets.length; x++){ for(let x = 0; x < bullets.length; x++){
bullets[x].x += bullets[x].direction.x * bulletSpeed; bullets[x].x += bullets[x].direction.x * bulletSpeed;
bullets[x].y += bullets[x].direction.y * bulletSpeed; bullets[x].y += bullets[x].direction.y * bulletSpeed;
//Bullet collision here?
//Delete bullet from list //Delete bullet from list
if(bullets[x].x < 0 || bullets[x].y < 0){ if(bullets[x].x < 0 || bullets[x].y < 0){
...@@ -138,8 +137,6 @@ class gun{ ...@@ -138,8 +137,6 @@ class gun{
} }
createBulletSheet(){ createBulletSheet(){
app.loader.reset();
app.loader.add("bullet2", "../art/Player/Gun/anim_bullet.png");
let bullet_sheet = new PIXI.BaseTexture.from(app.loader.resources["bullet2"].url); let bullet_sheet = new PIXI.BaseTexture.from(app.loader.resources["bullet2"].url);
let width = 64; let width = 64;
let height = 64; let height = 64;
... ...
......
...@@ -4,8 +4,10 @@ const app = new PIXI.Application({ ...@@ -4,8 +4,10 @@ const app = new PIXI.Application({
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight height: window.innerHeight
}); });
app.loader.add("basic", "art/Bat/Basic/bat_spritesheet.png")
app.loader.add("basic", "art/Bat/Basic/bat_spritesheet.png")
app.loader.add("enemy_bullet", "../art/Bat/Bullet/bullet.png");
app.loader.add("bullet2", "../art/Player/Gun/anim_bullet.png");
let map = new Map(2); let map = new Map(2);
map.generateMap(); map.generateMap();
...@@ -43,17 +45,27 @@ function ChangeRooms(nextRoom) { ...@@ -43,17 +45,27 @@ function ChangeRooms(nextRoom) {
} }
let animatedObjects = []; let animatedObjects = [];
let bulletObjects = [];
function loadSprites() { function loadSprites() {
app.loader.load(function() { app.loader.load(function() {
p1.createSheet() p1.createSheet();
p1.animate() p1.animate();
g1.createSheet() g1.createSheet();
g1.animate() g1.animate();
for (i in enemies) { for (i in enemies) {
enemies[i].createSheet() enemies[i].createSheet()
enemies[i].animate() enemies[i].animate()
} }
})
}
function loadBullet(){
app.loader.load(function(){
for(i in bulletObjects){
bulletObjects[i].createSheet();
bulletObjects[i].animate();
}
}) })
} }
...@@ -61,11 +73,15 @@ let p1 = new player("Bob", app.view.width/2, app.view.height/2, 5, "Pistol"); ...@@ -61,11 +73,15 @@ let p1 = new player("Bob", app.view.width/2, app.view.height/2, 5, "Pistol");
p1.create_p1(app); p1.create_p1(app);
console.log(p1); 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, 50, 10);
g1.create_gun(app, animatedObjects); g1.create_gun(app, animatedObjects);
console.log(g1); console.log(g1);
let mob;
let bullet;
let bulletList = []
let mobList = []
function randomlySpawnMobs(numMobs) { function randomlySpawnMobs(numMobs) {
let minX = (app.view.width - 20 * 64) / 2 + 64 let minX = (app.view.width - 20 * 64) / 2 + 64
let minY = (app.view.height - 12 * 64) / 2 + 64 let minY = (app.view.height - 12 * 64) / 2 + 64
...@@ -74,18 +90,88 @@ function randomlySpawnMobs(numMobs) { ...@@ -74,18 +90,88 @@ function randomlySpawnMobs(numMobs) {
for (let i = 0; i < numMobs; i++) { for (let i = 0; i < numMobs; i++) {
let x = Math.random() * (maxX - minX) + minX; let x = Math.random() * (maxX - minX) + minX;
let y = Math.random() * (maxY - minY) + minY; let y = Math.random() * (maxY - minY) + minY;
let mob = new Enemy(x, y, 3) mob = new Enemy(x, y, 3);
//mob.addToObjectsList(animatedObjects); mobList.push(mob);
enemies.push(mob); enemies.push(mob);
mob.addToObjectsList(animatedObjects);
}
}
//Making Enemy Bullets
function make_bullet(){
let eb;
for(let x = 0; x < enemies.length; x++){
if(enemies[x].sprite === null){
return;
}
bullet = new E_bullet(enemies[x].x, enemies[x].y);
eb = new PIXI.Point();
eb.x = p1.x - enemies[x].x;
eb.y = p1.y - enemies[x].y;
let length = Math.sqrt(eb.x * eb.x + eb.y * eb.y);
eb.x /= length;
eb.y /= length;
bullet.direction = eb;
bullet.rotation = enemies[x].sprite.rotation;
bullet.addToObjectsList(bulletObjects);
bulletList.push(bullet);
} }
loadBullet();
} }
//Update Enemy Bullets
function update_bullet(delta){
for(let x = 0; x < bulletList.length; x++){
if(bulletList[x].sprite === null){
return;
};
bulletList[x].sprite.rotation = bulletList[x].rotation;
bulletList[x].sprite.x += bulletList[x].direction.x * bulletList[x].speed;
bulletList[x].sprite.y += bulletList[x].direction.y * bulletList[x].speed;
if(bulletList[x].sprite.x < 0 || bulletList[x].sprite.y < 0){
bulletList[x].sprite.gone = true;
}
else if(bulletList[x].sprite.x > app.view.width || bulletList[x].sprite.y > app.view.height){
bulletList[x].sprite.gone = true;
}
}
for(let x = 0; x < bulletList.length; x++){
if(bulletList[x].sprite.gone){
app.stage.removeChild(bulletList[x].sprite);
bulletList.splice(x, 1);
bulletObjects.splice(x, 1);
}
}
if(bulletObjects.length === 0){
make_bullet();
}
}
//Enemy turning
function mobTurn(){
let mobX;
let mobY;
for(let x = 0; x < enemies.length; x++){
if(enemies[x].sprite === null){
return;
}
mobX = enemies[x].x - p1.x;
mobY = enemies[x].y - p1.y;
enemies[x].sprite.rotation = Math.atan2(mobY, mobX);
}
}
let bounds = map.currentRoom.getColliders(app); let bounds = map.currentRoom.getColliders(app);
let enemies = []
randomlySpawnMobs(5) let enemies = [];
console.log(enemies) randomlySpawnMobs(5);
loadSprites() loadSprites();
let playerCollided; let playerCollided;
...@@ -100,6 +186,7 @@ document.addEventListener("keydown", keyDownHandler, false); ...@@ -100,6 +186,7 @@ document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false); document.addEventListener("keyup", keyUpHandler, false);
app.view.setAttribute("onmousemove", "angle(event)"); app.view.setAttribute("onmousemove", "angle(event)");
function keyDownHandler(e) { function keyDownHandler(e) {
switch (e.key) { switch (e.key) {
case "d": case "d":
...@@ -202,9 +289,8 @@ function map_loop(delta) { ...@@ -202,9 +289,8 @@ function map_loop(delta) {
movePlayer() movePlayer()
playerCollided = false playerCollided = false
} }
//Angle for player's weapons/bullets
function angle(event){ function angle(event){
if(wep === undefined){ if(wep === undefined){
return; return;
...@@ -270,8 +356,33 @@ function bulletCollider(delta){ ...@@ -270,8 +356,33 @@ function bulletCollider(delta){
} }
} }
app.ticker.add(map_loop); function enemyBulletCollider(delta){
app.ticker.add(bulletCollider); if(bulletList.length === 0){
return;
}
else{
for(let e = 0; e < bulletList.length; e++){
for(b = 0; b < bounds.length; b++){
if(bulletList[e].sprite.x > bounds[b].x &&
bulletList[e].sprite.x < bounds[b].x + bounds[b].width &&
bulletList[e].sprite.y > bounds[b].y &&
bulletList[e].sprite.y < bounds[b].y + bounds[b].height){
bulletList[e].sprite.gone = true;
}
}
}
}
}
function delayTicker(){
app.ticker.add(update_bullet);
}
app.ticker.add(map_loop);
app.ticker.add(bulletCollider);
app.ticker.add(mobTurn);
app.ticker.add(enemyBulletCollider);
//Enemy bullet don't start shooting until 3 seconds later
let timeout = setTimeout(delayTicker, 3000);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment