objectIdle:
Create:
/// @description Movement variables
velocity_ = [0, 16];
gravity_ = 1.5;
jump_speed_ = 48;
max_velocity_ = [22, 42];
acceleration_ = 6.1;
shoot_speed = 40
// Get the tilemap id
var layer_id = layer_get_id("Collision");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
global.facing="right";
can_shoot = true;
hspd = 0;
vspd = 0;
hspd_max = 3; // Max horizontal speed. We will flip this when moving left to -hspd_max
vspd_max = 6; // Max vertical speed. We will flip this when jumping to -vspd_max
accel = 0.2;
fric = 0.2;
grav = 0.4;
climb_max = 8; // The max distance we can climb for ascending and for descending
Step:
/// @description Movement logic
// Get the input
var key_right, key_left, key_jump, input_x, on_ground;
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord("Z"));
input_x = keyboard_check(vk_right) - keyboard_check(vk_left);
// Vector variables
var vector2_x = 0;
var vector2_y = 1;
// Horizontal movement
velocity_[vector2_x] = clamp(velocity_[vector2_x]+input_x, -max_velocity_[vector2_x], max_velocity_[vector2_x]);
// Friction
if input_x == 0 {
velocity_[vector2_x] = lerp(velocity_[vector2_x], 0, .2);
}
// Gravity
velocity_[vector2_y] += gravity_;
// Move and contact tiles
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
// Jumping
on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if (input_x != 0)
{
// Set sprite if you're on the ground
if (on_ground)
{
sprite_index = spriteRun;
}
// Face right or left
image_xscale = input_x;
}
else
{
// Set sprite if you're on the ground
if (on_ground)
{
sprite_index = sprite0;
}
// Slow down
}
// Jump
if (key_jump && on_ground)
{
sprite_index = sprite2;
velocity_[vector2_y] = -jump_speed_;
}
// Gravity
if (!on_ground)
{
// Set your sprite if you're falling
if (vspd > 0)
{
sprite_index = sprite2;
}
}
Alarm 0:
can_shoot = true;
if collide with object8:
game_restart();
Key Press X:
var inst;
inst = instance_create_depth(x, y, -10000, objectBullet);
with (inst)
{
speed = other.shoot_speed;
direction = other.image_angle;
image_angle = direction;
}
Key Press R:
game_restart();
objectBullet:
Create:
alarm[0]=750; ///equals 2 and half seconds of bouncing fireball
gravity=10.5;
velocity_ = [0, 16];
gravity_ = 1.5;
var layer_id = layer_get_id("Collision");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
Step:
if place_free(x,y+1)
{
gravity=0.5;
}
var on_ground
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
// Jumping
on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if on_ground
{
vspeed = -10;
}
if global.facing="right"
{
image_xscale=1
hspeed=3
}
else
{
image_xscale =-1
hspeed=-3
}
Alarm 0:
instance_destroy();