The window resizing that is supposed to happen at lines 191-207 (right near the bottom) does nothing, and when I compile this on my ubuntu laptop, none of the window resizing does anything. Did I do something wrong?
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Go.h"
int main()
{
// The zoom multiplyer, default : 1
int zoomLevel = 1;
// Load the spritesheet
sf::Image spriteSheet;
if (!spriteSheet.LoadFromFile("Go_sprites.png"))
{
// Error
}
// Get rid of the blurring effect
spriteSheet.SetSmooth(false);
// Make magenta see-through
spriteSheet.CreateMaskFromColor(sf::Color::Magenta);
// Load the font
sf::Font myFont;
if (!myFont.LoadFromFile ("6x13font.ttf", 36))
{
// Error
}
// Create main window
sf::RenderWindow App(sf::VideoMode(245 * zoomLevel, 129 * zoomLevel),
"Go",
sf::Style::Titlebar | sf::Style::Close);
// Reduce CPU usage by setting a max fps
App.SetFramerateLimit(30);
// TEMPORARY, Set a board size for testing
int boardXDim = 9;
int boardYDim = 9;
// The main program loop
// Closes when the window is closed
while (App.IsOpened())
{
// Put all the menu stuff here
Board myBoard (App, myFont, spriteSheet, boardXDim, boardYDim, zoomLevel);
// The board loop
// Exits when the window is closed or the game is exited
while ((myBoard.inGame == true) && (App.IsOpened ()))
{
// Process the events list
sf::Event Event;
while (App.GetEvent (Event) && myBoard.inGame == true && App.IsOpened ())
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
{
App.Close ();
}
// If the left mouse button was pressed
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))
{
// Clear the alerts
myBoard.clearAlerts ();
// if the mouse's x and y co-ordinates are on the pass button
if (myBoard.onPassButton ((((Event.MouseButton.X + 1) / zoomLevel) - 1), (((Event.MouseButton.Y + 1) / zoomLevel) - 1)))
{
myBoard.pass ();
}
// if the mouse's x and y co-ordinates are on a space on the board
if ((((((((Event.MouseButton.X + 1) / zoomLevel) - 1) - 1) % 14) > 0) && ((((Event.MouseButton.X + 1) / zoomLevel) - 1) <= (myBoard.gridToPixel (myBoard.xMax) + 6))) && (((((((Event.MouseButton.Y + 1) / zoomLevel) - 1) - 1) % 14) > 0) && ((((Event.MouseButton.Y + 1) / zoomLevel) - 1) <= (myBoard.gridToPixel (myBoard.yMax) + 6))))
{
// If the piece is sucessfully placed at the co-ordinates
if (myBoard.placePiece (myBoard.pixelToGrid (((Event.MouseButton.X + 1) / zoomLevel) - 1), myBoard.pixelToGrid (Event.MouseButton.Y / zoomLevel)))
{
// Move the selector to where the piece was placed
myBoard.selectorX = myBoard.pixelToGrid (((Event.MouseButton.X + 1) / zoomLevel) - 1);
myBoard.selectorY = myBoard.pixelToGrid (((Event.MouseButton.Y + 1) / zoomLevel) - 1);
}
}
}
// If a button was pressed act depending on which button
if (Event.Type == sf::Event::KeyPressed)
{
// If the key was escape, close the window
if (Event.Key.Code == sf::Key::Escape)
{
App.Close ();
}
// If the key was an arrow key ,vim key, or wasd key, move the selector accordingly
if ((Event.Key.Code == sf::Key::K) || (Event.Key.Code == sf::Key::Up) || (Event.Key.Code == sf::Key::W))
{
myBoard.moveSelector (0, -1);
myBoard.clearAlerts ();
}
if ((Event.Key.Code == sf::Key::H) || (Event.Key.Code == sf::Key::Left) || (Event.Key.Code == sf::Key::A))
{
myBoard.moveSelector (-1, 0);
myBoard.clearAlerts ();
}
if ((Event.Key.Code == sf::Key::L) || (Event.Key.Code == sf::Key::Right) || (Event.Key.Code == sf::Key::D))
{
myBoard.moveSelector (1, 0);
myBoard.clearAlerts ();
}
if ((Event.Key.Code == sf::Key::J) || (Event.Key.Code == sf::Key::Down) || (Event.Key.Code == sf::Key::S))
{
myBoard.moveSelector (0, 1);
myBoard.clearAlerts ();
}
// If space or enter was pressed, try to place a piece
if ((Event.Key.Code == sf::Key::Space) || (Event.Key.Code == sf::Key::Return))
{
myBoard.placePiece (myBoard.selectorX, myBoard.selectorY);
}
// If 'p' was pressed, pass
if (Event.Key.Code == sf::Key::P)
{
myBoard.pass ();
myBoard.clearAlerts ();
}
// If 1 - 3 was pressed change the zoom level
if (Event.Key.Code == '1')
{
zoomLevel = 1;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
if (Event.Key.Code == '2')
{
zoomLevel = 2;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
if (Event.Key.Code == '3')
{
zoomLevel = 3;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
}
}
// If the game is over begin the final counting of points
if (myBoard.inGame == false)
{
// Start the wrap-up phase
myBoard.inWrapUp = true;
// Count surrounded space, add markers, update marker strings, and update the alerts string to who won and what to do next
myBoard.countSpace ();
// Continues to display until the window is closed, escape is pressed, or enter is pressed
while ((myBoard.inWrapUp == true) && App.IsOpened ())
{
// Process events for the wrap-up phase
sf::Event newEvent;
while (App.GetEvent (newEvent) && myBoard.inWrapUp == true && App.IsOpened ())
{
// Close window : exit
if (newEvent.Type == sf::Event::Closed)
{
App.Close ();
}
// If a button was pressed
if (newEvent.Type == sf::Event::KeyPressed)
{
// If the escape button was pressed exit the game
if (newEvent.Key.Code == sf::Key::Escape)
{
App.Close ();
}
// If the enter button was pressed, exit the wrap-up phase
if (newEvent.Key.Code == sf::Key::Return)
{
myBoard.inWrapUp = false;
}
// If 1 - 3 was pressed change the zoom level
if (Event.Key.Code == '1')
{
zoomLevel = 1;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
if (Event.Key.Code == '2')
{
zoomLevel = 2;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
if (Event.Key.Code == '3')
{
zoomLevel = 3;
App.SetSize (myBoard.smallWindowWidth * zoomLevel, myBoard.smallWindowHeight * zoomLevel);
}
}
}
// Draw and display the board
myBoard.drawBoard ();
}
}
// Draw and display the board
myBoard.drawBoard ();
}
}
return 0;
}