📄 dynamic.java
字号:
}
if (dy < 0) jump(0);
}
else
if (curObj.type == Main.C_Lift)
{
new_x += dx;
if ((curObj.x1 - (curObj.fw >> 1) <= new_x) && (curObj.x1 + (curObj.fw >> 1) >= new_x))
{
}
else
{
curObj = null;
isFalling = true;
}
if (dy < 0) jump(0);
}
else
if (curObj.type == Main.C_Sucker)
{
new_x = x + dx;
new_y = y + dy;
if (phase == 0)
{
dy = -4;
if (y < curObj.ymin)
{
new_y = curObj.ymin - frame.h;
phase = 1;
dy = 0;
dx = curObj.x1 < curObj.x2 ? 4 : - 4;
}
}
if (phase == 1)
{
if (((dx > 0) && (x > curObj.x2)) || ((dx < 0) && (x < curObj.x2)))
{
y_border = obj.y2;
new_x = curObj.x2;
new_y = curObj.y2;
phase = 2;
dx = 0;
dy = 0;
curObj = null;
}
}
}
else
if (curObj.type == Main.C_Slope)
{
dy = Main.step;
dx = curObj.k * Main.step;
new_x = x + dx;
new_y = y + dy;
for (i = 0; i < Main.aObj.length; i++)
{
obj = Main.aObj[i];
if ((obj.type == Main.C_P))
if ((obj.x1 - 1 <= new_x) && (obj.x2 + 1 >= new_x))
{
ty = obj.y1 + (x - obj.x1) * obj.dy / obj.dx;
if ((ty - y >= - 4) && (ty - y <= 4))
{
for (j = -6; j <= 6; j += 6)
{
n = (new_x - obj.xmin + j) / 10;
if (n < obj.blocks.length)
{
if (!(obj.blocks[n]))
{
obj.blocks[n] = true;
Main.obj = obj;
Main.closed_blocks --;
Main.p_num = n;
Main.drawP();
}
}
}
}
}
}
if (new_y >= curObj.y2)
{
curObj = null;
phase = -1;
isFalling = true;
}
}
else
if (curObj.type == Main.C_Teleport)
{
}
min_y = new_y;
}
else
// on floor
{
//(!isFalling) && (jumpIndex == -1)
if (y + 1 >= Main.a_h)
{
phase = -1;
isFallen = true;
dx = 0;
}
if (isFalling)
{
if (dx > 0 ) dx = 1;
if (dx < 0 ) dx = -1;
}
new_x = x + dx;
// if (dy < 0) jump(0);
}
// if current object is null
if ((curObj == null) && (y + 1 < Main.a_h))
{
for (i = 0; (i < Main.aObj.length) && (curObj == null); i++)
{
obj = Main.aObj[i];
if ((dy > 0) || (jumpIndex == -1))
{
if (obj.type == Main.C_P)
{
if (((obj.x1 - 1 <= new_x) && (obj.x2 >= new_x) && (dx >= 0)) ||
((obj.x1 <= new_x) && (obj.x2 + 1 >= new_x) && (dx < 0)))
// if ((obj.x1 <= new_x) && (obj.x2 >= new_x))
{
ty = obj.y1 + (x - obj.x1) * obj.dy / obj.dx;
if ((ty - y >= - 4) && (ty - y <= 4))
{
curObj = obj; // platform found
new_y = ty;
if (x < obj.x1)
{
new_x = obj.x1;
new_y = obj.y1;
}
if (x > obj.x2)
{
new_x = obj.x2;
new_y = obj.y2;
}
dy = dx = 0;
if (class_type == T_A) dx = 1;
isFalling = false;
isFallen = true;
started = true;
jumpIndex = -1;
phase = -1;
}
}
}
if (obj.type == Main.C_M)
{
if ((obj.mx - 8 <= new_x) && (obj.mx + 8 >= new_x) && (obj.my - 4 <= new_y) && (obj.my + 4 >= new_y))
{
curObj = obj; // moving found
new_y = obj.my;
dx = dy = 0;
if (class_type == T_A) dx = 1;
isFalling = false;
isFallen = true;
started = true;
jumpIndex = -1;
phase = -1;
}
}
if (obj.type == Main.C_Lift)
{
if ((obj.x1 - (obj.fw >> 1) <= x) && (obj.x1 + (obj.fw >> 1) >= x) &&
(obj.my - 4 <= y) && (obj.my + 4 >= y))
{
curObj = obj; // moving found
new_y = obj.my - 4;
dx = dy = 0;
if (class_type == T_A) dx = 1;
isFalling = false;
isFallen = true;
started = true;
jumpIndex = -1;
phase = -1;
}
}
}
if ((obj.type == Main.C_Sucker) && (dy < 0))
{
if ((obj.x1 - 4 <= x) && (obj.x1 + 4 >= x) && (obj.y1 >= y - frame.h) && (obj.y1 <= y))
{
y_border = obj.y1;
curObj = obj;
phase = 0;
new_x = curObj.x1;
dx = 0;
jumpIndex = -1;
isFalling = false;
}
}
}
if ((curObj == null) && (jumpIndex == -1) && (y < Main.a_h)) isFalling = true;
}
// falling check
if (isFalling)
{
dy = Main.step;
if (y - min_y > 20) dy++;
if (y - min_y > 60) dy++;
new_y = y + dy;
// new_x = x;
// dx = 0;
}
if ((Main.state == 0) || (class_type != T_M))
{
// update animations indices 0,1 2,3 4,5 6,7
if ((dy == 0) || (curObj == null))
{
if (dx < 0)
a1 = isFalling ? 0:2;
else
if (dx > 0)
a1 = isFalling ? 1:3;
else
{
if ((a1 == 0) || (a1 == 2) || (a1 == 8)) a1 = 0;
else a1 = 1;
}
}
if ((curObj != null) && (dy == 0))
if (curObj.type == Main.C_S)
{
a1 = 12;
}
if ((jumpIndex != -1) || (phase == 4))
{
if ((dx < 0) || (a1 == 0)) a1 = 8;
if ((dx > 0) || (a1 == 1)) a1 = 9;
}
if ((isFallen) && (class_type == T_M))
{
if ((new_y - min_y > 40) || (new_y + 1 >= Main.a_h)) crash();
}
if (phase == 5) a1 = 13; // into teleport
if (phase == 6) a1 = 14; // out of teleport
}
cb();
}
void crash()
{
Main.beep(1);
Main.state = 30;
dx = dy = 0;
if ((a1 == 0) || (a1 == 2) || (a1 == 8)) a1 = 10;
else a1 = 11;
a2 = 1;
finished = false;
loop = false;
}
void cb()
{
// check bounds
sdx = new_x - x;
sdy = new_y - y;
x = new_x;
y = new_y;
if (x < 0)
{
x = 0;
dx = 0;
}
if (x > Main.a_w)
{
x = Main.a_w;
dx = 0;
}
if (y < 0)
{
y = 0;
dy = 0;
}
if (y > Main.a_h)
{
y = Main.a_h;
dy = 0;
isFalling = false;
}
}
void draw()
{
if ((class_type == T_B) && (inUse == true))
{
if ((Main.man.phase >= 0) && (Main.man.phase < 4)) return;
}
if ((frame != null) && visible)
{
tx = x - Main.a_x_d - (frame.fw >> 1);
ty = y - Main.a_y_d - frame.fh;
// if (class_type == T_B) ty -= 2;
if ((tx > - frame.fw) && (ty > - frame.fh) && (tx < Main.s_w) && (ty < Main.s_h))
{
image_index = 0;
try
{
if (a != null)
{
b = a[a1];
if (b != null)
{
if (a2 >= b.length) a2 = 1;
image_index = b[a2];
delay = b[0];
if ((class_type == T_A) || (class_type == T_T))
if ((dx > 1) || (dx < -1)) delay = b[0] - 1;
if (time > delay)
{
if ((class_type == T_T) && (type > 0))
{
if (a2 == 1)
{
if (delay2 > 0) delay2--;
else
{
delay2 = delay_range + Main.rnd(delay_range);
a2++;
}
}
else a2++;
}
else
if ((class_type == T_T) && (type == 0))
{
if (alarm)
{
if (a2 != 3)
{
if (b.length <= ++a2)
{
a2 = 3;
}
}
else a2 = 3;
}
else
{
if (a2 != 1)
{
if (b.length <= ++a2)
{
a2 = 1;
}
}
else a2 = 1;
}
}
else a2++;
if (b.length <= a2)
{
if (loop) a2 = 1;
else visible = false;
// a2 = b.length - 1;
finished = true;
}
time = 0;
}
time++;
}
}
}
catch(Exception ex){System.out.println(ex + "");}
if (phase == -1)
{
Main.g.setClip(tx,ty,frame.fw,frame.fh);
}
else
{
Main.g.setClip(tx,ty > (y_border - Main.a_y_d) ? ty : y_border - Main.a_y_d,frame.fw,frame.fh);
}
Main.g.drawImage(Main.img[frame.index],tx - image_index,ty,20);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -