|
|  |
DownLoad LoadRunner.lzh(ソースコード付き)
import java.applet.Applet;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.ImageObserver;
import java.net.MalformedURLException;
import java.net.URL;
public class CLodeRunner extends Applet
implements KeyListener, Runnable
{
public CLodeRunner()
{
CellWidth = 16;
CellHeight = 16;
ImageLoaded = false;
step_right = false;
step_left = false;
step_up = false;
step_down = false;
step_hit = false;
}
public void ResetAllMovements()
{
step_left = false;
step_right = false;
step_up = false;
step_down = false;
step_hit = false;
}
public void destroy()
{
timer = null;
}
public boolean imageUpdate(Image image, int i, int j, int k, int l, int i1)
{
if(i == 32)
{
ImageLoaded = true;
repaint();
return false;
} else
{
return true;
}
}
public void init()
{
timer = null;
new_level = true;
game_over = false;
images = new Image[49];
engine = new CEngine();
engine.SetCellParam(CellWidth, CellHeight);
try
{
images[0] = getImage(new URL(getCodeBase(), "images/wall.gif"));
images[1] = getImage(new URL(getCodeBase(), "images/wall.gif"));
images[2] = getImage(new URL(getCodeBase(), "images/wall_beton.gif"));
images[3] = getImage(new URL(getCodeBase(), "images/staircase.gif"));
images[4] = getImage(new URL(getCodeBase(), "images/box.gif"));
images[5] = getImage(new URL(getCodeBase(), "images/rope.gif"));
images[6] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[7] = getImage(new URL(getCodeBase(), "images/man_left1.gif"));
images[8] = getImage(new URL(getCodeBase(), "images/man_left2.gif"));
images[9] = getImage(new URL(getCodeBase(), "images/man_left3.gif"));
images[10] = getImage(new URL(getCodeBase(), "images/man_right1.gif"));
images[11] = getImage(new URL(getCodeBase(), "images/man_right2.gif"));
images[12] = getImage(new URL(getCodeBase(), "images/man_right3.gif"));
images[13] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[14] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[15] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[16] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[17] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[18] = getImage(new URL(getCodeBase(), "images/man.gif"));
images[19] = getImage(new URL(getCodeBase(), "images/man_rope_left1.gif"));
images[20] = getImage(new URL(getCodeBase(), "images/man_rope_left2.gif"));
images[21] = getImage(new URL(getCodeBase(), "images/man_rope_left3.gif"));
images[22] = getImage(new URL(getCodeBase(), "images/man_rope_right1.gif"));
images[23] = getImage(new URL(getCodeBase(), "images/man_rope_right2.gif"));
images[24] = getImage(new URL(getCodeBase(), "images/man_rope_right3.gif"));
images[25] = getImage(new URL(getCodeBase(), "images/pit1.gif"));
images[26] = getImage(new URL(getCodeBase(), "images/pit2.gif"));
images[27] = getImage(new URL(getCodeBase(), "images/pit3.gif"));
images[28] = getImage(new URL(getCodeBase(), "images/pit4.gif"));
images[29] = getImage(new URL(getCodeBase(), "images/pit5.gif"));
images[30] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[31] = getImage(new URL(getCodeBase(), "images/enemy_left1.gif"));
images[32] = getImage(new URL(getCodeBase(), "images/enemy_left2.gif"));
images[33] = getImage(new URL(getCodeBase(), "images/enemy_left3.gif"));
images[34] = getImage(new URL(getCodeBase(), "images/enemy_right1.gif"));
images[35] = getImage(new URL(getCodeBase(), "images/enemy_right2.gif"));
images[36] = getImage(new URL(getCodeBase(), "images/enemy_right3.gif"));
images[37] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[38] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[39] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[40] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[41] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[42] = getImage(new URL(getCodeBase(), "images/enemy.gif"));
images[43] = getImage(new URL(getCodeBase(), "images/enemy_rope_left1.gif"));
images[44] = getImage(new URL(getCodeBase(), "images/enemy_rope_left2.gif"));
images[45] = getImage(new URL(getCodeBase(), "images/enemy_rope_left3.gif"));
images[46] = getImage(new URL(getCodeBase(), "images/enemy_rope_right1.gif"));
images[47] = getImage(new URL(getCodeBase(), "images/enemy_rope_right2.gif"));
images[48] = getImage(new URL(getCodeBase(), "images/enemy_rope_right3.gif"));
}
catch(MalformedURLException _ex) { }
Dimension dimension = getSize();
width = dimension.width;
height = dimension.height;
BackBuffer = createImage(width, height);
BackBufferGC = BackBuffer.getGraphics();
for(int i = 0; i < 49; i++)
BackBufferGC.drawImage(images[i], 0, 0, this);
addKeyListener(this);
requestFocus();
level_num = 1;
new_level = true;
new_level_counter = 100;
}
public void keyPressed(KeyEvent keyevent)
{
int i = keyevent.getKeyCode();
if(i == 0)
i = keyevent.getKeyCode();
if(i == 37)
step_left = true;
else
if(i == 39)
step_right = true;
else
if(i == 38)
step_up = true;
else
if(i == 40)
step_down = true;
else
if(i == 32)
step_hit = true;
}
public void keyReleased(KeyEvent keyevent)
{
}
public void keyTyped(KeyEvent keyevent)
{
}
public void paint(Graphics g)
{
Graphics g1 = g;
g = BackBufferGC;
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
if(!ImageLoaded)
{
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
g.setFont(new Font("TimesRoman", 1, 24));
g.setColor(Color.white);
g.drawString("Loading game...", 190, 175);
for(int i = 0; i < 49; i++)
g.drawImage(images[i], 0, 0, this);
g.setColor(Color.black);
g.fillRect(0, 0, 16, 16);
g1.drawImage(BackBuffer, 0, 0, null);
return;
}
if(game_over)
{
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
g.setFont(new Font("TimesRoman", 1, 24));
g.setColor(Color.white);
g.drawString("Game Over", 200, 160);
g.drawString("Your Score: " + engine.score, 180, 185);
g1.drawImage(BackBuffer, 0, 0, null);
ResetAllMovements();
game_over_counter--;
if(game_over_counter <= 0)
{
engine.Init();
game_over = false;
level_num = 1;
new_level = true;
new_level_counter = 100;
}
return;
}
if(new_level)
{
new_level_counter--;
if(new_level_counter <= 0)
{
new_level = false;
try
{
level_base = new URL(getCodeBase(), "levels/level" + level_num + ".dat");
}
catch(MalformedURLException _ex) { }
try
{
engine.Engine_Start(level_base);
}
catch(Exception _ex) { }
}
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
g.setFont(new Font("TimesRoman", 1, 24));
g.setColor(Color.white);
g.drawString("Level " + level_num, 220, 175);
g1.drawImage(BackBuffer, 0, 0, null);
ResetAllMovements();
return;
}
for(int j = 0; j < 22; j++)
{
for(int k = 0; k < 32; k++)
if(!engine.level.ObjectInPit(k, j))
{
byte byte0 = engine.level.GetXY(k, j);
if(byte0 > 0 && byte0 < 7)
g.drawImage(images[byte0 - 1], k * CellWidth, j * CellHeight, this);
}
}
for(CPit cpit = engine.level.pits; cpit != null; cpit = cpit.next)
if(cpit.sprite_num > 0)
g.drawImage(images[24 + cpit.sprite_num], cpit.x * CellWidth, cpit.y * CellHeight, this);
g.setXORMode(getForeground());
if(engine.man.GetDirection() == 4)
g.drawImage(images[6], engine.man.GetPosX(), engine.man.GetPosY(), this);
else
if(((CHuman) (engine.man)).onRope && engine.man.GetDirection() < 2)
g.drawImage(images[19 + engine.man.GetDirection() * 3 + engine.man.GetSpriteNum()], engine.man.GetPosX(), engine.man.GetPosY(), this);
else
g.drawImage(images[7 + engine.man.GetDirection() * 3 + engine.man.GetSpriteNum()], engine.man.GetPosX(), engine.man.GetPosY(), this);
for(int l = 0; l < engine.level.total_enemy; l++)
{
boolean flag = true;
for(int i1 = 0; i1 < l; i1++)
{
if(engine.enemies[l].GetPosX() != engine.enemies[i1].GetPosX() || engine.enemies[l].GetPosY() != engine.enemies[i1].GetPosY())
continue;
flag = false;
break;
}
if(flag)
if(engine.enemies[l].GetDirection() == 4)
g.drawImage(images[30], engine.enemies[l].GetPosX(), engine.enemies[l].GetPosY(), this);
else
if(((CHuman) (engine.enemies[l])).onRope && engine.enemies[l].GetDirection() < 2)
g.drawImage(images[43 + engine.enemies[l].GetDirection() * 3 + engine.enemies[l].GetSpriteNum()], engine.enemies[l].GetPosX(), engine.enemies[l].GetPosY(), this);
else
g.drawImage(images[31 + engine.enemies[l].GetDirection() * 3 + engine.enemies[l].GetSpriteNum()], engine.enemies[l].GetPosX(), engine.enemies[l].GetPosY(), this);
}
g.setPaintMode();
g.setColor(Color.white);
g.setFont(new Font("TimesRoman", 0, 12));
g.drawString("Score: " + engine.score + " Lives: " + engine.lives + " Level: " + level_num, 0, 362);
g1.drawImage(BackBuffer, 0, 0, null);
}
public void run()
{
do
{
if(!engine.DoCalculations())
{
if(engine.hero_is_dead)
{
engine.lives--;
if(engine.lives <= 0)
{
game_over = true;
game_over_counter = 100;
new_level = true;
repaint();
}
try
{
engine.Engine_Start(level_base);
}
catch(Exception _ex) { }
}
if(engine.level_is_complete)
{
engine.started = false;
engine.level_is_complete = false;
level_num++;
new_level = true;
new_level_counter = 100;
if(level_num > 50)
{
game_over = true;
game_over_counter = 100;
level_num = 1;
repaint();
}
}
if(!game_over && !new_level)
{
if(step_left)
{
step_left = false;
engine.StepLeft();
}
if(step_right)
{
step_right = false;
engine.StepRight();
}
if(step_up)
{
step_up = false;
engine.StepUp();
}
if(step_down)
{
step_down = false;
engine.StepDown();
}
if(step_hit)
{
step_hit = false;
engine.Hit();
}
}
} else
{
ResetAllMovements();
}
repaint();
try
{
Thread.currentThread();
Thread.sleep(40L);
}
catch(InterruptedException _ex) { }
} while(true);
}
public void start()
{
timer = new Thread(this);
timer.start();
}
public void stop()
{
timer = null;
}
public void update(Graphics g)
{
paint(g);
}
protected int CellWidth;
protected int CellHeight;
protected int width;
protected int height;
protected Image images[];
protected Image BackBuffer;
protected Graphics BackBufferGC;
protected boolean ImageLoaded;
protected URL level_base;
protected int level_num;
protected boolean new_level;
protected int new_level_counter;
protected boolean game_over;
protected int game_over_counter;
boolean step_right;
boolean step_left;
boolean step_up;
boolean step_down;
boolean step_hit;
CEngine engine;
Thread timer;
}
import java.net.URL;
public class CEngine
{
public CEngine()
{
man = new CMan();
level = new CLevel();
Init();
}
public boolean DoCalculations()
{
if(!started)
return false;
score += ((CHuman) (man)).number_of_boxes_score * 250;
man.number_of_boxes_score = 0;
for(int i = 0; i < level.total_enemy; i++)
{
score += enemies[i].total_in_pits * 125;
enemies[i].total_in_pits = 0;
}
level.DoPitTick();
man.RecalculateData();
tick++;
if(tick == 2)
{
for(int j = 0; j < level.total_enemy; j++)
{
enemies[j].AutomaticalStep(level, ((CHuman) (man)).m_pos_x_cell, ((CHuman) (man)).m_pos_y_cell);
enemies[j].DoCalculations(level);
enemies[j].RecalculateData();
if(((CHuman) (enemies[j])).m_pos_x_cell == ((CHuman) (man)).m_pos_x_cell && ((CHuman) (enemies[j])).m_pos_y_cell == ((CHuman) (man)).m_pos_y_cell)
man.is_dead = true;
}
tick = 0;
}
boolean flag = man.DoCalculations(level);
if(((CHuman) (man)).is_dead)
hero_is_dead = true;
if(man.CheckLevelIsComplete(level))
level_is_complete = true;
return flag;
}
public void Engine_Start(URL url)
throws Exception
{
level = new CLevel();
hero_is_dead = false;
level.pits = null;
level_is_complete = false;
man.number_of_boxes = 0;
man.number_of_boxes_score = 0;
level.LoadFromFile(url);
man.is_dead = false;
enemies = new CEnemy[4];
for(int i = 0; i < level.total_enemy; i++)
{
enemies[i] = new CEnemy();
enemies[i].SetPosition(level.enemy_coords[i][0] * cell_width, level.enemy_coords[i][1] * cell_height);
enemies[i].cell_width = cell_width;
enemies[i].cell_height = cell_height;
}
man.SetPosition(level.GetManX() * cell_width, level.GetManY() * cell_height);
started = false;
}
public void Hit()
{
started = true;
man.Hit(level);
}
public void Init()
{
tick = 0;
score = 0;
lives = 10;
hero_is_dead = false;
level_is_complete = false;
started = false;
}
public void SetCellParam(int i, int j)
{
cell_width = i;
cell_height = j;
level.cell_width = i;
level.cell_height = j;
man.cell_width = i;
man.cell_height = j;
}
public void StepDown()
{
started = true;
man.StepDown(level);
}
public void StepLeft()
{
started = true;
man.StepLeft(level);
}
public void StepRight()
{
started = true;
man.StepRight(level);
}
public void StepUp()
{
started = true;
man.StepUp(level);
}
public CMan man;
public CEnemy enemies[];
public CLevel level;
public int cell_width;
public int cell_height;
protected int tick;
public int lives;
public int score;
public boolean hero_is_dead;
public boolean level_is_complete;
public boolean started;
}
public class CHuman
{
public CHuman()
{
max_sprites = 3;
sprite_num = 0;
direction = 4;
m_only_one_cell = true;
m_only_one_cell_updown = true;
m_only_one_cell_leftright = true;
onRope = false;
number_of_boxes = 0;
in_the_fly = false;
man_type = 0;
is_dead = false;
in_pit = false;
}
public void CheckBounds(CLevel clevel)
{
if(m_pos_x < 0)
m_pos_x = 0;
if(m_pos_y < 0)
m_pos_y = 0;
if(m_pos_x >= cell_width * (clevel.level_width - 1))
m_pos_x = cell_width * (clevel.level_width - 1);
if(m_pos_y >= cell_height * (clevel.level_height - 1))
m_pos_y = cell_height * (clevel.level_height - 1);
}
public boolean DoCalculations(CLevel clevel)
{
in_the_fly = false;
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if(is_dead && man_type == 1)
{
int ai[][] = new int[32][2];
for(int j = 0; j < 22; j++)
{
int i = 0;
for(int k = 0; k < 32; k++)
{
byte byte0 = clevel.GetXY(k, j);
if(byte0 == 0 || byte0 == 4 || byte0 == 5 || byte0 == 6 || byte0 == 7)
{
ai[i][0] = k;
ai[i][1] = j;
i++;
}
}
if(i <= 0)
continue;
int l = (int)(Math.random() * (double)i);
m_pos_x = ai[l][0] * 16;
m_pos_y = ai[l][1] * 16;
break;
}
is_dead = false;
in_pit = false;
RecalculateData();
return false;
}
if(byte1 == 1)
{
is_dead = true;
return false;
}
if(in_pit)
return false;
if(byte1 == 5 && m_only_one_cell_updown)
if(man_type == 0)
{
number_of_boxes++;
number_of_boxes_score++;
clevel.SetXY(m_pos_x_cell, m_pos_y_cell, (byte)0);
if(number_of_boxes == clevel.GetBoxNumber())
clevel.Finishing();
} else
if(number_of_boxes == 0 && (int)(Math.random() * 5D) == 0)
{
number_of_boxes++;
clevel.SetXY(m_pos_x_cell, m_pos_y_cell, (byte)0);
}
if(byte1 == 6 && m_only_one_cell_leftright)
{
onRope = true;
return false;
}
onRope = false;
m_pos_x += cell_width - 1;
m_pos_y += cell_height;
RecalculateData();
byte byte2 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_x -= cell_width - 1;
m_pos_y -= cell_height;
RecalculateData();
if(m_pos_y_cell == clevel.level_height - 1)
return false;
m_pos_y += cell_height;
RecalculateData();
byte byte3 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if((byte3 == 0 || byte3 == 2 || byte3 == 5 || byte3 == 6 || byte3 == 7) && byte1 != 4 && (byte2 == 0 || byte2 == 2 || byte2 == 5 || byte2 == 6 || byte2 == 7))
{
m_pos_y -= cell_height;
m_pos_y += cell_height / 4;
CheckBounds(clevel);
direction = 4;
in_the_fly = true;
return true;
} else
{
m_pos_y -= cell_height;
RecalculateData();
return false;
}
}
public int GetDirection()
{
return direction;
}
public int GetPosX()
{
return m_pos_x;
}
public int GetPosY()
{
return m_pos_y;
}
public int GetSpriteNum()
{
return sprite_num;
}
public void Hit(CLevel clevel)
{
int i = m_pos_x;
int j = m_pos_y;
RecalculateData();
if(direction == 0)
{
if(m_pos_x != m_pos_x_cell * cell_width)
m_pos_x = (m_pos_x_cell + 1) * cell_width;
CheckBounds(clevel);
RecalculateData();
byte byte0 = clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell + 1);
byte byte2 = clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell);
if(byte0 == 1 && (byte2 == 0 || byte2 == 6 || byte2 == 7))
{
clevel.AddNewPit(m_pos_x_cell - 1, m_pos_y_cell + 1);
} else
{
m_pos_x = i;
m_pos_y = j;
RecalculateData();
return;
}
} else
if(direction == 1)
{
if(m_pos_x != m_pos_x_cell * cell_width)
m_pos_x = m_pos_x_cell * cell_width;
CheckBounds(clevel);
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell + 1);
byte byte3 = clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell);
if(byte1 == 1 && (byte3 == 0 || byte3 == 6 || byte3 == 7))
{
clevel.AddNewPit(m_pos_x_cell + 1, m_pos_y_cell + 1);
} else
{
m_pos_x = i;
m_pos_y = j;
RecalculateData();
return;
}
}
}
protected void IncreaseSprite()
{
sprite_num++;
if(sprite_num >= max_sprites)
sprite_num = 0;
}
public void RecalculateData()
{
m_pos_x_cell = m_pos_x / cell_width;
m_pos_y_cell = m_pos_y / cell_height;
if(m_pos_x_cell * cell_width == m_pos_x)
m_only_one_cell_updown = true;
else
m_only_one_cell_updown = false;
if(m_pos_y_cell * cell_height == m_pos_y)
m_only_one_cell_leftright = true;
else
m_only_one_cell_leftright = false;
if(m_only_one_cell_updown && m_only_one_cell_leftright)
m_only_one_cell = true;
}
public void SetPosition(int i, int j)
{
m_pos_x = i;
m_pos_y = j;
}
public boolean StepDown(CLevel clevel)
{
RecalculateData();
byte byte0 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_x += cell_width - 1;
m_pos_y += cell_height;
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_x -= cell_width - 1;
m_pos_y -= cell_height;
RecalculateData();
m_pos_y += cell_height;
RecalculateData();
byte byte2 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if(byte0 == 6 && byte1 == 0 && byte2 == 0)
{
m_pos_y -= cell_height;
m_pos_y += cell_height / 4;
CheckBounds(clevel);
IncreaseSprite();
direction = 3;
return true;
}
if(byte2 == 4 && m_only_one_cell_updown)
{
m_pos_y -= cell_height;
m_pos_y += cell_height / 4;
CheckBounds(clevel);
IncreaseSprite();
direction = 3;
return true;
}
if(byte2 != 1 && byte2 != 3 && m_only_one_cell_updown)
{
m_pos_y -= cell_height;
m_pos_y += cell_height / 4;
CheckBounds(clevel);
IncreaseSprite();
direction = 3;
return true;
} else
{
m_pos_y -= cell_height;
RecalculateData();
return false;
}
}
public boolean StepLeft(CLevel clevel)
{
RecalculateData();
byte byte0 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_x -= cell_width / 4;
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if((byte1 == 0 || byte1 > 3) && m_only_one_cell_leftright)
{
CheckBounds(clevel);
IncreaseSprite();
direction = 0;
return true;
} else
{
m_pos_x += cell_width / 4;
RecalculateData();
return false;
}
}
public boolean StepRight(CLevel clevel)
{
RecalculateData();
byte byte0 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_x += cell_width;
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if((byte1 == 0 || byte1 > 3) && m_only_one_cell_leftright)
{
m_pos_x -= cell_width;
m_pos_x += cell_width / 4;
CheckBounds(clevel);
IncreaseSprite();
direction = 1;
return true;
} else
{
m_pos_x -= cell_width;
RecalculateData();
return false;
}
}
public boolean StepUp(CLevel clevel)
{
m_pos_y--;
RecalculateData();
byte byte0 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
m_pos_y++;
m_pos_y += cell_height - 1;
RecalculateData();
byte byte1 = clevel.GetXY(m_pos_x_cell, m_pos_y_cell);
if(byte1 == 4 && m_only_one_cell_updown && byte0 != 1 && byte0 != 2 && byte0 != 3)
{
m_pos_y -= cell_height - 1;
m_pos_y -= cell_height / 4;
CheckBounds(clevel);
IncreaseSprite();
direction = 2;
return true;
} else
{
m_pos_y -= cell_height - 1;
RecalculateData();
return false;
}
}
protected int max_sprites;
protected int m_pos_x;
protected int m_pos_y;
public int m_pos_x_cell;
public int m_pos_y_cell;
protected boolean m_only_one_cell;
protected boolean m_only_one_cell_updown;
protected boolean m_only_one_cell_leftright;
protected int direction;
public boolean onRope;
protected int sprite_num;
public int cell_width;
public int cell_height;
protected int number_of_boxes;
public int number_of_boxes_score;
protected boolean in_the_fly;
protected int man_type;
public boolean is_dead;
public boolean in_pit;
}
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
public class CLevel
{
public CLevel()
{
level_width = 32;
level_height = 22;
level_data = new byte[level_height][level_width];
gold_box = 0;
pits = null;
on_finishing_stage = false;
}
public void AddNewPit(int i, int j)
{
SetXY(i, j, (byte)0);
CPit cpit = new CPit();
cpit.next = pits;
pits = cpit;
pits.x = i;
pits.y = j;
}
public void DoPitTick()
{
CPit cpit = pits;
CPit cpit1 = null;
while(cpit != null)
{
cpit.DoStep(this);
if(cpit.is_dead)
if(cpit1 != null)
{
cpit1.next = cpit.next;
} else
{
pits = cpit.next;
cpit = pits;
continue;
}
cpit1 = cpit;
cpit = cpit.next;
}
}
public void Finishing()
{
for(int i = 0; i < level_height; i++)
{
for(int j = 0; j < level_width; j++)
if(level_data[i][j] == 7)
level_data[i][j] = 4;
}
on_finishing_stage = true;
}
public int GetBoxNumber()
{
return gold_box;
}
public int GetManX()
{
return man_x;
}
public int GetManY()
{
return man_y;
}
public byte GetXY(int i, int j)
{
if(i >= level_width || i < 0)
return 0;
if(j >= level_height || j < 0)
return 0;
else
return level_data[j][i];
}
public void LoadFromFile(URL url)
throws Exception
{
int i = 1;
on_finishing_stage = false;
URLConnection urlconnection = url.openConnection();
try
{
InputStream inputstream = urlconnection.getInputStream();
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
for(String s = bufferedreader.readLine(); s != null;)
{
if(i == 1)
{
if(s.charAt(1) == ' ')
man_x = Integer.parseInt(s.substring(0, 1));
else
man_x = Integer.parseInt(s.substring(0, 2));
if(man_x > 9)
man_y = Integer.parseInt(s.substring(3));
if(man_x < 10)
man_y = Integer.parseInt(s.substring(2));
}
if(i == 2)
{
total_enemy = Integer.parseInt(s);
enemy_coords = new int[total_enemy][2];
}
if(i > 2 && i < total_enemy + 3)
{
if(s.charAt(1) == ' ')
enemy_coords[i - 3][0] = Integer.parseInt(s.substring(0, 1));
else
enemy_coords[i - 3][0] = Integer.parseInt(s.substring(0, 2));
if(enemy_coords[i - 3][0] > 9)
enemy_coords[i - 3][1] = Integer.parseInt(s.substring(3));
if(enemy_coords[i - 3][0] < 10)
enemy_coords[i - 3][1] = Integer.parseInt(s.substring(2));
}
if(i > total_enemy + 2)
{
for(int j = 0; j < level_width; j++)
{
SetXY(j, i - total_enemy - 3, Byte.parseByte(s.substring(j, j + 1)));
SetBoxNumber(Byte.parseByte(s.substring(j, j + 1)));
}
}
s = bufferedreader.readLine();
i++;
}
bufferedreader.close();
inputstream.close();
}
catch(IOException ioexception)
{
System.out.println("Error: " + ioexception);
}
}
public boolean ObjectInPit(int i, int j)
{
for(CPit cpit = pits; cpit != null; cpit = cpit.next)
if(cpit.time_to_step != 0 && cpit.x == i && cpit.y == j)
return true;
return false;
}
void SetBoxNumber(byte byte0)
{
if(byte0 == 5)
gold_box++;
}
public void SetXY(int i, int j, byte byte0)
{
if(i >= level_width || i < 0 || j >= level_height || j < 0)
{
return;
} else
{
level_data[j][i] = byte0;
return;
}
}
public byte level_width;
public byte level_height;
public int cell_width;
public int cell_height;
protected byte level_data[][];
protected int man_x;
protected int man_y;
public int total_enemy;
public int enemy_coords[][];
protected int gold_box;
CPit pits;
public boolean on_finishing_stage;
}
public class CEnemy extends CHuman
{
public CEnemy()
{
step_direction = 1;
prev_step_direction = 1;
first_step = true;
man_type = 1;
total_in_pits = 0;
in_pit_delay = 80;
}
public void AutomaticalStep(CLevel clevel, int i, int j)
{
float f = 100000F;
RecalculateData();
if(first_step)
{
if(m_pos_x_cell < i && canRight(clevel))
step_direction = 2;
else
if(m_pos_x_cell > i && canLeft(clevel))
step_direction = 1;
else
if(m_pos_y_cell < j && canDown(clevel))
step_direction = 4;
else
if(m_pos_y_cell > j && canUp(clevel))
step_direction = 3;
first_step = false;
}
if(clevel.ObjectInPit(m_pos_x_cell, m_pos_y_cell))
{
in_pit_delay--;
if(in_pit_delay == 0)
{
in_pit = false;
int l = m_pos_x_cell;
int i1 = m_pos_y_cell;
m_pos_x = m_pos_x_cell * 16;
m_pos_y = (m_pos_y_cell - 1) * 16;
RecalculateData();
if(step_direction == 1)
StepLeft(clevel);
if(step_direction == 2)
StepRight(clevel);
if(step_direction == 3)
StepUp(clevel);
if(step_direction == 4)
StepDown(clevel);
clevel.SetXY(l, i1, (byte)0);
in_pit_delay = 80;
return;
}
if(!in_pit)
total_in_pits++;
in_pit = true;
in_the_fly = false;
clevel.SetXY(m_pos_x_cell, m_pos_y_cell, (byte)3);
if(number_of_boxes == 1)
{
clevel.SetXY(m_pos_x_cell, m_pos_y_cell - 1, (byte)5);
number_of_boxes = 0;
}
return;
}
if((m_pos_x / 16) * 16 == m_pos_x && (m_pos_y / 16) * 16 == m_pos_y && !in_the_fly)
{
if(clevel.GetXY(m_pos_x_cell, m_pos_y_cell) == 0 && clevel.GetXY(m_pos_x_cell, m_pos_y_cell - 1) != 0 && !in_the_fly && number_of_boxes == 1 && (int)(Math.random() * 2D) == 0)
{
number_of_boxes = 0;
clevel.SetXY(m_pos_x_cell, m_pos_y_cell, (byte)5);
}
boolean flag = false;
int k = step_direction;
if(canUp(clevel) && step_direction != 4)
{
flag = true;
float f2 = CalculateLineLength(m_pos_x_cell, m_pos_y_cell - 1, i, j);
if(j < m_pos_y_cell && (int)(Math.random() * 3D) == 0)
f2 = 0.0F;
if(f2 < f)
{
k = 3;
f = f2;
}
}
if(canDown(clevel) && step_direction != 3)
{
flag = true;
float f3 = CalculateLineLength(m_pos_x_cell, m_pos_y_cell + 1, i, j);
if(j > m_pos_y_cell && (int)(Math.random() * 3D) == 0)
f3 = 0.0F;
if(f3 < f)
{
k = 4;
f = f3;
}
}
if(canRight(clevel) && step_direction != 1)
{
flag = true;
float f4 = CalculateLineLength(m_pos_x_cell + 1, m_pos_y_cell, i, j);
if(f4 < f)
{
k = 2;
f = f4;
}
}
if(canLeft(clevel) && step_direction != 2)
{
flag = true;
float f5 = CalculateLineLength(m_pos_x_cell - 1, m_pos_y_cell, i, j);
if(f5 < f)
{
k = 1;
float f1 = f5;
}
}
if(!flag)
if(step_direction == 1)
k = 2;
else
if(step_direction == 2)
k = 1;
else
if(step_direction == 3)
k = 4;
else
if(step_direction == 4)
k = 3;
step_direction = k;
}
if(!in_the_fly && !in_pit)
{
if(step_direction == 1)
StepLeft(clevel);
if(step_direction == 2)
StepRight(clevel);
if(step_direction == 3)
StepUp(clevel);
if(step_direction == 4)
StepDown(clevel);
}
}
float CalculateLineLength(int i, int j, int k, int l)
{
return (float)Math.sqrt((float)(k - i) * (float)(k - i) + (float)(l - j) * (float)(l - j));
}
public boolean canDown(CLevel clevel)
{
if(m_pos_y_cell + 1 >= clevel.level_height)
return false;
return clevel.GetXY(m_pos_x_cell, m_pos_y_cell + 1) == 0 || clevel.GetXY(m_pos_x_cell, m_pos_y_cell + 1) == 4 || clevel.GetXY(m_pos_x_cell, m_pos_y_cell + 1) == 5;
}
public boolean canLeft(CLevel clevel)
{
if(m_pos_x_cell - 1 < 0)
return false;
return clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell) == 0 || clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell) == 4 || clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell) == 5 || clevel.GetXY(m_pos_x_cell - 1, m_pos_y_cell) == 6;
}
public boolean canRight(CLevel clevel)
{
if(m_pos_x_cell + 1 >= clevel.level_width)
return false;
return clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell) == 0 || clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell) == 4 || clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell) == 5 || clevel.GetXY(m_pos_x_cell + 1, m_pos_y_cell) == 6;
}
public boolean canUp(CLevel clevel)
{
if(m_pos_y_cell - 1 < 0)
return false;
if(clevel.GetXY(m_pos_x_cell, m_pos_y_cell - 1) == 4)
return true;
return clevel.GetXY(m_pos_x_cell, m_pos_y_cell - 1) == 0 && clevel.GetXY(m_pos_x_cell, m_pos_y_cell) == 4;
}
protected int step_direction;
protected int prev_step_direction;
protected boolean first_step;
public int total_in_pits;
public int in_pit_delay;
}
public class CMan extends CHuman
{
CMan()
{
man_type = 0;
}
public boolean CheckLevelIsComplete(CLevel clevel)
{
RecalculateData();
return (m_pos_x / 16) * 16 == m_pos_x && (m_pos_y / 16) * 16 == m_pos_y && clevel.on_finishing_stage && m_pos_y_cell == 0;
}
}
class CStep
{
public CStep()
{
Next = null;
}
public CStep Next;
public int x;
public int y;
}
インターネットスタートページ 鈴木維一郎 石橋三重子
|
|
|
|
|
|