Stair.java 1.6 KB
Newer Older
RunAtWorld's avatar
RunAtWorld 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
package com.yzu.daydayrun.entity;



import com.yzu.daydayrun.ui.MainFrame;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

public class Stair {

    public static final int WIDTH = 200;
    public static final int HEIGHT = 37;

    private BufferedImage image;
    private int x, y;
    private int xSpeed;
    private int index;
    Random random = new Random();

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getxSpeed() {
        return xSpeed;
    }

    public void setxSpeed(int xSpeed) {
        this.xSpeed = xSpeed;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Stair() {

        try {
            image = ImageIO.read(new File("D:/study/run-day/image/hhh.png"));
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        index = 0;
        x = random.nextInt(500)+MainFrame.WIDTH;
        y = 270-random.nextInt(150);
        xSpeed = 2;
    }

    public void step() {
        x -= xSpeed;
    }

    public void paintStair(Graphics g) {
        g.drawImage(image, x, y, WIDTH, HEIGHT, null);
    }
}