private void takeInput(GameContainer gc) { Input input = gc.getInput(); // jump if (input.isKeyDown(Input.KEY_SPACE) || input.isKeyDown(Input.KEY_UP) || input.isKeyDown(Input.KEY_W)) { player.jump(); } if (input.isKeyDown(Input.KEY_LEFT) || input.isKeyDown(Input.KEY_A)) { player.move(DirectionEnum.LEFT); } if (input.isKeyDown(Input.KEY_RIGHT) || input.isKeyDown(Input.KEY_D)) { player.move(DirectionEnum.RIGHT); } }
public void render(GameContainer gc, Graphics g) throws SlickException { // clears g.clear(); // backgrond g.setColor(new Color(103, 194, 240)); g.fillRect(0, 0, MainApp.SCREEN_WIDTH, MainApp.SCREEN_HEIGHT); // compute shift right shiftRight += computeShiftRight(); // draws every object ObjectBoilerplate object; for (int x = 0; x < WORLD_LENGTH; x++) { for (int y = 0; y < WORLD_HEIGHT; y++) { object = tileArray[x][y]; if (object != null) { object.render(shiftRight); g.setColor(Color.red); // g.fillRect(object.rect.getX() - shiftRight, MainApp.SCREEN_HEIGHT - // object.rect.getY(), object.rect.getWidth(), object.rect.getHeight()); } } } // g.setColor(Color.red); // g.fillRect(player.rect.getX() - shiftRight, MainApp.SCREEN_HEIGHT - // player.rect.getY(), player.rect.getWidth(), -player.rect.getHeight()); player.render(shiftRight); }
public void init(GameContainer gc) throws SlickException { createGround(); SpriteSheet image = new SpriteSheet(new Image("images/BallSprites.png"), 16, 16); player = new ObjectPlayerBetter( PLAYER_START_X, PLAYER_START_Y, (int) (image.getSubImage(0, 0).getWidth() * 1), (int) (image.getSubImage(0, 0).getHeight() * 1), image); player.init(); }
public void update(GameContainer gc, int deltaTime) throws SlickException { takeInput(gc); player.update(); }