📄 comp.java
字号:
/* * Comp.java * * Created on 2007年12月18日, 下午12:27 * 图像中元素的基类,描述可运动物体的基本属性 * To change this template, choose Tools | Template Manager * and open the template in the editor. */package graphics;import SBGameCore.*;import java.awt.Image;import java.awt.Dimension;import java.awt.*;/** * * @author Saerdna */public class Comp { GraphicsPanel a; int px,py;//new position int opx,opy;//old position int w,h;//the height and the wide int vx,vy;//the speed int face;//鸟类飞行方向 public boolean active = false;//鸟的属性,活or死 Image img = null;//存放鸟类图片的对象 /** Creates a new instance of Comp */ public Comp() {//构造函数为空 } public boolean active(){//鸟置成活鸟 return active; } public void set_pos(int x,int y){ px = opx = x; py = opy = y; } public void set_speed(int x,int y){ vx = x; vy = y; } public void set_size(int x,int y){ w = x; h = y; } public void set_draw_rectangles(Rectangle o,Rectangle n){//设置绘制区域,包括要擦掉的区域和即将绘制的区域 int sh = a.window_size.height; int x = px - w/2; int y = (sh - py) - h/2; int ox = opx - w/2; int oy = (sh - opy) - h/2; o.reshape(ox,oy,w,h); n.reshape(x,y,w,h); } public void active(boolean s){//按照参数设定鸟的状态,死or活 active = s; } public void draw(){//画图方法 //set the size set_draw_rectangles(a.paint_area,a.new_area); //设置缓冲区域 Graphics bg = a.buffer.getGraphics(); bg.clipRect(a.paint_area.x,a.paint_area.y,w,h); bg.drawImage(a.backdrop,0,0,a); bg.dispose(); //fullfill the area a.buf_g.fillRect(a.new_area.x,a.new_area.y,w,h); //use the new area a.paint_area.add(a.new_area); //print to the screen Graphics g = a.getGraphics(); g.clipRect(a.paint_area.x,a.paint_area.y,a.paint_area.width,a.paint_area.height); g.drawImage(a.buffer,0,0,a); g.dispose(); } //the object's erase public void erase(){ set_draw_rectangles(a.paint_area,a.new_area); a.paint_area.add(a.new_area); Graphics bg = a.buffer.getGraphics(); bg.clipRect(a.paint_area.x,a.paint_area.y,a.paint_area.width,a.paint_area.height); bg.drawImage(a.backdrop,0,0,a); bg.dispose(); Graphics g = a.getGraphics(); g.clipRect(a.paint_area.x,a.paint_area.y,a.paint_area.width,a.paint_area.height); g.drawImage(a.buffer,0,0,a); g.dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -