caractor.java

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

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

/**
 * An VehicleActor that represents a little car (the only customisation is the
 * size and the drawing code).
 * @author Martin J. Wells
 */
public class CarActor extends VehicleActor
{
   /**
    * Constructs a new car 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 CarActor(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 car.
    */
   public int getActorWidth()
   {
      return 12;
   }

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

      graphics.setColor(0x00aa9922);
      graphics.fillRect(getX(), getY(), u, u);
      graphics.fillRect(getX() + (u / 2) + 5, getY(), u, u);
      graphics.setColor(0x00ffcc66);
      graphics.fillRect(getX() + u - 2, getY(), u, u);
   }
}


⌨️ 快捷键说明

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