/// motion(right,jump,left) // CONTROLS ///////////// if(argument0-argument2==1) { spr_dir = 1; hsp = min(max_spd,hsp+acc_spd); } if(argument1==1) { if(free==0 && hold==0) { vsp = jmp_spd; jump = 1; } hold = 1; } else {hold = 0;} if(argument2-argument0==1) { spr_dir =-1; hsp = max(-max_spd,hsp-acc_spd); } // HORIZONTAL MOVEMENT //////////////////////// repeat(round(abs(hsp))) { var blk, mov; blk = place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90)),y+lengthdir_y(1,grv_dir+(sign(hsp)*90)),par_solid); mov = 0; if(blk==1) { for(a=1;a<=max_slp;a+=1) { if(place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))-lengthdir_x(a,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))-lengthdir_y(a,grv_dir),par_solid)==0) { x += lengthdir_x(1,grv_dir+(sign(hsp)*90))-lengthdir_x(a,grv_dir); y += lengthdir_y(1,grv_dir+(sign(hsp)*90))-lengthdir_y(a,grv_dir); mov = 1; break; } } if(mov==0) { hsp = 0; break; } } else { var jt; jt = instance_place(x+lengthdir_x(1,grv_dir+(sign(hsp)*90)),y+lengthdir_y(1,grv_dir+(sign(hsp)*90)),par_jump_through); if(jt!=noone) { if(place_meeting(x,y,jt)==0) { for(a=1;a<=max_slp;a+=1) { if(place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))-lengthdir_x(a,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))-lengthdir_y(a,grv_dir),par_jump_through)==0) { x += lengthdir_x(1,grv_dir+(sign(hsp)*90))-lengthdir_x(a,grv_dir); y += lengthdir_y(1,grv_dir+(sign(hsp)*90))-lengthdir_y(a,grv_dir); mov = 1; break; } } } } if(mov==0) { for(a=max_slp;a>=1;a-=1) { if(place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))+lengthdir_x(a,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))+lengthdir_y(a,grv_dir),par_solid)==0 && (place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))+lengthdir_x(a,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))+lengthdir_y(a,grv_dir),par_jump_through)==0 && sign(vsp)>-1)) { if(place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))+lengthdir_x(a+1,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))+lengthdir_y(a+1,grv_dir),par_solid)==1 || place_meeting(x+lengthdir_x(1,grv_dir+(sign(hsp)*90))+lengthdir_x(a+1,grv_dir),y+lengthdir_y(1,grv_dir+(sign(hsp)*90))+lengthdir_y(a+1,grv_dir),par_jump_through)==1) { x += lengthdir_x(1,grv_dir+(sign(hsp)*90))+lengthdir_x(a,grv_dir); y += lengthdir_y(1,grv_dir+(sign(hsp)*90))+lengthdir_y(a,grv_dir); mov = 1; break; } } } } if(mov==0) { x+= lengthdir_x(1,grv_dir+(sign(hsp)*90)); y+= lengthdir_y(1,grv_dir+(sign(hsp)*90)); } } } // VERTICAL MOVEMENT ////////////////////// repeat(round(abs(vsp))) { if(place_meeting(x+lengthdir_x(1,grv_dir-90+(sign(vsp)*90)),y+lengthdir_y(1,grv_dir-90+(sign(vsp)*90)),par_solid)==1) { vsp = 0; landed = 1; break; } var jt; jt = instance_place(x+lengthdir_x(1,grv_dir),y+lengthdir_y(1,grv_dir),par_jump_through); jt = collision_line(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1,par_jump_through,1,1); if(jt!=noone && sign(vsp)>-1) { if(place_meeting(x,y,jt)==0) { vsp = 0; landed = 1; break; } } x+= lengthdir_x(1,grv_dir-90+(sign(vsp)*90)); y+= lengthdir_y(1,grv_dir-90+(sign(vsp)*90)); } free = 1; if(place_meeting(x+lengthdir_x(1,grv_dir),y+lengthdir_y(1,grv_dir),par_solid)==1) { free = 0; } var jt; jt = instance_place(x+lengthdir_x(1,grv_dir),y+lengthdir_y(1,grv_dir),par_jump_through); jt = collision_line(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1,par_jump_through,1,1); if(jt!=noone && sign(vsp)>-1) { if(place_meeting(x,y,jt)==0)free=0; } // GRAVITY & FRICTION /////////////////////// if(free==1) { vsp+= grv_spd; if(argument0-argument2==0){hsp=max(0,abs(hsp)-air_frc)*sign(hsp);} } else { jump = 0; if(argument0-argument2==0){hsp=max(0,abs(hsp)-gnd_frc)*sign(hsp);} }
B2: Tạo 2 object: 1 object tên là "par_solid" và 1 object tên là "par_jump_through"(2 object này sẽ làm parent cho các object tường) B3: Tạo object tên là "obj_player" Đặt ở event create script sau: ////////////////////// // Object Variables // ////////////////////// //The default platforming stats for all platforming units. //Modify these to your heart's content. max_spd = 6; //Max hspeed acc_spd = 0.8; //hspeed accelaration jmp_spd =-12; //Jumping speed(decreases by grv_spd every step) grv_spd = 0.6; //vspeed accelaration/gravity grv_dir = 270; //gravity direction(0=Right, 90=Up, 180=Left, 270=Down) air_frc = 0.15; //Number to decrease hspeed by when no key is pressed in air gnd_frc = 0.85; //Number to decrease hspeed by when no key is pressed on ground max_slp = 2; //Highest slope you can climb (in px) //Required variables, don't mess with 'em hsp = 0; vsp = 0; free = 1; //Whether you're in the air (1) or on the ground (0) spr_dir = 1; //Sprite direction (useful for image_xscale) hold = 0; //Whether you're holding the jump key
Ở event Step, đặt code sau motion(keyboard_check(vk_right),keyboard_check(vk_up),keyboard_check(vk_left))
B4: Tiếp theo chúng ta tạo 1 obj_wall, đặt parent cho obj_wall này là par_solid(không thể đi xuyên qua) hoặc par_jump_through(nhảy xuyên được, sau khi xuyên thì đứng lên phía trên luôn). B5: Bày biện chúng trong room B6: Chạy game!!! Chúc các bạn thành công!!! có gì để lại lời nhắn với mình qua comment nha, mình sẽ trợ giúp!
0 nhận xét: