Giter Site home page Giter Site logo

linked-doors's Introduction

Linked Doors Cover Image

Linked Doors

Linked Doors is a GameMaker asset to simplify moving a player between rooms. The goal of this asset is to remove hardcoded coordinates from room transitioning by relying on door instances with "links" between them. No assumptions are made about how the player will interact with the doors, meaning Linked Doors should work for all games.

Installation

Download the latest release and import the .yymps file into GameMaker by dragging it into the IDE window or using the tools tab.

Usage

Using Linked Doors is meant to be simple. There are only three functions that need to be used. You'll also want a door object that the player can interact with.


ld_declare_door(link_name, other_room)

Intended to be ran in instance creation code of your door object. This function will declare the calling instance as a "door". This door will automatically be "linked" to a door in the other_room with the same link_name.

Argument Type Description
link_name String Identifying name that will link two doors between rooms.
other_room GM Room Asset The room asset that the other door can be found in.
/// Room: r_outside
/// Instance creation code of an object
ld_declare_door("house_abc_front", r_house_abc);
/// Room: r_house_abc
/// Instance creation code of an object
ld_declare_door("house_abc_front", r_outside);

ld_trigger_door([id])

Signals that the player has interacted with a certain door instance. The room will change to the triggered door's other_room and the matching door can then be found in this new room with the following ld_roomstart_find_door() function.

Argument Type Description
[id] GM Instance ID Optional. Defaults to the calling instance's ID. This argument can be used if the function is called outside of a door instance's scope.
/// Ex1: Door step event. Key press activated
if (distance_to_object(o_player) < 32 && keyboard_check_pressed(vk_enter)) {
    ld_trigger_door();
}
/// Ex2: Door object collision with player event. Collision activated
ld_trigger_door();

ld_roomstart_find_door()

Should be ran on room start. Returns the instance ID of the door with a link_name that matches the one triggered with ld_trigger_door(). I would recommend using this function in the room start event of either: a persistent object that spawns/moves the player, or the player itself to move it to the correct spot.

/// Room start event of persistent object
var door = ld_roomstart_find_door();
if (door != noone) {
	o_player.x = door.x + lengthdir_x(16, door.image_angle);
	o_player.y = door.y + lengthdir_y(16, door.image_angle);
}

In the above example, if a linked door is found when entering a room, the player is placed 16px away from that door in the direction that it is facing.


License

MIT

linked-doors's People

Contributors

colmeye avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.