zoukankan      html  css  js  c++  java
  • java 之2D过气游戏类的写法

    2D游戏中各对象的父类

    package cn.littlepage.game;
    
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Rectangle;
    
    public class GameObject {
    /*
     * 任何一个2D游戏都必须要有图片,坐标,速度,大小,矩形(碰撞检测)
     * 所以,这个可以做成一个2D游戏的父类
     */
        public Image img;
        public int x,y;
        public int speed;
        public int width,height;
        
        public void drawSelf(Graphics g) {
            g.drawImage(img, x, y, null);
            
        }
        
    
        public GameObject() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        public GameObject(Image img, int x, int y, int speed, int width, int height) {
            super();
            this.img = img;
            this.x = x;
            this.y = y;
            this.speed = speed;
            this.width = width;
            this.height = height;
        }
        
    
        public Rectangle getRect() {
            return new Rectangle(x, y, width, height);
        }
        
        
        
    }
  • 相关阅读:

    k
    通过类名调用类方法
    类Area的getArea方法是一个重载方法
    构造cry
    两个lader对象共享bottom
    向一个方法的基本数据类型参数传值
    Circle
    常量的用法
    显示本机时间
  • 原文地址:https://www.cnblogs.com/littlepage/p/9488556.html
Copyright © 2011-2022 走看看