How to get timestamp in Monkey 2 with libc and in C

This morning I got implemented a little code, that can be used to get timestamp based on ANSI C code using Monkey 2 programming language’s libc.

Let’s take first look at the Monkey 2 code:

At the moment the output of the program is as follows: 40-31-8-26-10-2018

Year 2018, month 10, day 26, hour 8, min 31, sec 40.

Reversed order might be more useful in practice…

Let’s take a look at the C version:

To the year is again added 1900. This gives following output: 26.10.2018

The tm_mon is between 0..11, tm_year between 1900 + 0..n.

That’s it for now, lots of things to do…

 

 

Sine Wave Scroller in Monkey2

Today’s little code, sine scroller in Monkey2. In the previous post you can download the code and data files for plain scroller. In this project same data files are used. Let’s take a look at the video:

The scrolling isn’t very smooth in the video, but try the code:

The idea is to build a string (“scrollString”) which characters are drawn one by one to the screen in order to achieve the sine wave effect.

Feel free to use this code.

Simple text scrollers in Monkey X and Monkey2

I coded today simple text scrollers in Monkey X and Monkey2. When the old school bug had bitten me I coded among other things the following:

This night it’s time to just simple text scrollers code.

Let’s take a look at the result of the Monkey X code:

The source code:

For the font I’ve used my Font 2 PNG and its data file. Notice, that the update rate is only 15, change that to 60.

 

For the first time I made a text scroller in Monkey2 too. The result is in video below:

As you can see, the code is a little different:

In order the get coding going, you may download both the projects with all the data files. Password to download: scroller

Later it’s time to again for sine wave scrollers… 🙂

Have fun!

Unique Random Integers part II

Last year I wrote about my clumsy implementation of unique random integers system, I’ve used in my Memorable Ladies games. In those the speed isn’t a critical factor. It’s sufficient that the idea works. 🙂

In this post the idea behind unique random integers is the same, but implemented in a faster way.

In the implementation I have used an array that consists of all desired integers and each is drawn in a way that the same integer doesn’t get drawn again. Let’s take a look at the code (I have used Monkey2 programming language in the example):

Image courtesy of nonicknamephoto at FreeDigitalPhotos.net

First an array is initialized with desired integers. Then an random integer from the array is fetched using random index inside the array.  After that the numbers after the drawn number are moved to “left”. For the end the amount of integers is decreased by 1 and the array is resized by the new amount of integers. That’s it.

This way one gets always different random integer from the set of desired integers.

Furthermore, if one would like to get, for example, number four (4) to be drawn three times, one could just include 4 three times in the array.

Depending on what one is doing, one could keep a copy of the original array for future usage.

Although I have used Monkey2 as example programming language, it should be easy to implement similar implementation to many other programming languages quite straight forwardly.

 

 

Scaling ttf-font in Monkey2

In Monkey2 programming language it is possible to load ttf (and otf & fon) font directly and use the DrawText method of canvas to draw the text. But how to scale the font? In this example I made today it is done in a clumsy way, but may give you some ideas…

The source code:

Below is the video related to this post:

Feel free to use my code!

Scrolling of Picture Larger Than Visible Area in Monkey2

I finally today made my first Monkey2 app. I think it was someday in September I finally noticed that Monkey X has evolved into hugely more advanced programming language: Monkey2.

As I wrote in previous post I have an unfinished game project in Monkey X Pro. I think think I’ll finish it someday in Monkey2… I have one other little project in my mind to be done in Monkey2.

This is why I decided to try to make my first Monkey2 program today. In my older post I wrote a  short tutorial on scrolling a picture larger than visible area in Monkey X Pro keeping Android target in mind. In this post the same thing is written in Monkey2 to desktop.

The picture is scrolled with mouse, to change the code to touch screen, just change the mouse related code to touch related code.

Source code below:

Video below demos the source (the text in the video is in video only, though):

https://youtu.be/U9DLogNGeoo

Below is a video from the mentioned older blog post written in Monkey X Pro to Android:

Feel free to use my code as you wish.