Android Open Source - RPGWorld Monster Character






From Project

Back to project page RPGWorld.

License

The source code is released under:

MIT License

If you think the Android project RPGWorld listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Jun 10, 2013/*from  w w  w. ja  va 2 s .c o  m*/
 * MonsterCharacter.java
 * Daniel Pok
 * AP Java 6th
 */
package com.nokarateclass.rpgworld.characters;

import java.util.*;

import com.nokarateclass.rpgworld.R;
import com.nokarateclass.rpgworld.editor.CharacterFactory;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;

/**
 * @author poler_000
 *
 */
public class MonsterCharacter extends CharacterActor {

  public static final int mDefaultId = CharacterFactory.MONSTER;


  /**
   * 
   */
  public MonsterCharacter(Context context) {
    super(context.getResources().getDrawable(R.drawable.monster), mDefaultId);
        mPlayer.setMaxHealth(50);
        mPlayer.setHealth(50);
  }

  /**
   * @param sprite
   */
  public MonsterCharacter(Drawable sprite) {
    super(sprite, mDefaultId);
    mPlayer.setMaxHealth(50);
    mPlayer.setHealth(50);
  }
  public void interact(CharacterActor character){
    if(isAdjacent(character)){
      mPlayer.addHealth(-10);
    }
  }
  @Override
  public void act(int beat){
    //Log.i("Monster", "Getting characters in range(5)");
    ArrayList<CharacterActor> inRange = fourWayLineOfSight(5);
    //Log.i("Monster", inRange.toString());
    for(int i = 0; i < inRange.size(); i++){
      if(inRange.get(i).mId == CharacterFactory.HERO){
        Log.i("Monster", "Found Hero: " + inRange.get(i).toString());
        setTarget(inRange.get(i).getLocation());
        stepTowardTarget();
      }
    }

    if(beat == 0){
      ArrayList<CharacterActor> adjacent = getAdjacentCharacters();
      //Log.i("Monster", adjacent.toString());
      for(int i = 0; i < adjacent.size(); i++){
        if(adjacent.get(i).mId == CharacterFactory.HERO){
          adjacent.get(i).mPlayer.addHealth(-10);
        } if(adjacent.get(i).mId == CharacterFactory.MONSTER){
          adjacent.get(i).mPlayer.addHealth(-5);
        }
      }  
    }  
  }
  
  @Override
  public void onDeath(){
    Log.d("Player", toString() + " died" + String.format(" HP: %d/%d", mPlayer.getHealth(), mPlayer.getMaxHealth()));
    for(CharacterActor i: getAdjacentCharacters()){
      i.mPlayer.addHealth(20);
    }
    Log.d("Player", "Remove status: " + toString() + " " + removeSelfFromGrid());
  }
  
}




Java Source Code List

com.nokarateclass.rpgworld.Grid.java
com.nokarateclass.rpgworld.MapEditor.java
com.nokarateclass.rpgworld.backgrounds.BackgroundCharacter.java
com.nokarateclass.rpgworld.backgrounds.GrassBackground.java
com.nokarateclass.rpgworld.backgrounds.SandBackground.java
com.nokarateclass.rpgworld.characters.AndroidCharacter.java
com.nokarateclass.rpgworld.characters.CactusCharacter.java
com.nokarateclass.rpgworld.characters.CharacterActor.java
com.nokarateclass.rpgworld.characters.HeroCharacter.java
com.nokarateclass.rpgworld.characters.MonsterCharacter.java
com.nokarateclass.rpgworld.characters.Player.java
com.nokarateclass.rpgworld.characters.RockCharacter.java
com.nokarateclass.rpgworld.characters.Status.java
com.nokarateclass.rpgworld.characters.TreeCharacter.java
com.nokarateclass.rpgworld.editor.CharacterFactory.java
com.nokarateclass.rpgworld.editor.EditorGrid.java
com.nokarateclass.rpgworld.grid.BackgroundGrid.java
com.nokarateclass.rpgworld.grid.BeatTask.java
com.nokarateclass.rpgworld.grid.CharacterGrid.java
com.nokarateclass.rpgworld.grid.Location.java
com.nokarateclass.rpgworld.grid.MainCharacterGrid.java
com.nokarateclass.rpgworld.io.FileExporter.java
com.nokarateclass.rpgworld.io.FileIO.java
com.nokarateclass.rpgworld.io.FileImporter.java
com.nokarateclass.rpgworld.io.GridSerializer.java
com.nokarateclass.rpgworld.io.SettingsHolder.java
com.nokarateclass.rpgworld.ui.GridClickListener.java
com.nokarateclass.rpgworld.ui.ImageGridView.java
com.nokarateclass.rpgworld.world.Region.java
com.nokarateclass.rpgworld.world.World.java
com.nokarateclass.rpgworld.world.Zone.java