CSCI 261 - Programming Concepts - Spring 2021

Lab 7A - SFML Drawing

This lab is due by Tuesday, April 20, 2021, 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 C++, 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.1 documentation.


Setup


Be sure to start with the template as it will automatically link against the SFML library for you. 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.

Windows Users: Download the Windows Project file.

Mac OSX Users: Download the Mac OSX Project file.


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 draw 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? 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 Tuesday, April 20, 2021, 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.