September Valentine

Hearts, particularly valentine hearts, tend to be a feature of February rather than September. Fortunately, my valentine isn’t crammed full of them. I’ll share it with you, below, as it’s a Snap project.  This school year, I’m providing what TEALS refers to as “lab support” for students in the morning class at DeKalb High School of Technology—South (DHSTS) in Decatur, Georgia.  And, as part of that, I’m working the projects, same as last year, although now, Snap, is not a stranger to me.

DHSTS is a magnet school.  Students are bused in from other high schools to spend half a school day (four periods) in my class, five days a week. This means we cover a lot of material in a short time. In fact, they’re doing an intro to tech first quarter, Code.org‘s Computer Science Principles during the second quarter and AP Computer Science (with Java and a test), third and fourth quarters.

Which brings me back to the valentine.  As part of the intro, we’re doing a little Snap and we’ve chosen what TEALS calls the Animated Storytelling Project.  Last year, I did a nursery rhyme, “Itsy Bitsy Spider” and all of my students did nursery rhymes as well. This year, it’s expanded. It does have to (loosely) tell a story/narrative and fulfill the rubric.

And so, I present to you.  Carol Ann Duffy’s poem “Valentine” in Snap.

back in business

I am back,  I’ve hiatused long enough and I have fixed the images and code snippets.  What you’ve missed is lists.  Traversals and sequential searches of same.  I’ll cover them as part of Hangman, which I wrote in Snap, but as my students are writing it now, I’ll not be posting mine quite yet.

I’ll post my platform game though. CatStuff.  Here’s a screenshot.Basically, the cat can jump over the saucerbot but if they collide, the game is over.  That’s it.  It wraps. It’s boring.

background check

How do you get the background to move in Snap? How do you get trees or rocks or buildings to move when your hero goes across the stage? The quick answer is, you don’t. The stage doesn’t move. So how do you have moving tress, rocks, or buildings?  You make them sprites.

Making something a sprite doesn’t move it though, you need a script.  You also need to do some things outside of the script to ensure your sprites do what you want.  First of all, make sure that your sprite can only face one direction.  There are three buttons at the top that control the direction(s) your sprite can face.  Make sure to click the bottom one.That arrow pointing to the right means that the sprite can only point one way, and that’s the way the costume points by default.

Next, make sure the Draggable box is unchecked.  That keeps the player from moving your sprite around.

Now you’re ready for your script.  The important principle here is that when your hero moves right, your background sprites scroll to the left.  If you have a “forever” level, they need to also disappear and reappear when they get to the edge.  Scrolling is perfect for a custom block because you’re going to have more than one background sprite and you can reuse the same code with different speeds for the different sprites.   Sprites that are intended to be closer to the viewer move faster (and are generally lower on the screen) than sprites farther away.

Here is code for a sprite scrolling left.  Note that like any other code, it’s only one possible way,  not the only way.This allows you to plug in two parameters, the speed and the height.

Here, kitty-kitty-kitty

I have a platform game.  It doesn’t have a game name yet; the file name is CatStuff and it’s a cat and a zoomba (kinda like a  cross between a trademarked robot vacuum cleaner and a drone).  I have some very cool code in my pocket for this game.  Jumping.  for example.

In Snap, you animate by changing costume and moving the sprite. My cat has 12 costumes—eight walking and four jumping.  Walking animation is pretty simple.  You cycle through the costumes and change the x-coordinate by an amount.  depending on how fast you want to move.  Jumping involves the y-coordinate as well and you have to do both at the same time.  It’s tricky.  Here’s my code to walk right.

You see the variable for the number of steps to move.  That can be set for all the walking the cat does (and it figures into jumping too) in one place.  That’s the point of having it there.  -240 and 240 are magic numbers in Snap as they are the farthest left and right x-coordinates on the standard stage.

Now for jumping.  Because jumping is not an even process, I couldn’t easily abstract it into a loop like I did walking.  It’s long messy code.  I don’t have comments in the code I’m posting here because it makes it difficult to share the images neatly.You’ll notice there’s an if-else at the bottom.  This is to deal with repeating presses of the space bar that don’t resolve fluidly.  The cat will fall if too high and if somehow it gets below ground, it’ll pop back up.   That’s an in-case because I’ve not observed it, but it is theoretically possible.

Jumping is faster than walking but not twice as fast and I wanted a finagle factor so there’s a place to set one.  I’m math-impaired (really) so my formulas aren’t always mathematically sound.  They work for the game though.

Next time, I’ll talk about scrolling the scenery.

Itsy-Bitsy Webspinner

Before Pong we had to do a nursery rhyme. With animation, not simply a storyboard with text.  In Snap, the main way to animate is to change the sprite’s costume.  There are two costume-switching blocks. These are in the Looks section.  One is which changes to the next costume in the set of costumes loaded for that particular sprite. The other iswhich allows the coder to choose which of the loaded costumes to switch to at that point in the code.

Animation also often involves movement from one position on the screen to another and there are two blocks for that, too.  (well, several actually, but two that are useful in animation).  These are found in the Motion section and are  and Both of these take numbers or variables as parameters in the little ovals that I left blank.

There was a rubric for the nursery rhyme.  Students can earn up to 20 points for their project. Here is a screenshot of my nursery rhyme.You can see it here.  Assets are from clker.com except the background (included with Snap) and the waterspout (created in GIMP).  The text sprite was also done in GIMP.  Most assets were modded in some way—either to make a second costume or (in the case of the sun) to make the text sprite more readable.

Apparently, Unit 3 is a “platform game” and I don’t even like those (except maybe Cosmo’s Cosmic Adventure). Watch this space for more exciting Snap stuff as I figure out what kind of platform game I’m going to create and how it will work.