I followed what i think to be fairly standard practices when it comes to organizing my code. I think the main game loop could be cleaned up. If i were to remake the project from scratch i would use jsons to hold the level data, that way i can hold more information each tile. I could then use a program called Tilded, which is perfect for this sort of thing.
Full Download: Download




Boss:
class Boss extends Enemy{
boolean FacingRight;
boolean GoLeft =false;
boolean canAttack=true;
boolean Awake=false;
boolean Wake=false;
boolean IsStomp=false;
boolean canPush=true;
boolean spawnedCOllider=false;
boolean SpawnedRocks=false;
Boss(PVector SpawnPos,int id){
Health=0;
DamageToDeal=10;
Position=SpawnPos;
ID=id;
EntityScale.x=213*2;
EntityScale.y=128*2;
EntityColliderPosition= new PVector(54*3,33*3);
ColliderScale= new PVector(58*2,(63*2)+32);
Weight=6;
invinsable=true;
}
void UpdateEnemies(){
Update();
if(MCollision!=null){
if(MCollision.UpdateMovingCollider()==true){//moving COllider has made a successful hit
MakeAttack(new PVector(0,1));
}
}
}
void SpawnRocks(){
if(SpawnedRocks==false){
SoundEffects[18].rewind();
SoundEffects[18].play();
Enemies.add(new Falling_Rock(new PVector(theplayer.Position.x+random(-500,500),theplayer.Position.y-(64*5)),60,LoadLevel.addedEnemies));
LoadLevel.addedEnemies++;
Enemies.add(new Falling_Rock(new PVector(theplayer.Position.x+random(-500,500),theplayer.Position.y-(64*5)),90,LoadLevel.addedEnemies));
LoadLevel.addedEnemies++;
Enemies.add(new Falling_Rock(new PVector(theplayer.Position.x+random(-500,500),theplayer.Position.y-(64*5)),100,LoadLevel.addedEnemies));
LoadLevel.addedEnemies++;
SpawnedRocks=true;
}
}
void StaggerEnemy(int getType){
if(getType==0){
isAttacking=false;
isStagger=true;
}
canAttack=true;
}
void Update(){
if(Dead==false&&Dying==false){
EntityColliderPosition= new PVector(54*3,33*3);
ColliderScale= new PVector(58*2,(63*2)+32);
MovePhysics();
if(Awake){
if(lastPlayerhit+240<=frameCount||theplayer.Position.x<747 if="" int="" lastplayerhit="frameCount;" randomdec="">40&&isAttacking==false&&isStagger==false&&canAttack==true){
canAttack=false;
IsStomp=true;
}
}
// println(theplayer.Position.xdd);
if(theplayer.Position.x>2500) {
lastPlayerhit=frameCount;
if(isAttacking==false&&isStagger==false&&canPush==true){
canPush=false;
MakeAttack(new PVector(-1,0));
theplayer.grounded=false;
theplayer.MovementForce.x-=15;
theplayer.MovementForce.y-= theplayer.JumpSpeed;
theplayer.FrictionTime=frameCount;
theplayer.JumpTime=frameCount;
}
}
else if(theplayer.Position.x<1800 are="" canpush="true;" if="" in="" nemies="" player="" point="" range="" theplayer.position.x="" they="" towards="" when="">=Position.x+160)
lookingRight=true;
else
lookingRight=false;
if(dist(Position.x+128+40,theplayer.Position.y,theplayer.Position.x+64,theplayer.Position.y)<50 canattack="false;" dist="" if="" isattacking="true;" move="" osition.x="" player="" theplayer.position.x="" theplayer.position.y="" towards="">40){
if(lookingRight){
AddForceToEntity(new PVector(random(0.1,0.01),0));
}
else
AddForceToEntity(new PVector(random(-0.1,-0.01),0));
}
if(isStagger==true){//Staggering
ShakeScreen=false;
spawnedCOllider=false;
ObjectAnimation=BossAnimation2;
UpdateAnimationArray(Position.x,Position.y+3,0,6,4,true);
if(animationFinished==true){
isStagger=false;
canAttack=true;
}
}
else if(isAttacking==true){ //attacking
ShakeScreen=false;
ObjectAnimation=BossAnimation;
UpdateAnimationArray(Position.x,Position.y+4,0,18,4,true);
if(currentFrame==7){
if(spawnedCOllider==false){
MCollision=new MovingCollider(10,Position.x+48,Position.y+26,Position.x+100-32,Position.y+246-32,96*2,64);
spawnedCOllider=true;
}
}
if(animationFinished==true){
isAttacking=false;
canAttack=true;
spawnedCOllider=false;
}
}
else if(IsStomp==true){
ObjectAnimation=BossAnimation5;
UpdateAnimationArray(Position.x,Position.y+4,0,10,4,true);
if(currentFrame>6){
ShakeScreen=true;
SpawnRocks();
if(theplayer.Position.x<747 akeattack="" animationfinished="=true){" canattack="true;" canpush="true;" else="" if="" isstomp="false;" new="" objectanimation="BossAnimation3;" osition.x="" osition.y="" ovementforce.x="" pvector="" shakescreen="false;" spawnedrocks="false;" theplayer.frictiontime="frameCount;" theplayer.grounded="false;" theplayer.jumptime="frameCount;" theplayer.movementforce.x="" theplayer.movementforce.y-="theplayer.JumpSpeed;" true="" updateanimationarray="" walking="">=0.01){
ObjectAnimation=BossAnimation4;
UpdateAnimationArray(Position.x,Position.y+4,0,14,4,true);
}
else{
ObjectAnimation=BossAnimation3;
UpdateAnimationArray(Position.x,Position.y+4,0,0,2,true);
}
}
}
else if(Wake==false){ //boss is asleep
EntityColliderPosition= new PVector(54*3,33*100);
ColliderScale= new PVector(58*2,63*2);
ObjectAnimation=BossAnimation6;
UpdateAnimationArray(Position.x,Position.y+6,0,0,4,true);
if(dist(Position.x+128,theplayer.Position.y,theplayer.Position.x+32,theplayer.Position.y)<80 and="" animationfinished="=true){" awake="true;" boss="" close="" dead="true;" ealth="" else="" enough="" false="" getgain="" health="0;" if="" invinsable="false;" is="" objectanimation="BossAnimation7;" osition.x="" osition.y="" oundeffects="" player="" pre="" setgain="" soundeffects="" the="" to="" true="" up="" updateanimationarray="" wake="" ying="=true||Dead==true)">
80>747>50>1800>747>
Bow Enemy:
class Enemy_Bow extends Enemy{
int lastattack=0;
Enemy_Bow(PVector SpawnPos,int getID){
ID=ID;
Position=SpawnPos;
Health=50;
AgroRange=600;
ObjectAnimation=BowEnemyAnimation;
}
void AiShoot(){
SoundEffects[12].rewind();
SoundEffects[12].play();
isAttacking=true;
PVector ShootingDirection;
if(theplayer.Position.y+64<=Position.y+32){// player is above
ShootingDirection=new PVector(10,-3);
}
else if(theplayer.Position.y>=Position.y&&theplayer.Position.y+64<=Position.y+64){ //the player is on level
ShootingDirection=new PVector(13,-0.5);
}
else{
ShootingDirection=new PVector(10,1);
}
if(lookingRight){
EArrow.add(new Enemy_Arrow(ShootingDirection,Position.x,Position.y,11));
}
else{
EArrow.add( new Enemy_Arrow(new PVector(-1*(ShootingDirection.x),ShootingDirection.y),Position.x,Position.y,11));
}
}
void UpdateEnemies(){
if(Dead==false&&Dying==false){
MovePhysics();
if(theplayer.Position.x+32>=Position.x+32)
lookingRight=true;
else
lookingRight=false;
if(AIState==0){
if(dist(Position.x+32,Position.y,theplayer.Position.x+32,theplayer.Position.y)lastattack+50){
if(doshoot>10){
isAttacking=true;
}
lastattack=frameCount;
}
}
// player is too far away
if(dist(Position.x+32,Position.y,theplayer.Position.x+32,theplayer.Position.y)>AgroRange+10){
AIState=0;
}
}
if(isAttacking==true){ //attacking
if(lookingRight)
UpdateAnimationArray(Position.x,Position.y,0,9,5,false);
else
UpdateAnimationArray(Position.x,Position.y,9,9,5,false);
if(animationFinished==true){
AiShoot();
isAttacking=false;
if(lookingRight)
UpdateAnimationArray(Position.x,Position.y,8,0,5,true);
else
UpdateAnimationArray(Position.x,Position.y,17,0,5,true);
}
}
else{
if(lookingRight)
UpdateAnimationArray(Position.x,Position.y,8,0,5,true);
else
UpdateAnimationArray(Position.x,Position.y,17,0,5,true);
}
}
else if(Dying==true&&Dead==false){
UpdateAnimationArray(Position.x,Position.y,18,5,4,false);
if(animationFinished==true){
DropPikcups();
Dead=true;
}
}
}
}
No comments:
Post a Comment