C
cheezy_squeezy
Guest
Someone asked me to share the code for my Mega Man X Engine found here:
Here's the information for obj_player. Everything else is standard stuff. obj_options basically stores my control variables and obj_player_dash is the fading effect while the player dashes. They are pretty basic so I will only share the code for the player There are 101 tutorials on how to make bullets, etc.
Information about object: obj_player
Here's the information for obj_player. Everything else is standard stuff. obj_options basically stores my control variables and obj_player_dash is the fading effect while the player dashes. They are pretty basic so I will only share the code for the player There are 101 tutorials on how to make bullets, etc.
Information about object: obj_player
Sprite: spr_player_idle
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
/// Initialize
// Platform Physics
hspd = 0;
vspd = 0;
jspd = 15;
grav = 0.5;
fric = 1;
spd = 8;
facing = 0;
dashing = false;
dashended = false;
wall = false;
fallmax = 30;
canblur = true;
canshoot = true;
shooting = false;
bulletsalive = 0;
shotcharge = 0;
shotchargemax = 125;
execute code:
/// Create necessary objects
if !instance_exists(obj_options) {
instance_create(0,0,obj_options);
}
if !instance_exists(obj_view) {
instance_create(x,y,obj_view);
}
Alarm Event for alarm 0:
execute code:
/// Dash ending
dashended = true;
Alarm Event for alarm 1:
execute code:
/// Can blur
canblur = true;
Alarm Event for alarm 2:
execute code:
/// Canshoot
canshoot = true;
Alarm Event for alarm 3:
execute code:
/// Not shooting
shooting = false;
Step Event:
execute code:
/// Platform physics
// Get the control input
var right = obj_options.right;
var left = obj_options.left;
var jump = obj_options.jump;
var jumprelease = obj_options.jumprelease;
var dash = obj_options.dash;
var dashhold = obj_options.dashhold;
var dashreleased = obj_options.dashreleased;
// Check for ground
if (place_meeting(x, y+1, obj_solid)) {
if dashended = true && !place_meeting(x,y-1,obj_solid) && !place_meeting(x,y-33,obj_solid) {
dashing = false;
dashended = false;
}
vspd = 0;
// Jumping
if (jump) {
if dashhold {
dashing = true;
dashended = true;
}
vspd = -jspd;
shooting = false;
dashended = true;
}
} else {
// Gravity
if (vspd < fallmax)
{
vspd += grav;
}
if (jumprelease && vspd <-2) {
vspd = -2;
}
}
// Moving right
if !(dashing = true && place_meeting(x,y+1,obj_solid)) {
if (right) {
if (hspd < spd) {
if hspd = 0 && wall = 0{
shooting = false;
}
hspd += fric;
} else {
hspd = spd;
}
}
// Moving left
if (left) {
if (hspd > -spd) {
if hspd = 0 && wall = 0 {
shooting = false;
}
hspd -= fric;
} else {
hspd = -spd;
}
}
}
// Check for not moving
if !(dashing = true && place_meeting(x,y+1,obj_solid)) {
if ((!right && !left) || (left && right)) {
if (hspd != 0) {
if (hspd < 0) {
hspd += fric;
} else {
hspd -= fric;
}
}
}
}
// Horizontal Collisions
if place_meeting(x+hspd, y, obj_solid) {
while (!place_meeting(x+sign(hspd), y, obj_solid)) {
x += sign(hspd);
}
hspd = 0;
}
// Move Horizontally
x += hspd;
// Vetical Collisions
if place_meeting(x, y+vspd, obj_solid) {
while (!place_meeting(x, y+sign(vspd), obj_solid)) {
y += sign(vspd);
}
vspd = 0;
}
// Move Vertically
y += vspd;
if vspd > fallmax {
vspd = fallmax;
}
if !place_meeting(x,y+1,obj_solid) && place_meeting(x+1,y,obj_solid) {
dashing = false;
wall = 1;
} else {
if !place_meeting(x,y+1,obj_solid) && place_meeting(x-1,y,obj_solid) {
dashing = false;
wall = 2
} else {
wall = 0;
}
}
if wall = 1 {
image_xscale = 1;
facing = 180;
if jump {
if dashhold {
dashing = true;
vspd = -20;
hspd = -spd*2;
dashended = true;
} else {
vspd = -20;
hspd = -spd*1.25;
}
}
}
if wall = 2 {
image_xscale = -1;
facing = 0;
if jump {
if dashhold {
dashing = true;
vspd = -20;
hspd = spd*2;
dashended = true;
} else {
vspd = -20;
hspd = spd*1.25;
}
}
}
if wall >= 1 {
fallmax = 5;
} else {
fallmax = 25;
}
if dashreleased {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
if dash && dashing = false && place_meeting(x,y+1,obj_solid) {
dashing = true;
alarm[0] = 40;
shooting = false;
}
if dashing = false {
fric = 1;
spd = 8;
mask_index = spr_player_mask
}
if dashing = true {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
if facing = 0 {
if left {
facing = 180;
}
}
if facing = 180 {
if right {
facing = 0;
}
}
}
if place_meeting(x,y+1,obj_solid) {
mask_index = spr_player_dash_mask;
if facing = 0 {
spd = 16;
hspd = 16;
fric = 2;
if left {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
}
if facing = 180 {
spd = 16;
hspd = -16;
fric = 2;
if right {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
}
}
spd = 16;
fric = 2;
if canblur = true {
var trail = instance_create(x,y,obj_player_dash);
trail.sprite_index = sprite_index;
trail.image_xscale = image_xscale;
trail.image_index = image_index;
trail.image_speed = 0;
canblur = false;
alarm[1] = 3;
}
}
if !(dashing = true && place_meeting(x,y+1,obj_solid)) && wall = 0 {
if left {
facing = 180;
}
if right {
facing = 0;
}
}
execute code:
/// Shoot
var shoot = obj_options.shoot;
var charge = obj_options.charge;
var chargereleased = obj_options.chargereleased;
// Shoot pellets
if shoot && canshoot = true {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+90,y+20,obj_bullet);
} else {
bullet = instance_create(x+65,y-23,obj_bullet);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-90,y+20,obj_bullet);
} else {
bullet = instance_create(x-65,y-23,obj_bullet);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
canshoot = false;
alarm[2] = 5;
alarm[3] = 15;
shooting = true;
}
// Charge
if charge {
shotcharge += 1;
}
if shotcharge > shotchargemax {
shotcharge = shotchargemax;
}
// Half charged effect
if shotcharge >= 30 {
if !instance_exists(obj_charge1) {
instance_create(x,y,obj_charge1);
}
} else {
if instance_exists(obj_charge1) {
with obj_charge1 instance_destroy();
}
}
// Fully charged bubble effect
if shotcharge >= 125 {
if !instance_exists(obj_charge2) {
instance_create(x,y,obj_charge2);
}
} else {
if instance_exists(obj_charge2) {
with obj_charge2 instance_destroy();
}
}
// Shooting charge shots
if chargereleased {
if shotcharge = 125 {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+80,y+20,obj_chargeshot2);
} else {
bullet = instance_create(x+50,y-23,obj_chargeshot2);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-80,y+20,obj_chargeshot2);
} else {
bullet = instance_create(x-50,y-23,obj_chargeshot2);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
}
if shotcharge >= 30 && shotcharge < 125 {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+80,y+20,obj_chargeshot1);
} else {
bullet = instance_create(x+50,y-23,obj_chargeshot1);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-80,y+20,obj_chargeshot1);
} else {
bullet = instance_create(x-50,y-23,obj_chargeshot1);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
}
if shotcharge >= 30 {
shooting = true;
alarm[3] = 20;
canshoot = false;
alarm[2] = 25;
}
shotcharge = 0;
}
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
/// Initialize
// Platform Physics
hspd = 0;
vspd = 0;
jspd = 15;
grav = 0.5;
fric = 1;
spd = 8;
facing = 0;
dashing = false;
dashended = false;
wall = false;
fallmax = 30;
canblur = true;
canshoot = true;
shooting = false;
bulletsalive = 0;
shotcharge = 0;
shotchargemax = 125;
execute code:
/// Create necessary objects
if !instance_exists(obj_options) {
instance_create(0,0,obj_options);
}
if !instance_exists(obj_view) {
instance_create(x,y,obj_view);
}
Alarm Event for alarm 0:
execute code:
/// Dash ending
dashended = true;
Alarm Event for alarm 1:
execute code:
/// Can blur
canblur = true;
Alarm Event for alarm 2:
execute code:
/// Canshoot
canshoot = true;
Alarm Event for alarm 3:
execute code:
/// Not shooting
shooting = false;
Step Event:
execute code:
/// Platform physics
// Get the control input
var right = obj_options.right;
var left = obj_options.left;
var jump = obj_options.jump;
var jumprelease = obj_options.jumprelease;
var dash = obj_options.dash;
var dashhold = obj_options.dashhold;
var dashreleased = obj_options.dashreleased;
// Check for ground
if (place_meeting(x, y+1, obj_solid)) {
if dashended = true && !place_meeting(x,y-1,obj_solid) && !place_meeting(x,y-33,obj_solid) {
dashing = false;
dashended = false;
}
vspd = 0;
// Jumping
if (jump) {
if dashhold {
dashing = true;
dashended = true;
}
vspd = -jspd;
shooting = false;
dashended = true;
}
} else {
// Gravity
if (vspd < fallmax)
{
vspd += grav;
}
if (jumprelease && vspd <-2) {
vspd = -2;
}
}
// Moving right
if !(dashing = true && place_meeting(x,y+1,obj_solid)) {
if (right) {
if (hspd < spd) {
if hspd = 0 && wall = 0{
shooting = false;
}
hspd += fric;
} else {
hspd = spd;
}
}
// Moving left
if (left) {
if (hspd > -spd) {
if hspd = 0 && wall = 0 {
shooting = false;
}
hspd -= fric;
} else {
hspd = -spd;
}
}
}
// Check for not moving
if !(dashing = true && place_meeting(x,y+1,obj_solid)) {
if ((!right && !left) || (left && right)) {
if (hspd != 0) {
if (hspd < 0) {
hspd += fric;
} else {
hspd -= fric;
}
}
}
}
// Horizontal Collisions
if place_meeting(x+hspd, y, obj_solid) {
while (!place_meeting(x+sign(hspd), y, obj_solid)) {
x += sign(hspd);
}
hspd = 0;
}
// Move Horizontally
x += hspd;
// Vetical Collisions
if place_meeting(x, y+vspd, obj_solid) {
while (!place_meeting(x, y+sign(vspd), obj_solid)) {
y += sign(vspd);
}
vspd = 0;
}
// Move Vertically
y += vspd;
if vspd > fallmax {
vspd = fallmax;
}
if !place_meeting(x,y+1,obj_solid) && place_meeting(x+1,y,obj_solid) {
dashing = false;
wall = 1;
} else {
if !place_meeting(x,y+1,obj_solid) && place_meeting(x-1,y,obj_solid) {
dashing = false;
wall = 2
} else {
wall = 0;
}
}
if wall = 1 {
image_xscale = 1;
facing = 180;
if jump {
if dashhold {
dashing = true;
vspd = -20;
hspd = -spd*2;
dashended = true;
} else {
vspd = -20;
hspd = -spd*1.25;
}
}
}
if wall = 2 {
image_xscale = -1;
facing = 0;
if jump {
if dashhold {
dashing = true;
vspd = -20;
hspd = spd*2;
dashended = true;
} else {
vspd = -20;
hspd = spd*1.25;
}
}
}
if wall >= 1 {
fallmax = 5;
} else {
fallmax = 25;
}
if dashreleased {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
if dash && dashing = false && place_meeting(x,y+1,obj_solid) {
dashing = true;
alarm[0] = 40;
shooting = false;
}
if dashing = false {
fric = 1;
spd = 8;
mask_index = spr_player_mask
}
if dashing = true {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
if facing = 0 {
if left {
facing = 180;
}
}
if facing = 180 {
if right {
facing = 0;
}
}
}
if place_meeting(x,y+1,obj_solid) {
mask_index = spr_player_dash_mask;
if facing = 0 {
spd = 16;
hspd = 16;
fric = 2;
if left {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
}
if facing = 180 {
spd = 16;
hspd = -16;
fric = 2;
if right {
if place_meeting(x,y-1,obj_solid) || place_meeting(x,y-33,obj_solid) {
dashended = true;
} else {
dashing = false;
}
}
}
}
spd = 16;
fric = 2;
if canblur = true {
var trail = instance_create(x,y,obj_player_dash);
trail.sprite_index = sprite_index;
trail.image_xscale = image_xscale;
trail.image_index = image_index;
trail.image_speed = 0;
canblur = false;
alarm[1] = 3;
}
}
if !(dashing = true && place_meeting(x,y+1,obj_solid)) && wall = 0 {
if left {
facing = 180;
}
if right {
facing = 0;
}
}
execute code:
/// Shoot
var shoot = obj_options.shoot;
var charge = obj_options.charge;
var chargereleased = obj_options.chargereleased;
// Shoot pellets
if shoot && canshoot = true {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+90,y+20,obj_bullet);
} else {
bullet = instance_create(x+65,y-23,obj_bullet);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-90,y+20,obj_bullet);
} else {
bullet = instance_create(x-65,y-23,obj_bullet);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
canshoot = false;
alarm[2] = 5;
alarm[3] = 15;
shooting = true;
}
// Charge
if charge {
shotcharge += 1;
}
if shotcharge > shotchargemax {
shotcharge = shotchargemax;
}
// Half charged effect
if shotcharge >= 30 {
if !instance_exists(obj_charge1) {
instance_create(x,y,obj_charge1);
}
} else {
if instance_exists(obj_charge1) {
with obj_charge1 instance_destroy();
}
}
// Fully charged bubble effect
if shotcharge >= 125 {
if !instance_exists(obj_charge2) {
instance_create(x,y,obj_charge2);
}
} else {
if instance_exists(obj_charge2) {
with obj_charge2 instance_destroy();
}
}
// Shooting charge shots
if chargereleased {
if shotcharge = 125 {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+80,y+20,obj_chargeshot2);
} else {
bullet = instance_create(x+50,y-23,obj_chargeshot2);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-80,y+20,obj_chargeshot2);
} else {
bullet = instance_create(x-50,y-23,obj_chargeshot2);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
}
if shotcharge >= 30 && shotcharge < 125 {
if facing = 0 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x+80,y+20,obj_chargeshot1);
} else {
bullet = instance_create(x+50,y-23,obj_chargeshot1);
}
bullet.direction = 0;
bullet.image_angle = 0;
instance_create(x,y,obj_muzzleflash);
}
if facing = 180 {
if dashing = true && place_meeting(x,y+1,obj_solid) {
bullet = instance_create(x-80,y+20,obj_chargeshot1);
} else {
bullet = instance_create(x-50,y-23,obj_chargeshot1);
}
bullet.direction = 180;
bullet.image_angle = 180;
instance_create(x,y,obj_muzzleflash);
}
}
if shotcharge >= 30 {
shooting = true;
alarm[3] = 20;
canshoot = false;
alarm[2] = 25;
}
shotcharge = 0;
}
Last edited by a moderator: