import models.IModel; import models.JumpingGameModel; import org.lwjgl.glfw.GLFWKeyCallback; import views.IView; import views.PlayerRenderer; import views.TileMapRenderer; import java.util.ArrayList; import static org.lwjgl.glfw.GLFW.*; public class JumpingGame { private ArrayList<IView> views = new ArrayList<>(); private IModel model = new JumpingGameModel(); private GLFWKeyCallback keyCallback; public void gravity(double y) { JumpingGameModel jumpingGameModel = (JumpingGameModel) model; jumpingGameModel.gravity(y); jumpingGameModel.updateGroundFlag(); } public void init() { JumpingGameModel jumpingGameModel = (JumpingGameModel) model; jumpingGameModel.run(2); views.add(new TileMapRenderer(model)); views.add(new PlayerRenderer("resources/JCasC.png")); } public void update(long window) { for (IView view : views) { view.update(model); view.display(); } glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_SPACE && action != GLFW_PRESS) { JumpingGameModel jumpGameModel = (JumpingGameModel) model; jumpGameModel.jump(256); } } }); gravity(-256); } public void delete() { for (IView view : views) view.delete(); } }