?? gamemain.java
字號:
/*
* Created on 2005-02-10
*
* Main class where all game play stuff happens
*
*/
//package com.nano.KangooJumper;
import javax.microedition.lcdui.*;
/**
* @author plumkawka
*
*/
public class GameMain extends TiledScreen
{
private int PosY = 120;
private int MenuIndex = 1;
private Main game;
private int[] tileTimeTable = null;
private int[] monkeyTime = null;
private int[] aFlares = null;
private int[] tabStars;
private int countFlares;
public Sprite sprKangoo;
private Sprite[] sprPelican;
private Sprite[] sprCrab;
public Sprite[] sprBonuses;
private Sprite[] sprMonkey;
private int countMonkey;
//private int[] dirPelican;
private Image iPelicanRight, iPelicanLeft, iPanel, iFlare, iCrab, iStar, iMonkey;
public Image iBonus5, iBonus10, iBonusLife, iBonusSlow, menubox1, arrow004;
public Image imgSub[] = new Image[4];
private int heroX, heroY;
private int oldHeroX, oldHeroY;
private long scrollStartTime, scrollMessageTime, scrollLastTime;
private int scrollY, scrollMessageWidth, scrollMiddle,scrollPause;
private long respawnTime, bonusTimeExpire, nextMove, leafChange;
private String sMessage, sScrollMessage;
private boolean canPlay, levelPrepared, bSlowMode, bFastMode, bFinished, bHitByPelican, bHitByMonkey;
private Image iDigits;
private int digitsWidth, digitsHeight;
private int levelSpeed;
long tempo =0;
private int ANIM_KANGOO_STANDS[] = {0,0,0,1,1,1,2,2,2};
private int ANIM_KANGOO_JUMP_FORWARD[] = {1,3,4,5,5,5,5,5,5,4,3,1};
private int ANIM_KANGOO_JUMP_LEFT[] = {18,19,20,21,21,21,21,21,21,20,19,18};
private int ANIM_KANGOO_JUMP_RIGHT[]={14,15,16,17,17,17,17,17,17,16,15,14};
private int ANIM_KANGOO_JUMP_LEFT_UP[]={10,11,12,13,13,12,11,10};
private int ANIM_KANGOO_JUMP_RIGHT_UP[]={6,7,8,9,9,8,7,6};
private int ANIM_KANGOO_DROWNS[]={22,22,23,23,23,24,24,24, -1,-1,-1,-1};
private int ANIM_PELICAN_RIGHT[]={0,1,2,3,4};
private int ANIM_BONUS[]={0,1,2,3,4};
private int ANIM_CRAB[]={0,1,2,3,4,5,6,6,6,6,6,6,6,6,6,6,6,5,4,3,2,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
private int ANIM_MONKEY_TO_RIGHT[] = {3,3,3,4,4,4,5,5,5};
private int ANIM_MONKEY_TO_LEFT[] = {0,0,0,1,1,1,2,2,2};
private MenuList SubMenuOptions;
private String[] sSubOptions;
public boolean bDisplaySubMenu = false;
//private static SoundManager snd;
private static SoundManager6600 snd;
//private static SoundManagerEmpty snd;
GameMain(Main g)
{
game = g;
}
/**
*
* loads all data that doesn't need to be free'd between levels
*
*/
public void init(int part)
{
sMessage = "";
if (part == 0)
{
try{
menubox1 = Image.createImage("/000.png");
arrow004 = Image.createImage("/004.png");
imgSub[0] = Image.createImage("/resume.png");
imgSub[1] = Image.createImage("/restart.png");
imgSub[2] = Image.createImage("/mainmenu.png");
imgSub[3] = Image.createImage("/main7.png");
}
catch(Exception e)
{
}
if (SubMenuOptions == null)
{
if (sSubOptions == null)
sSubOptions = Utils.readUTFStrings("/submenu.utf8");
SubMenuOptions = new MenuList(game.writer,
game.writerDisabled, sSubOptions,
(Config.SCREEN_WIDTH - Config.SUBMENU_WIDTH) >> 1,
(Config.SCREEN_HEIGHT - Config.SUBMENU_HEIGHT) >> 1,
Config.SUBMENU_WIDTH, Config.SUBMENU_HEIGHT, 1);
SubMenuOptions.bDrawRectangle = true;
SubMenuOptions.iBackImage = game.iBackg;
SubMenuOptions.setSelectedLine(0);
}
_tileset = Utils.LoadImage(FileIds.TILES_PNG);
iPelicanRight = Utils.LoadImage(FileIds.PELICAN2_PNG);
iPelicanLeft = Utils.LoadImage(FileIds.PELICAN1_PNG);
iPanel = Utils.LoadImage(FileIds.PANEL_PNG);
iMonkey = Utils.LoadImage(FileIds.MONKEY_PNG);
}
else
if (part == 1)
{
iBonus5 = Utils.LoadImage(FileIds.BONUS5_PNG);
iBonus10 = Utils.LoadImage(FileIds.BONUS10_PNG);
iBonusLife = Utils.LoadImage(FileIds.BONUSLIFE_PNG);
iBonusSlow = Utils.LoadImage(FileIds.BONUSSLOW_PNG);
}
else
if (part == 2)
{
iFlare = Utils.LoadImage(FileIds.FLARE_PNG);
iStar = Utils.LoadImage(FileIds.STAR_PNG);
iCrab = Utils.LoadImage(FileIds.CRAB_PNG);
sprKangoo = new Sprite(FileIds.KANGOO_PNG, Config.SPR_KANGOO_WIDTH, Config.SPR_KANGOO_HEIGHT);
iDigits = Utils.LoadImage(FileIds.CYFRY_PNG);
digitsWidth = iDigits.getWidth() / 10;
digitsHeight= iDigits.getHeight();
snd = game.snd;
// initialize tables so the stars are behind screen
tabStars = new int[Config.GAME_STARS_COUNT * 3];
for (int a=0; a<Config.GAME_STARS_COUNT; a++)
{
int ofs = a * 3;
tabStars[ofs + 0] = Math.Rand(0, Config.GAME_STARS_TIME);
tabStars[ofs + 1] = -50;//- 3 + Math.Rand(0, 16 + 6);
tabStars[ofs + 2] = -50;//- 3 + Math.Rand(0, 16 + 6);
}
}
}
void reset()
{
}
public int getXTileCenter(int x)
{
return (x * Config.TILE_WIDTH) + Config.SPR_KANGOO_OFFSETX;
}
public int getYTileCenter(int y)
{
return (y * Config.TILE_HEIGHT) + Config.SPR_KANGOO_OFFSETY;
}
public void setScroll(String s)
{
sScrollMessage = s;
scrollMessageWidth = game.writer.strLen(sScrollMessage);
scrollMessageTime = game.getTime() + Config.SCROLL_TIME + Config.SCROLL_TIME_PAUSE;
scrollPause = ((Config.SCREEN_WIDTH + scrollMessageWidth) << 16) / (Config.SCROLL_TIME + Config.SCROLL_TIME_PAUSE);
scrollPause = (scrollPause * Config.SCROLL_TIME_PAUSE) >> 16;
scrollMiddle = Config.SCREEN_WIDTH_HALF + (scrollMessageWidth >> 1) + 10;
}
/**
* initializes the game, frees all previous data and loads wished level Also
* generates a random background
*
* @param nr
* level number ("/level0"+nr+".mob")
*/
public void startLevel(int nr)
{
int x,y;
levelPrepared = false;
// clear old data
tileTimeTable = null;
aFlares = null;
monkeyTime = null;
if (countPelican !=0)
{
for (int i=0; i<countPelican; i++)
sprPelican[i] = null;
sprPelican = null;
}
if (countCrab != 0)
{
for (int i=0; i<countCrab; i++)
sprCrab[i] = null;
sprCrab = null;
}
if (countMonkey != 0)
{
for (int i=0; i<countMonkey; i++)
sprMonkey[i] = null;
sprMonkey = null;
}
sprKangoo.reset();
sprKangoo.setFrameSequenceTotalTime(ANIM_KANGOO_STANDS, Sprite.PONG, 1000);
Utils.callGcShort();
// speed up the scrolling speed according to the level number
levelSpeed = Config.GAME_KANGOO_MOVE_TIME + (Config.GAME_KANGOO_MOVE_TIME >> 1) - (nr * 10);
scrollLastTime = 0;
scrollStartTime = 0;
respawnTime = 0;
sMessage = sScrollMessage = "";
tileTimeTable = null;
Utils.callGcShort();
loadLevel(game.nPlayerLevel);
redrawTiledScreen();
scrollY = 0;
tempo = 0;
bDisplaySubMenu = false;
scrollScreenAbsoluteY( mapHeightPix - Config.TILED_SCREEN_HEIGHT - scrollY);
//
// pelican!
//
sprPelican = new Sprite[countPelican];
for (int i=0; i<countPelican; i++)
{
// from which side?
if (Math.Rand(0, 100) > 50)
{
// from left to right
sprPelican[i] = new Sprite(iPelicanRight, Config.SPR_PELICAN_WIDTH, Config.SPR_PELICAN_HEIGHT);
sprPelican[i].posX = - (Math.Rand(1, 5) * Config.TILE_WIDTH) + Config.SPR_PELICAN_OFFSETX;
sprPelican[i].dir = Config.DIR_RIGHT;
}
else
{
// from right to left
sprPelican[i] = new Sprite(iPelicanLeft, Config.SPR_PELICAN_WIDTH, Config.SPR_PELICAN_HEIGHT);
sprPelican[i].posX = Config.SCREEN_WIDTH + (Math.Rand(1, 5) * Config.TILE_WIDTH) + Config.SPR_PELICAN_OFFSETX;
sprPelican[i].dir = Config.DIR_LEFT;
}
sprPelican[i].setFrameSequenceTotalTime(ANIM_PELICAN_RIGHT,Sprite.FORWARD_LOOP, 1000);
boolean ok = false;
y = 0;
int mapy = 0;
while (!ok)
{
ok = true;
mapy = Math.Rand(2, mapHeight - 2);
y = ((mapy - mapMaxOffsetY) * Config.TILE_HEIGHT) + Config.SPR_PELICAN_OFFSETY + Config.TILED_SCREEN_OFFSETY;
for (int j=0; j<i; j++)
if (sprPelican[j].mapY == mapy)
ok = false;
}
//Utils.Log(y);
sprPelican[i].posY = y;
sprPelican[i].mapY = mapy;
}
//
// monkey!
//
if (nr < 5)
countMonkey = 0;
else
{
countMonkey = (nr - 5) / 5;
}
sprMonkey = new Sprite[countMonkey];
monkeyTime = new int[countMonkey];
for (int i=0; i<countMonkey; i++)
{
monkeyTime[i] = Math.Rand(0, 10) * 500;
sprMonkey[i] = new Sprite(iMonkey, Config.SPR_MONKEY_WIDTH, Config.SPR_MONKEY_HEIGHT);
// from which side?
if (Math.Rand(0, 100) > 50)
{
// from left to right
sprMonkey[i].posX = 0 - Config.SPR_MONKEY_OFFSETX;
sprMonkey[i].mapX = 0;
sprMonkey[i].dir = Config.DIR_RIGHT;
sprMonkey[i].setFrame(3);
}
else
{
// from right to left
sprMonkey[i].posX = Config.SCREEN_WIDTH - Config.SPR_MONKEY_WIDTH + Config.SPR_MONKEY_OFFSETX;
sprMonkey[i].mapX = Config.GAME_LEVEL_WIDTH - 1;
sprMonkey[i].dir = Config.DIR_LEFT;
sprMonkey[i].setFrame(0);
}
boolean ok = false;
y = 0;
int mapy = 0;
while (!ok)
{
ok = true;
mapy = Math.Rand(2, mapHeight - 2);
y = ((mapy - mapMaxOffsetY) * Config.TILE_HEIGHT) + Config.SPR_MONKEY_OFFSETY + Config.TILED_SCREEN_OFFSETY;
// check with other monkeys
for (int j=0; j<i; j++)
if (sprMonkey[j].mapY == mapy)
ok = false;
// check with pelicans
for (int j=0; j<countPelican; j++)
if (sprPelican[j].mapY == mapy)
ok = false;
// must be a platform right there
if (getTile(sprMonkey[i].mapX, mapy) == Config.TILE_WATER)
ok = false;
}
//Utils.Log(y);
sprMonkey[i].posY = y;
sprMonkey[i].mapY = mapy;
}
boolean bFoundAPlace = false;
int a;
//
// flares
//
countFlares = countWater / 4;
aFlares = new int[countFlares * 3];
for (a=0; a<countFlares; a++)
{
int ofs = a * 3;
aFlares[ofs + 2] = 0;
}
//
// bonuses
//
int cntall = countBonus5 + countBonus10 + countBonusSlow + countBonusLife;
sprBonuses = new Sprite[cntall];
for (a=0; a<cntall; a++)
{
bFoundAPlace = false;
x = 0; y = 0;
while (bFoundAPlace == false)
{
x = Math.Rand(mapWidth - 1);
y = Math.Rand(2, mapHeight - 2);
//Utils.Log(x+", "+y);
// check type of map pos
int tile = getTile(x, y);
if ((tile != Config.TILE_FINISH) && (tile != Config.TILE_START) &&
(tile != Config.TILE_WATER))
bFoundAPlace = true;
// check for other bonuses
for (int b=0; b<a; b++)
if ((sprBonuses[b].mapX == x) && (sprBonuses[b].mapY == y))
bFoundAPlace = false;
}
// calc the type
Image image = null;
int type = 0;
if (a < countBonus5)
{
image = iBonus5;
type = Config.SPR_TYPE_BONUS5;
}
else
if ((a >= countBonus5) && (a < (countBonus5 + countBonus10)))
{
image = iBonus10;
type = Config.SPR_TYPE_BONUS10;
}
else
if ((a >= (countBonus5 + countBonus10)) && (a < (countBonus5 + countBonus10 + countBonusSlow)))
{
image = iBonusSlow;
type = Config.SPR_TYPE_BONUSSLOW;
}
else
if ((a >= (countBonus5 + countBonus10 + countBonusSlow)) && (a < (countBonus5 + countBonus10 + countBonusSlow + countBonusLife)))
{
image = iBonusLife;
type = Config.SPR_TYPE_BONUSLIFE;
}
if (image != null)
{
sprBonuses[a] = new Sprite(image, Config.SPR_BONUS_WIDTH, Config.SPR_BONUS_HEIGHT);
sprBonuses[a].setFrameSequenceTotalTime(ANIM_BONUS, Sprite.FORWARD_LOOP, Config.GAME_BONUS_ANIM_TIME);
sprBonuses[a].m_playbackStartTime += Math.Rand(0, Config.GAME_BONUS_ANIM_TIME);
sprBonuses[a].posX = (x * Config.TILE_WIDTH) + Config.SPR_BONUS_OFFSETX;
sprBonuses[a].posY = ((y - mapMaxOffsetY) * Config.TILE_HEIGHT) +
Config.SPR_BONUS_OFFSETY + Config.TILED_SCREEN_OFFSETY;
sprBonuses[a].mapX = x;
sprBonuses[a].mapY = y;
sprBonuses[a].type = type;
}
else
Utils.Log("bonus sprite zero!!!");
}
//
// crab!
//
sprCrab = new Sprite[countCrab];
for (int i=0; i<countCrab; i++)
{
bFoundAPlace = false;
x = 0; y = 0;
int tile = -1;
while (bFoundAPlace == false)
{
x = Math.Rand(mapWidth - 1);
y = Math.Rand(2, mapHeight - 2);
//Utils.Log(x+", "+y);
// check type of map pos
tile = getTile(x, y);
if (tile >= Config.TILE_GROUND1)
bFoundAPlace = true;
// check for other crabs
for (int b=0; b<i; b++)
if ((sprCrab[b].mapX == x) && (sprCrab[b].mapY == y))
bFoundAPlace = false;
// and for bonuses - you cant have a bonus item and a crab on the same isle
for (int b=0; b<cntall; b++)
if ((sprBonuses[b].mapX == x) && (sprBonuses[b].mapY == y))
bFoundAPlace = false;
}
int ofsx = 0;
int ofsy = 0;
switch (tile)
{
case Config.TILE_GROUND1:
ofsx = Config.SPR_CRAB_OFFSETX1;
ofsy = Config.SPR_CRAB_OFFSETY1;
break;
case Config.TILE_GROUND2:
ofsx = Config.SPR_CRAB_OFFSETX2;
ofsy = Config.SPR_CRAB_OFFSETY2;
break;
case Config.TILE_GROUND3:
ofsx = Config.SPR_CRAB_OFFSETX3;
ofsy = Config.SPR_CRAB_OFFSETY3;
break;
case Config.TILE_GROUND4:
ofsx = Config.SPR_CRAB_OFFSETX4;
ofsy = Config.SPR_CRAB_OFFSETY4;
break;
}
sprCrab[i] = new Sprite(iCrab, Config.SPR_CRAB_WIDTH, Config.SPR_CRAB_HEIGHT);
sprCrab[i].setFrameSequenceTotalTime(ANIM_CRAB, Sprite.FORWARD_LOOP, Config.GAME_CRAB_ANIM_TIME);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -