• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Keyboard Input In Miniscript

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Introduction


Hey fellas, welcome back to the How to

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

tutorial series!

Yeah yeah, I know—it’s been a while since the last post.
But guess what? We’re back, and we’re doing going to do it better than ever.

Before we jump in, here’s a quick recap of the previous articles in this series:


If you're new here, I suggest you check those out first.
Alright, lets get started

Getting Basics Done.

Mouse Input?


This post is all about handling keyboard input in Mini Micro.
Mouse input? Don’t worry, that’s coming up soon!
But if you’re curious, this blog already aligns a bit with that concept:

?

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Choosing Your Sprite.


Normally I love making my own sprites, but today… I took a shortcut.
Why? Because this gives me the perfect opportunity to show you something awesome:


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

comes with a whole library of built-in sprites!

Here’s how to explore the built-in sprite collection:

Use this command:


findFile

Then go to: /sys → /pics → /animals

We're using an animal sprite today—because why not?
I picked a crocodile, but feel free to grab any animal that vibes with your coding soul.

Setting the Background


For the background, I actually made something myself (in like 3 minutes?).


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



It’s not fancy, but it works for a test setup!

Setting Up the Scene


Now let’s bring everything into the display:


//Set up display
clear
display(4).mode = displayMode.sprite

//Set up bg
bg = new Sprite
bg.image = file.loadImage("/usr/Bg.png")
display(4).sprites.push bg
bg.x = 480
bg.y = 320

// Set up crocodile sprite
crocodile = new Sprite
crocodile.image = file.loadImage("/sys/pics/animals/crocodile.png")
display(4).sprites.push crocodile
crocodile.x = 480
crocodile.y = 120
crocodile.scale = 1.5
Don’t know how to load sprites in Mini Micro?
Check out this intro post:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

Creating Variables


Now we need to create a variables.


speed = 5 //Handles Movement Speed
Coding Movement



Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

makes keyboard input super simple with key.pressed(key)function.
For example, if you want to detect a jump on the spacebar, you'd write:


if key.pressed("space") then
//jump code
end if

But today we’re focusing on left and right movement.


speed = 5

while true
// Handle left and right movement
if key.pressed("left") then
crocodile.x = crocodile.x - speed
else if key.pressed("right") then
crocodile.x = crocodile.x + speed
end if

// Keep crocodile within screen bounds (960x640)
if crocodile.x < 0 then crocodile.x = 0
if crocodile.x > 960 then crocodile.x = 960

// Exit on escape key
if key.pressed("escape") then break

yield
end while

What’s Happening Here?


  • Left arrow pressed? → Sprite moves left by decreasing its x position by speed.


  • Right arrow pressed? → Sprite moves right by increasing its x position by speed.


  • Speed controls how fast the movement is (you can tweak it).


  • We make sure the crocodile stays within screen limits so it doesn’t disappear off-screen.

-You can exit the loop by pressing Escape.

And just like that, you've got a moving croc sliding left and right across your screen.

And that's how you handle keyboard input in miniscript.

Outro


Till Then Stay Curios , Stay Selfish


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу