@Test public void testGenericBulletAttack() { init(); world.debugReset(); Player player = new Player(); world.addEntity(player); world.gameLoop(1); player.getEquippedWeapon().basicAttack(player, 1, 1, 1, 1); world.gameLoop(1); assertEquals(world.getAllEntities().size(), 2); assertTrue(world.getAllEntities().get(0).getClass() == Player.class); assertTrue(world.getAllEntities().get(1).getClass() == GenericBullet.class); }
public int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage) { World world = World.getInstance(); if (this.multishot) { int shotNum = this.shots; double angle = Math.atan2(velY, velX); ArrayList<CustomBullet> bullets = new ArrayList<>(); for (int i = 0; i < shotNum; i++) { double newAngle = angle + ((((i-shotNum/2) * shotArc) + (Math.random() * 2 - 1)) * Math.PI/180) ; float newVelX = (float)Math.cos(newAngle); float newVelY = (float)Math.sin(newAngle); CustomBullet bullet = new CustomBullet(owner, newVelX, newVelY, this.bulletSpeed + statSpeed, (this.damage + statDamage)/shotNum, this.range, this.travelSprite, 0.3f, 0.15f, null, 0, 0); bullets.add(bullet); } for (CustomBullet bullet : bullets) { world.addEntity(bullet); } } else { if (this.projectileType == ProjectileType.BULLET) { GenericBullet bullet = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.travelSprite); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.GRENADE) { GrenadeBullet nade = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.grenadeTime, this.damage + statDamage, this.grenadeRadius, this.travelSprite, true); world.addEntity(nade); } else if (this.projectileType == ProjectileType.MELEE) { GenericBlade blade = new GenericBlade(owner, this.damage + statDamage, this.actionSprite, this.swingTime); world.addEntity(blade); } else if (this.projectileType == ProjectileType.ROCKET) { GrenadeBullet rocket = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, 0, this.damage + statDamage, this.grenadeRadius, this.travelSprite, false); world.addEntity(rocket); } else if (this.projectileType == ProjectileType.LAZOR) { GenericBullet lazor = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.actionSprite); world.addEntity(lazor); } else if (this.projectileType == ProjectileType.CUSTOM_BULLET) { CustomBullet bullet = new CustomBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage , this.range, this.travelSprite, this.travelWidth, this.travelHeight, this.actionSprite, this.actionWidth, this.actionHeight); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.PORTAL) { PortalBullet bullet = new PortalBullet(owner, velX, velY, this.bulletSpeed + statSpeed, portal); if(((Player) owner).getPortal(portal) != null) { ((Player) owner).killPortal(portal); } ((Player) owner).setPortal(bullet, portal); world.addEntity(bullet); portal = !portal; } else if (this.projectileType == ProjectileType.FLAME) { FireProjectile bullet = new FireProjectile(owner, velX, velY, this.bulletSpeed + statSpeed, 10); world.addEntity(bullet); } } return 1; }
Weapon extends Item { public int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage) { World world = World.getInstance(); if (this.multishot) { int shotNum = this.shots; double angle = Math.atan2(velY, velX); ArrayList<CustomBullet> bullets = new ArrayList<>(); for (int i = 0; i < shotNum; i++) { double newAngle = angle + ((((i-shotNum/2) * shotArc) + (Math.random() * 2 - 1)) * Math.PI/180) ; float newVelX = (float)Math.cos(newAngle); float newVelY = (float)Math.sin(newAngle); CustomBullet bullet = new CustomBullet(owner, newVelX, newVelY, this.bulletSpeed + statSpeed, (this.damage + statDamage)/shotNum, this.range, this.travelSprite, 0.3f, 0.15f, null, 0, 0); bullets.add(bullet); } for (CustomBullet bullet : bullets) { world.addEntity(bullet); } } else { if (this.projectileType == ProjectileType.BULLET) { GenericBullet bullet = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.travelSprite); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.GRENADE) { GrenadeBullet nade = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.grenadeTime, this.damage + statDamage, this.grenadeRadius, this.travelSprite, true); world.addEntity(nade); } else if (this.projectileType == ProjectileType.MELEE) { GenericBlade blade = new GenericBlade(owner, this.damage + statDamage, this.actionSprite, this.swingTime); world.addEntity(blade); } else if (this.projectileType == ProjectileType.ROCKET) { GrenadeBullet rocket = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, 0, this.damage + statDamage, this.grenadeRadius, this.travelSprite, false); world.addEntity(rocket); } else if (this.projectileType == ProjectileType.LAZOR) { GenericBullet lazor = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.actionSprite); world.addEntity(lazor); } else if (this.projectileType == ProjectileType.CUSTOM_BULLET) { CustomBullet bullet = new CustomBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage , this.range, this.travelSprite, this.travelWidth, this.travelHeight, this.actionSprite, this.actionWidth, this.actionHeight); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.PORTAL) { PortalBullet bullet = new PortalBullet(owner, velX, velY, this.bulletSpeed + statSpeed, portal); if(((Player) owner).getPortal(portal) != null) { ((Player) owner).killPortal(portal); } ((Player) owner).setPortal(bullet, portal); world.addEntity(bullet); portal = !portal; } else if (this.projectileType == ProjectileType.FLAME) { FireProjectile bullet = new FireProjectile(owner, velX, velY, this.bulletSpeed + statSpeed, 10); world.addEntity(bullet); } } return 1; } }
Weapon extends Item { public int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage) { World world = World.getInstance(); if (this.multishot) { int shotNum = this.shots; double angle = Math.atan2(velY, velX); ArrayList<CustomBullet> bullets = new ArrayList<>(); for (int i = 0; i < shotNum; i++) { double newAngle = angle + ((((i-shotNum/2) * shotArc) + (Math.random() * 2 - 1)) * Math.PI/180) ; float newVelX = (float)Math.cos(newAngle); float newVelY = (float)Math.sin(newAngle); CustomBullet bullet = new CustomBullet(owner, newVelX, newVelY, this.bulletSpeed + statSpeed, (this.damage + statDamage)/shotNum, this.range, this.travelSprite, 0.3f, 0.15f, null, 0, 0); bullets.add(bullet); } for (CustomBullet bullet : bullets) { world.addEntity(bullet); } } else { if (this.projectileType == ProjectileType.BULLET) { GenericBullet bullet = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.travelSprite); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.GRENADE) { GrenadeBullet nade = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.grenadeTime, this.damage + statDamage, this.grenadeRadius, this.travelSprite, true); world.addEntity(nade); } else if (this.projectileType == ProjectileType.MELEE) { GenericBlade blade = new GenericBlade(owner, this.damage + statDamage, this.actionSprite, this.swingTime); world.addEntity(blade); } else if (this.projectileType == ProjectileType.ROCKET) { GrenadeBullet rocket = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, 0, this.damage + statDamage, this.grenadeRadius, this.travelSprite, false); world.addEntity(rocket); } else if (this.projectileType == ProjectileType.LAZOR) { GenericBullet lazor = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.actionSprite); world.addEntity(lazor); } else if (this.projectileType == ProjectileType.CUSTOM_BULLET) { CustomBullet bullet = new CustomBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage , this.range, this.travelSprite, this.travelWidth, this.travelHeight, this.actionSprite, this.actionWidth, this.actionHeight); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.PORTAL) { PortalBullet bullet = new PortalBullet(owner, velX, velY, this.bulletSpeed + statSpeed, portal); if(((Player) owner).getPortal(portal) != null) { ((Player) owner).killPortal(portal); } ((Player) owner).setPortal(bullet, portal); world.addEntity(bullet); portal = !portal; } else if (this.projectileType == ProjectileType.FLAME) { FireProjectile bullet = new FireProjectile(owner, velX, velY, this.bulletSpeed + statSpeed, 10); world.addEntity(bullet); } } return 1; } Weapon(WeaponBuilder builder); }
Weapon extends Item { public int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage) { World world = World.getInstance(); if (this.multishot) { int shotNum = this.shots; double angle = Math.atan2(velY, velX); ArrayList<CustomBullet> bullets = new ArrayList<>(); for (int i = 0; i < shotNum; i++) { double newAngle = angle + ((((i-shotNum/2) * shotArc) + (Math.random() * 2 - 1)) * Math.PI/180) ; float newVelX = (float)Math.cos(newAngle); float newVelY = (float)Math.sin(newAngle); CustomBullet bullet = new CustomBullet(owner, newVelX, newVelY, this.bulletSpeed + statSpeed, (this.damage + statDamage)/shotNum, this.range, this.travelSprite, 0.3f, 0.15f, null, 0, 0); bullets.add(bullet); } for (CustomBullet bullet : bullets) { world.addEntity(bullet); } } else { if (this.projectileType == ProjectileType.BULLET) { GenericBullet bullet = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.travelSprite); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.GRENADE) { GrenadeBullet nade = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.grenadeTime, this.damage + statDamage, this.grenadeRadius, this.travelSprite, true); world.addEntity(nade); } else if (this.projectileType == ProjectileType.MELEE) { GenericBlade blade = new GenericBlade(owner, this.damage + statDamage, this.actionSprite, this.swingTime); world.addEntity(blade); } else if (this.projectileType == ProjectileType.ROCKET) { GrenadeBullet rocket = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, 0, this.damage + statDamage, this.grenadeRadius, this.travelSprite, false); world.addEntity(rocket); } else if (this.projectileType == ProjectileType.LAZOR) { GenericBullet lazor = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.actionSprite); world.addEntity(lazor); } else if (this.projectileType == ProjectileType.CUSTOM_BULLET) { CustomBullet bullet = new CustomBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage , this.range, this.travelSprite, this.travelWidth, this.travelHeight, this.actionSprite, this.actionWidth, this.actionHeight); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.PORTAL) { PortalBullet bullet = new PortalBullet(owner, velX, velY, this.bulletSpeed + statSpeed, portal); if(((Player) owner).getPortal(portal) != null) { ((Player) owner).killPortal(portal); } ((Player) owner).setPortal(bullet, portal); world.addEntity(bullet); portal = !portal; } else if (this.projectileType == ProjectileType.FLAME) { FireProjectile bullet = new FireProjectile(owner, velX, velY, this.bulletSpeed + statSpeed, 10); world.addEntity(bullet); } } return 1; } Weapon(WeaponBuilder builder); int getDamage(); int getFiringRate(); ProjectileType getProjectileType(); int getBulletSpeed(); int getGrenadeRadius(); int getGrenadeTime(); int getSwingTime(); SpriteList getActionSprite(); SpriteList getTravelSprite(); int getAccuracy(); int getRange(); int getShots(); boolean getSoilerAdder(); int getAmmoDeduction(); int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage); }
Weapon extends Item { public int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage) { World world = World.getInstance(); if (this.multishot) { int shotNum = this.shots; double angle = Math.atan2(velY, velX); ArrayList<CustomBullet> bullets = new ArrayList<>(); for (int i = 0; i < shotNum; i++) { double newAngle = angle + ((((i-shotNum/2) * shotArc) + (Math.random() * 2 - 1)) * Math.PI/180) ; float newVelX = (float)Math.cos(newAngle); float newVelY = (float)Math.sin(newAngle); CustomBullet bullet = new CustomBullet(owner, newVelX, newVelY, this.bulletSpeed + statSpeed, (this.damage + statDamage)/shotNum, this.range, this.travelSprite, 0.3f, 0.15f, null, 0, 0); bullets.add(bullet); } for (CustomBullet bullet : bullets) { world.addEntity(bullet); } } else { if (this.projectileType == ProjectileType.BULLET) { GenericBullet bullet = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.travelSprite); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.GRENADE) { GrenadeBullet nade = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.grenadeTime, this.damage + statDamage, this.grenadeRadius, this.travelSprite, true); world.addEntity(nade); } else if (this.projectileType == ProjectileType.MELEE) { GenericBlade blade = new GenericBlade(owner, this.damage + statDamage, this.actionSprite, this.swingTime); world.addEntity(blade); } else if (this.projectileType == ProjectileType.ROCKET) { GrenadeBullet rocket = new GrenadeBullet(owner, velX, velY, this.bulletSpeed + statSpeed, 0, this.damage + statDamage, this.grenadeRadius, this.travelSprite, false); world.addEntity(rocket); } else if (this.projectileType == ProjectileType.LAZOR) { GenericBullet lazor = new GenericBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage, this.actionSprite); world.addEntity(lazor); } else if (this.projectileType == ProjectileType.CUSTOM_BULLET) { CustomBullet bullet = new CustomBullet(owner, velX, velY, this.bulletSpeed + statSpeed, this.damage + statDamage , this.range, this.travelSprite, this.travelWidth, this.travelHeight, this.actionSprite, this.actionWidth, this.actionHeight); world.addEntity(bullet); } else if (this.projectileType == ProjectileType.PORTAL) { PortalBullet bullet = new PortalBullet(owner, velX, velY, this.bulletSpeed + statSpeed, portal); if(((Player) owner).getPortal(portal) != null) { ((Player) owner).killPortal(portal); } ((Player) owner).setPortal(bullet, portal); world.addEntity(bullet); portal = !portal; } else if (this.projectileType == ProjectileType.FLAME) { FireProjectile bullet = new FireProjectile(owner, velX, velY, this.bulletSpeed + statSpeed, 10); world.addEntity(bullet); } } return 1; } Weapon(WeaponBuilder builder); int getDamage(); int getFiringRate(); ProjectileType getProjectileType(); int getBulletSpeed(); int getGrenadeRadius(); int getGrenadeTime(); int getSwingTime(); SpriteList getActionSprite(); SpriteList getTravelSprite(); int getAccuracy(); int getRange(); int getShots(); boolean getSoilerAdder(); int getAmmoDeduction(); int basicAttack(Entity owner, float velX, float velY, int statSpeed, int statDamage);  }