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
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 15:53 Edited at: 7th Apr 2012 01:48
The UCF Project

Latest release HERE


Lottery draw!


The UCF Project stands for Useful Community Functions, it's goal is to take community submitted functions, test, and document them. Once complete a template project is released with the documentation in four formats (CHM, HTML, DOC and PDF).

This project aims to create a valuable resource that is free and easy to use. By generating commonly used functions you can speed up your projects development.

Community members who submit functions will also be placed into a lottery once every three months for a £10 cash prize, the more functions any user submits the better their chances of winning.

In addition to this, the best of these functions will be judged in January 2013, and awarded first, second and third place. The first place prize has yet to be decided, while second place will receive £15 and the third £10.

The rules:

1) Once you submit a function to this project you agree to relinquish all rights to it and you agree that your work can be used by anyone.

2) Functions must be submitted with a brief summary so we all know what they are and what they do.

3) Submissions may be made to this thread, or sent to daniel@dcforeman.co.uk

4) Functions must be for AppGameKit Tier 1

5) All prize decisions made by myself are final and can not be disputed.

6) If you are chosen by the lottery you will need a paypal account to receive your winnings. If you are selected for the grand prize you will need to supply your home address, no personal user details will ever been released publicly or used by myself for any other reason then granting the prizes. Please note official e-mails will only come from daniel@dcforeman.co.uk if anyone else contacts you from any other e-mail address asking for your information, then please disregard that e-mail.

7) As the project develops I reserve the right to change the rules at any time without notice.

** New rules 15/01/12

8) Functions submitted must be your own, please don't copy them from other sources.

** New rule 23/01/12

9) The submitting author agrees that their function may be released as public domain.

The function Lottery!

In addition to the fame and admiration you'll receive from your fellow coders, I will put all user names who submitted a function or functions that was accepted into a release into a random number generator. The winner will receive one $50 voucher donated by The Game Creators and another $20 voucher from my own pocket. That the winner will receive a total of $70 in TGC Vouchers on:

March 31st, June 30th, September 30th, and December 31st

Your name will be entered into the engine for every function you submit and which is included in any UCF offical release.

Grand prize

In addition to this, I will hold a best of UCF competition in January 2013 with a mystery grand prize for the winner, and 2 runner up cash prizes of £15 and £10 respectively.

UCF Releases:

Official releases

Offical release 0.0.2.0


109 documented functions
183 undocumented functions
including new draw commands! Those who've missed these should download now!

Lottery result for April 7th coming soon!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jan 2012 16:08 Edited at: 16th Jan 2012 14:55
Here's a couple of fairly simple functions I've been working on to save me some headaches. I thought I'd share them.

This now works for both percentage and pixel resolution setup.

You can use this to get a position on your sprite in world co-ordinates (even if the sprite is rotated):


Nice idea Dan!

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 16:08 Edited at: 15th Jan 2012 16:11
Thanks baxslash that was super quick, you got a submission in even before I could write an example submission! lol

Example submission:

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jan 2012 16:27
OK, I'll rewrite my previous post with a simpler version (I want to add a "pixel" version anyway), it occurs to me there are ways to make my functions easier to use without initialising any globals.

I think I checked the forums just as you posted this

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 16:31
The enthusiasm is very encouraging! If everyone else responds in the same way this project will be very successful.

Updates will be great, I'll be releasing new UFC version at any time, and will include any updates coders feel are necessary or useful.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Jan 2012 16:45
Wish I could participate/contribute but still waiting on the next release before I start on AGK...

Noticed you did not set out a rule... which should be obvious however...

Submissions must be of the individuals code in entirity and not copied from other sources...

Just a thought ^^

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 15th Jan 2012 17:23
Is this for T1 or T2?
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 17:36 Edited at: 15th Jan 2012 17:44
I think T1 as it will reach the most users.

Added that rule MrValentine
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 15th Jan 2012 17:45 Edited at: 17th Jan 2012 02:32
Here's mine

As AppGameKit doesn't have a debug console option, I have been using this code to produce a log file for me to check back on to help in tracking down bugs.

You'll need to gosub the initDebug: label from your main source, but then you'll just need to writeDebug() to add a line to the log file.



>Edit<
This is intended to be it's own source file, included at the start of the main source file.

apocolyp4
14
Years of Service
User Offline
Joined: 10th Jun 2010
Location:
Posted: 15th Jan 2012 17:47
Here is three calculation based functions that I use in my projects.

Calculate the distance in pixels between two X,Y Positions


Calculate the angle in pixels between two X,Y Positions.


Calculate the velocity of an object using the angle its moving, and its current speed in pixels per frame.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 17:48 Edited at: 15th Jan 2012 17:51
Awesome, thank you. I'll get to start on the documentation.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 18:50 Edited at: 15th Jan 2012 18:52
Here's a couple of my own, don't worry I won't submit myself to the lottery, or the grand prize!

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 15th Jan 2012 18:51
Here's the color picker function I wrote...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jan 2012 18:53 Edited at: 15th Jan 2012 18:53
apocolyp4, you might not be aware but I have a couple of pointers regarding your functions.

The angle between two points can be calculated using the "atanfull" command as follows:
angle# = atanfull(x2# - x1#, y2# - y1#)

Using square root makes the higher number irrelevant as you multiply the difference by itself giving a positive number anyway:
This...
distance# = sqrt((x1# - x2#)^2 + (y1# - y2#)^2)

... will give the same answer even if you swap the x's and y's about.

Not trying to be a smart alec, just trying to increase your knowledge

anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 15th Jan 2012 19:03 Edited at: 15th Jan 2012 19:05
I posted this in another thread but here we go, a global split string function without the need for arrays. Includes companion helper function too.

Edit: includes demonstration too



Hi there. My name is Dug. I have just met you, and I love you.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 15th Jan 2012 19:20
Daniel it would be nice if you could expand the FadeSprite function and make it timer based
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 19:38
ah but first we need someone to submit a good timer function, others have said my version isn't the best way of doing it.
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 15th Jan 2012 20:02
Function getTimeElapsed()
This is similar to a function I have in my app to make sure that to my program, FPS never drops below 60fps. I typed this on my phone, but it should work. I'll verify later, or if someone could do that, it would be great!



Hi there. My name is Dug. I have just met you, and I love you.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 15th Jan 2012 20:24 Edited at: 15th Jan 2012 20:32
This is the first very quickly compiled UCF file, it's not been compiled or tested yet it's just a hash up of everyone's functions except Answerman's timer which has yet to be verified.

It has a little organisation, and I've added a few notes from users posts, I'll keep a version like this going with the latest updates and posts I see, and release the proper release as often as I can.

Functions submitted so far:

Sprites:
FadeSprite(Sprite ID, speed, mode)
HScrollSprite(Sprite ID, Sprite Co-ordinate, Speed, Mode)
VScrollSprite(Sprite ID, Sprite Co-ordinate, Speed, Mode)

Other Graphics:
ColorPick(x as integer, y as integer)

Text:
SplitStringCount(pString as string, pDelimiter as string)
SplitString(pString as string, pDelimiter as string, pSegment)

Debugging:
writeDebug(text$)
closeDebugLog()

Not bad for a project less than four hours old!

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 16th Jan 2012 09:43
This is a neat idea Daniel!

For those who use the percentage system.



What this function does is scales the specified sprite back to what it would look like if loaded into a virtual resolution, back to its 'pixel' form.

A small demo:



Simply sub in your own image and comment/uncomment the _Percent_To_Pixel() function call to see the difference.

westalke
12
Years of Service
User Offline
Joined: 8th Dec 2011
Location:
Posted: 16th Jan 2012 09:51
simple string zero padding for games
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Jan 2012 11:14
Import a CSV file and load all images from said CSV file into memory. This includes setting the Mag and Min filters on a per image basis. Function asks for a string (path) and an integer (overwrite existing).

Includes definition of what the CSV file should look like.



Hi there. My name is Dug. I have just met you, and I love you.
Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 16th Jan 2012 11:23
Simple one

PointerWithin( posX#,posY#,width#,height# )



This function will check if the pointer is within a specified area.

Example:



anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Jan 2012 11:43 Edited at: 16th Jan 2012 11:46
Not sure if having a global variable and constant is valid for this project. I'm doing it this way, because the alternative would be to check if "if X > Y then X=Y" every time the function is called, which would be a waste of processing power. Do it once per frame and save some CPU cycles for when they're needed!

So, that being said...



Hi there. My name is Dug. I have just met you, and I love you.
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Jan 2012 11:45
Function I posted above without a global variable and constant. Choose which ever one works best for this project.



Hi there. My name is Dug. I have just met you, and I love you.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 16th Jan 2012 13:54
Thanks for the great submissions so far!

I'm starting to organize and document these now. In terms of organisation I think I'm going to keep it simple.

Categories in alphabetical order, followed by function name in alphabetical order.

The official release won't have any comments in it, I'll move any comments and examples to the help file system. This will reduce the overall lines of code in the project.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jan 2012 15:02 Edited at: 16th Jan 2012 18:20
I just edited my "SpriteToWorld" functions in my original (pre-emptive) post

Now the two functions will work in percentage based and pixel based resolution setup.

Examples:
x# = spriteToWorldX(spr,0,0)
y# = spriteToWorldY(spr,0,0)
...will give you the x# and y# in world co-ordinates of the centre of rotation of your sprite.

x# = spriteToWorldX(spr,50,50)
y# = spriteToWorldY(spr,50,50)
...will give a point half the width and half the height of your sprite away from the centre of rotation using a percentage system OR a point 50 pixels across and 50 pixels down from the centre of rotation.

The returned point will be relative to the rotation of the sprite. Enjoy! EDIT: AND the scale of your sprite.



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Jan 2012 15:56
FONT REGISTRATION

Rather than keep track of multiple fonts across multiple program paths, use this function to automatically check and load font image files when required. Similarly you can use RegisterFont() to identify fonts by name rather than number when using them.

Requires: 1 Global, 1 Type

Step 1 : InitFont()
to initialise the system

Step 2 : RegisterFont(file$)
supply file name of the font image. If it already exists in your program then it will return the current Font Image ID. If it does not already exist then it will load the image and return the image ID.

This is one initialisation function and one operational function



anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Jan 2012 23:42
Hey,
Would it be possible to come up with a base of guidelines for the following:

constants, types, arrays

I foresee a problem with this file becoming absolutely huge, and by association having a bunch of arrays, constants, and types being included with your program even if you're not using them. At bare minimum, have a naming system so that we can keep everything organized.

Hi there. My name is Dug. I have just met you, and I love you.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 17th Jan 2012 00:40 Edited at: 17th Jan 2012 02:29
Great idea.

I've not seen an Instring function posted anywhere, so here's my offering;

Examples of use include;
Reading words sequentially into an array;

Lines read from an ini or parameter file can be split into parameter and value;

or it can be included in a much smaller SplitString function;

which can be demonstrated with the following;


Edit: added examples of use
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 17th Jan 2012 04:03 Edited at: 17th Jan 2012 04:06
Here is my Randomization Function that I call at the beginning of my game. Since SetRandomSeed() only accepts an integer I had to come up with something that would work for randomization.


Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Jan 2012 05:59
@ XanthorXIII: Not trying to be a smart alec or anything like it but AppGameKit automatically gets a seed based off the current time.

http://www.appgamekit.com/documentation/Reference/Core/SetRandomSeed.htm

Ultimately, wouldn't your function be dependent of the seed AppGameKit retrieves?

Either way, nice function and it's good to see everyone contributing.

XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 17th Jan 2012 20:24
@Hodgey: I ran into an issue where if I didn't feed it a value the randomization came out exactly the same each game run. This function produces a good randomization set.
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 18th Jan 2012 14:08
If anyone has any text or graphics animation functions that would be extremely useful as well.
tornado
19
Years of Service
User Offline
Joined: 21st Jul 2005
Location:
Posted: 18th Jan 2012 17:57 Edited at: 18th Jan 2012 18:07
a small contribution from me:

function counter_MSS(time#) converts float value (e.g. timer() value) into a digital-clock-type string with dividers like 0:00 or 999:59

function counter_HMMSS(time#) converts float value (e.g. timer() value) into a digital-clock-type string with dividers like 0:00:00 or 999:59:59

NOTE: works on positive values





never give up
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Jan 2012 23:42
Thank you Tornado, you have confirmed that the routine I use (which is virtually identical!) is a reasonable way to achieve this. I have spent a long time trying to find a better algorithm but failed.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Jan 2012 11:42 Edited at: 20th Jan 2012 16:26
Here's a simple text colouring function that can be applied to any text (could use a little tweaking on the colours to suit your own needs):


EDIT: changed the float to an integer for the length of the text. I forgot it was no longer needed in the code...

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 20th Jan 2012 16:20 Edited at: 20th Jan 2012 16:21
This is the first example of the help file, please leave comments and if I've made any mistakes please let me know.

I've gone with a basic CHM system, it's easy to search and maintain.

Link

Attachments

Login to view attachments
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 20th Jan 2012 16:52 Edited at: 20th Jan 2012 16:52
Do you allow a full set of functions? XML Library

It also includes 2 string functions.

Here is the blog about it:

http://blog.codepard.com/xml-parser-for-agk-tier-1/

...and here the thread about it:

http://forum.thegamecreators.com/?m=forum_view&t=193049&b=41

Cheers,

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 20th Jan 2012 17:04
If it works with AppGameKit Tier 1's base command set then I have no issues. But this project won't revolve around 3rd party plugins or other alternations to the engine.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Jan 2012 02:59
It's looking good Daniel!

I saw the calculateDistance command and here's a more compact version:


In the unlikely event that you need to work out the factorial of a value:

Note: There is no negative value checks in the factorial function to improve speed.

Degrees to Radians


...and vice versa


A timer function (the count down version)

Note: A few warnings for this function:
1. It uses global arrays to retain data throughout iterations of the loop it is called in.
2. Only one timer can exist at one time with this function.
3. Set the 'reset' flag to 0 to reset the timer. Don't do this every iteration of a loop otherwise the timer will not work.
4. The timer will go into negative minutes but not negative seconds.

One more thing Daniel, you don't need to include my name in the lottery because I think just the project in itself is generous gesture by you.... and I'm too lazy to set up a paypal account.

I wish the others good luck.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Jan 2012 03:04 Edited at: 21st Jan 2012 03:06
Ok I've added all 26 (barring the functions I noticed Hodgey just added) functions into the help file now, tomorrow I'll start testing and organsing the main UCF.AGC file.

The help file has all the function code in it, so you can use it to build your own custom UCF file if you want to reduce your programs overall code.

Download helpfile

I've compiled the help file in both CHM (standard windows help file format) and HTML for mac users.

Attachments

Login to view attachments
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Jan 2012 15:59 Edited at: 21st Jan 2012 16:00
Ok here's the first release of the project, all functions have been added and the project compiles without errors.

Download UCF First offical release

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Jan 2012 19:02
Not bad for six days work Dan

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Jan 2012 21:39 Edited at: 21st Jan 2012 21:48
Yes, thank you to everyone who contributed. I would like to see this project hit 300 functions by the middle of the year. Some additional categories I'd like to see added, include:

Sprite and text FX
Collision detection and reaction
Timers and triggers
Physics

I'm currently working on the following functions myself.

Splash screen
Menu function
Options function
Game over function
Game win function

Something generic that I can use to wrap around any game.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 22nd Jan 2012 14:45 Edited at: 22nd Jan 2012 18:38
Several maths functions taken from UnifyCommunity and converted for AGK:

If you haven't already got PI somewhere then you will need it for some of the functions:


Hermite - This method will interpolate while easing in and out at the limits.



Sinerp - Short for 'sinusoidal interpolation', this method will interpolate while easing around the end, when value is near one.



Coserp - Similar to Sinerp, except it eases in, when value is near zero, instead of easing out (and uses cosine instead of sine).


Bounce - Returns a value between 0 and 1 that can be used to easily make bouncing GUI items (a la OS X's Dock)



Berp - Short for 'boing-like interpolation', this method will first overshoot, then waver back and forth around the end value before coming to a rest.



Lerp - Short for 'linearly interpolate'



SmoothStep - Works like Lerp, but has ease-in and ease-out of the values.


Approx - Check for a value that is close enough to the target (floating point inprecision)


Clerp (Circular lerp) is like a lerp but handles the wrap-around from 0-360)


Pow - Kinda superfluous but it makes the conversion easier


Clamp - forces a value to remain within the constraints of min and max


I should point out that I haven't tested all of these functions - simply converted them from C#. Please let me know if you find any errors.

[Edit] I am aware that I am in breach of rule (8) which excludes me from the 'lottery' but that is OK. I just saw this as a good opportunity to share some useful functions.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 22nd Jan 2012 17:21 Edited at: 22nd Jan 2012 17:22
Technically Scraggle's functions are from a 3rd party source. But the source announces these as creative commons licensed free for alternation and commercial usage. By adding the original source and credit to the original site I believe I'm within the letter of that agreement therefore I'm allowing scraggle's useful interpolation and mathematical functions.

Thanks for converting these, I can already see dozens of uses from them in animation and scene generation alone. They are exactly what UCF is about, providing resources to users who may be unaware of this area in mathematics and unsure how to convert these mathematical functions for use in their programs.

This brings the function count up to 41, and the tested project version up to 0.0.0.4 which you can download HERE. Everything has been documented and the functions have been added to the template project and test compiled successfully.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Jan 2012 17:35
Those are great scraggle! I will definitely be using some of those at some point thanks

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 22nd Jan 2012 20:34
GREAT animation functions! MORE please!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Jan 2012 23:17
I've been looking for a Berp for a looong time, thank you! I didn't know it was a Berp.

Login to post a reply

Server time is: 2024-11-23 08:19:17
Your offset time is: 2024-11-23 08:19:17