Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
- // Coolgamers Z3 Scrolling, Version 2 Update/Itteration 4 Module 2. \\
- // Module 2: \\
- // Link and Item related functions, variables, & constants. \\
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
- // ~ Constants and Variables ~
- // These are indices into the LinkStats Array.
- // Link Stats Array. Use the LS_ constants as indices into this.
- float LinkStats[64];
- // Link's current Action.
- const int LS_ACTION = 0;
- // The speed at which Link walks. This is measured in pixels per frame.
- const int LS_WALKSPEED = 1;
- // Link X, Y, and Z positions.
- // I'm not sure the purpose of this originally. Gonna keep it in for now though.
- const int LS_X = 2;
- const int LS_Y = 3;
- const int LS_Z = 4;
- // Link Hitbox X, Y, and Z positions.
- const int LS_HIT_X = 5;
- const int LS_HIT_Y = 6;
- const int LS_HIT_Z = 7;
- // Link Hitbox X, Y, and Z offsets.
- const int LS_HIT_X_OFFSET = 8;
- const int LS_HIT_Y_OFFSET = 9;
- const int LS_HIT_Z_OFFSET = 10;
- // Link Hitbox Width (x), Height (y), and Depth (z).
- const int LS_HIT_W = 11; // width
- const int LS_HIT_H = 12; // height
- const int LS_HIT_D = 13; // depth
- // Link Draw X and Y positions.
- const int LS_DRAW_X = 14;
- const int LS_DRAW_Y = 15;
- // Link Draw X and Y offsets.
- const int LS_DRAW_X_OFFSET = 16;
- const int LS_DRAW_Y_OFFSET = 17;
- // Link Draw Width and Height, in tiles.
- const int LS_DRAW_W = 18;
- const int LS_DRAW_H = 19;
- // The Opacity of Link. OP_OPAQUE makes Link Opaque, OP_TRANS makes Link Transparent, and OP_INVIS (or 0) makes Link Invisible.
- const int LS_OPACITY = 20;
- // The layer to draw Link to.
- const int LS_DRAWLAYER = 21;
- // Start of Link's tilesheet.
- const int LS_ANIMATION_SHEET_START = 22;
- // The amount of frames that each animation frame lasts.
- // const int LS_ANIMATIONDELAY = 23;
- // Link's Animation Flip.
- const int LS_FLIP = 24;
- // If Link detects collisions with weapons.
- const int LS_WEPDETECT = 25;
- // If Link detects collisions with enemies.
- const int LS_ENEMYDETECT = 26;
- // If Link detects collisions with solid objects (ie. doesn't go into solid areas).
- const int LS_SOLIDETECT = 27;
- // If Links Animation Timer should be paused or not.
- const int LS_PAUSEANIMATIONTIMERS = 28;
- // Links' Direction.
- const int LS_DIR = 29;
- // Links' Angle.
- const int LS_ANGLE = 30;
- // Links' action in the previous frame.
- const int LS_PREVACTION = 31;
- // Link Animation Timer.
- const int LS_ANIMATIONTIMER = 32;
- // Link Action Timer.
- const int LS_ACTIONTIMER = 33;
- // Number of seperate frames used for Link's animation per Direction.
- const int LS_ANIMATIONFRAMES = 34;
- // Number of tiles between the end of Link action set of tiles and the start of the next one
- // (This is factored into the sets of tiles for normal directions and diagonal directions).
- const int LS_DIR_OR_ACTION_END_TILEDIST = 35;// may be renamed.
- // If Links Action Timer should be paused or not.
- const int LS_PAUSEACTIONTIMERS = 36;
- // The amount of frames that each frame of Links current Action lasts.
- int LS_ANIMATIONDELAY[32]; // The array needs populated with the function SetLinkActionFrameDelays()
- // ~ Scrolling engine Link Actions ~
- // No action. This would be used for something such as a cutscene.
- const int SCRL_LA_NONE = -1;
- // When link is standing still.
- const int SCRL_LA_STAND = 0;
- // When link is walking.
- const int SCRL_LA_WALK = 1;
- // When link is slashing with something.
- const int SCRL_LA_SLASH = 2;
- // When link is stabbing with something.
- const int SCRL_LA_STAB = 3;
- // When link is pounding with something.
- const int SCRL_LA_POUND = 4;
- // When link is in the air.
- const int SCRL_LA_JUMP = 5;
- // When link is charging a weapon.
- const int SCRL_LA_CHARGE = 6;
- // When link is holding an item up, 1 hand, on land.
- const int SCRL_LA_HOLD1LAND = 7;
- // When link is holding an item up, 2 hands, on land.
- const int SCRL_LA_HOLD2LAND = 8;
- // When link is casting a spell (eg. dins fire).
- const int SCRL_LA_CAST = 9;
- // When link is frozen, on land.
- const int SCRL_LA_FROZELAND = 10;
- // When link is hurt, on land.
- const int SCRL_LA_HURTLAND = 11;
- // When link is dying, on land.
- const int SCRL_LA_DIELAND = 12;
- // When link is floating still (in water).
- const int SCRL_LA_FLOATWATER = 13;
- // When link is swimming.
- const int SCRL_LA_SWIM = 14;
- // When link is diving.
- const int SCRL_LA_DIVE = 15;
- // When link is holding an item up, 1 hand, in water.
- const int SCRL_LA_HOLD1WATER = 16;
- // When link is holding an item up, 2 hands, in water.
- const int SCRL_LA_HOLD2WATER = 17;
- // When link is drowning.
- const int SCRL_LA_DROWN = 18;
- // When link is frozen, in water.
- const int SCRL_LA_FROZEWATER = 19;
- // When link is hurt, in water.
- const int SCRL_LA_HURTWATER = 20;
- // When link is dying, in water.
- const int SCRL_LA_DIEWATER = 21;
- // When link is falling.
- const int SCRL_LA_FALL = 22;
- // ~ Link Action Animation Timer(s) ~
- float LinkAnimationTimer[32]; // Depreciated. This needs to be removed.
- // ~ Scripted Item Classes ~
- // A list of flags in one of the ->InitD[] registers will be used to determine the exact behavior of these weapons.
- const int SCRL_IC_NONE = 89; // The first zz### item class.
- const int SCRL_IC_TESTWEP = 90;
- // ~ Scripted Item Options ~
- const int SCRL_INITD_FLAGSET = 0; // The ->InitD register to use for flags.
- const int SCRL_INITD_SCRIPT_FLAGSET = 1; // The ->InitD register to use for some other flags.
- const int SCRL_INITD_SPRITE = 2; // Sprite of the weapon.
- // ~ Functions ~
- // Populates the LS_ANIMATIONDELAY array.
- void SetLinkActionFrameDelays()
- {
- LS_ANIMATIONDELAY[SCRL_LA_STAND] = 8;
- LS_ANIMATIONDELAY[SCRL_LA_WALK] = 8;
- LS_ANIMATIONDELAY[SCRL_LA_SLASH] = 8;
- // need to set up the code here.
- }
- void HandleLinkItems()
- {
- if(LinkStats[LS_ACTION] == SCRL_LA_STAND || LinkStats[LS_ACTION] == SCRL_LA_WALK)
- {
- if(Link->InputA)
- {
- itemdata itID = Game->LoadItemData(GetEquipmentA());
- if(itID->Family == SCRL_LW_TESTWEP)
- {
- //CreateCustomWeapon(SCRL_LW_GENERALW, itID->InitD[SCRL_INITD_FLAGSET], itID->InitD[SCRL_INITD_SPRITE], FrontOfLinkX(), FrontOfLinkY()); // The function needs implemented, in the custom weapon Module.
- }
- }
- if(Link->InputB)
- {
- itemdata itID = Game->LoadItemData(GetEquipmentB());
- }
- }
- }
- // button: -1 to only check if Link's action is Stand or Walk, 0 for A, 1 for B. Other buttons may be added in the future.
- bool CanUseItem(int button)
- {
- if(LinkStats[LS_ACTION] == SCRL_LA_STAND || LinkStats[LS_ACTION] == SCRL_LA_WALK)
- {
- if(button == -1)
- {
- return true;
- }
- if(button == 0)
- {
- if(Link->InputA == false)
- {
- return true;
- }
- }
- if(button == 1)
- {
- if(Link->InputB == false)
- {
- return true;
- }
- }
- }
- return false;
- }
- // Draws Link and any equipment he may have.
- void DrawLink()
- {
- int LinkAnimationTile;
- int LinkDirAnimationOffset;
- if(LinkStats[LS_ACTION] == SCRL_LA_STAND || LinkStats[LS_ACTION] == SCRL_LA_WALK
- || LinkStats[LS_ACTION] == SCRL_LA_FLOATWATER || LinkStats[LS_ACTION] == SCRL_LA_SWIM)
- {
- if(Link->InputUp && Link->InputDown == false && Link->InputLeft == false && Link->InputRight == false) {LinkStats[LS_DIR] = DIR_UP;}
- if(Link->InputDown && Link->InputUp == false && Link->InputLeft == false && Link->InputRight == false) {LinkStats[LS_DIR] = DIR_DOWN;}
- if(Link->InputLeft && Link->InputDown == false && Link->InputUp == false && Link->InputRight == false) {LinkStats[LS_DIR] = DIR_LEFT;}
- if(Link->InputRight && Link->InputUp == false && Link->InputLeft == false && Link->InputUp == false) {LinkStats[LS_DIR] = DIR_RIGHT;}
- if(Link->InputUp && Link->InputDown == false && Link->InputLeft && Link->InputRight == false) {LinkStats[LS_DIR] = DIR_LEFTUP;}
- if(Link->InputUp && Link->InputDown == false && Link->InputLeft == false && Link->InputRight) {LinkStats[LS_DIR] = DIR_RIGHTUP;}
- if(Link->InputDown && Link->InputUp == false && Link->InputLeft && Link->InputRight == false) {LinkStats[LS_DIR] = DIR_LEFTDOWN;}
- if(Link->InputDown && Link->InputUp == false && Link->InputLeft == false && Link->InputRight) {LinkStats[LS_DIR] = DIR_RIGHTDOWN;}
- }
- // If Links' dir is DIR_UP/DIR_DOWN/DIR_LEFT/DIR_RIGHT.
- if(LinkStats[LS_DIR] <= 3)
- {
- LinkDirAnimationOffset = (LinkStats[LS_ANIMATIONFRAMES] * LinkStats[LS_DIR]);
- }
- // If Links' dir is DIR_LEFTUP/DIR_LEFTDOWN/DIR_RIGHTUP/DIR_RIGHTDOWN.
- if(LinkStats[LS_DIR] >= 4)
- {
- LinkDirAnimationOffset = (LinkStats[LS_ANIMATIONFRAMES] * LinkStats[LS_DIR]) + LinkStats[LS_DIR_OR_ACTION_END_TILEDIST];
- }
- LinkAnimationTile = LinkStats[LS_ANIMATION_SHEET_START]
- + ((((LinkStats[LS_ANIMATIONFRAMES] * 4) + LinkStats[LS_DIR_OR_ACTION_END_TILEDIST]) * LinkStats[LS_ACTION]) * 2)
- + CurLinkAnimationFrame()
- + LinkDirAnimationOffset;
- if(LinkStats[LS_OPACITY] != OP_INVIS)
- {
- if(LinkStats[LS_ACTION] > SCRL_LA_NONE)
- {
- // You'd want to put any equipment drawing code that goes BEHIND Link here.
- Screen->FastTile(LinkStats[LS_DRAWLAYER], LinkStats[LS_DRAW_X] + LinkStats[LS_DRAW_X_OFFSET], LinkStats[LS_DRAW_Y] + LinkStats[LS_DRAW_Y_OFFSET], LinkAnimationTile, 6, LinkStats[LS_OPACITY]);
- // You'd want to put any equipment drawing code that goes INFRONT of Link here.
- }
- }
- }
- // This isn't Link's animation tile, this is just the current frame the animation is at.
- int CurLinkAnimationFrame()
- {
- return Floor(LinkStats[LS_ANIMATIONTIMER] / LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]);
- }
- // Handles items (such as swords).
- void HandleItems()
- {
- // example how to handle an item and create a weapon for it
- if(LinkStats[LS_ANIMATIONTIMER] == 0)
- {
- if(LinkStats[LS_ACTION] == SCRL_LA_SLASH)
- {
- // ...
- }
- }
- }
- // Does things based on Links' action.
- void HandleLinkActions()
- {
- if(LinkStats[LS_ACTION] == SCRL_LA_STAND && (Link->InputUp || Link->InputDown || Link->InputLeft || Link->InputRight))
- {
- LinkStats[LS_ACTION] = SCRL_LA_WALK;
- }
- if(LinkStats[LS_ACTION] == SCRL_LA_WALK && Link->InputUp == false && Link->InputDown == false && Link->InputLeft == false && Link->InputRight == false)
- {
- LinkStats[LS_ACTION] = SCRL_LA_STAND;
- }
- if(LinkStats[LS_ACTION] == SCRL_LA_SLASH && LinkStats[LS_ANIMATIONTIMER] >= ((4 * LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]) -1))
- {
- LinkStats[LS_ACTION] = SCRL_LA_STAND;
- }
- }
- // Handles Links' Animation timers.
- void HandleLinkAnimationTimer()
- {
- if(LinkStats[LS_PAUSEANIMATIONTIMERS] == 0)
- {
- LinkStats[LS_ANIMATIONTIMER] += 1;
- if(LinkStats[LS_ANIMATIONTIMER] >= (LinkStats[LS_ANIMATIONFRAMES] * LS_ANIMATIONDELAY[LinkStats[LS_ACTION]]))
- {
- LinkStats[LS_ANIMATIONTIMER] = 0;
- }
- if(LinkStats[LS_ACTION] != LinkStats[LS_PREVACTION])
- {
- LinkStats[LS_ANIMATIONTIMER] = 0;
- }
- LinkStats[LS_PREVACTION] = LinkStats[LS_ACTION];
- }
- }
- void HandleLink()
- {
- HandleItems();
- HandleLinkActions();
- HandleLinkAnimationTimer();
- DrawLink();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement