CSCI 200 - Foundational Programming Concepts & Design - Fall 2022

Lab 6A - SFML: Bob Ross

This lab is due by Tuesday, December 06, 2022, 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 utilizes graphics, sound effects, and/or networking. 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


The first step is to download the source code from SFML from the SFML Download Page. Be sure to download the zip for the Source Code and not an OS specific package. This is at the bottom of the page. Once downloaded, unzip the package.

Next, download the cross-platform Makefile package. Once downloaded, unzip the package and place the contents inside the SFML-2.5.1 folder from the above step alongside the readme.md file.

Now in a terminal, navigate into the SFML-2.5.1 folder and type make.

This Makefile will build each of the necessary libraries. If you receive errors during this step, please post to the corresponding post on Piazza matching your operating system. YMMV in this process but we are here to help!

Once successfully built, you'll now need to copy the library files to your installation. First, you'll need to copy the include headers that declare all the classes within the library. Next, you'll need to copy the precompiled library files. Finally, you'll need to copy the runtime files. Where each of these go will depend on operating system:


Instructions


Download the SFML Template. This will create an empty window to start working with. First, take a look at the main.cpp file provided. 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 face and color it yellow
CircleShape face;
face.setPosition( 15, 15 );
face.setRadius( 300 );
face.setFillColor( Color::Yellow );
window.draw( face );
        
// Draw a rectangle object called eye and color it blue
RectangleShape eye;
eye.setSize( Vector2f( 45, 150 ) );
eye.setPosition( 200, 150 );
eye.setFillColor( Color(0, 0, 255));
window.draw( eye );
         
// Draw a text object called label
// place in file loading section
Font myFont;
if( !myFont.loadFromFile( "data/arial.ttf" ) )
    return -1;
// place in drawing section
Text label;
label.setFont( myFont );
label.setString( "Hello World!" );
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 3 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 based on a variable. Try it!


Lab Submission


Submit your main.cpp, Makefile, data/* file(s).

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


This lab is due by Tuesday, December 06, 2022, 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.