truckactor.java

来自「《J2ME Game Programming》随书光盘源代码」· Java 代码 · 共 52 行

JAVA
52
字号
import javax.microedition.lcdui.Graphics;

/**
 * An VehicleActor that represents a truck (the only customisation is the
 * size and the drawing code).
 * @author Martin J. Wells
 */
public class TruckActor extends VehicleActor
{
   /**
    * Constructs a new truck setting the GameScreen, starting position (x, y)
    * and the speed at which it should move.
    * @param gsArg GameScreen Actor is associated with.
    * @param xArg The starting x position.
    * @param yArg The starting y position.
    * @param speedArg The speed of the vehicle.
    */
   public TruckActor(GameScreen gsArg, int xArg, int yArg, int speedArg)
   {
      super(gsArg, xArg, yArg, speedArg);
   }

   /**
    * Get the Actor width (overriden to set the width properly).
    * @return The width of the truck.
    */
   public int getActorWidth()
   {
      return 28;
   }

   /**
    * Draws a truck using rectangles.
    * @param graphics The graphics context on which to draw the car.
    */
   public void render(Graphics graphics)
   {
      int u = getActorHeight();

      // the front
      graphics.setColor(0x00aa9922);
      graphics.fillRect(getX(), getY(), 4, u);
      // the trailer
      graphics.setColor(0x00aa9922);
      graphics.fillRect(getX()+9, getY(), 18, u);
      // the cab
      graphics.setColor(0x00ffcc66);
      graphics.fillRect(getX() + 4, getY(), u-3, u);

   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?