Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ApplyVelocity(VelocityX, VelocityY) {
- OldStandingOnSolid = StandingOnSolid;
- StandingOnSolid = false;
- SideBlocked = false;
- local OldPosX = PosX, OldPosY = PosY;
- // check against touching stuff
- if(VelocityX > 0) {
- if(!lib.ChkBlockFlagXY(((PosX+VelocityX)>>8)+Width-1, (PosY>>8) + (Height/2), BlockFlags.SolidMiddle)
- && !lib.ChkBlockFlagXY(((PosX+VelocityX)>>8)+Width-1, (PosY>>8) + (Height-1), BlockFlags.SolidMiddle)
- && !lib.ChkBlockFlagXY(((PosX+VelocityX)>>8)+Width-1, (PosY>>8), BlockFlags.SolidMiddle))
- PosX += VelocityX;
- else {
- PosX = (((PosX+VelocityX)+(Width-1<<8)) & ~0xfff) - (16<<8);
- SideBlocked = true;
- }
- } else {
- if(!lib.ChkBlockFlagXY((PosX+VelocityX)>>8, (PosY>>8) + (Height/2), BlockFlags.SolidMiddle)
- && !lib.ChkBlockFlagXY((PosX+VelocityX)>>8, (PosY>>8) + (Height-1), BlockFlags.SolidMiddle)
- && !lib.ChkBlockFlagXY((PosX+VelocityX)>>8, (PosY>>8), BlockFlags.SolidMiddle))
- PosX += VelocityX;
- else {
- PosX = ((PosX-VelocityX) & ~0xfff);
- SideBlocked = true;
- }
- }
- // check for solids above
- if(lib.ChkBlockFlagXY((PosX>>8), (PosY>>8), BlockFlags.SolidMiddle)
- || lib.ChkBlockFlagXY((PosX>>8)+(Width-1), (PosY>>8), BlockFlags.SolidMiddle)) {
- VelY = 0x0f0;
- } else {
- }
- PosY += VelocityY;
- // check for flat floor (best kind)
- if(lib.ChkBlockFlagXY((PosX>>8), (PosY>>8) + Height, BlockFlags.SolidTop)
- || lib.ChkBlockFlagXY((PosX>>8)+(Width-1), (PosY>>8) + Height, BlockFlags.SolidTop)) {
- local CanFallLeft = lib.ChkBlockFlagXY((PosX>>8), (PosY>>8) + Height, BlockFlags.FallThrough);
- local CanFallRight = lib.ChkBlockFlagXY((PosX>>8) + Width - 1, (PosY>>8) + Height, BlockFlags.FallThrough);
- if((VelocityY >= 0 && ((((PosY>>8) + Height) >>4) != (((OldPosY>>8) + Height - 1)>>4)))
- && !(WillFallThrough && CanFallLeft && CanFallRight)) {
- PosY = ((PosY+(Height<<8)) & 0xf000)-(Height<<8);
- VelY = 0;
- StandingOnSolid = true;
- }
- }
- // slopes mostly fixed but still a bit buggy
- if(lib.ChkBlockFlagXY((PosX>>8)+(Width-1), (PosY>>8)+Height-1, BlockFlags.SlopeL) && VelocityY >= 0) {
- local PartX = ((PosX>>8)+(Width-1))&15, PartY = ((PosY>>8)+(Height-1))&15, MaxY = 15-PartX;
- if(PartY>MaxY) PosY = (((((PosY>>8)+Height-1) & ~15)) - Height + MaxY) <<8;
- StandingOnSolid = true;
- }
- if(lib.ChkBlockFlagXY((PosX>>8), (PosY>>8)+Height-1, BlockFlags.SlopeR) && VelocityY >= 0) {
- local PartX = (PosX>>8)&15, PartY = ((PosY>>8)+(Height-1))&15, MaxY = PartX;
- if(PartY>MaxY) PosY = (((((PosY>>8)+Height-1) & ~15)) - Height + MaxY) <<8;
- StandingOnSolid = true;
- }
- if(lib.ChkBlockType((PosX>>8), (PosY>>8) + Height - 1, 23)
- || lib.ChkBlockType((PosX>>8)+(Width-1), (PosY>>8) + Height - 1, 23)) {
- VelY = -0x0500;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement