Skip to content

Player Interaction Sprint 1

Vermouth10 edited this page Aug 31, 2021 · 45 revisions

The Player can interact with other Entities in the game.

Interact with enemies

  • Touch enemies -- If the player touches an enemy, the player will receive a health deduction.
  • Player attack animation -- When the space button is pressed, the player texture will be switch to attack animation. And after the space key go up the animation will switch to the origanl player.
  • Attack enemy -- The player can try to attack the nearby enemies by pressing the space button. If the distance between the player and the nearest enemy is smaller than the threshold, the enemy can be successfully destroyed.
    1. Simple enemies(ghost) -- Players can kill them by one attack.
    2. Difficult enemies(ghost king) -- Players cannot destroy these enemies at this stage.

Interact with obstacles

  • Destroy obstacles -- The player can try to destroy the nearby obstacles by pressing the space button. If the distance between the player and the nearest obstacle is smaller than the threshold, the obstacle can be successfully destroyed.

Judgment distance setting

  • The judgment distance is set to be different. When player is facing enemies, the judgment distance is set to be longer, and for obstacles, it set to be shorter.

Code Usage

  • Setting the judgment distance:
private Entity findNearestTargets(Array<Entity> entities) {
    Entity result = null;
    float minDstEnemy = 2.0f;
    float minDstObstacle = 1.1f;
    for (Entity en: entities) {
      if (en.getType() == Entity.Type.GHOST || en.getType() == Entity.Type.GHOSTKING) {
        float dst = entity.getPosition().dst(en.getPosition());
        if (minDstEnemy > dst) {
          minDstEnemy = dst;
          result = en;
        }
      } else if (en.getType() == Entity.Type.OBSTACLE) {
        float dst = entity.getPosition().dst(en.getPosition());
        if (minDstObstacle > dst) {
          minDstObstacle = dst;
          result = en;
        }
      }
    }
    return result;
}
  • Attack enemies and obstacles:
void attack() {
    logger.info("attack");
    Array<Entity> entities = ServiceLocator.getEntityService().getEntities();
    Entity nearest = findNearestTargets(entities);
    logger.info("attack nearest--{}", nearest);
    if (nearest != null) {
      if (nearest.getType().equals(Entity.Type.GHOSTKING)) {
        logger.info ("nearest.getType()--{}", nearest.getType());
        nearest.attack();
      } else {
        logger.info ("nearest.getType()--{}", nearest.getType());
        nearest.dispose();
      }
    }
    Sound attackSound = ServiceLocator.getResourceService().getAsset("sounds/Impact4.ogg", Sound.class);
    attackSound.play();
    animator.startAnimation("attack");
}
  • Attack animation:
public static Entity createPlayer() {
    InputComponent inputComponent =
        ServiceLocator.getInputService().getInputFactory().createForPlayer();

    AnimationRenderComponent animator =
            new AnimationRenderComponent(
                    ServiceLocator.getResourceService()
                            .getAsset("images/attack.atlas",
                                    TextureAtlas.class));
    animator.addAnimation("attack", 10f, Animation.PlayMode.LOOP); (Animation)
}
void unAttack(){
    animator.stopAnimation();
} //new function connceted to the space key to stop attack animation
  • Attack animation design: When the space button is pressed, the player texture will be switch to attack animation. And after the space key go up the animation will switch to the origanl player.use sword and let the player wave his hands to stimulate the attack action.

Table of Contents

Home

Game Design

Player Health System, Scoring System & Game Over
  • Enemies

Enemies
Enemies testing and testing plan
Player Interaction Sprint1 & Sprint2
Player Interaction Sprint3
Player Interaction Sprint4
Map contents Sprint1-3
Map contents Sprint4

Game Features

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally