DEV Community

Cover image for Platformer Controller
Kartik Patel
Kartik Patel

Posted on

1

Platformer Controller

Introduction

Image description

Micro Jam #41 is happening once again.

This time the theme is Platformer. Last time when I participated, I lost badly, but I gained enough knowledge that was worth the Loss.

So I decided to try this jam again, and this time, help you too.

In this blog. I am gonna tell you how you could make a simple platformer controller for your game in Mini Micro.

If you prefer to learn visually, I suggest checking out my video on the same topic -> How to Create a Platformer Controller in Mini Micro

Platformer Controller

In most engines and frameworks, this is a very hard task, but why?

Because you have to code every single thing,
Collision, Ground Detection, Movement on keys, and Jump Mechanism.

But Mini Micro takes a special approach, which makes the creation of a platformer controller way easier

See, there is a library in Mini Micro in /sys/lib called spriteControllers. This library has everything you need for creating a platformer sprite controller.

// Set up our player character, "Kip"
newAnim = @spriteControllers.newAnimation
kip = new spriteControllers.Platformer
display(4).sprites.push kip
kip.x = 400; kip.y = 80
kip.idleAnim = newAnim(file.loadImage("/sys/pics/KP/KP-stand.png"))
kip.runAnim = newAnim([
   file.loadImage("/sys/pics/KP/KP-run1.png"),
   file.loadImage("/sys/pics/KP/KP-run2.png")], 10)
kip.jumpUpAnim = newAnim(file.loadImage("/sys/pics/KP/KP-jump.png"))
kip.fallDownAnim = kip.jumpUpAnim
kip.climbAnim = newAnim([
   file.loadImage("/sys/pics/KP/KP-climb1.png"),
   file.loadImage("/sys/pics/KP/KP-climb2.png")], 10)
kip.curAnim = kip.idleAnim

// Main loop:
while true
    spriteControllers.updateSprites 1/60
    yield
end while
Enter fullscreen mode Exit fullscreen mode

THIS CODE IS TAKEN FROM THIS BLOGPOST I HIGHLY RECOMMEND TO CHECK IT OUT TOO - HWYDT: Donkey Kong

Jam is a time when people are usually in a rush (Especially if it's for 48 hours). So I have answered some questions below before explaining the logic.

How to Turn Off Climb?

Just delete this part from your code

kip.climbAnim = newAnim([
   file.loadImage("/sys/pics/KP/KP-climb1.png"),
   file.loadImage("/sys/pics/KP/KP-climb2.png")], 10)
Enter fullscreen mode Exit fullscreen mode
What if this code doesn't have the logic I want?

Mostly Everything You need would be available in the library, so make sure to check out /sys/lib/spriteControllers, but if it's not, then you have to create your functionality

Explaination

  • This code sets up a player character named "Kip" game using a spriteControllers system.
  • First, it initializes Kip as a Platformer sprite in spriteControllers and adds it to the display layer.
  • The character's starting position is then set to (400, 80). - The code then defines various animations for the player: an idle animation, a running animation, a jump animation, and a climbing animation.

  • The main loop runs continuously, updating all sprites at 60 frames per second (FPS) by calling spriteControllers.updateSprites with an argument of 1/60.

Outro

If you do have any doubts, write them down (I promise I will try my best to help you).
To get more in-depth details about spriteControllers, make sure to check out

Till then stay awesome, Best of the luck for the game jam and BYE

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server ⏰

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay