The Mezunian

Die Positivität ist das Opium des Volkes, aber der Spott ist das Opium der Verrückten

Let’s Code a Crappy 2D Platformer Like Millions o’ Other People on the Internet & Lose Interest & Give Up Only a Few Months In, Part V

Nothing too radical today: mostly just a bunch o’ gimmicks I added in.

Simplified Sprites

Nothing exciting: just merged the SpriteMovement class into the Sprite class, since I found the difference ’tween the 2 too hard to find. Also, SpriteMovement oft had to manipulate a lot o’ Sprite’s stuff, requiring me to make too much public.

Updated Level-Select Screen

Now there’s a li’l checkmark next to levels beaten, as well as the highest gem score & lowest time ’pon beating a level.

Sloped Ground

The rightward slope’s a bit buggy, but the left slopes work perfectly. They e’en slow you down as you go up slopes & allow you to slide down them by pressing down. All that’s needed, other than fixing the right slopes, is to change Autumn’s graphics ’pon sliding downward & a way to kill enemies ’pon sliding into them.

Sloped ground is split into 2 blocks: “low” & “high.” You can see the pattern here:

Vertically-tiled Backgrounds

As mentioned earlier, the backgrounds only tiled horizontally before. Adding vertical tiling was just as simple as I expected: simply had to pull the horizontal code into a separate method, & then copy that code & replace all the horizontal variables with vertical variables, replacing the graphic-drawing functions with calls to the renderX function, pushing in sy, dy, & h.

I also added in a way to have animated backgrounds—though this is limited. Basically, there’s an extra parameter to the constructor that allows one to change the # o’ frames. In this case, the width given to the constructor is s’posed to be the width o’ a frame, & for the 1st “cycle” o’ the renderX function, ( width_ * current_frame_ ) is added to sx & subtracted from right.

Finally, I added “foregrounds” to the map class, which is just ’nother vector o’ Background objects, ’cept these are drawn ’bove all o’ the blocks & sprites (though not the UI). This & the animated background are used in a new level I’m starting called “The Streets o’ Storms” to make falling rain appear in front o’ everything.

The rain animation isn’t particularly good; but it’s passable for now.

As a bonus, this level has the light-gray background flash white every so oft. This was done by setting the bg_ variable in the palette to 7, which is ’bove the limit, & changing the code that disallows colors ’bove the range to make colors ’bove the range use some custom code. Right now this extra code is hard-coded to use the 3rd & 1st (white) colors for the background, which is fine for now, since it’s just a rare extra used for only 1 level so far. If I need to use this in any other level, I can always change it. I did consider doing some complex thing where the # ’bove the limit determines the 2 colors (7-12 has colors 1 & 1-6, 13-18 has colors 2 & 1-6, & so on…), but for now I’ll stick to the “You Ain’t Gonna Need It” principles. It’s not as if it’d be harder to implement later than it would be to implement it now.

Sawdust Crush Gimmick

“Sawdust Crush” is a horizontal version o’ the Donkey Kong Country 3 level, “Ripsaw Rage,” but without the stupid bullshit where you can’t scroll too far ’head, which I ne’er liked in autoscrollers1. ¿What’s keeping me back? ¿The great Camera God? The gimmick is entirely programmed in the saw’s sprite code: it sets itself a flag so that it doesn’t fall, constantly moves rightward, & automatically adjusts the camera if its x coordinate ends up lower than the saw’s so that the saw pushes the camera forward if the player lags too far ’hind. This & the way the saw acts solid if the player runs into it prevents the player from letting the saw pass them. Finally, the saw hurts the player ’pon touch & automatically kills the player if it finds that the player has collided into something solid to the right ’pon touch—essentially squishing them ’tween it & a block.

(A li’l detail I noticed: I should probably make it so that the player’s hearts in the UI automatically disappear ’pon death.)

Wind

“Windy Woods” is a short demo o’ the wind mechanic, which simply subtracts a certain # from the player’s vx_ every frame, making it hard to move forward & making movement backward go extra quickly. Not hard @ all.

Auto-Run Gimmick

This is like the cannon levels in New Super Mario Bros. 2: Autumn constantly runs forward no matter what the player presses & the player needs to jump o’er any obstacles. In levels with this goal, if the game detects the player colliding with a wall to the right, she’s automatically killed.

Adventure Island Gimmick

’Nother simple 1, though not used in e’en a demo level yet: the player starts with 500₧ & loses 25 every frame or so. If it reaches 0, she dies. Thus, the player must repeatedly collect gems to stay ’live.

“Land o’ Communism” Gimmick

This is almost the opposite: if Autumn gets any money @ all, she automatically dies.

Golden Gear Solid Gimmick

There’s also a new enemy that paces left & right & can kill the player just by looking @ it. As this name implies, the goal is to sneak past them without being seen. My only problem is that I can’t figure out how to keep them from looking past solid objects. Right now my main plan is to limit their eyesight to 8 blocks & just ne’er allow the player to be less than 8 blocks in front o’ a guard from ’hind a wall.

The Future

I’ll try to focus a li’l mo’ on finishing some levels, though I did also want to make some moving platform sprites, & maybe a bouncy block like the note blocks in Mario games.

There is this odd glitch that pops up sometimes: sometimes immediately ’pon entering a level, one gets the “¡Failed!” screen, but the game treats it as if one beat the level, giving one the checkmark & a high score o’ 0 gems & seconds. I still have no idea why this happens.

For those who want spaghetti code full o’ stupid gimmicks that only bloat the code, download the source code here.

¿Liked it? ¡Take a second to support this idiot on Patreon!
Posted in Boskeopolis Land, Programming