常州大学本科生毕业设计(论文)
}
paint(offScreenGraphics);
g.drawImage(offScreenImage, 0, 0, this);
6.2本游戏的模块设计 6.2.1墙体绘制模块设计
通过Wall的public类,根据x、y[19]数组和图片索引构造实现墙体的绘制,见图6-2,代码如下: }
public Wall(int a, int b, int c){ xPos = a; yPos = b;
IndexOfImage = c;
wall = new Rectangle(xPos - 10, yPos - 10, 21, 21); } /**
* 返回墙的边界 */
public Rectangle getWallBorder(){ return wall; } /**
* 返回图片索引构的值 */
public int getImageIndex(){ return IndexOfImage; }
public int getxPos(){ return xPos; }
public int getyPos(){ return yPos; }
第 24 页 共41页
24
常州大学本科生毕业设计(论文)
图6-2 墙体图
6.2.2豆子绘制模块设计
通过Gold的public类,根据x、y数组来设置中心位置和豆子的类型构造一个豆子的对象从而实现豆子的绘制,见图6-3,代码如下:
public void draw(Graphics g){ }
public Rectangle getBorder(){
图6-3使敌人丧失战斗力的大豆子和普通小豆子图片
return gold; }
g.setColor(Color.yellow); //普通的小豆子 if(goldSpecies == 1){ }
//可以使敌人失去防抗能力的大豆子 if(goldSpecies == 2){ }
g.fillOval(xPos - 4, yPos - 4, 9, 9); g.fillOval(xPos - 2, yPos - 2, 4, 4);
第 25 页 共41页
25
常州大学本科生毕业设计(论文)
6.2.3吃豆者的绘制模块设计
通过Player的public类,根据x、y数组来设置中心位置以及对吃豆者外观设置要求从而实现吃豆者的绘制,见图5-,代码如下:
public Player(){
xPos = 210; yPos = 357; xVPos = xPos; yVPos = yPos; direction = 2;
//构造一个新的 Rectangle,其左上角被指定为(xPos - 10, yPos - 5),而其宽度和高度为(11,11)。
}
public void draw(Graphics g){
int DirectionAngle = 180; g.setColor(Color.yellow); if(direction == 0)
DirectionAngle = 90; DirectionAngle = -90; DirectionAngle = 180; DirectionAngle = 0; if(direction == 1) if(direction == 2) if(direction == 3) if(dead)
第 26 页 共41页
26
player = new Rectangle(xPos - 10, yPos - 5, 11, 11); //吃豆者的初始张开角度为30度 mouthDegree = 30; //初始张合状态:张开 mouthOpen = true; speed = 2;
常州大学本科生毕业设计(论文)
DirectionAngle = 90;
//填充覆盖指定矩形的圆弧或椭圆弧。
//得到的弧由(mouthDegree + DirectionAngle)并跨越(180 - mouthDegree)角度。 //弧的中心是矩形的中心,此矩形的原点为 (xPos - 10, yPos - 10),大小为(21, 21)
g.fillArc(xPos - 10, yPos - 10, 21, 21, mouthDegree + DirectionAngle, 180 -
mouthDegree);
图6-4 吃豆者图片
6.2.4敌人绘制模块设计
通过Enemy的public类,根据x、y数组来设置中心位置,并敌人进牢笼和没进牢笼的两种状态需要有不同的颜色来以示区别的要求,来实现对敌人的绘制,代码如下:
if(gameFlow% 16 < 9){
int[] xPoints = {xPos - 5,
};
第 27 页 共41页
27
}
g.fillArc(xPos - 10, yPos - 10, 21, 21, 180 + DirectionAngle, 180 - mouthDegree);
xPos - 9, xPos - 9, xPos - 6, xPos, xPos + 6, xPos + 10, xPos + 10, xPos + 5,
相关推荐: