Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [STICKY] The Useful Community Functions Project

Author
Message
Hodgey
9
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 23rd Jan 2012 02:25 Edited at: 23rd Jan 2012 09:22
Nice functions Scraggle!

Stopwatch

Same warnings as the my timer function above.

I couldn't find a Log() command (let me know if there is one) and so had a go at writing one myself. There isn't any 'invalid' value checking so don't enter anything <=0. The function is only approximate as it uses a 'halving the solution' type method for working out the power. There are two functions here, an intLog( which only works on integer powers > 0) and a Log function.

Note: The accuracy is not to how many decimal places it is accurate to but to how many times the function goes through the halving process. Naturally the higher this value is the more accurate the returned power is. I find an accuracy of 10 is accurate enough but you can increase it at the cost of a few extra iterations of a while loop.

And some old DBP favourites:
Wrapvalue:


NewXValue:


NewYValue:


Edit- found a bug in the Log function which has now been fixed.

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 23rd Jan 2012 09:45
Convert time to string format = "HH:MM:SS"

So if you do something like timeValue# = timer() - startTime# and pass the value in it will return how much time has passed since the start time:


bitJericho
16
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 23rd Jan 2012 13:32
This is great, once I get going I'll submit a few myself. One thing I noticed is that this is released under the GPL. AFAIK this means that for anyone who uses this library, their entire project would have to be released as open source.

Is this the intent? If not, the LGPL might be a better alternative.


Talairina
13
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 23rd Jan 2012 14:46 Edited at: 29th Jan 2012 13:46
This is a Text creation function, act's as a all in one for setting up text.



Example usage:


or



Supports the following options:


Have to thank Rich Dersheimer and Mobiius for the advice in making this
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 23rd Jan 2012 15:22 Edited at: 23rd Jan 2012 15:36
Good point on the license. In 0.0.0.5 I've removed any license at all, this project is now public domain so you can all do whatever you want with it.

If anyone has any objections to their functions being classified as public domain please let me know and I'll remove them from the project.

I've also added Talairina, Hodgey and baxslash's new functions bringing the total up to 48 functions.

Release version 0.0.0.5

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 23rd Jan 2012 15:29
I assumed these could be used by anyone without having to give credit even.

The spirit of something like this is the spirit of sharing. Yes there's a slight cash incentive but it's more to help each other out right? I'm willing to waive any winnings, or if you want put it towards Birmingham Children's Hospital or Great Ormond Street or something...

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 23rd Jan 2012 15:35
We'll run the lottery first, then if anyone doesn't want their winnings you can instruct me to donate the payment to any charity of your choice.
MrValentine
AGK Backer
8
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Jan 2012 16:19
Daniel... I think that should be the process really... just pick a Charity... I think the figure is small enough to not be desired dont get me wrong but personally speaking though its unlikely I may ever post a script... but I would feel better knowing if I won the money would go to [insert charity name here] instead of me...

Just a personal view... perhaps a thread vote on this¿ or just stick to either being optional...

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 23rd Jan 2012 16:32
We'll keep it optional, you never know someone might find £10 useful one day. I can think of a few students who's consider a whole £10 a good night out!
Hodgey
9
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 23rd Jan 2012 22:02 Edited at: 29th Jan 2012 20:32
I like the charity idea.

Anyone miss the good ol' text command? I certainly did.

This function uses global arrays so be careful not to use the same names for your arrays.

Edit: If anyone wants to convert this to a colour version feel free to do so.

Edit 2: Fixed appearance bug in virtual resolutions.

Rich Dersheimer
AGK Developer
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 25th Jan 2012 23:26
Here's a simple little function that bumps a text string.

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Jan 2012 15:11
This functions creates a block sprite, I saw similar code used in the 3tris post and thought that this would be useful for placement holders when designing your game.

This function will create a block based on your settings, colour it, alpha it, and position it. It also sets the default sprite offset as the middle of the block.



MakeObjectBlock( x position, y position, size in x, size in y, red, green, blue, alpha )

example program:

Talairina
13
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 28th Jan 2012 15:39 Edited at: 28th Jan 2012 15:40
Incredibly simple dice roller I wrote for my DBP function library. Can easily be used to roll pretty much any type of die that's currently in use in PnP RPG's/Tabletop Wargames from percentile (d100) to d4, d6, d8, d10, d12 and d20. Of cause you can assign any value you like within the function so you can even make up your die if you so wish.



Example usage of a 1d6+4 roll;
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Jan 2012 15:41
Here's a simple Orbit function that takes a sprites position, and then automatically orbits another sprite around it, this function assumes that both sprites offset is set to the middle.



Orbit( Sprite ID to orbit, Sprite Planet to orbit around, radius of orbit and angle of orbit)

Example code:



Note you can also use the wrapvalue function in this program.
Impetus73
7
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 28th Jan 2012 18:07
What about renaming all the functions to start with UCF_ so they are more easy to spot in any code that uses them?

Maybe TGC should look at adding some of the functions as new commands to AppGameKit also.

----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Jan 2012 18:09
This function is based on the Particles Explosion demo that comes with App Game Kit. I've adjusted explosion to my liking and reduced it's system requirements by half to better support multiple explosions. The graphics file used in the demonstration code can be found under the Particles - Explosion example within App Game Kit, or you can just open that project and paste the code in directly

I may do some more tweaks on this in the future, but at the moment it's quick and easy way of getting a particle based explosion.

Explosion(ID, x, y, img)

ID is the particle emitter ID, x and y are the spacial co-ordinates, and img sets the image for this emitter.



Example Program:

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Jan 2012 18:13
Thanks for the suggestion, but I don't see any real advantage in beginning all these commands with UCF_ it would just make them unnecessarily long to type. So I'm attempting to keep the names as straight forward as possible. If users find that the functions clash, they they can just use the help documentation to bring the specific functions they want manually.
Talairina
13
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 29th Jan 2012 13:56 Edited at: 29th Jan 2012 14:01
Hey Daniel, quick note about the CreateFormattedText function in the help files.;

1) The example code is missing an extra parameter i.e. the last '0' for TextDepth

Needs to be like so;

An additional and better example would also be like so;

Basically keeps it all on one line and saves some extra code.

You also have authors note as;

Which naturally is not based around that function but belongs to 'initFont()' set after it in the help files.

Just pointing it out so we can make sure everything is up to date and correct As trying the code as the example has it it would of cause throw up an error.

I also have a suggesting to have the author of each function attached to the function somewhere so that way if someone has an issue with it, they know who in the forums wrote in regards to asking for support with issues on it. For example I have an issue with Hodgey's 'Text( X#, Y#, txt$ )' function which I need to ask about (in another thread at one point).

Keep up the great work and if you ever need a hand with documentation with this just shout More then happy to lend a hand with this great project. Already owe thanks to yourself for the MakeObjectBlock function. Comes in handy whilst I design UI's before having to actually break out the GIMP.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 29th Jan 2012 15:36 Edited at: 29th Jan 2012 15:39
Ok, thanks for letting me know. I'll add the changes in the next version which should appear around the 4th of February. Don't worry if someone has an issue with a function then they can deal with me directly, and if necessary I'll go to the author. It's best that I know of any such problems because then I can address them directly in the projects documentation.
Hodgey
9
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Jan 2012 20:14 Edited at: 29th Jan 2012 23:43
Quote: "For example I have an issue with Hodgey's 'Text( X#, Y#, txt$ )' function which I need to ask about (in another thread at one point)."

Thanks for pointing that out mate.

Try this:


Edit: Decided to expand on the text commands.

CenterText function

Displays a centered version of the string passed into the function.

Ink command

Changes the colour of the text and CenterText commands.

TextSize command

Changes the size of the text outputted from the Text and CenterText comands.

bitJericho
16
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 1st Feb 2012 23:12 Edited at: 1st Feb 2012 23:13
I've corrected and enhanced the vscrollsprite and hscrollsprite functions:



there were some typos that caused them not to work.

Also, now that you need to input both the u and v offset in either function, you can use the two commands together, side-by-side.

Here's how you could use them:




Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 2nd Feb 2012 04:47 Edited at: 2nd Feb 2012 04:57
This is a brilliant idea! I've got several functions which I was going to release for free anyway in a Useful Functions Pack, but I will give them to you to release for me

They were originally written in C++ as a plugin for DBPro, but I've converted most of them for use in the AppGameKit recently while testing the AGK.

There is only one global value. The Round functions support negative values as well (I think). The ResizeValue functions were the very first functions I wrote in this pack, and purely out of necessity while programming once in DBPro. I hate maths, so I was lucky to work out how to write them at all. I think they are basically "lerp" functions, whatever that is. The ReverseValue functions...well...it's a bit hard to explain. They just reverse a value based on the min# and max# parameters. So, as far as I can remember (I wrote these a long time ago), if you input 0.3, with a min# of 0.0 and a max# of 1.0, it will return 0.7. Complicated... The one listed as NOT FINISHED was something I was writing for DBPro, but I haven't removed it yet as I may still finish it for AGK. Also, some of these functions are already available in the AppGameKit command set.



EDIT: I just remembered I wrote some help files on an old version of the plugin for DBPro. I am attaching them to this post. They may help you if you can't work out how to use a particular function, but just remember that they are old and don't cover all the functions.

Have fun!
Clonkex

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Feb 2012 12:43 Edited at: 2nd Feb 2012 14:39
Just wrote these functions for another thread but on checking I realised nobody had added these in yet so...

moveSprite(spriteID,amount#)
moveSpriteUp(spriteID,amount#)

Pretty obvious what they do really, they work for both percentage and pixel setups as usual



Rich Dersheimer
AGK Developer
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Feb 2012 14:24 Edited at: 2nd Feb 2012 14:25
Very nice baxslash. It would be really cool to also have

RotateSpriteRight(spriteID, degrees#)
RotateSpriteLeft(spriteID, degrees#)
PointSprite(spriteID, x#, y#)
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Feb 2012 14:33 Edited at: 2nd Feb 2012 15:12
How about turn sprite?


EDIT: and point sprite:


EDIT2: and turn sprite to


EDIT3: edited the previous function


Rich Dersheimer
AGK Developer
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Feb 2012 19:44
Excellent, that should make sprite control easier.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 2nd Feb 2012 21:18
I was planning to compile version 0.0.0.6 today but I've got a stinking cold and a pounding headache. I'll see how I feel after a good nights sleep (I hope) but it might not happen until next friday now, sorry guys!
MrValentine
AGK Backer
8
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 2nd Feb 2012 21:25
Get well soon buddy have some spicy or hot soup...

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 2nd Feb 2012 22:47 Edited at: 2nd Feb 2012 23:01
I noticed that the AppGameKit examples (space shooter and accelerometer) don't currently calibrate the accelerometer to the players natural holding position. These two functions will remedy that.

SetAccelerometer() and GetDirectionYOffset(), use SetAccelerometer() to calibrate the device, and replace the GetDirectionY() AppGameKit command with GetDirectionYOffset().

Note, these functions appear to work well, but they were written under the influence of bad cold, thumping headache and several cough medicines so I might not be thinking at my best!

SetAccelerometer()


float = GetDirectionYOffset()


Function's starting requirements


This code is a modified version of AGK's example program for the Accelerometer, simply open it up from Projects\Basic\Examples\Input\Accelerometer and paste this code in then compile it.



Right now this problem has stopped bugging me I'm going to sleep until next month.
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Feb 2012 09:59
That's nice code Dan! Hope you're feeling better soon.

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 5th Feb 2012 17:52 Edited at: 5th Feb 2012 17:54
Here's an improved version of my accelerometer functions. The first is the same but I'll repost it anyway, the rest now have deadzone options in both X and Y, as well as sensitivity options so you can adjust the speed directly within the function. Again I used the accelerometer example from the App Game Kit examples folder as the basis for testing these functions.

Startup code:


SetAccelerometer()


float = GetDirectionYOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value



float = GetDirectionXOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value



example code (modified version of projects/input/accelerometer/)
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Feb 2012 19:33
This function returns the ID of a virtual button pressed.

Startup code required:


integer = VirtualButtonCheck(max)
max as integer, this sets the maximum number of buttons to check.

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 7th Feb 2012 19:41 Edited at: 7th Feb 2012 19:42
These functions display a SplashScreen and basic menu system, this largely acts as a basic framework to wrap your games in. Allowing users to focus on their core game while adding in an options menu to quickly calibrate the accelerometer.

At a later date I will also add an Options menu. For now all this does is launch the accelerometer calibration.

Please note this version uses pre-made media, I'll produce a media-less version next.

Required startup code:


SplashScreen(time)
time as float, each 1000 milliseconds = 1 second




Example program
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 9th Feb 2012 00:43 Edited at: 9th Feb 2012 17:50
Example code for the Bounce function

3d point in space
9
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 9th Feb 2012 18:07 Edited at: 9th Feb 2012 18:09
here is one of the most usefull c++ functions.
it takes the system time, and separates it into day mounth and year.


i wonder if this can be duplicated in tier 1.

Developer of Space Chips, pianobasic, and zipzapzoom apps.
Veterian for the military.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 9th Feb 2012 19:00
I was working out a program example using the Hermite interpolation formula, and decided to build upon it with a new function called AnimateSpriteWithHermite, this function should take all the pain out of drawing curves and animated paths using the Hermite method.

Requirements:
This function requires the following two functions.


float = AnimateSpriteWithHermite( spr, x1#, x2#, y1#, y2#, speed#, x# )
spr = sprite ID
x1# = starting position X
x2# = end position X
y1# = starting position Y
y2# = end position Y
speed# = speed of the sprite (1.0 is default)
x# = the output of the function returned to the function


This function animates a sprite along a hermite path. Here's a full medialess example you can use.

Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 10th Feb 2012 10:05
Quote: "i wonder if this can be duplicated in tier 1."


Easily, if you would supply all the code you wrote. For example, the line "struct tm *timeinfo;" relies on a struct that's obviously defined in another file.

Clonkex

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Feb 2012 10:09
Time and date info are not available in Tier 1 until the next update. Then this code could be easily translated into something useful.

Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 10th Feb 2012 21:13 Edited at: 10th Feb 2012 22:39
AnimateSpriteWithHermiteWithStop( spr, x1#, x2#, y1#, y2#, speed#, x# )

Exactly the same as the last one, except this version animates then stops at the end of the animation. I modified this for my own usage initially, the modification is a little ugly. I'll likely improve it when it comes to optimising the game I'm currently working on.



P.S. I'll be working on the next UCF release tomorrow.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 10th Feb 2012 22:04
Websafe colour names function:

This function needs to be run at the beginning of the program after any #include statements, it adds a set of constants with websafe colour names. So if you ever want "SkyBlue", "Azure", "Aquamarine", "Lavender", etc without wanting to look up the RGB lists, then this function will solve your problems! Just type the colour you want and let the #constants do the rest.

Colours()
Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 10th Feb 2012 22:10
I didn't know you could make constants that fill multiple parameters! That's extremely useful!

Clonkex

MikeMax
AGK Academic Backer
7
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 14th Feb 2012 19:09 Edited at: 19th Feb 2012 02:48
I'm sure Base64 encoding/decoding functions will be appreciated

Thanks to Randy Charles Morin (C++ Version), Phaelax for the DBP Version (for my side i've done almost... nothing ... except convert byte type (which doesn't exist in AGK) to integer and other minor changes to get it compiled

bitJericho
16
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 15th Feb 2012 23:33 Edited at: 15th Feb 2012 23:43
Here's some trim commands for your string parsing pleasure. Took about 30 minutes, mainly due to wrestling with AGK Also it's a good example of a function calling itself (recursion):



And an example using it:



MikeMax
AGK Academic Backer
7
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 16th Feb 2012 18:40 Edited at: 16th Feb 2012 18:52
Quote: "I didn't know you could make constants that fill multiple parameters! That's extremely useful!

Clonkex"


Keep in mind that a constant is almost a replacement of code cause It seems #constant in AppGameKit Tier1 is between #define and const statement in c++. In certain case it can increase execution speed (i know that it's the case in C++ (for a define statement) but i don't know how AppGameKit is managing its constants in low level (textual substitution by preprocessor or not ?).

For example you can declare some operations or functions like this (more readable sometimes or shorter to write in code) :




Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 16th Feb 2012 19:46 Edited at: 16th Feb 2012 20:29
Animated Lerp function. Moves sprites between two points in space, in a straight line.

animatedLerp( sprite, x#, x2#, y#, y2#, v# )
spirte = sprite ID
x# = starting x pos
x2# = ending x pos
y# = starting y pos
y2# = ending y pos
v# = value between 0 and 1, 0 is the start, 1 is the end.


Note, this function is suitable for timer or cycle based movement.
Daniel TGC
Retired Moderator
12
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 16th Feb 2012 19:55 Edited at: 16th Feb 2012 20:29
Animate a sprite using the Hermite interpolation Curve, looks a little bit more pleasing than basic lerp and you can use a timer input or cycle input.

AnimateWithHermite( sprite, x#, x2#, y#, y2#, v# )
sprite = sprite ID
x# = starting position x
x2# = ending position x
y# = starting position y
y2# = ending position y
v# = value between 0 and 1 sets the position of the sprite along the path. 0 = start, 1 = end
MikeMax
AGK Academic Backer
7
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 20th Feb 2012 23:21
My prefered string function in all languages ^^ : a replaceString function i've done based on the UCF existing "inString" function. It will replace every occurence of thisSearch$ by thisReplace$ and return the Result as a string



Example usage :


Ched80
8
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 23rd Feb 2012 07:01 Edited at: 23rd Feb 2012 07:01
Made a simple function that returns the next free sprite ID, could be useful for setting up sprite for animations:



Example use:


bitJericho
16
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 23rd Feb 2012 11:15
That's not really necessary, because CreateSprite can return automagically the sprite number it wants to use:

Player.sprite = CreateSprite(0)

Ched80
8
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 23rd Feb 2012 11:18
Ah, I thought you could only use 0 when the sprite ID was known.
Cheers

Login to post a reply

Server time is: 2019-06-26 10:34:09
Your offset time is: 2019-06-26 10:34:09