public Enemy( Vector2f pos, int texid, Controller parent, EnemyPath ep, Sprite player, ArrayList<EnemyBullet> playerbullets, String texloc, int lowesttexid, int highesttexid, int width, int pattern) { this.width = width / Display.getWidth(); this.playerbullets = playerbullets; this.parent = parent; this.pattern = pattern; this.lti = lowesttexid; this.hti = highesttexid; this.pos = new Vector2f(((pos.x / Display.getWidth())), ((pos.y) / (Display.getHeight() / 2.0f))); this.playersprite = player; this.ep = ep; this.texid = texid; this.player = new Rectangle2D.Float(); this.myrect = new Rectangle2D.Float(); ImageReturn images = new ImageReturn(); GridParser gp = new GridParser(); TextureHolder texture; try { texture = gp.parseGrid(images.getImage("explosion.png"), 30); this.explosion = new Sprite( images.getImage("explosion.png"), parent, 70, 70, texture, 0, new Vector2f(0.0f, 0.0f)); texture = gp.parseGrid(images.getImage("bullets2.png"), 20); this.bullet = new Sprite( images.getImage("bullets2.png"), parent, 40, 40, texture, 0, new Vector2f(0.0f, 0.0f)); texture = gp.parseGrid(images.getImage(texloc), 50); me = new Sprite(images.getImage(texloc), parent, 100, 100, texture, 0, this.pos); } catch (IOException e) { System.err.println("err at enemy"); System.exit(1); e.printStackTrace(); } }
public static void isSlotHover(int x, int y, int i, int j, int k) { if (Mideas.mouseX() >= Display.getWidth() / 2 + x && Mideas.mouseX() <= Display.getWidth() / 2 + x + 42 && Mideas.mouseY() >= Display.getHeight() / 2 + y + i && Mideas.mouseY() <= Display.getHeight() / 2 + y + j) { slot_hover[k] = true; } }
@Override public void update(float delta) { if (getX() + getWidth() > Display.getWidth() / 2) { velocity.x = 0; setX((int) (Display.getWidth() / 2 - getWidth())); } super.update(delta); }
/** Handles a Display-Resize-Event */ private void handleDisplayResize() { if (this.width != Display.getWidth() || this.height != Display.getHeight()) { this.width = Display.getWidth(); this.height = Display.getHeight(); this.renderer.handleDisplayResize(this.width, this.height); this.guiRenderer.handleDisplayResize(this.width, this.height); } }
public void rotate(float angle) { modelmatrix.translate( new Vector2f( -pos.x - ((float) getWidth() / Display.getWidth() / 2), -pos.y - ((float) getHeight() / Display.getHeight() / 2))); modelmatrix.rotate(angle, new Vector3f(0.0f, 0.0f, 1.0f)); modelmatrix.translate( new Vector2f( pos.x + ((float) getWidth() / Display.getWidth() / 2), pos.y + ((float) getHeight() / Display.getHeight() / 2))); }
private void setupDisplay() { int width = Display.getWidth(); int height = Display.getHeight(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glScissor(0, 0, width, height); GL11.glViewport(0, 0, width, height); renderHandler.init(); }
/** Draw a chatbox from the bottom of the screen to ChatTop, and fill the screen horizontally */ private void drawChatBox() { glBegin(GL_QUADS); { glColor4f(0.0f, 0.0f, 0.0f, 0.5f); glVertex2f(0.0f, Display.getHeight()); glVertex2f(0.0f, ChatTop); glVertex2f(Display.getWidth(), ChatTop); glVertex2f(Display.getWidth(), Display.getHeight()); } glEnd(); }
public static void update() { if (displayMode.getWidth() != Display.getWidth() || displayMode.getHeight() != Display.getHeight()) { displayMode = new DisplayMode(Display.getWidth(), Display.getHeight()); // TODO: MAKE FOV, zNear, zFar CHANGABLE GameEngine.getInstance() .getRenderer() .getCamera() .setParameters(70f, getWidth() / getHeight(), 0.1f, 1000); GameEngine.getInstance().getRenderer().getCamera().updateCenterPosition(); glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight()); } }
private static void drawShopItem(int i, int x, int y) { if (i + 10 * page < shopList.size() && shopList.get(i + 10 * page) != null && StuffManager.getStuff(shopList.get(i + 10 * page).getId()) != null) { Draw.drawQuad( IconsManager.getSprite35( StuffManager.getStuff(shopList.get(i + 10 * page).getId()).getSpriteId()), Display.getWidth() / 2 + x + 3, Display.getHeight() / 2 + y + 3); Draw.drawQuad( Sprites.shop_border, Display.getWidth() / 2 + x - 1, Display.getHeight() / 2 + y); } }
public void renderBackground(float paramRed, float paramGreen, float paramBlue) { glPushMatrix(); glDisable(GL_BLEND); glBegin(GL_QUADS); glColor3f(paramRed, paramGreen, paramBlue); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glNormal3f(0f, 0f, 1.0f); glVertex2f(0, 0); glVertex2f(Display.getWidth(), 0); glVertex2f(Display.getWidth(), Display.getHeight()); glVertex2f(0, Display.getHeight()); glEnd(); glPopMatrix(); }
public abstract class GElement { public int id; protected float xPos, yPos; protected float width, height; protected float xScale = Display.getWidth(); protected float yScale = Display.getHeight(); public boolean visible = true; public boolean enabled = true; public abstract void render(); public void update(boolean leftClicked, boolean leftReleased) {} public boolean isHovered() { if (!enabled) return false; int x = Mouse.getX(); int y = Display.getHeight() - Mouse.getY(); boolean flagX = x >= xPos && x < xPos + width; boolean flagY = y >= yPos && y < yPos + height; if (flagX && flagY && enabled && visible) return true; return false; } }
private static void setUpCamera() { cam = new EulerCamera( (float) Display.getWidth() / (float) Display.getHeight(), -2.19f, 1.36f, 11.45f); cam.setFieldOfView(70); cam.applyPerspectiveMatrix(); }
public void render(ShaderHandler sh, DisplaySetup d, DataUtils util) { for (int i = 0; i < size(); i++) { pellet.changePos(get(i).getPos().x - currentpos.x, get(i).getPos().y - currentpos.y); pellet.changeTexture(get(i).getTexid()); if (get(i).getAnimationWait() > 3) { if (get(i).getTexid() < 11) { get(i).changeTexid(1); } else { get(i).setTexid(0); } get(i).resetWait(); } else { get(i).animationWait(); } currentpos = new Vector2f(get(i).getPos().x, get(i).getPos().y); pellet.render(sh, util, 0); if (get(i) .contains( player.getPos(), (float) player.getWidth() / Display.getWidth(), (float) player.getHeight() / Display.getHeight(), d)) { parent.score(get(i).getScore()); remove(i); } } }
public static void resizedRefresh() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // Resets any previous projection matrices GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1000, -1000); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }
private void shoot(float rot) { bullets.add( new EnemyBullet( new Vector2f( me.getPos().x + (me.getWidth() / (Display.getWidth() * 2.0f)), me.getPos().y), rot)); }
public void start() { System.out.println("SplitMan starting..."); try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setResizable(false); Display.setVSyncEnabled(true); Display.setTitle("SplitMan"); Display.create(); } catch (Exception e) { e.printStackTrace(); Display.destroy(); System.exit(1); } WIDTH = Display.getWidth(); HEIGHT = Display.getHeight(); System.out.println("Display: " + WIDTH + " x " + HEIGHT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); Resources.load(); setScreen(new GuiGame()); System.out.println("SplitMan started"); }
public static void init() { WorldShapes.init(); ImageLibrary.init(); worldOne = new World(); // Setting up arbitrary testing entities for (int i = -10; i < 10; i++) { for (int j = -10; j < 10; j++) { Entity e = new Entity(i * 10, j * 10, 5, ImageLibrary.randomImage()); e.getParticle() .setVelocityVector( new Complex(Calculation.rand(-0.1f, 0.1f), Calculation.rand(-0.1f, 0.1f))); e.getParticle().setAngularVelocity(Calculation.rand(-1, 1)); e.getParticle().setAngularVelocity(Calculation.rand(-100, 100)); worldOne.Entity_HashMap.put(Calculation.rand(0, 1000) + "", e); } } worldOne.Entity_HashMap.put("player", new Entity(12, 12, 12, ImageLibrary.get("smile"))); mainCamera = new POV( worldOne.Entity_HashMap.get("player").getParticle().getPositionVector(), Display.getWidth(), Display.getHeight(), 0, 5, worldOne); }
// Size Adjustment public void AdjustToWindow() { if (Display.getHeight() != 0 && Display.getWidth() != 0) { double WModifier = (double) Display.getWidth() / TetrisClone.WWidth; double HModifier = (double) Display.getHeight() / TetrisClone.WHeight; this.BLCorner.setX((int) (BLCorner.getX() * WModifier)); this.BLCorner.setY((int) (BLCorner.getY() * HModifier)); this.BRCorner.setX((int) (BRCorner.getX() * WModifier)); this.BRCorner.setY((int) (BRCorner.getY() * HModifier)); this.TLCorner.setX((int) (TLCorner.getX() * WModifier)); this.TLCorner.setY((int) (TLCorner.getY() * HModifier)); this.TRCorner.setX((int) (TRCorner.getX() * WModifier)); this.TRCorner.setY((int) (TRCorner.getY() * HModifier)); TetrisClone.WWidth = Display.getWidth(); TetrisClone.WHeight = Display.getHeight(); } }
/** * Paints a character against the map for rendering * * @param g - Graphics component that'll draw the map to the display * @param cam - Camera of where to center the map at * @param c - Character to draw on the map */ public void paintCharacter(Graphics g, Camera cam, MapCharacter c) { // TODO add culling so characters outside of camera bounds are not drawn Image sprite = c.sprite; int w = c.sprite.getWidth() / 2; int h = c.sprite.getHeight(); g.drawImage( c.sprite, (c.x - cam.x) + Display.getWidth() / 2, (c.y - cam.y) + Display.getHeight() / 2); }
/** * Connect to the server and execute the initial data exchange. Returns when the connection is * successfully established * * @return false if the connection failed and the game should quit (or go back to the menu) */ public boolean loop() { networkedGame = new NetworkedGame(loop, httpUrl, nickname); loadingCamera = new Camera(resourceDB); loadingStarfield = new StarField(SwissArmyKnife.random.nextInt(), resourceDB); loadingCamera.setScreenPosition(0, 0); loadingCamera.setPosition(0, loadingCameraY); connection = new SingleGameConnection(wsUri, loop); connection.addListener(networkedGame); connection.connect(); loop.addTickEvent(this); try { while (!loop.isInterruped() && networkedGame.isConnecting()) { Display.update(); if (Display.isCloseRequested()) { log.log(Level.WARNING, "Close requested in connect loop"); return false; } loadingCamera.setDimension(Display.getWidth(), Display.getHeight()); Graph.graphicsLoop(); Client.initGL(); loop.loop(); loadingStarfield.render(loadingCamera); String line = "Connecting..."; int line_width = Graph.g.getFont().getWidth(line); Graph.g.setColor(Color.white); Graph.g.drawString( line, loadingCamera.dimensionHalf.x - line_width / 2, loadingCamera.dimension.y * 0.75f); loadingCamera.setPosition(0, loadingCameraY); Display.sync(60); } if (loop.isInterruped()) { log.log(Level.WARNING, "Connect loop interrupted"); return false; } return !networkedGame.isConnecting() && !networkedGame.isDisconnected(); } finally { loop.removeTickEvent(this); } }
private static void setUpCamera() { camera = new EulerCamera.Builder() .setAspectRatio((float) Display.getWidth() / Display.getHeight()) .setPosition(-2.19f, 1.36f, 11.45f) .setFieldOfView(70) .build(); camera.applyOptimalStates(); camera.applyPerspectiveMatrix(); }
private void applyOculusDistortion(FBO inputBuffer) { materials.ocDistortion.enable(); int texId = 0; GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId); inputBuffer.bindTexture(); materials.ocDistortion.setInt("texInputBuffer", texId, true); if (renderingProcess.isNotTakingScreenshot()) { updateOcShaderParametersForVP( 0, 0, fullScale.width() / 2, fullScale.height(), WorldRenderer.WorldRenderingStage.LEFT_EYE); renderFullscreenQuad(0, 0, Display.getWidth(), Display.getHeight()); updateOcShaderParametersForVP( fullScale.width() / 2 + 1, 0, fullScale.width() / 2, fullScale.height(), WorldRenderer.WorldRenderingStage.RIGHT_EYE); renderFullscreenQuad(0, 0, Display.getWidth(), Display.getHeight()); } else { // what follows -should- work also when there is no screenshot being taken, but somehow it // doesn't, hence the block above updateOcShaderParametersForVP( 0, 0, fullScale.width() / 2, fullScale.height(), WorldRenderer.WorldRenderingStage.LEFT_EYE); renderFullscreenQuad(0, 0, fullScale.width(), fullScale.height()); updateOcShaderParametersForVP( fullScale.width() / 2 + 1, 0, fullScale.width() / 2, fullScale.height(), WorldRenderer.WorldRenderingStage.RIGHT_EYE); renderFullscreenQuad(0, 0, fullScale.width(), fullScale.height()); } }
public MapRender(Map m) { try { map = new Image(DataDirs.MapsDir.path + m.getName() + "/map.png"); map_offset_x = -(m.getWidthInTiles() * (TILE_DIMENSIONS[0] / 2)) + Display.getWidth() / 2; map_offset_y = Display.getHeight() / 2; } catch (SlickException e) { System.err.println("Could not load image of map " + m.getName()); e.printStackTrace(); } }
public static void clickToLearn(int x, int y) { TTF2.itemNumber.drawStringShadow( Display.getWidth() / 2 + x, Display.getHeight() / 2 + y, "Cliquer pour apprendre", Color.green, Color.black, 1, 1, 1); }
public static void clickToUnlearn(int x, int y) { TTF2.itemNumber.drawStringShadow( Display.getWidth() / 2 + x, Display.getHeight() / 2 + y, "Clic droit pour d�sapprendre", Color.red, Color.black, 1, 1, 1); }
private float calcHorizontalAlign(EHorizontalAlign align) { if (align == EHorizontalAlign.LEFT) { return 0f; } else if (align == EHorizontalAlign.CENTER) { if (positionType == EPositionType.RELATIVE && parent != null) { return parent.getSize().x / 2 - size.x / 2; } else if (positionType == EPositionType.ABSOLUTE) { return Display.getWidth() / 2 - size.x / 2; } } else if (align == EHorizontalAlign.RIGHT) { if (positionType == EPositionType.RELATIVE && parent != null) { return parent.getSize().x - size.x; } else if (positionType == EPositionType.ABSOLUTE) { return Display.getWidth() - size.x; } } return 0f; }
private static void requiredPoint( int numberTalentSpec, int number, int talent, int numberTalent, int x_string, int y_string, int y_stringClickToLearn, String string) { if (numberTalentSpec >= number) { if (talent != numberTalent) { clickToLearn(Talent.getX() + 24 + x_string, Talent.getY() + y_stringClickToLearn); } else { clickToUnlearn(Talent.getX() + 24 + x_string, Talent.getY() + y_stringClickToLearn); } } if (number != 0 && numberTalentSpec >= 5) { TTF2.talent.drawStringShadow( Display.getWidth() / 2 + Talent.getX() + 24 + x_string, Display.getHeight() / 2 + Talent.getY() + y_string, string, Color.green, Color.black, 1, 1, 1); } else if (numberTalentSpec <= number && number != 0) { TTF2.talent.drawStringShadow( Display.getWidth() / 2 + Talent.getX() + 24 + x_string, Display.getHeight() / 2 + Talent.getY() + y_string, string, Color.red, Color.black, 1, 1, 1); } }
public void render() { if (Display.wasResized()) { WIDTH = Display.getWidth(); HEIGHT = Display.getHeight(); if (currentScreen != null) { currentScreen.setSize(WIDTH, HEIGHT); } } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); if (currentScreen != null) { currentScreen.render(); } }
public static void iterate() { // Dealing with the user input UserInterface.iterate(); UserInterface soul = new UserInterface(); soul.update(getPlayerEntity()); // Dealing with the Camera WorldShapes.setCamera(mainCamera); mainCamera.setZoom(mainCamera.getZoom() * Math.pow(1.001, Mouse.getDWheel())); mainCamera.followParticle(mainCamera.world.Entity_HashMap.get("player").getParticle()); mainCamera.iterate(); mainCamera.entityDrag(); // Deals with dragging points // Update the physics updateWorld(worldOne); // Rendering and stuff Render.testResize(); FrameBufferObject.setFrameBuffer( extra_frame.getFrameBufferIdentifier()); // applies the extra framebuffer mainCamera.render(); FrameBufferObject.setFrameBuffer(0); // applies the normal screen // Drawing the framebuffer HUDShapes.drawTexturedQuad( 0, 0, Display.getWidth(), Display.getHeight(), extra_frame.getTexture(), Display.getWidth(), Display.getHeight()); Display.update(); }
public void update(DisplaySetup d) { Vector4f p = new Vector4f((float) playersprite.getPos().x, (float) playersprite.getPos().y, 0.0f, 1.0f); p = Matrix4f.transform(d.getModelViewMatrixAsMatrix(), p, p); Vector4f p2 = new Vector4f((float) me.getPos().x, (float) me.getPos().y, 0.0f, 1.0f); p2 = Matrix4f.transform(d.getModelViewMatrixAsMatrix(), p2, p2); this.player.setRect( p.x, p.y, (float) playersprite.getWidth() / Display.getWidth(), (float) playersprite.getHeight() / Display.getHeight()); this.myrect.setRect( p2.x - width / 2, p2.y, (float) width, (float) me.getHeight() / Display.getHeight()); }