Showing posts with label 【GAMEMAKER】Snake Fluid Movement. Show all posts
Showing posts with label 【GAMEMAKER】Snake Fluid Movement. Show all posts

Thursday, June 17, 2021

【GAMEMAKER】Snake Fluid Movement

Information about object: obj_head

Sprite: spr_head
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask: spr_body
No Physics Object
Create Event:
execute code:

x = 240
y = 450
move_snap(16,16)

dir = 90
direction = 90
speed = 4
image_single = 1

dsx = ds_list_create()
dsy = ds_list_create()
dsd = ds_list_create()
global.tails = 1

step = 0
Step Event:
execute code:

if y mod 16 = 0 && x mod 16 = 0 {
dir2 = direction + 180
if dir2 >= 360 { dir2 -= 360 }
if dir != direction && dir != dir2 {
direction = dir
image_single = direction / 90
}
ds_list_add(dsd,direction)
ds_list_add(dsx,x)
ds_list_add(dsy,y)
step += 1
}

score = global.tails - 1
Collision Event with object obj_body:
execute code:

eaten = other.step
//show_message(string(step - eaten))
//if eaten <= step - 2 { exit }
with obj_body { if step <= obj_head.eaten { instance_destroy() } }
Collision Event with object obj_wall:
execute code:

game_restart()
Other Event: Intersect Boundary:
execute code:

game_restart()
Other Event: Game End:
execute code:

ds_list_destroy(dsd)
ds_list_destroy(dsx)
ds_list_destroy(dsy)
Key Press Event for <Enter> Key:
execute code:

show_message("Game Paused. Press ok or hit enter again to resume")
Key Press Event for <Left> Key:
execute code:

dir = 180
Key Press Event for <Up> Key:
execute code:

dir = 90
Key Press Event for <Right> Key:
execute code:

dir = 0

Key Press Event for <Down> Key:
execute code:

dir = 270

Information about object: obj_body
Sprite: spr_body
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

global.tails += 1
step = obj_head.step - global.tails
x = ds_list_find_value(obj_head.dsx,step)
y = ds_list_find_value(obj_head.dsy,step)
direction = ds_list_find_value(obj_head.dsd,step)
speed = obj_head.speed
Destroy Event:
execute code:

instance_create(x,y,obj_deadtail)
global.tails -= 1
Step Event:
execute code:

if place_snapped(16,16) {
direction = ds_list_find_value(obj_head.dsd,step)
step += 1
}

Information about object: obj_wall
Sprite: spr_wall
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

Information about object: obj_item
Sprite: spr_item
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

x = 0
y = 0

xx = x
yy = y
while !place_empty(xx,yy) {
 xx = floor((random(room_width - 32) + 16) / 16) * 16
  yy = floor((random(room_height - 32) + 16) / 16) * 16
  }
  x = xx
  y = yy
Collision Event with object obj_head:
execute code:

instance_create(x,y,obj_body)

xx = x
yy = y
while !place_empty(xx,yy) {
 xx = floor((random(room_width - 32) + 16) / 16) * 16
  yy = floor((random(room_height - 32) + 16) / 16) * 16
  }
  x = xx
  y = yy

Information about object: obj_deadtail
Sprite: spr_deadtail
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Other Event: Animation End:
execute code:

instance_destroy()

End of Summer Sale ☀️😎

20% OFF Inside!🤯 ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏...