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

📄 invaders.jc

📁 JILRuntime A general purpose, register based virtual machine (VM) that supports object-oriented feat
💻 JC
字号:
//------------------------------------------------------------------------------
// invaders.jc
//------------------------------------------------------------------------------
//
// A simple shoot-em-up game applet for the ScriptApp application.
//
//------------------------------------------------------------------------------

// import native types

import stdlib;
import Screen;
import Bitmap;
import BitmapLayer;
import TextLayer;
import Sound;

// import project class definitions

import classes.GameApplet;
import classes.Explosion;
import classes.Missile;
import classes.Player;
import classes.Enemy;
import classes.SmallEnemy;
import classes.BossEnemy;
import classes.AttackEnemy;

//------------------------------------------------------------------------------
// global constants
//------------------------------------------------------------------------------

const long kSpace				= 32;

const long kPlayerSpeed			= 3;
const long kPlayerMissileSpeed	= -4;
const array& kEnemySpeed		= { 1, 2, 2, 3, 3 };
const long kEnemyMissileSpeed	= 4;
const long kNumberOfEnemies		= 5;
const long kNumberOfMoreEnemies	= 5;
const long kHardEnemyLimit		= 50;
const long kInitialBossHealth	= 1000;		// number of hits the BOSS can take
const long kBossLevelInterval	= 5;		// BOSS comes each 5th level
const long kBossSpeed			= 1;		// pixels per move
const long kTimeOutTicks		= 2000;		// pause after level won / game over in ms
const long kHardMissileLimit	= 5;		// max player missiles at once
const long kAttIdleTime			= 10000;	// time the attack enemy is idle

// score constants

const long kScoreMothershipHit	= 100;		// BOSS hit
const long kScoreMothership		= 1000;		// BOSS dead
const array& kEnemyScore		= { 10, 25, 50, 100, 200 };

// bitmap array

const array& kBitmapList = {
	new Bitmap( "bitmaps/background.png", false ),
	new Bitmap( "bitmaps/enemy5.png", true ),
	new Bitmap( "bitmaps/enemy4.png", true ),
	new Bitmap( "bitmaps/enemy3.png", true ),
	new Bitmap( "bitmaps/enemy2.png", true ),
	new Bitmap( "bitmaps/enemy1.png", true ),
	new Bitmap( "bitmaps/enemy6.png", true ),
	new Bitmap( "bitmaps/explo16.png", true ),
	new Bitmap( "bitmaps/explo24.png", true ),
	new Bitmap( "bitmaps/bluemissile.png", true ),
	new Bitmap( "bitmaps/redmissile.png", true ),
	new Bitmap( "bitmaps/ship.png", true ),
	new Bitmap( "bitmaps/ship2.png", true ),
	new Bitmap( "bitmaps/mothership.png", true ),
	new Bitmap( "bitmaps/shield40.png", true )
};

// sound array

const array& kSoundList = {
	new Sound( "sounds/bullet.wav", 5 ),
	new Sound( "sounds/explo.wav", 5 ),
	new Sound( "sounds/explo2.wav", 5 ),
	new Sound( "sounds/squeak.wav", 1 )
};

// bitmap array indexes

const long kBmBackground	= 0;
const long kBmEnemy1		= 1;
const long kBmEnemy2		= 2;
const long kBmEnemy3		= 3;
const long kBmEnemy4		= 4;
const long kBmEnemy5		= 5;
const long kBmAttackEnemy	= 6;
const long kBmExplo16		= 7;
const long kBmExplo24		= 8;
const long kBmBlueMissile	= 9;
const long kBmRedMissile	= 10;
const long kBmShip			= 11;
const long kBmShip2			= 12;
const long kBmMothership	= 13;
const long kBmShield		= 14;

// sound array indexes

const long kSndBullet		= 0;
const long kSndExplo		= 1;
const long kSndExplo2		= 2;
const long kSndSqueak		= 3;

// runmode constants

const long kModeInit		= 0;	// (re)start at level 1
const long kModeStart		= 1;	// start next level
const long kModeContinue	= 2;	// run game loop
const long kModeTimeOut		= 3;	// run game loop w/ timeout
const long kModeNextLevel	= 4;	// init next level, then -> continue
const long kModeGameOver	= 5;	// de-init, then -> init
const long kModeWait		= 6;	// wait for user key press

// attack enemy modes

const long kAttIdle			= 0;
const long kAttAttack		= 1;
const long kAttFlee			= 2;

// "sprite" group ID's

const long kGrpNothing		= 0;
const long kGrpPlayer		= 1;
const long kGrpEnemy		= 2;
const long kGrpMissile		= 3;
const long kGrpBigExplo		= 4;
const long kGrpSmallExplo	= 5;
const long kGrpShield		= 6;

const string kCredits =
	"The Jewel user interface framework\n"
	"and JewelScript language\n"
	"are beeing developed by www.jewe.org\n\n"
	"Thanks to Ari Feldman\n"
	"for his free SpriteLib graphics\n\n"
	"Press SPACE to continue";

//------------------------------------------------------------------------------
// global reference to our applet
//------------------------------------------------------------------------------
// This allows us to store a reference to our GameApplet as a global variable.
// Several classes need access to our applet, and this is the most convenient
// way to do it.

var& g_Applet = null;

//------------------------------------------------------------------------------
// function CreateApplet
//------------------------------------------------------------------------------
// The Application calls this function to create our applet.
// We need to implement this function and return an instance of our applet.

function Applet& CreateApplet(Screen& screen)
{
	g_Applet = new GameApplet( screen );
	return g_Applet;
}

//------------------------------------------------------------------------------
// function XToPan
//------------------------------------------------------------------------------
// Helper function to compute a panpot value from an x coord.

function long XToPan(long x)
{
	return (x - 320) * 3;
}

⌨️ 快捷键说明

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