1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 Help with Christmas Game

Discussion in 'Programming' started by Alexthom, Dec 3, 2019.

  1. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    12
    So I'm kinda new to game maker. But I'm making a christmas game where you play as santa, dropping presents into chimneys, and eventually I'll make it so clouds are also an obstacle.
    I want to make the present fall, hit a chimney, and then re-appear in the sleigh, but i can't figure out how to do it.
    Here's the programming for the Sleigh:
    //These commands tell santa to move with the keys, and also change angle to look like he's moving upwards.
    if (keyboard_check(ord("W"))){
    y = y -5
    image_angle = 5
    }

    if (keyboard_check(ord("S"))){
    y = y +5
    image_angle = -5
    }

    if (keyboard_check(ord("A"))){
    x = x -5
    }

    if (keyboard_check(ord("D"))){
    x = x +5
    }

    if (keyboard_check(vk_nokey)){
    image_angle = 0
    }
    Here's the programming for the presents:
    (Step):

    //This will make the present follow the sleigh.
    if (keyboard_check(ord("W"))){
    y = y -5
    image_angle = 5
    }

    if (keyboard_check(ord("S"))){
    y = y +5
    image_angle = -5
    }

    if (keyboard_check(ord("A"))){
    x = x -5
    }

    if (keyboard_check(ord("D"))){
    x = x +5
    }

    if (keyboard_check(vk_nokey)){
    image_angle = 0
    }
    //This sets the start point and tells it to drop when I press "E".
    xstart = 63
    ystart = 350

    if(keyboard_check_direct(ord("E"))){
    motion_add(90, -0.8)
    motion_add(180, 0.15)
    }
    //sets the score
    variable_global_set("Score", 0)
    (Create):
    sprite_index = choose(
    spr_present1, spr_present2, spr_present3, spr_present4, spr_present5, spr_present6)

    And Here's the programming for the chimney:
    (Step):
    //starting point
    xstart = 1085
    ystart = 765
    //tells it to move left
    motion_add(-180, 0.01)
    //tells it to go back to the beggining when it reaches the end
    move_wrap(true, false, sprite_yoffset)
    (collision with obj_present)

    with(other){
    instance_destroy()
    if(sprite_index == spr_present1){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    if(sprite_index == spr_present2){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    if(sprite_index == spr_present3){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    if(sprite_index == spr_present4){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    if(sprite_index == spr_present5){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    if(sprite_index == spr_present6){
    instance_create_layer(xstart, ystart, "Instances", obj_present)
    }
    }

    Also, I tried to make it so the present was not visible until you dropped it, but every time it would only appear while the "E" key was pressed, and not just after. Any help?

    Thanks!
     
  2. TailBit

    TailBit Member

    Joined:
    Oct 16, 2019
    Posts:
    76
    you can do this many ways:

    example1:
    - create it anywhere
    - if speed is 0 then draw it on top of the sleight, that way you don't have to move it after direction keys
    Code:
    if(speed == 0){
        x = obj_sleight.x;
        y = obj_sleight.y;
    }
    draw_self();
    - then just set its speed when you press Z and it will stop setting its position to the sleight.


    example2:
    - have some sort of can_shoot variable in the sleight
    Code:
    have_gift = choose(spr_present1, spr_present2, spr_present3, spr_present4, spr_present5, spr_present6);
    - in the draw event you do:
    Code:
    draw_self();
    if(have_gift != noone) draw_sprite(have_gift,0,x,y);
    - and in the sleight you check if you press Z:
    Code:
    if(have_gift != noone){
        ins = instance_create_layer(x,y,"instance_layer", obj_present);
        ins.sprite_index = have_gift; // give it the sprite we drew
        have_gift = noone; // and tell that we have no more gifts to drop
    }
    - when present is destroyed then you have to tell sleight to set have_gift to a random sprite again:
    Code:
    with(obj_sleight) have_gift = choose(spr_present1, spr_present2, spr_present3, spr_present4, spr_present5, spr_present6);
    - then you can create it falling right away
     
  3. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    12
    Thanks
     
    TailBit likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice