Y
Yogen
Guest
GML:
function onGround() {
//grab the layer id
var lay_id = layer_get_id("Tiles_1")
//grab the tile set id
var map_id = layer_tilemap_get_id(lay_id)
var grounded = tilemap_get_at_pixel(map_id,x,bbox_bottom+vel_y)
var onWall = tilemap_get_at_pixel(map_id,bbox_left+vel_x,y-20) - tilemap_get_at_pixel(map_id,bbox_right+vel_x,y-20)
for (var i = -25; i < 25; i ++) {
grounded = tilemap_get_at_pixel(map_id,x + i,bbox_bottom+vel_y)
}
show_debug_message(grounded)
if grounded == 0 vel_y += global.grav
else
vel_y = 0
if sides != 0 {
dir = sides
show_debug_message(momentum)
}
if grounded != 0 && sides != 0 && onWall == 0 {
momentum = approach(momentum,walk_speed,fric)
} else if sides == 0 && grounded != 0 {
momentum = approach(momentum,0,fric)
}
if onWall != 0 && wall_Leave < wall_Leave_Max wall_Leave ++
if onWall != 0 && sign(onWall) != dir {
momentum = 0
vel_x = 0
show_debug_message("you walk into a wall")
} else if onWall != 0 && sign(onWall) == dir {
onWall = false
wall_Leave = 0
momentum = approach(momentum,walk_speed,fric)
show_debug_message("you leave wall")
}
if onWall != 0 show_debug_message("stuck to wall")
vel_x = (momentum / mass)* dir
if jump state = jumping; is_jumping = false
}
function inputs() {
sides = keyboard_check(vk_right) - keyboard_check(vk_left)
//set if jumping or not
jump = keyboard_check_pressed(vk_space)
teleporting = keyboard_check_pressed(vk_shift)
}