Posted: 31st Jul 2021 11:59
I made my first commit to the core, just added a few (every project should have) quality of life functions

If this gets accepted and merged I will add a bunch more

https://github.com/TheGameCreators/AGKTier2/pull/18

What quality of life functions, or function sets would you like to see added to the core?

No stupid functions, lets keep this inline with the current function set, if we work together we can give both Tier 1&2 some handy updates.
Posted: 1st Aug 2021 18:08
Can you describe what these do?

MoveSpriteLocalX ( iSpriteIndex, fAmount );
MoveSpriteLocalY( iSpriteIndex, fAmount );
TurnSpriteToPosition( iSpriteIndex, fX, fY, fAmount );
FixSpriteToSprite( iSpriteIndex, iParentID );
Posted: 1st Aug 2021 18:58
Can you describe what these do?

the demo is visually tough to follow but i expect:
MoveSpriteLocalX = Strafe (relative to Sprite Angle)
MoveSpriteLocalY = Move Forward/Backward (" ")
TurnSpriteToPosition = PointSprite
FixSpriteToSprite = Maintain a sprite's relative position/angle to its "parent"

many of us have made similar with variations as i'm sure you have. ie, i sometimes do MoveSprite(Spr,fx, fy) as a single command or combine MoveSprite with PointSprite to MoveSprite "In/Out" (toward or away from a point) with Rotate/Circle around the point vs Strafe.

we may as well add things like FixSpriteToObject while we're at it

not to diminish this as i think MoveSprite and PointSprite, for example(s), should have been included out of the box but i'd personally like to see work done on fixing issues, adding new functionality or expanding existing commands vs combining existing functions.
Posted: 1st Aug 2021 21:25
I think we should be able to have our cake and eat it, fix what needs fixing plus make an awesome GUI , although Nuklear is good it is not supported in Vulkan. ( I think). They could even charge a bit for the GUI and have it as an extra (plugin) or something . I feel it would take AppGameKit to a new level and make it an excellent business and game package . This would attract more programmers to AppGameKit .
Posted: 1st Aug 2021 22:38
Can you describe what these do?


Really!?

MoveSpriteLocalX - Moves a sprite in its local x direction taking into account its current angle
MoveSpriteLocalY - Moves a sprite in its local y direction taking into account its current angle
TurnSpriteToPosition - Turns a sprite to face the x,y, position by the given factor
FixSpriteToSprite - Fixes a sprite to another sprite to inherit its location and angle (like FixObjectToObject ETC)

i'd personally like to see work done on fixing issues, adding new functionality or expanding existing commands vs combining existing functions.


The whole GitHub thing takes a little bit of setting up this first one was more of a test on how the system works while adding IMO some very handy functions that new users would appreciate, I have some ideas but I wont waist my time if TGC wont implement them, also things like FixSpriteToSprite, yes it can be done in basic but its very easy dealt with on the backend, no need for updates functions and wrappers

This
+ Code Snippet
FixSpriteToSprite(child_id, parent)


V's This
+ Code Snippet
// FixSpriteToSprite
Type tSprite
    ParentID
    ChildID
    ChildOffsetX
    ChildOffsetY
EndType
Global gSprite as tSprite[-1]
 
Function FixSpriteToSprite(parent_id, child_id)
    spr as tSprite
    spr.ParentID=parent_id
    spr.ChildID=child_id
    spr.ChildOffsetX=GetSpriteXByOffset(child_id)-GetSpriteXByOffset(parent_id)
    spr.ChildOffsetY=GetSpriteYByOffset(child_id)-GetSpriteYByOffset(parent_id)
    gSprite.insert(spr)
EndFunction
 
Function UpdateFixSpriteToSprite()
    for index=0 to gSprite.length
        px# = GetWorldXFromSprite( gSprite[index].ParentID, gSprite[index].ChildOffsetX, gSprite[index].ChildOffsetY )
        py# = GetWorldYFromSprite( gSprite[index].ParentID, gSprite[index].ChildOffsetX, gSprite[index].ChildOffsetY )
        SetSpritePositionByOffset(gSprite[index].ChildID, px#, py#)
        SetSpriteAngle(gSprite[index].ChildID, GetSpriteAngle(gSprite[index].ParentID))
    next
EndFunction
// ####################


FixSpriteToObject ... of coures, 2d healthbars, infoboxes and such attached to a 3d object ...


There are lots of things I have wanted in Basic for a long time like XML support, path finding and a big long list of others, yes I know it can and has been done in basic, my POV is, this is a game making language, so lets make it the best dam game making language out there, not with complex 3d math and physics functions (although they are very handy) but functions that allow new users to move a sprite along an axis with a single function call, save some data to XML without having to first write a parser, path finding out the box .... you know .... like every other game making system out there bar the odd one!
Posted: 2nd Aug 2021 3:15
TurnSpriteToPosition - Turns a sprite to face the x,y, position by the given factor


So basically its like point sprite but with a step value? Will a negative value make it rotate opposite direction or does it just take the shortest way?
Posted: 2nd Aug 2021 5:10
So basically its like point sprite but with a step value?


Yes, kind of like a Lerp

Will a negative value make it rotate opposite direction or does it just take the shortest way?


Yes shortest way round and No, for that we need the RotateSprite(sprite_id, amount) but I figured SetSpriteAngle(sprite_id, GetSpriteAngle(sprite_id)+amount) is not to painful to type out anyway so not much point in adding it?

Its to easy to go overboard and add in loads of unneeded functions, 102 flavours of CreateSprite and 19 angle functions are just not needed, I thought those 4 functions would save some headaches for the noobs and my make my own life a little easier.

Make the sprite follow the mouse:
+ Code Snippet
	float mouse_x = agk::GetRawMouseX();
	float mouse_y = agk::GetRawMouseY();

	if (agk::GetRawMouseLeftState())
	{
		agk::MoveSpriteLocalX(parent_1_id, 1.5f);
		agk::TurnSpriteToPosition(parent_1_id, mouse_x, mouse_y, 0.5f);
	}


And the full C++ test code for the 4 functions, it creates 2 parent sprites and attaches a bunch of child sprites to each parent with FixSpriteToSprite, one will follow the mouse on the x axis on left button, the other will follow the mouse on the y axis on the right button, 1 parent is setup to use sprite offset the other is not, this was for testing the internal code.

+ Code Snippet
// Includes
#include "template.h"

// Namespace
using namespace AGK;

app App;

UINT parent_1_id;
UINT parent_2_id;
const int USE_OFFSET = 1;

UINT CreateChildSprite(UINT parent, float x, float y, int r, int g, int b)
{
	UINT child_id = agk::CreateSprite(0);
	agk::SetSpriteSize(child_id, 20, 10);
	agk::SetSpritePosition(child_id, x, y);
	agk::SetSpriteColor(child_id, r, g, b, 255);

	agk::FixSpriteToSprite(child_id, parent);

	return child_id;
}

UINT CreateChildSpriteByOffset(UINT parent, float x, float y, int r, int g, int b)
{
	UINT child_id = agk::CreateSprite(0);
	agk::SetSpriteSize(child_id, 20, 20);
	agk::SetSpriteOffset(child_id, 10, 10);
	agk::SetSpritePositionByOffset(child_id, x, y);
	agk::SetSpriteColor(child_id, r, g, b, 255);

	agk::FixSpriteToSprite(child_id, parent);


	return child_id;
}

void app::Begin(void)
{
	agk::SetVirtualResolution(1024, 768);
	agk::SetClearColor(151, 170, 204); // light blue
	agk::SetSyncRate(60, 0);
	agk::SetScissor(0, 0, 0, 0);


	// Test with sprite offset (Left Bitton)
	parent_1_id = agk::CreateSprite(0);
	agk::SetSpriteSize(parent_1_id, 100, 30);
	agk::SetSpriteColor(parent_1_id, 255, 0, 0, 255);
	agk::SetSpriteOffset(parent_1_id, 50, 15);
	agk::SetSpritePositionByOffset(parent_1_id, 0, 0); 

	CreateChildSpriteByOffset(parent_1_id, 60, 0, 0, 0, 255);
	CreateChildSpriteByOffset(parent_1_id, 40, -15, 0, 255, 0);
	CreateChildSpriteByOffset(parent_1_id, 40, 15, 0, 255, 0);
	CreateChildSpriteByOffset(parent_1_id, -40, -15, 255, 255, 0);
	CreateChildSpriteByOffset(parent_1_id, -40, 15, 255, 255, 0);

	agk::SetSpritePositionByOffset(parent_1_id, 200, 200);

	// Test with no offset (Right Button)
	parent_2_id = agk::CreateSprite(0);
	agk::SetSpriteSize(parent_2_id, 100, 30);
	agk::SetSpriteColor(parent_2_id, 255, 0, 0, 255);
	agk::SetSpritePosition(parent_2_id, 0, 0);

	CreateChildSprite(parent_2_id, 110, 5, 0, 0, 255);
	CreateChildSprite(parent_2_id, 80, -15, 0, 255, 0);
	CreateChildSprite(parent_2_id, 80, 35, 0, 255, 0);
	CreateChildSprite(parent_2_id, 20, -15, 255, 255, 0);
	CreateChildSprite(parent_2_id, 20, 35, 255, 255, 0);

	agk::SetSpritePosition(parent_2_id, 400, 400);


}


int app::Loop(void)
{

	float mouse_x = agk::GetRawMouseX();
	float mouse_y = agk::GetRawMouseY();

	if (agk::GetRawMouseLeftState())
	{
		agk::MoveSpriteLocalX(parent_1_id, 1.5f);
		agk::TurnSpriteToPosition(parent_1_id, mouse_x, mouse_y, 0.5f);
	}

	if (agk::GetRawMouseRightState())
	{
		agk::MoveSpriteLocalY(parent_2_id, 1.5f);
		agk::TurnSpriteToPosition(parent_2_id, mouse_x, mouse_y, 0.5f);
	}

	agk::Print(agk::ScreenFPS());
	agk::Sync();

	return 0; // return 1 to close app
}


void app::End(void)
{

}