⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 missile.jc

📁 JILRuntime A general purpose, register based virtual machine (VM) that supports object-oriented feat
💻 JC
字号:
//------------------------------------------------------------------------------
// File: Missile.jc
//------------------------------------------------------------------------------
//
// Description:
// ------------
//  Class definition for invaders game applet.
//------------------------------------------------------------------------------

class Missile
{
    method          Missile(long imageID, long sizeX, long sizeY);
    method          Start(long x, long y, long deltaY);
    method          Move();
    method          Kill();
    method			Dispose();
    method			Link(Screen& screen);
    method			Unlink(Screen& screen);

    long            m_Alive;
    long            m_X;
    long            m_Y;
    long            m_DeltaY;
    long			m_MinY;
    long            m_MaxY;
    BitmapLayer&    m_Layer;
}

//------------------------------------------------------------------------------
// class Missile
//------------------------------------------------------------------------------
// constructor

method Missile::Missile(long imageID, long sizeX, long sizeY)
{
    m_Layer = new BitmapLayer();
    m_Layer.GroupID( kGrpMissile );
    m_Layer.Bitmap( kBitmapList[imageID] );
    m_Layer.ResizeTo(sizeX, sizeY);
    m_Alive = false;
    m_DeltaY = 0;
    m_X = 0;
    m_Y = 0;
    m_MinY = 0;
    m_MaxY = 0;

    Link( g_Applet.GameApplet::m_Screen );
}

//------------------------------------------------------------------------------
// Start
//------------------------------------------------------------------------------
//

method Missile::Start(long x, long y, long deltaY)
{
    GameApplet& game = g_Applet;
    m_Layer.MoveTo(x, y);
    m_Layer.Show();
    m_DeltaY = deltaY;
    m_Alive = true;
    m_X = x;
    m_Y = y;
    m_MinY = -m_Layer.Height();
    m_MaxY = game.m_Screen.Height();
}

//------------------------------------------------------------------------------
// Move
//------------------------------------------------------------------------------
//

method Missile::Move()
{
    if( not m_Alive )
    	return;

	// move and check bounds
	m_Layer.MoveTo(m_X, m_Y);
	m_Y += m_DeltaY;
	if( m_Y < m_MinY or m_Y >= m_MaxY )
	{
		Dispose();
		return;
	}

    GameApplet& game = g_Applet;
    Screen& screen = game.m_Screen;

	// check collisions
	for(long index = -1;;)
	{
		Layer& otherLayer = screen.LayerCollision( m_Layer, index );
		if( otherLayer == null )
			break;
		// what has been hit?
		switch( otherLayer.GroupID() )
		{
			case kGrpNothing:
			case kGrpSmallExplo:
			case kGrpBigExplo:
			{
				// fly through
				break;
			}
			case kGrpEnemy:
			{
				// if this is a player missile...
				if( m_DeltaY < 0 )
				{
					Enemy& enemy = otherLayer.User();
					game.AddScore( enemy.Score() );
					enemy.Kill();
					// kill self
					Kill();
				}
				break;
			}
			case kGrpPlayer:
			{
				// if this is a enemy missile...
				if( m_DeltaY > 0 )
				{
					Player& player = otherLayer.User();
					if( player.m_Bonus )
						game.RemoveBonusShip();
					player.Kill();
					Kill();
				}
				break;
			}
			case kGrpMissile:
			{
				Missile& missile = otherLayer.User();
				missile.Kill();
				Kill();
				break;
			}
			default:
			{
				Kill();
				break;
			}
		}
		index = otherLayer.Index();
	}
}

//------------------------------------------------------------------------------
// Kill
//------------------------------------------------------------------------------
//

method Missile::Kill()
{
    GameApplet& game = g_Applet;
    if( m_Alive )
    {
        m_Alive = false;
        m_Layer.Hide();
        game.SmallExplosion(m_X, m_Y);
    }
}

//------------------------------------------------------------------------------
// Dispose
//------------------------------------------------------------------------------
//

method Missile::Dispose()
{
    if( m_Alive )
    {
        m_Alive = false;
        m_Layer.Hide();
    }
}

//------------------------------------------------------------------------------
// Link
//------------------------------------------------------------------------------
//

method Missile::Link(Screen& screen)
{
	m_Layer.User( this );
    screen.AddLayer( m_Layer );
}

//------------------------------------------------------------------------------
// Unlink
//------------------------------------------------------------------------------
//

method Missile::Unlink(Screen& screen)
{
    m_Alive = false;
    screen.RemoveLayer( m_Layer );
    m_Layer.User( null );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -