【GAMEMAKER】Snake

 Information about object: objHead

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

Init();
MoveDir="Left";
SwitchDir="Left";
MoveSpeed=4;
SafeStart=true;
alarm[0]=8;
Alarm Event for alarm 0:
execute code:

SafeStart=false;
Step Event:
execute code:

Store();
if keyboard_check(vk_left) {
    SwitchDir="Left";
}

if keyboard_check(vk_right) {
    SwitchDir="Right";
}

if keyboard_check(vk_up) {
    SwitchDir="Up";
}

if keyboard_check(vk_down) {
    SwitchDir="Down";
}

if (place_snapped(32,32)) {
    switch (SwitchDir) {
        case "Up":
            sprite_index = (SprHeadUp);
            MoveDir="Up"
            break;
        case "Down":
            sprite_index = (SprHeadDown);
            MoveDir="Down"
            break;
        case "Left":
            sprite_index = (SprHeadLeft);
            MoveDir="Left"
            break;
        case "Right":
            sprite_index = (SprHeadRight);
            MoveDir="Right"
            break;
    }
}

MoveX=0;
MoveY=0;

switch (MoveDir) {
    case "Up":
        y-=MoveSpeed;
        MoveY=-MoveSpeed;
        break;
    case "Down":
        y+=MoveSpeed;
        MoveY=MoveSpeed;
        break;
    case "Left":
        x-=MoveSpeed;
        MoveX=-MoveSpeed;
        break;
    case "Right":
        x+=MoveSpeed;
        MoveX=MoveSpeed;
        break;
}

Collision Event with object objBody:
execute code:

if SafeStart=true then exit;
sound_play(sound0);
Collision Event with object objFood:
execute code:

with (other) instance_destroy();
score+=10;
aa=instance_create(0,0,objFood);
with (aa) move_random(32,32);
AddBody();
Mouse Event for Left Button:
execute code:

AddBody();
io_clear();
Other Event: Game Start:
execute code:

aa=instance_create(x,y,objBody1);
aa.Follows=objHead;
global.LastBody=aa;
for (z=1; z<4; z+=1) {
    AddBody();
}
aa=instance_create(0,0,objFood);
with (aa) move_random(32,32);

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

Init();
Step Event:
execute code:

Store();
Get();

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

Init();
Step Event:
execute code:

Store();
Get();

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

addBody()
aa=instance_create(global.LastBody.x, global.LastBody.y, objBody) aa.Follows=global.LastBody global.LastBody=aa;

init()
for (z=0; z<9; z+=1) { LastX[z]=x; LastY[z]=y; }

store()

for (z=8; z>1; z-=1) { LastX[z]=LastX[z-1]; } for (z=8; z>1; z-=1) { LastY[z]=LastY[z-1]; } LastX[1]=x; LastY[1]=y;

get()
x=Follows.LastX[7]; y=Follows.LastY[7];

No comments:

Power Is Shifting Rapidly to Indie Creators

The exodus from Twitter since the election is a sign of things to come ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ...

Contact Form

Name

Email *

Message *