CSCI 261 - Programming Concepts - Fall 2019

Lab 7A - SFML Drawing

This lab is due by Friday, November 08, 2019, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Concepts


For this assignment, you have the opportunity to play with the power that SFML (a special framework called Simple and Fast Multimedia Library) offers.


SFML


SFML is a multimedia Application Programming Interface (API) written in C++ with bindings for various programming languages, including Java, Python, and Ruby. SFML provides an easy way to write code that requires graphics and/or sound effects. SFML is the chosen platform for many cool games, including the Atom Zombie Smasher. You can check out everything SFML has to offer by reading the SFML 2.5.0 documentation.


Setup


Be sure to start with the template as it will automatically link against the SFML library for you. This template has been tested to work on the lab machines. Begin by unzipping the template for the operating system you are running. Then in CLion, open the folder of the unzipped file. You will need to unzip this template for every SFML Project you wish to create.

If you want to set up your own personal machine, YMMV (your mileage may vary).

Windows Users / Lab Machines: Download the Windows Project file. On your peronsal machine: if your version of MinGW matches the lab machines that SFML was compiled for, it may work out of the box. If it doesn't work, some users have reported using this version of MinGW. Unzip it anywhere on your computer (I like C:\) and then launch CLion; go into Settings... from the File menu and find Toolchains under Build, Execution, and Deployment in the left-hand pane. In the right hand pane, use the drop down to choose the MinGW directory you just created. The project should then work correctly.

Mac High Sierra Users: Download the MacOS High Sierra Project file.

Mac Mojave Users: Download the MacOS Mojave Project file.

Linux Users: You can likely install SFML from your corresponding package manager or need to build from source.


Instructions


First, take a look at the main.cpp file provided in the provided SFML template.

In class, we discussed each of the commands shown (e.g., creation of the window object and the polling for events); ask questions if there is any confusion.

Second, we also saw the development of a smiley face in class today. A few key lines of code covered follow:

// Draw a circle object called star and color it yellow
CircleShape star;
star.setPosition( 15, 15 );
star.setRadius(300 );
star.setFillColor( Color::Yellow );
window.draw( star);
        
// Draw a rectangle object called rect and color it blue
RectangleShape rect;
rect.setSize( Vector2f( 45, 150 ) );
rect.setPosition( 200, 150 );
rect.setFillColor( Color(0, 0, 255));
window.draw( rect );
         
// Draw a text object calledlabel
Font myFont;
if( !myFont.loadFromFile( "data/arial.ttf" ) )
    return -1;
Text label;
label.setFont( myFont );
label.setString( "HelloWorld!" );
label.setPosition( 250, 520 );
label.setFillColor(Color::Black );
window.draw( label ); 

Your job is to draw something in SFML. What you draw can be anything you want EXCEPT a smiley face (e.g., a tree, a bike, a dog, a word using rectangles/circles, etc.). For full credit, you must draw at least five shapes. Be creative and have fun!


Possible Extra Credit


You can earn 2 points of extra credit if the item you draw actually moves (yes, is animated - awesome!). Animation in SFML is actually easier than you might think. As you know, you add all your draw commands in the window loop:

while (window.isOpen()) {
    // ADD SEVERAL DRAW COMMANDS HERE
         
    // Apply all the draws to the screen
    window.display();
} 

To create an animation, you only need to change the draw commands a small amount that are executed on a given loop. Try it!

Remember your smiley face solution for A1? You've sure come a long way since then! Do you recall how we had a prize for the best smiley face submitted in all sections (a debug duck)? That was cool. Let's do this again for Lab7A. That is, we'll have a prize for the best Lab7A submitted in all sections. Good luck!


Lab Submission



You will submit your solution to this lab with the rest of Set7. Detailed instructions for doing this are posted in Assignment 7.


This lab is due by Friday, November 08, 2019, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.