@Override public void init(GameContainer gc, StateBasedGame sb) throws SlickException { background = new Image("res/hubRoom.png"); shoes = new Sprite(new Image("res/hangingShoes.png")); shoes.x = 150; shoes.y = 150; shoes.alive = true; bib = new Sprite(new Image("res/bib.png")); bib.x = 350; bib.y = 65; bib.alive = true; } // end init
public void move() { if (winTime > 0) { winTime++; xa = 0; ya = 0; return; } if (deathTime > 0) { deathTime++; if (deathTime < 11) { xa = 0; ya = 0; } else if (deathTime == 11) { ya = -15; } else { ya += 2; } x += xa; y += ya; return; } // if (world.paused) // System.out.println("Sim World Paused!"); if (powerUpTime != 0) { if (powerUpTime > 0) { powerUpTime--; } else { powerUpTime++; } if (powerUpTime == 0) { if (world.paused) System.out.println("Sim World Unpaused!"); world.paused = false; } return; } if (invulnerableTime > 0) invulnerableTime--; wasOnGround = onGround; float sideWaysSpeed = keys[KEY_SPEED] ? 1.2f : 0.6f; // float sideWaysSpeed = onGround ? 2.5f : 1.2f; if (onGround) { if (keys[KEY_DOWN] && large) { ducking = true; } else { ducking = false; } } if (xa > 2) { facing = 1; } if (xa < -2) { facing = -1; } if (keys[KEY_JUMP] || (jumpTime < 0 && !onGround && !sliding)) { if (jumpTime < 0) { xa = xJumpSpeed; ya = -jumpTime * yJumpSpeed; jumpTime++; } else if (onGround && mayJump) { xJumpSpeed = 0; yJumpSpeed = -1.9f; jumpTime = 7; ya = jumpTime * yJumpSpeed; onGround = false; sliding = false; } else if (sliding && mayJump) { xJumpSpeed = -facing * 6.0f; yJumpSpeed = -2.0f; jumpTime = -6; xa = xJumpSpeed; ya = -jumpTime * yJumpSpeed; onGround = false; sliding = false; facing = -facing; } else if (jumpTime > 0) { xa += xJumpSpeed; ya = jumpTime * yJumpSpeed; jumpTime--; } } else { jumpTime = 0; } if (keys[KEY_LEFT] && !ducking) { if (facing == 1) sliding = false; xa -= sideWaysSpeed; if (jumpTime >= 0) facing = -1; } if (keys[KEY_RIGHT] && !ducking) { if (facing == -1) sliding = false; xa += sideWaysSpeed; if (jumpTime >= 0) facing = 1; } if ((!keys[KEY_LEFT] && !keys[KEY_RIGHT]) || ducking || ya < 0 || onGround) { sliding = false; } if (keys[KEY_SPEED] && canShoot && this.fire && world.fireballsOnScreen < 2) { // System.out.println("Adding fireball!"); world.addSprite(new Fireball(world, x + facing * 6, y - 20, facing)); } world.paused = GlobalOptions.pauseWorld; canShoot = !keys[KEY_SPEED]; mayJump = (onGround || sliding) && !keys[KEY_JUMP]; runTime += (Math.abs(xa)) + 5; if (Math.abs(xa) < 0.5f) { runTime = 0; xa = 0; } if (sliding) { ya *= 0.5f; } onGround = false; move(xa, 0); move(0, ya); // System.out.println("Mario Sim Speed: "+xa); if (y > world.level.height * 16 + 16) { die(); } if (x < 0) { x = 0; xa = 0; } if (x > world.level.xExit * 16) { win(); } if (x > world.level.width * 16) { x = world.level.width * 16; xa = 0; } ya *= 0.85f; if (onGround) { xa *= GROUND_INERTIA; } else { xa *= AIR_INERTIA; } if (!onGround) { ya += 3; } if (carried != null) { carried.x = x + facing * 8; carried.y = y - 2; if (!keys[KEY_SPEED]) { // System.out.println("Releasing shell!"); carried.release(this); carried = null; } } // System.out.println("Mariopos: "+x+" "+y); }