📄 shellsprite.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
public class ShellSprite : SpriteDrawing
{
int shellWidth, shellHeight;
int formWidth, formHeight;
int launchDirection;
Image shellImg;
Form TankGame2008;
int speed;
/// <summary>
/// ShellSprite类的构造函数
/// </summary>
/// <param name="shellImg">炮弹的Image对象</param>
/// <param name="launchdirection">炮弹方向</param>
/// <param name="speed">炮弹速度</param>
/// <param name="TankGame2008">Form对象</param>
public ShellSprite(Image shellImg, int launchdirection, int speed, Form TankGame2008)
: base(shellImg, 0, 0, TankGame2008)
{
this.shellImg = shellImg;
this.launchDirection = launchdirection;
this.speed = speed;
this.TankGame2008 = TankGame2008;
formWidth = TankGame2008.Width;
formHeight = TankGame2008.Height;
shellWidth = shellImg.Width;
shellHeight = shellImg.Height;
setVisible(false);
setActive(false);
}
public override void updatePos(int SpriteDirection)
{
base.updatePos(SpriteDirection);
switch (launchDirection)
{
//left
case 0:
if (this.getX() <= (-shellWidth))
{
setVisible(false);
setActive(false);
}
else
{
this.setPos(this.getX() - speed, this.getY());
}
break;
//right
case 1:
if (this.getX() >= (formWidth + shellWidth))
{
setVisible(false);
setActive(false);
}
else
{
this.setPos(this.getX() + speed, this.getY());
}
break;
//up
case 2:
if (this.getY() <= (-shellHeight))
{
setVisible(false);
setActive(false);
}
else
{
this.setPos(this.getX(), this.getY() - speed);
}
break;
//down
case 3:
if (this.getY() >= formHeight + shellHeight)
{
setVisible(false);
setActive(false);
}
else
{
this.setPos(this.getX(), this.getY() + speed);
}
break;
}
}
public int getShellDirection()
{
return launchDirection;
}
public void setShellDirection(int direction)
{
this.launchDirection = direction;
}
public override void drawSprite(Graphics g)
{
base.drawSprite(g);
if (this.getVisible() == true)
{
g.DrawImage(shellImg, new Point(this.getX(), this.getY()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -