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.

AppGameKit Classic Chat / Extended API... a work in progress

Author
Message
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 5th Sep 2018 04:26 Edited at: 10th Sep 2018 13:48
2018-09-09 UPDATED THE APIGeneral.agc file as follows to fix some bugs, add a TColor type and to implement constants for the full range of known key codes:


I am sure most of you do the same thing I do when developing continually writing little bits of code to provide functionality that is very useful and often needed yet is not included in the built-in API. Unfortunately, I often end up writing these same things again and again. So I decided to make a proper project of it creating an Extended API I can use in all projects going forward. It'd be awesome if it is was built in but this is the next best thing... include files.

Ultimately, I will have 3 include files... APIGeneral.agc, API2D.agc and API3D.agc which each holding the type of stuff their name implies. For now I am putting everything into APIGeneral.agc because there is not a lot to this yet and it is more convenient to mess with one external file inclusion instead of multiple at this point.

So far I have implemented the following...


** CONSTANT DECLARATIONS **

TRUE
FALSE
TRANSPARENCY_MODE_OFF
TRANSPARENCY_MODE_ALPHA
TRANSPARENCY_MODE_ADDITIVE
KEY_LEFT
KEY_A
KEY_RIGHT
KEY_D
KEY_UP
KEY_W
KEY_DOWN
KEY_S
KEY_T
KEY_E
KEY_SPACE
KEY_N
KEY_ESC
KEY_Z
KEY_X
KEY_C
KEY_SHIFT
KEY_ENTER
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_F1
KEY_F2
KEY_F3
KEY_F4

** TYPES **
TVector2D


** GENERAL FUNCTIONS **
InitDisplay(title as string, width as integer, height as integer, maxFrameRate as float, allowResize as integer, fullscreen as integer)
MinF(value1 as float, value2 as float)
Min(value1 as integer, value2 as integer)
MaxF(value1 as float, value2 as float)
Max(value1 as integer, value2 as integer)
SgnF(value as float)
Sgn(value as integer)
GetFormatedInteger(value as integer, totalLength as integer)


** 2D VECTOR FUNCTIONS **
Vector2DGetRatios(v2d ref as TVector2D)
Vector2DNormalize(v2d ref as TVector2D)


** ANGLE FUNCTIONS **
AngleGetDistanceToAngle(fromAngle as float, toAngle as float)
AngleGetShortestDistanceToAngle(fromAngle as float, toAngle as float)
AngleIsWithin(testAngle as float, AngleToCompareTo as float, degrees as float)
AngleIsBetween(testAngle as float, Angle1 as float, Angle2 as float)
AngleAddWithLimits(angle as float, valueToAdd as float, angleMin as float, angleMax as float)


** SPRITE FUNCTIONS **
SetSpriteFaceSprite(sprite as integer, SpriteToFace as integer)
SetSpriteFacePosition(sprite as integer, targetX as float, targetY as float)
SetSpriteFaceMouse(sprite as integer)


And I created a little demo illustrating most of these functions...

The top 5 lines on the screen are Angle tests where A0 to A2 are angle values.
The blue sprite rotates to face the yellow sprite by using the SetSpriteFaceSprite function.
The green sprite rotates to face the yellow sprite by using the SetSpriteFacePosition passing in the position of the yellow sprite.
The red sprite rotates to face the mouse pointer (that is not visible) by using the SetSpriteFaceMouse function.



I've also added this to the CodeBase here.

And the project for this demo is attached to this post.

Anyway, just thought this might be useful to some of you.

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Sep 2018 05:08 Edited at: 5th Sep 2018 05:09
Looks great! The more you can get rid of that evil math the better!
Some more scan codes too

Some suggs;
LineLineIntersect2D() and 3D
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Sep 2018 08:55 Edited at: 5th Sep 2018 08:59
This is a good idea and its something I did when I first got AppGameKit last year. I now have over 20 library files that perform various useful functionality - theres about another 8 that I have but have never used but its nice to have them - im sure tht most people do this in some way. This is typical in other languages (C/C++/Python/C# etc...)



One thing I would say....

1) I created one file which then includes all the other library files - a master library file. That way you just have to include one file into any project to get the use of all the extra functions.

2)When you start doing things like this its also important to make sure that any global variables are named in such a way that they will only affect the library they come from and wont interfere with any other project files. Typically im careful with the first 2/3 letters to make that the case since AppGameKit doesnt have namespaces.

There is at least 6 libraries that were posted on this forum that are really good.

It could be a great idea to start a community set of libraries on codebase or git or whatever and pool some useful functions so everyone can get more advanced functionality. It should all be documented though.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 5th Sep 2018 11:23
I pretty much do the same thing gar
I have some framework i reuse constantly for Projects thats why i can be fast with Project from time to time.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 5th Sep 2018 12:01 Edited at: 5th Sep 2018 13:40
I figured most people did the same. Definitely agree with you on the naming Bengismo and that is what I do as well when making libraries.

Here although yes I guess it is kind of the same thing I hadn't looked at it that way. I kind of see this particular initiative different because it is not a normal kind of library I mean it's not like a dedicated set of functions to implement new features such as working with tile maps or pathfinding or similar more advanced bigger features. This is focused on just adding in all of the stuff that most would expect to be in the api.

At least I did. I am surprised sometimes the api has this and this and this and then it will not have that which one would fully expect it to because it had those others. Lol

So I'm just trying to patch holes. Fundamental things that are missing from the real api.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 5th Sep 2018 12:13 Edited at: 5th Sep 2018 13:40
I use bitbucket a lot and will be throwing this up there as well.

Bengismo where are these libraries? That is one of the things I think can be handled a lot better here although not sure how exactly.

I see people posting snippets of code often for shaders or other 3D stuff sometimes multiple times per day even but it seems to me like this stuff just gets buried and lost in the passing of time and then other people will write the same things over.

I wouldn't be surprised if every function I have here has already been written (and possibly multiple times) and posted on these forums over the years. But who would know it? Lol How to find it? Searching for such things will no doubt bring up page after page of results and most people if they are like me will think I am not digging through all of those threads looking to see if someone has wrote this function already... I can just write it myself in a tenth of the time it would take me to check for it already existing.

So I think we need a way to manage this stuff better. Just throwing that out there for thought.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 8th Sep 2018 18:14 Edited at: 8th Sep 2018 18:15
Just a note here the SetSpriteFaceSOMETHING functions are incorrect. I never get used to and probably never will the atan math functions taking the Y component as the first parameter and the X as the second which is completely opposite from 99.99% of all game related code I write which is always something(x,y).

Anyway just swap those around in the atanfull math function.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 10th Sep 2018 13:47 Edited at: 10th Sep 2018 14:00
I updated the first post with my current version of the GeneralAPI.agc file at the very top. Copy & paste.

This fixes a few bugs I encountered in recent development activities, adds a new type TColor and implements the remainder of the documented Key Codes as #constants.

This has grown on to a new project where I am now focusing on implementing fundamental game component behaviors...

All of this motion is handled through behaviors assigned to sprites and happens automatically with one call to SpriteBehaviorUpdate() in the main loop.
Collision checking is also performed automatically on all sprites that have Collide Behaviors attached.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Sep 2018 03:20
A suggestion;
There are a raft of commands that return individual properties of an object/sprite etc.
Maybe you could create functions that combine those individual properties into types;

ie;

type point2D
x as float
y as float
endtype

type SpriteProperties
pos as point2D
off as point2D
scale as point2D
hw as point2D
endtype

function GetSpriteProperties(s as integer)
p as SpriteProperties

p.pos.x = GetSpriteX(s)
p.pos.y = GetSpriteY(s)
p.off.x = GetSpriteXByOffset(s)
p.off.y = GetSpriteYByOffset(s)
p.scale.x = GetspriteScaleX(s)
p.scale.y = GetSpriteScaleY(s)
p.hw.x = GetSpriteWidthY(s)
p.hw.y = GetSpriteHeight(s)

endfunction p

I think you could really condense the language like this. There must be 30 or more statement that you could reduce to just a handfull.
ps: I just rolled that code off the top of my head
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 20th Sep 2018 03:40 Edited at: 20th Sep 2018 03:41
Great idea Blink and I thought about that too. It does seem somewhat verbose to need to do the functions one at a time although I also appreciate that straightforwardness about the api.

One thing along the lines you are saying that I thought would be useful would be something like SetSpriteSizeWithCenteredOffset that would set the new sprite size then automatically set the offset to the center. Alternatively could make some constants like OFFSET_TOP_LEFT, TOP_CENTER, TOP_RIGHT, LEFT_MIDDLE, CENTER, RIGHT_MIDDLE, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT and handle these very common cases automatically. For my own work it would be useful where for platform games for example I almost always put the handle at the bottom center of the sprite and for many other games put the offset right in the center of the sprite.

Appreciate you contributing! I really should post what I have so far for this. It is quite useful at this point. I fixed a bug with the FixSpriteToSprite system so now it is very solid I think. And all of the behaviors are quite handy as well.
Again it is basic stuff but the point is why should people have to code it all again and again and again. The main reason I haven't posted the work on the behaviors yet is because I was considering maybe porting it to C and making a DLL out of it. BUT I think it would be good to just release it in the BASIC as it is. it would be easy to port it to C if anyone wanted to do so and honestly I have more than enough projects going on as it is. And I hope maybe someone might look at what I have done with these behaviors and think of just how much could be added to the native api to really boost our game dev efforts.

Login to post a reply

Server time is: 2024-04-20 15:11:18
Your offset time is: 2024-04-20 15:11:18