Jump to content

Photo

Game Maker - Help With Doors?


  • Please log in to reply
6 replies to this topic

#1 kurt91

kurt91

    Follower of Destiny

  • Members
  • Real Name:Kurtis
  • Location:Eastern Washington University

Posted 08 June 2013 - 02:52 AM

Okay, first off, I'm sorry if this is the wrong place to ask this and it needs to be in the computers section, but I figured it had to do with Game Maker, a program that is used for making games, so it would be fine here. Anyways...

 

I'm trying to piece together a platformer game. I've been doing fairly well so far, having figured out general movement, jumping/falling, animations, shooting (mostly), etc. My big issue that I can't seem to figure out is making doors. I want to have doors that work similarly to games like Super Mario World, where you stand in front of them, press the up button, and go to a different area.

 

I've been learning most of what I've been doing by looking up various engines and how they work, and adapting the different methods into my game. Unfortunately, the doors are something that I still haven't been able to figure out. The only source I could use to figure it out was from scouring the forums on the Game Maker website and even then, I only found a few lines of code with no example or anything. I tried just copy/pasting the code into my game and following the directions to make it work, but it doesn't. Instead of spawning the player in the next room, it just takes the player back to the starting point of the same room.

 

I figured that at least a couple of the people here are pretty good at working with Game Maker, so I thought I'd ask. Could anybody here please explain to me how to make a doorway between rooms work? I don't have my current version of the project uploaded anywhere, but if you'd like to see what I've got so far, I could get it uploaded somewhere.



#2 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 08 June 2013 - 04:55 AM

I'm not a fan of GM at all, but it should be fairly simple to conceptualize. Game Maker uses (I believe) monolithic object components for every type of game entity instance, so a door might just be one of those: if 1. Player object stands over door object, then if 2. Input up is pressed, then 3. warp to room of some id at some x,y Basically something like this:
//door code
if( self.collides(player) and game.input(UP) )
{
  update_other_objects(false); //..or set player invincible, or whatever.
  player.animation = UP;
  warp_player_with_fade_effects(room_id, x, y);
}
This was probably the least helpful post ever since I don't use GM, but meh.. There;s probably an easier way too... If I was doing this in c++ I would probably generate an event rather than putting player logic in a door class, but it's a script, so things are supposed to be quick and dirty. ...Maybe someone better qualified can answer this for me. ;)

#3 grayswandir

grayswandir

    semi-genius

  • Members

Posted 08 June 2013 - 07:12 AM

It's been years since I've touched Game Maker, but I might be able to help. Could you post whatever code you're using?



#4 kurt91

kurt91

    Follower of Destiny

  • Members
  • Real Name:Kurtis
  • Location:Eastern Washington University

Posted 08 June 2013 - 02:22 PM

Alright, here's what I've got so far...

 

Creation Code

{
  if (!variable_local_exists("teleX")) { teleX = 16; }
  if (!variable_local_exists("teleY")) { teleY = 16; }
  if (!variable_local_exists("newRoom")) { newRoom = -1; }
}

Collision Code - With Player

if keyboard_check(vk_up){
  other.x = teleX;
  other.y = teleY;
  if (newRoom > -1) { room_goto(newRoom); }
}

Creation Code (Connects Level1_Area1 with Level1_Area2)

if keyboard_check_pressed(vk_up){
    teleX = 40;
    teleY = 120;
    newRoom = Level1_Area2;
}


#5 grayswandir

grayswandir

    semi-genius

  • Members

Posted 08 June 2013 - 02:34 PM

I'm thinking you don't want the if statement in the second creation code block. Unless you're holding up when the door is created, it won't set the targets.

 

See if that works?



#6 kurt91

kurt91

    Follower of Destiny

  • Members
  • Real Name:Kurtis
  • Location:Eastern Washington University

Posted 08 June 2013 - 02:45 PM

That worked perfectly! Thank you, I would have never thought of that. So, if I understand correctly, the reason it wasn't working before was because the creation code is ran when the room is first loaded, meaning that in order to trigger the door, I would have had to be pressing the button when the room was loaded. This way, it just sets the variables when the room is loaded, and the collision code activates them and makes the door work? The way I had originally thought it worked was that the creation code was to simply make tweaks to individual instances of the same object.



#7 grayswandir

grayswandir

    semi-genius

  • Members

Posted 08 June 2013 - 03:06 PM

Yeah, I think you got the idea.

 

Strictly speaking, it's not "for" anything. It's just the code that gets run when whatever is created. You can use it to tweak like that, but you can use it for plenty of other things, too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users