Class Pickup

java.lang.Object
com.codename1.gaming.platformer.LevelEntity
com.codename1.gaming.platformer.Pickup

public class Pickup extends LevelEntity

A collectible: a coin or gem that scores, a heart that heals, a key, an extra life, or a power-up that switches an ability on.

Only the player collects pickups. The kind is the entity type, and decides the effect:

Type Effect
coin +1 coin, + value score
gem + value score, counted as a secret
heart heals value
life +1 life
key adds key name to the inventory
powerup enables the ability named name ("dash", "walljump", "jetpack", ...)
anything else + value score
  • Constructor Details

    • Pickup

      public Pickup(String id, String type, int x, int y, int size, int value, String name)

      Creates a pickup.

      Parameters
      • id: the id
      • type: the kind, see the class description
      • x: left, fixed point
      • y: top, fixed point
      • size: width and height, fixed point
      • value: score or healing
      • name: the key or ability name, may be null
  • Method Details

    • getValue

      public int getValue()

      The pickup's value.

      Returns

      score or healing

    • getName

      public String getName()

      The key or ability name.

      Returns

      the name, or null

    • onTouch

      public void onTouch(PlatformWorld world, Actor c)
      Description copied from class: LevelEntity

      Called each tick a living actor overlaps the entity.

      Parameters
      • world: the world
      • c: the actor
      Overrides:
      onTouch in class LevelEntity