H
HypSandar
Guest
I'm working on this practice project via tutorial which was published on Feb 15, 2013
Here's a link to it.
Object Snake
Object Controller
Issue
Pressing the left button key sends the snake to the right side of the screen
Here's a link to it.
Object Snake
Code:
Information about object: obj_snake
Sprite: spr_snake
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
//Snake speed, 2 blocks of 32x32 per second.
// 30 ticks is 1 second.
currentID = 0;
alarm[0] = 15;
move_snap(32,32);
Alarm Event for alarm 0:
execute code:
if (currentID == 0) {
//Direction
//0 = right
//1 = left
//2 = up
//3 = down
currentID += 1;
alarm[0] = 15;
switch(global.dir) {
case 0:
instance_create(x + 34, y, obj_snake);
break;
case 1:
instance_create(x + 34, y, obj_snake);
break;
case 2:
instance_create(x, y - 34, obj_snake);
break;
case 3:
instance_create(x, y + 34, obj_snake);
break;
// Cases are equal to = "if(global.dir = 0);"
}
}else if(currentID == (global.length - 1)) {
instance_destroy();
}else{
currentID += 1;
alarm[0] = 15;
}
Object Controller
Code:
Information about object: obj_controller
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
//Direction
//0 = right
//1 = left
//2 = up
//3 = down
global.dir = 3;
global.length = 4;
Step Event:
execute code:
//Direction
//0 = right
//1 = left
//2 = up
//3 = down
if(keyboard_check_pressed(vk_right)) global.dir = 0;
if(keyboard_check_pressed(vk_left)) global.dir = 1;
if(keyboard_check_pressed(vk_up)) global.dir = 2;
if(keyboard_check_pressed(vk_down)) global.dir = 3;
Pressing the left button key sends the snake to the right side of the screen