Skip to content

Commit

Permalink
states implemented and ai component added. commiting for push
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 5, 2023
1 parent e08fd81 commit 0be049d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.csse3200.game.components.tasks.MobTask;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.tasks.MovementTask;
import com.csse3200.game.components.tasks.bosstask.PatrickTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

public class MobMeleeTask extends DefaultTask implements PriorityTask {
public class MobTask extends DefaultTask implements PriorityTask {

// Constants
private static final int PRIORITY = 3;
Expand All @@ -24,19 +23,22 @@ public class MobMeleeTask extends DefaultTask implements PriorityTask {
Entity mob;
AnimationRenderComponent animation;
MovementTask movementTask;

// Flags
boolean melee;

// Enums
private enum State {
RUN, ATTACK, DEATH, DEFAULT
}

public MobMeleeTask(MobType mobType) {
public MobTask(MobType mobType) {
this.mobType = mobType;
}

@Override
public void start() {
System.out.println("harrypotter");
super.start();
mob = owner.getEntity();
animation = mob.getComponent(AnimationRenderComponent.class);
Expand All @@ -46,6 +48,7 @@ public void start() {
movementTask = new MovementTask(new Vector2(0f, mob.getPosition().y));
movementTask.create(owner);
movementTask.start();
changeState(State.RUN);

if (melee) {
mob.getComponent(PhysicsMovementComponent.class).setSpeed(MELEE_MOB_SPEED);
Expand All @@ -60,6 +63,11 @@ public void update() {

switch (state) {
case RUN -> {
if (enemyDetected()) {
changeState(State.ATTACK);
}
}
case ATTACK -> {

}
}
Expand Down Expand Up @@ -123,6 +131,11 @@ private void changeState(State state) {
this.state = state;
}

private boolean enemyDetected() {
return ServiceLocator.getEntityService().getEntityAtPosition(mob.getPosition().x - 1,
mob.getPosition().y) != null; // if theres an entity within x of - 1 of mob
}

@Override
public int getPriority() {
return PRIORITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import com.csse3200.game.components.tasks.MobDodgeTask;
import com.csse3200.game.components.tasks.MobMeleeAttackTask;
import com.csse3200.game.components.tasks.MobRangedAttackTask;
import com.csse3200.game.components.tasks.MobTask.MobMeleeTask;
import com.csse3200.game.components.tasks.MobTask.MobTask;
import com.csse3200.game.components.tasks.MobTask.MobType;
import com.csse3200.game.components.tasks.MobWanderTask;
import com.csse3200.game.components.tasks.bosstask.DemonBossTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.Melee;
import com.csse3200.game.entities.PredefinedWeapons;
Expand Down Expand Up @@ -309,12 +308,13 @@ public static Entity createGregMob(int health) {
animator.addAnimation("default", 0.1f);

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new MobMeleeTask(MobType.DRAGON_KNIGHT));
.addTask(new MobTask(MobType.DRAGON_KNIGHT));

dragonKnight
.addComponent(new CombatStatsComponent(health, 10, drops))
.addComponent(animator)
.addComponent(new DragonKnightAnimationController());
.addComponent(new DragonKnightAnimationController())
.addComponent(aiTaskComponent);

dragonKnight.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
dragonKnight.getComponent(AnimationRenderComponent.class).scaleEntity();
Expand Down

0 comments on commit 0be049d

Please sign in to comment.