Advertisement
XorDev

10-Line 2048

Jun 2nd, 2022
1,835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. //Update blocks when at start or when an arrow key is pressed. Then move all blocks haven't finished moving
  2. if (instance_number(obj_block)<1 || keyboard_check_pressed(vk_left) || keyboard_check_pressed(vk_right) || keyboard_check_pressed(vk_down) || keyboard_check_pressed(vk_up)) {with(obj_block){move_contact_all(obj_control.direction,384);
  3. //Set the slide direction globally using the control object
  4. obj_control.direction = darctan2(keyboard_check_pressed(vk_up)-keyboard_check_pressed(vk_down),keyboard_check_pressed(vk_right)-keyboard_check_pressed(vk_left));
  5. //If there is a block to merge into (using same image index), level up the other block
  6. if (place_meeting(x+dcos(obj_control.direction),y-dsin(obj_control.direction),obj_block) && instance_place(x+dcos(obj_control.direction),y-dsin(obj_control.direction),obj_block).image_index==image_index) {window_set_caption("Score: "+string(real(string_digits(window_get_caption()))+(4<<instance_place(x+dcos(obj_control.direction),y-dsin(obj_control.direction),obj_block).image_index++)));
  7. //Destroy the merged block
  8. instance_destroy();}}
  9. //Loop through all blocks until we find an empty space and place a block there
  10. for(var i=irandom(15); i<32; i++) {if (!position_meeting(384+64+(i%4)*128,96+64+((i div 4)%4)*128,obj_block)) {instance_create_depth(384+(i%4)*128,96+((i div 4)%4)*128,depth,obj_block).image_index = choose(0,0,0,1);
  11. //Stop the loop when we've placed one block
  12. break;}}}
  13. //Move every moveable block with a speed of 16
  14. with(obj_block) {move_contact_all(obj_control.direction,16);}
  15. //Reset the room and score with the "R" key
  16. if keyboard_check_pressed(ord("R")) window_set_caption("Score: "+string(room_restart()!=undefined));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement