Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///@param tileMapID
- ///@param tileSize
- ///@param velocityArray
- ///NOTE: when velocity[vector2_x] is <= 0.5 when moving right or >= -0.5 when going left, it pushes the player back 1 pixel every 4-6 frames. I am using subpixels.
- var tileMapID = argument0;
- var tileSize = argument1;
- var velocity = argument2;
- //For the velocity array
- var vector2_x = 0;
- var vector2_y = 1;
- //Move horizontally
- //TODO: standard collision if (place_free(x + velocity[vector2_x], y))
- x += velocity[vector2_x];
- if (velocity[vector2_x] > 0) //Right collisions
- {
- var isTileRight = TileCollideAtPoints(global.collisionMapID, [bbox_right >= 0.5 ? round(bbox_right) - 1 : bbox_right - 1, bbox_top], [bbox_right >= 0.5 ? round(bbox_right) - 1 : bbox_right - 1, bbox_bottom - 1]); //-1 on right and bottom. Subpixel movements.
- if (isTileRight)
- {
- x = bbox_right & ~(tileSize - 1);
- x -= bbox_right - x;
- velocity[@ vector2_x] = 0; //Access actual value with @
- }
- }
- else //Left collisions
- {
- show_debug_message("velocity x: " + string(velocity[vector2_x]));
- show_debug_message("round(bbox_left) " + string(round(bbox_left)));
- show_debug_message("bbox_left " + string(bbox_left));
- var isTileLeft = TileCollideAtPoints(global.collisionMapID, [velocity[vector2_x] >= -0.5 ? round(bbox_left) : bbox_left, bbox_top], [velocity[vector2_x] >= -0.5 ? round(bbox_left) : bbox_left, bbox_bottom - 1]);
- if (isTileLeft)
- {
- x = bbox_left & ~(tileSize - 1);
- x += tileSize + x - bbox_left;
- velocity[@ vector2_x] = 0; //Access actual value with @
- }
- }
- //Move vertically
- //TODO: standard collision if (place_free(x, y + velocity[vector2_y]))
- y += velocity[vector2_y];
- if (velocity[vector2_y] > 0) //Down collision
- {
- var isTileBottom = TileCollideAtPoints(global.collisionMapID, [bbox_left, bbox_bottom >= 0.5 ? round(bbox_bottom) - 1 : bbox_bottom - 1], [bbox_right - 1, bbox_bottom <= 0.5 ? round(bbox_bottom) - 1 : bbox_bottom - 1]);
- if (isTileBottom)
- {
- y = bbox_bottom & ~(tileSize - 1);
- y -= bbox_bottom - y;
- velocity[@ vector2_y] = 0;
- }
- }
- else
- {
- var isTileTop = TileCollideAtPoints(global.collisionMapID, [bbox_left, bbox_top], [bbox_right - 1, bbox_top]);
- if (isTileTop)
- {
- y = bbox_top & ~(tileSize - 1);
- y += tileSize + y - bbox_top;
- velocity[@ vector2_y] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement