Skip to content
Cawd Logo GAWD
  • Home
  • About
  • Assignments
  • Resources
  • Contact

Wednesday, April 30th

Wednesday, April 30th

Class hours: 10:05 – 2:45
Mr. Bohmann | wbohmann@ewsd.org

10:05 Today’s Notes & Attendance

  • Today is a Wacky Wednesday
  • Call Backs:
  • SkillsUSA Gold Medalist Meeting at 1pm – GAWD2 classroom

Flow Control Continued….

image of rocket landing

On Tuesday we added some logic to our PinBall prototype that stated if the ball count was below 1, our game would end and the ball would be destroyed (or set the Killbox to inactive so no more balls can spawn. Let’s continue working with the concept of flow control and logic with the Lunar Lander we made yesterday.

You can use any logical expression inside an if() or else if() statement. So, you can ask complex questions like “is score greater than 100 AND is playerHealth less than or equal to 0?” In our working example yesterday we checked to see the velocity at which the lander hit the platform.

 if (currentVelocity > 5)
 {
     shipStatus.text = "Crash";
 }
 else if (currentVelocity > 4)
 {
     shipStatus.text = "Easy, Cowbody";
 }
 else if (currentVelocity > 3)
 {
     shipStatus.text = "Improving";
 }
 else
 {
     shipStatus.text = "Nicely Done Captain";
 }

You can also ask very simple questions such as “is shipStatus equal to 1″? In fact, you may frequently want to ask a series of “equal to” questions about one variable or expression and take some different action with each result.

if (shipStatus == 1)
{
   Debug.Log("All Systems Green");
}
else if (shipStatus == 2)
{
   Debug.Log("Yellow Alert");
}
else if (shipStatus == 3)
{
   Debug.Log("Getting toasty in here");
}
else
{
   Debug.Log("Head for the life pods!");
}

While this if / else-if / else chain will work fine, C# provides a cleaner way to test if one variable or expression is “equal to” many different values.

The if() statement is not the only way to control your program flow. The switch has decision-making power similar to an if / else-if / else chain. Switch statements are useful when you want to compare one value against a series of other values and execute different code on each “equal to” match.

The “switch” statement

The switch() statement will accept one variable or expression to test, and then allow you to write different blocks of code for each possible value or “case“. Let’s rewrite our example using the switch statement.

switch (shipStatus)
{
   case 1:
      messageText.text = "All Systems Green";
      break;
   case 2:
      messageText.text = "Yellow Alert";
      break;
   case 3:
      messageText.text = "Getting Toasty in Here";
      break;
   default:
      messageText.text = "Head for the Life-pods!";
      break;
}

What’s going on here? The switch statement begins with the switch keyword, followed by an expression in parentheses. The expression must evaluate to an integer number such as byte, int or long, or a char or string. In our example, we simply used the variable shipStatus, which has been declared elsewhere as some integer type. Important – You cannot switch on a fractional data type such as a float.

Let’s open the Lunar Lander project and see how this works.

The entire body of the switch statement is contained within the opening and closing curly braces.

Within the switch, curly braces are one or more case statements. A case represents one possible value of the switch expression and the code you want to run when the expression is “equal to” that value.

You can add as many case statements as you like; one for each value you want to check. You can also add a default case at the very end. This is similar to the else statement after an if() expression. The default case will be executed if no other case value matches (see above code example for a default case)

switch (health)
        {
            case 3:
                Debug.Log("Your Health is Excellent");
                break;
            case 2:
                Debug.Log("Your Health is declining");
                break;
            case 1:
                Debug.Log("Your are almost finished!");
                break;
            case 0:
                Debug.Log("You are dead");
                break;

        }

Now that we have seen this done. Let’s look at the if / else statements we made in our Lunar Lander and clean them up with a switch statement. Remember when I said we cannot use floats?. A float is a (fractional) value, and you can’t use fractional data types directly in a switch statement.

So, the first thing you’ll do is convert the float to an integer data type. You can cast (convert) a fractional data type to an integer type by placing the new data type in parentheses in front of the fractional value.

// explicitly cast fractional value to integer
 int shipLandingstatus = (int)relativeVelocity; // converts float to int & now we can use in switch statement

10:50 Break

11:00 Pixel Art Here

Sprites (Working towards Pixel Perfect) in Photoshop

  • Tools for Pixel Art – Photoshop, Aseprite, Piskel
  • Games with great pixel art – HyperLightDrifter, ScottPilgrim, Video of Pixel Games
  • Character Size – the evolution from 16 to 128 pixels (DonkeyKong Mario 16 pixels!)
  • Setting up in Photoshop, brushes, shapes, symmetry, text
  • Line theory – for pixel perfect lines-
  • Character Creation or Object Creation
  • Export
pixel perfect shapes

Line Theory:

A “jaggy” is an unintentional break in a otherwise smooth line or curve. This makes the line look strange and pointy, too many jaggies can ruin an artwork.

To make a smooth line you should have the same number of pixels on every “step” of the line, for example: 1, 1, 1, 1, is a smooth line whereas 1, 2, 1, 1, is not.

A smooth curve always follows a pattern. When you are moving towards the centre of the curve the number of pixels should be lower than or the same as the previous number of pixels. 

When moving away from the center you should do the opposite, the number should be higher or the same as the one before it. For example: 6, 3, 2, 1, 1, 1, 2, 4, 4 is a smooth curve

We’ll practice making a character today. Place your creation in Dailies today so we can see what you did. All designs are good!

11:55 Lunch

tacos

12:25 Independent Reading

book covers

12:50 Break

1:00 Production Time and Guided Support

  • One Button Game
  • Finish Pinball
  • Game Careers Worksheet

1:50 Dailies

Dailies can be placed in the CAWD2 Dailies Folder on the CAWD2 Public Folders drive

1:55 Dismissal

GAWD Instructors:

Matt Cronin

Will Bohmann

Instragram Facebook Twitter

A little about GAWD:

Serving high school students interested in Gaming, Animation, and Web Development in North Western Vermont.

Students continue at:

University of Vermont Ringling School of Art and Design Northeastern University Rochester Institute of Technology Concordia University

Students find careers at:

Dealer.com Union Street Media Rovers North Prudential Investments DockYard
Navigate to top of page