public void draw(RenderWindow window) { super.draw(window); window.setView(m_currentView); m_petriDish.draw(window); window.setView(m_defaultView); window.draw(m_timeText); if (m_showGps) window.draw(m_fpsText); }
public MainCharacter(RenderWindow window) { super(window); setSprite("Pics/Human/Ash_Sprite.jpg", new IntRect(0, 10, 16, 26)); Vector2i windowSize = window.getSize(); setScale(3, 3); setPosition(new Vector2f(windowSize.x / 2 - 24, windowSize.y / 2 - 24)); }
public PlayPanel(Vector2f size, Vector2f position, RenderWindow window) { super(size, position); m_petriDish = new PetriDish(400.0f, new Vector2f(50.0f, 50.0f)); m_gameTime = Time.ZERO; m_showGps = false; // Load font Font m_timeFont = new Font(); try { InputStream istream = getClass().getResourceAsStream("/Resources/00TT.TTF"); m_timeFont.loadFromStream(istream); } catch (IOException ex) { // Failed to load font ex.printStackTrace(); } m_timeText = new Text("", m_timeFont, 30); m_timeText.setColor(Color.BLACK); m_timeText.setPosition(new Vector2f(10.0f, 5.0f)); m_fpsText = new Text("FPS: ", m_timeFont, 30); m_fpsText.setColor(Color.BLACK); m_fpsText.setPosition(new Vector2f(350.0f, 5.0f)); m_defaultView = window.getDefaultView(); m_currentView = new View(new Vector2f(400, 300), new Vector2f(800, 600)); m_zoom = 0; m_leftMouseHold = false; m_currentPan = m_holdMousePos = m_pan = Vector2i.ZERO; }
@Override public void draw(RenderTarget renderTarget, RenderStates renderStates) { int adjustedFrame = Math.round((animationFrame * ANIMATION_FRAMES) / (ANIMATION_FRAMES * ANIMATION_SPEED)); // TODO: Improve efficiency if required. There is no use in looping through tiles immediately // adjacent to the // start of the chunk. // Apply the tile sheet to the tiles. RenderStates states = new RenderStates(TILE_SHEET); // Get the player's current position. Vector2f playerPosition = player.getPosition(); // Get the window's current size. Vector2i windowSize = WINDOW.getSize(); // Determine how many tiles fit the window horizontally and vertically taking zoom into account, // then halve // both values. int xDistance = (int) Math.ceil(windowSize.x / (TILE_SIZE * 2 / ZOOM)); int yDistance = (int) Math.ceil(windowSize.y / (TILE_SIZE * 2 / ZOOM)); Vector2f distance = new Vector2f(xDistance + 1, yDistance + 1); // Create a rectangle representing the positions currently viewable by the player. FloatRect visibleArea = new FloatRect( playerPosition.x - distance.x, playerPosition.y - distance.y, distance.x * 2, distance.y * 2); // Create a set to keep track of the already rendered chunks. Set<Integer> renderedChunks = new HashSet<Integer>(); // Loop through every position currently in view. for (float i = visibleArea.left; i <= visibleArea.left + visibleArea.width; i++) { for (float j = visibleArea.top; j <= visibleArea.top + visibleArea.height; j++) { // Convert the current position to a chunk ID. int chunkID = positionToChunkID(new Vector2f(i, j)); // If the chunk is valid and hasn't been drawn yet, draw it. if (isValidChunkID(chunkID) && !renderedChunks.contains(chunkID)) { // Draw the chunk vertex array with the tile sheet. VERTEX_ARRAYS[chunkID][0].draw(renderTarget, states); if (adjustedFrame > 0) { VERTEX_ARRAYS[chunkID][adjustedFrame].draw(renderTarget, states); } // Add the drawn chunk ID to the set to check against in order to save resources by not // drawing // it twice. renderedChunks.add(chunkID); } } } }