"ParentBlock" code with demo

Talk about making games.

"ParentBlock" code with demo

Postby Hblade » Wed Nov 05, 2014 4:00 am

This script allows you to create a block which many actors can become "parrented" to.

Instructions:
updateParentBlock(id, x, y, width, height, z);
This code sets/updates the initial variables of the ParentBlock ID.

snapToParentBlock(id, offsetx, offsety, offsetz);
This sets the actor's X and Y equal to the blocks X and Y, plus the offsets you specified. It also alters the Z depth, which can also be offset.

drawParentBlock(id);
This is used in a canvas, make sure to stretch the canvas to the views size.

Copy the code to your global code, and name it something fitting.

Code: Select all
//Creating the struct
typedef struct {
    int x, y, width, height;
    double z;
               } parentBlock;

parentBlock ParentBlock[9999];

//Struct Creation

void updateParentBlock(int id, int X, int Y, int Width, int Height, double Z) //Set the initial X and Y, or update it.
{
    ParentBlock[id].x=X;
    ParentBlock[id].y=Y;
    ParentBlock[id].width=Width;
    ParentBlock[id].height=Height;
    ParentBlock[id].z=Z;
}


void snapToParentBlock(int id, int offsetX, int offsetY, double offsetZ) //Snaps an actor to the given block, technically "parrenting" it. Also effects Z depth.
{
    x=ParentBlock[id].x+offsetX;
    y=ParentBlock[id].y+offsetY;
    ChangeZDepth("Event Actor", ParentBlock[id].z+offsetZ);
}

void drawParentBlock(int id) // Use this in a canvas to debug/draw the window, stretch canvas to views size.
{
    moveto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y); //Honestly don't know why it has to be negative.
    lineto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y+ParentBlock[id].height);
    lineto(-view.x+ParentBlock[id].x+ParentBlock[id].width, -view.y+ParentBlock[id].y+ParentBlock[id].height);
    lineto(-view.x+ParentBlock[id].x+ParentBlock[id].width, -view.y+ParentBlock[id].y);
    lineto(-view.x+ParentBlock[id].x, -view.y+ParentBlock[id].y);
}


Skydereign will probably notice some more optimized way of doing this, but that's part of the fun! :D Enjoy guys.

Reason for file size: I apparently used a font that's about 20MB lol O:...

In the demo, you can use left and right to control the box :D.
Attachments
ParentBlock.zip
(13.2 MiB) Downloaded 97 times
example.png
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: "ParentBlock" code with demo

Postby lcl » Fri Nov 07, 2014 12:51 am

Pretty nice demo. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: "ParentBlock" code with demo

Postby Zivouhr » Fri Nov 07, 2014 1:28 am

I have to check out the demo, but this looks interesting. What are some of the advantages in a video game of this Parenting code? Thanks.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: "ParentBlock" code with demo

Postby Hblade » Fri Nov 07, 2014 3:58 pm

At the moment, one thing I can think of would be to create a boss made of multiple parts.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: "ParentBlock" code with demo

Postby Zivouhr » Sat Nov 08, 2014 7:20 am

That sounds interesting, thanks HBlade.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron