public void update() { if (crush) { if (animation.getCurrent() == crushSprites.length - 1) { crush = false; } } if (crush) { if (leftCrush) { dx -= (moveSpeed + 0.3); if (dx < -(maxSpeed + 2.0)) dx = -(maxSpeed + 2.0); } else { if (rightCrush) { dx += moveSpeed + 0.3; if (dx > maxSpeed + 2.0) dx = maxSpeed + 2.0; } else { if (dx < 0) { dx += stopSpeed; if (dx > 0) dx = 0; } if (dx > 0) { dx -= stopSpeed; if (dx < 0) dx = 0; } } } } if (!crush && !blockMove && left) { dx -= moveSpeed; if (dx < -maxSpeed) dx = -maxSpeed; } else { if (!crush && !blockMove && right) { dx += moveSpeed; if (dx > maxSpeed) dx = maxSpeed; } else { if (dx < 0) { dx += stopSpeed; if (dx > 0) dx = 0; } if (dx > 0) { dx -= stopSpeed; if (dx < 0) dx = 0; } } } if (jumping) { sfx.get("jumping").play(); falling = true; jumping = false; dy = startJumping; upCrush = false; } if (falling) { if (reverse) { if (gravity > 0) { gravity *= -1; startJumping *= -1; } dy += gravity; if (dy < -maxFallingSpeed) dy = -maxFallingSpeed; } else { if (gravity < 0) { gravity *= -1; startJumping *= -1; } dy += gravity; if (dy > maxFallingSpeed) dy = maxFallingSpeed; } } else { dy = 0; } curRow = mp.getRowMap((int) y); curCol = mp.getColMap((int) x); toX = x + dx; toY = y + dy; tempX = x; tempY = y; calculateCorners(x, toY); if (dy < 0) { if (reverse) { if (bottomLeft || bottomRight) { dy = 0; falling = false; tempY = curRow * mp.getMapSize() + height1 / 2; } else { tempY += dy; } } else { if (topLeft || topRight) { dy = 0; tempY = curRow * mp.getMapSize() + height1 / 2; } else { tempY += dy; } } } if (dy > 0) { if (reverse) { if (topLeft || topRight) { dy = 0; tempY = (curRow + 1) * mp.getMapSize() - height1 / 2; } else { tempY += dy; } } else { if (bottomLeft || bottomRight) { dy = 0; falling = false; tempY = (curRow + 1) * mp.getMapSize() - height1 / 2; } else { tempY += dy; } } } calculateCorners(toX, y); if (dx < 0) { if (topLeft || bottomLeft) { dx = 0; tempX = curCol * mp.getMapSize() + width1 / 2; } else { tempX += dx; } } if (dx > 0) { if (topRight || bottomRight) { dx = 0; tempX = (curCol + 1) * mp.getMapSize() - width1 / 2; } else { tempX += dx; } } if (!falling) { if (reverse) { calculateCorners(x, y - 1); } else { calculateCorners(x, y + 1); } if (!bottomRight && !bottomLeft) falling = true; } x = tempX; y = tempY; if (!blockMove) { mp.setX((int) (GamePanel.WIDTH / 2 - x)); mp.setY((int) (GamePanel.HEIGHT / 2 - y)); } if (crush) { animation.setFrame(crushSprites); animation.setDelay(400); animation.setSpeed(10); } else { if (left || right) { animation.setFrame(walkSprites); animation.setDelay(100); animation.setSpeed(15); } else { if (telekinesTo || telekinesFrom) { animation.setFrame(telekinesSprites); animation.setDelay(400); animation.setSpeed(8); } else { animation.setFrame(idSprites); animation.setDelay(400); animation.setSpeed(5); } } } if (dy < 0) { if (!reverse) { animation.setFrame(jumpSprites); animation.setDelay(100); animation.setSpeed(10); } else { animation.setFrame(fallSprites); animation.setDelay(100); animation.setSpeed(10); } } if (dy > 0) { if (reverse) { animation.setFrame(jumpSprites); animation.setDelay(100); animation.setSpeed(10); } else { animation.setFrame(fallSprites); animation.setDelay(100); animation.setSpeed(10); } } animation.update(); if (left) { factingRight = false; } else { if (right) { factingRight = true; } } }
private static void createGraphicData(List<String> lines) { Model m = null; ModelAnim a = null; Particle p = null; Texture t = null; TextureCliped c = null; Animation A = null; for (String l : lines) { if (l.charAt(0) == '+') continue; String[] data = l.split(" "); String action = data[0]; if ("new".equals(action)) { // create new thing String object = data[1]; String name = data[2]; if ("Model".equals(object)) { a = null; m = new Model(); models.put(name, m); System.out.println("new model " + name); } else if ("ModelRepeat".equals(object)) { a = null; m = new ModelRepeat(); models.put(name, m); System.out.println("new modelRepeat " + name); } else if ("ModelAnim".equals(object)) { a = new ModelAnim(); m = null; models.put(name, a); System.out.println("new modelAnim " + name); } else if ("Particle".equals(object)) { p = new Particle(); a = null; m = null; models.put(name, p); System.out.println("new particle " + name); } else if ("Texture".equals(object)) { t = Texture.loadTexture(name); c = null; textures.put(name, t); System.out.println("new texture " + name); } else if ("TextureCliped".equals(object)) { c = TextureCliped.loadTextureCliped(name); textures.put(name, c); System.out.println("new textureCliped " + name); } else if ("Animation".equals(object)) { A = new Animation(); if (a != null) a.setAnimation(name, A); System.out.println("new animation " + name); } } else if ("set".equals(action)) { // set stuff String attribute = data[1]; if (m != null) { if ("Texture".equals(attribute)) { String path = data[2]; m.setTexture(getTexture(path)); } } else if (A != null) { if ("Texture".equals(attribute)) { String path = data[2]; A.setTexture(getTexture(path)); } else if ("Duration".equals(attribute)) { String duration = data[2]; A.setDuration(Float.valueOf(duration)); } else if ("FrameCount".equals(attribute)) { String count = data[2]; A.setFrameCount(Integer.valueOf(count)); } else if ("Frame".equals(attribute)) { String frame = data[2]; String clipID = data[3]; A.setFrame(Integer.valueOf(frame), Integer.valueOf(clipID)); } } else if (c != null) { if ("FrameCount".equals(attribute)) { String x = data[2]; String y = data[3]; c.setFrameCount(Integer.valueOf(x), Integer.valueOf(y)); } } } } }