Package ru.vagrant_ai.questionmarkgame.obj.mob

Source Code of ru.vagrant_ai.questionmarkgame.obj.mob.Elvis

package ru.vagrant_ai.questionmarkgame.obj.mob;

import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.util.list.ML;
import ru.vagrant_ai.questionmarkgame.util.list.MS;

public class Elvis extends Monster {

  private int opt_dead = 55;
  private int opt_walk = 90;
 
  /**
   * "Elvis" specification:
   * More powerful than Whacker but w/o charge attack
   * HP = 120
   * SPEED = [0.9..1]
   * SIZE = [1.2..1.4]
   */
  public Elvis() {
    id = ML.ELVIS;
    hp_default = 120;
    power = 1;
    y = ground_level;
    speed = (float)(new Random().nextInt(10))/100+0.9f;
    size = (float)(new Random().nextInt(200))/1000+1.2f;
    height = 45*size;
    width = 25*size;
    state = MS.WALK;
    performDefault();
  }
 
 
  /* UPDATE ZONE */ 
 
  @Override
  public void perform()
  {
    if (state == MS.WALK)
    {
      x += speed*((GameplayState.player.getY() > GameplayState.ground_level) ? -1.25f : (getDirection() ? -1 : 1));
      if (x < -50 && x > Game.getAppX()+55) Suicide(1);
      opt_walk--;
      if (opt_walk == 0)
      {
        opt_walk = 90; //WALK is 90 frames long (before the checkFacing())
        updateFacing();
      }
    }
    else if (state == MS.DEAD)
    {
      opt_dead--;
      if (opt_dead == 0) state = MS.NULL;
    }
  }
 
  /* RENDER ZONE */
 
  @Override
  public void renderMain(Graphics g) throws SlickException
  {
    switch(state)
    {
    case NULL: break;
    case DEAD:
      for (int i = 0; i < 6; i++)
      {
        g.setLineWidth(9);
        g.setColor(new Color(0,90,0)); //poison green
        g.drawRect(x-death_rects_x[i], y-death_rects_y[i], 15+opt_dead/2, 15+opt_dead/2);
        g.setColor(new Color(13,142,19)); //poison green
        g.fillRect(x-death_rects_x[i], y-death_rects_y[i], 15+opt_dead/2, 15+opt_dead/2);
      }
      break;
    default:
      g.setLineWidth(6);
      g.setColor(new Color(0,90,0)); //poison green
      g.drawRect(x-width, y-height, width, height);
      g.setColor(new Color(13,142,19)); //poison green
      g.fillRect(x-width, y-height, width, height);
      break;
    }
  }
 
}
TOP

Related Classes of ru.vagrant_ai.questionmarkgame.obj.mob.Elvis

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.