diff --git a/SMIMS-Game/Enemy.class b/SMIMS-Game/Enemy.class index 77ba588..3b556b2 100644 Binary files a/SMIMS-Game/Enemy.class and b/SMIMS-Game/Enemy.class differ diff --git a/SMIMS-Game/Enemy.ctxt b/SMIMS-Game/Enemy.ctxt index 214f50f..b6b41cc 100644 --- a/SMIMS-Game/Enemy.ctxt +++ b/SMIMS-Game/Enemy.ctxt @@ -1,7 +1,11 @@ #BlueJ class context comment0.target=Enemy -comment1.params= -comment1.target=void\ act() +comment1.params=targetX\ targetY +comment1.target=Enemy(int,\ int) comment2.params= -comment2.target=void\ shootAtPlayer() -numComments=3 +comment2.target=void\ act() +comment3.params=targetX\ targetY +comment3.target=void\ moveToTargetLocation(int,\ int) +comment4.params= +comment4.target=void\ shootAtPlayer() +numComments=5 diff --git a/SMIMS-Game/Enemy.java b/SMIMS-Game/Enemy.java index 26b2436..c8f8695 100644 --- a/SMIMS-Game/Enemy.java +++ b/SMIMS-Game/Enemy.java @@ -2,12 +2,36 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Enemy extends Actor { + int targetX; + int targetY; + + boolean targetReached = false; + + int speed = 3; + public Enemy (int targetX, int targetY) { + this.targetX = targetX; + this.targetY = targetY; + } + int shootTimer; public void act() { shootAtPlayer(); + if (!targetReached){ + moveToTargetLocation(targetX, targetY); + } + } + public void moveToTargetLocation(int targetX, int targetY){ + double dx = targetX - getX(); + double dy = targetY - getY(); + double distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + if (distance < 2){ + targetReached = true; + } + setLocation(getX() + (int)(dx/distance*speed), getY() + (int)(dy/distance*speed)); + } public void shootAtPlayer(){ shootTimer++; diff --git a/SMIMS-Game/project.greenfoot b/SMIMS-Game/project.greenfoot index c10bfd7..6115ca5 100644 --- a/SMIMS-Game/project.greenfoot +++ b/SMIMS-Game/project.greenfoot @@ -22,104 +22,113 @@ dependency1.from=GameOverWorld dependency1.to=Button dependency1.type=UsesDependency dependency10.from=MyWorld -dependency10.to=BreakingPlattform +dependency10.to=MovingPlattform dependency10.type=UsesDependency dependency11.from=MyWorld -dependency11.to=SpikedPlattform +dependency11.to=BreakingPlattform dependency11.type=UsesDependency dependency12.from=MyWorld -dependency12.to=Projectile +dependency12.to=SpikedPlattform dependency12.type=UsesDependency dependency13.from=MyWorld -dependency13.to=TargetingProjectile +dependency13.to=Projectile dependency13.type=UsesDependency -dependency14.from=Spike -dependency14.to=GameOverWorld +dependency14.from=MyWorld +dependency14.to=TargetingProjectile dependency14.type=UsesDependency dependency15.from=Spike -dependency15.to=MyWorld +dependency15.to=GameOverWorld dependency15.type=UsesDependency dependency16.from=Spike -dependency16.to=Player +dependency16.to=MyWorld dependency16.type=UsesDependency -dependency17.from=Player -dependency17.to=GameOverWorld +dependency17.from=Spike +dependency17.to=Player dependency17.type=UsesDependency dependency18.from=Player -dependency18.to=Plattform +dependency18.to=GameOverWorld dependency18.type=UsesDependency dependency19.from=Player -dependency19.to=PlayerProjectile +dependency19.to=Plattform dependency19.type=UsesDependency dependency2.from=PlayerTestWorld dependency2.to=Ground dependency2.type=UsesDependency dependency20.from=Player -dependency20.to=Projectile +dependency20.to=PlayerProjectile dependency20.type=UsesDependency dependency21.from=Player -dependency21.to=Enemy +dependency21.to=Projectile dependency21.type=UsesDependency -dependency22.from=UnactiveSpike -dependency22.to=SpikedPlattform +dependency22.from=Player +dependency22.to=Enemy dependency22.type=UsesDependency dependency23.from=UnactiveSpike -dependency23.to=MyWorld +dependency23.to=SpikedPlattform dependency23.type=UsesDependency dependency24.from=UnactiveSpike -dependency24.to=Spike +dependency24.to=MyWorld dependency24.type=UsesDependency -dependency25.from=Plattform -dependency25.to=MyWorld +dependency25.from=UnactiveSpike +dependency25.to=Spike dependency25.type=UsesDependency -dependency26.from=Plattform +dependency26.from=Healthbar dependency26.to=Player dependency26.type=UsesDependency -dependency27.from=MovingPlattform +dependency27.from=Plattform dependency27.to=MyWorld dependency27.type=UsesDependency -dependency28.from=MovingPlattform +dependency28.from=Plattform dependency28.to=Player dependency28.type=UsesDependency -dependency29.from=SpikedPlattform -dependency29.to=Spike +dependency29.from=MovingPlattform +dependency29.to=MyWorld dependency29.type=UsesDependency dependency3.from=PlayerTestWorld dependency3.to=Player dependency3.type=UsesDependency -dependency30.from=SpikedPlattform -dependency30.to=GameOverWorld +dependency30.from=MovingPlattform +dependency30.to=Player dependency30.type=UsesDependency dependency31.from=SpikedPlattform -dependency31.to=MyWorld +dependency31.to=Spike dependency31.type=UsesDependency dependency32.from=SpikedPlattform -dependency32.to=UnactiveSpike +dependency32.to=GameOverWorld dependency32.type=UsesDependency -dependency33.from=TargetingProjectile -dependency33.to=Player +dependency33.from=SpikedPlattform +dependency33.to=MyWorld dependency33.type=UsesDependency -dependency34.from=Button -dependency34.to=MyWorld +dependency34.from=SpikedPlattform +dependency34.to=UnactiveSpike dependency34.type=UsesDependency -dependency35.from=PowerUps +dependency35.from=TargetingProjectile dependency35.to=Player dependency35.type=UsesDependency -dependency36.from=JumpBoostItem -dependency36.to=Player +dependency36.from=Button +dependency36.to=MyWorld dependency36.type=UsesDependency -dependency37.from=Enemy +dependency37.from=PowerUps dependency37.to=Player dependency37.type=UsesDependency -dependency38.from=Enemy -dependency38.to=EnemyProjectile +dependency38.from=HealthItem +dependency38.to=Player dependency38.type=UsesDependency -dependency39.from=PlayerProjectile -dependency39.to=Enemy +dependency39.from=JumpBoostItem +dependency39.to=Player dependency39.type=UsesDependency dependency4.from=PlayerTestWorld dependency4.to=JumpBoostItem dependency4.type=UsesDependency +dependency40.from=Enemy +dependency40.to=Player +dependency40.type=UsesDependency +dependency41.from=Enemy +dependency41.to=EnemyProjectile +dependency41.type=UsesDependency +dependency42.from=PlayerProjectile +dependency42.to=Enemy +dependency42.type=UsesDependency dependency5.from=StartWorld dependency5.to=Button dependency5.type=UsesDependency @@ -133,15 +142,15 @@ dependency8.from=MyWorld dependency8.to=Plattform dependency8.type=UsesDependency dependency9.from=MyWorld -dependency9.to=MovingPlattform +dependency9.to=Healthbar dependency9.type=UsesDependency editor.fx.0.height=737 editor.fx.0.width=814 editor.fx.0.x=360 editor.fx.0.y=26 -height=830 -package.numDependencies=39 -package.numTargets=22 +height=822 +package.numDependencies=42 +package.numTargets=23 project.charset=UTF-8 publish.hasSource=false publish.locked=true @@ -164,70 +173,70 @@ target1.width=120 target1.x=0 target1.y=0 target10.height=70 -target10.name=PlayerTestWorld +target10.name=GameOverWorld target10.showInterface=false target10.type=ClassTarget target10.width=120 target10.x=0 target10.y=0 target11.height=70 -target11.name=StartWorld +target11.name=PlayerTestWorld target11.showInterface=false target11.type=ClassTarget target11.width=120 target11.x=0 target11.y=0 target12.height=70 -target12.name=Plattform +target12.name=StartWorld target12.showInterface=false target12.type=ClassTarget target12.width=120 target12.x=0 target12.y=0 target13.height=70 -target13.name=TargetingProjectile +target13.name=Plattform target13.showInterface=false target13.type=ClassTarget target13.width=120 target13.x=0 target13.y=0 target14.height=70 -target14.name=Projectile +target14.name=TargetingProjectile target14.showInterface=false target14.type=ClassTarget target14.width=120 target14.x=0 target14.y=0 target15.height=70 -target15.name=Score +target15.name=Projectile target15.showInterface=false target15.type=ClassTarget target15.width=120 target15.x=0 target15.y=0 target16.height=70 -target16.name=Button +target16.name=Score target16.showInterface=false target16.type=ClassTarget target16.width=120 target16.x=0 target16.y=0 target17.height=70 -target17.name=EnemyProjectile +target17.name=Button target17.showInterface=false target17.type=ClassTarget target17.width=120 target17.x=0 target17.y=0 target18.height=70 -target18.name=PowerUps +target18.name=EnemyProjectile target18.showInterface=false target18.type=ClassTarget target18.width=120 target18.x=0 target18.y=0 target19.height=70 -target19.name=Enemy +target19.name=PowerUps target19.showInterface=false target19.type=ClassTarget target19.width=120 @@ -241,26 +250,33 @@ target2.width=120 target2.x=0 target2.y=0 target20.height=70 -target20.name=PlayerProjectile +target20.name=Enemy target20.showInterface=false target20.type=ClassTarget target20.width=120 target20.x=0 target20.y=0 target21.height=70 -target21.name=SpikedPlattform +target21.name=PlayerProjectile target21.showInterface=false target21.type=ClassTarget target21.width=120 target21.x=0 target21.y=0 target22.height=70 -target22.name=MyWorld +target22.name=SpikedPlattform target22.showInterface=false target22.type=ClassTarget target22.width=120 target22.x=0 target22.y=0 +target23.height=70 +target23.name=MyWorld +target23.showInterface=false +target23.type=ClassTarget +target23.width=120 +target23.x=0 +target23.y=0 target3.height=70 target3.name=MovingPlattform target3.showInterface=false @@ -290,28 +306,28 @@ target6.width=120 target6.x=0 target6.y=0 target7.height=70 -target7.name=JumpBoostItem +target7.name=Healthbar target7.showInterface=false target7.type=ClassTarget target7.width=120 target7.x=0 target7.y=0 target8.height=70 -target8.name=BreakingPlattform +target8.name=JumpBoostItem target8.showInterface=false target8.type=ClassTarget target8.width=120 target8.x=0 target8.y=0 target9.height=70 -target9.name=GameOverWorld +target9.name=BreakingPlattform target9.showInterface=false target9.type=ClassTarget target9.width=120 target9.x=0 target9.y=0 version=3.1.0 -width=1550 +width=715 world.lastInstantiated=MyWorld -xPosition=0 -yPosition=0 +xPosition=532 +yPosition=117