Author Topic: Making a save blocker  (Read 1860 times)

PanKarmelek

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Making a save blocker
« on: January 16, 2016, 01:55:20 PM »
Hello!
I decided to have fun and make a fangame. I understand the basics of Gamemaker but I'm having a small problem. How do I make a save blocker? I tried it many different ways but I just don't know how to force an object to block bullets. I'd really appreciate the help, thanks!  :atkHappy:

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #1 on: January 16, 2016, 02:15:58 PM »
 You might be using a fairly archaic engine if it doesn't come with them constructed already. Anyway, there are a bunch of different ways, so I'm just going to copy/paste the code from the KS engine for you.

Create an object called bulletBlocker and give it a sprite. Using a 32x32 one is easiest. Make sure the visible box is unchecked unless you want it to be something the player can see.

In the step event of the bullet object, use this code:
if place_meeting(x+hspeed,y,bulletBlocker) {
    instance_destroy();
}

Then, just place the bulletBlocker object wherever you want bullets to be blocked.

If you want to make something fancy a slightly different method is better. For instance, if you want to make something that animates whenever a bullet hits it, you'll want to make that entire animation before anything else (make sure it starts from an image that is empty if you want it to be invisible at first.) Set image_speed = 0 in the create event. Then instead of using code in the bullet use a collision event in the bullet blocker object to destroy the bullet and set the image_speed to something above 0. That will play the animation.

Then just make an animation end event that sets the image_index and image_speed back to 0 so everything goes back to normal when the animation's done playing. It's pretty simple when it comes down to it, and you can apply this sort of coding to a lot of other things in your game.

Again though, I would make sure you're using a modern engine before getting too far in your game.
« Last Edit: January 20, 2016, 09:39:53 PM by Kyir »

PanKarmelek

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #2 on: January 16, 2016, 02:17:53 PM »
Thanks for help! I'm using the yuutu engine. I hope it's good?

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #3 on: January 16, 2016, 02:23:17 PM »
I think yuutu used to be standard? I never used it personally. YoYo's GMS engine is probably better annotated if you're still trying to find your way around an engine.

PanKarmelek

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #4 on: January 16, 2016, 02:25:31 PM »
I'm still learning, my fangame is nothing really special. The problem I have is that I can't make an object that's like, 1px wide and will block the bullets. Im gonna try to use the thing you just gave me, maybe it will work.

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #5 on: January 16, 2016, 02:29:37 PM »
The reason that's not working is because bullets travel faster than one pixel at a time, so they'll go through a 1 px object quite often.

PanKarmelek

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #6 on: January 16, 2016, 02:35:55 PM »
Oh, that makes a lot of sense.
I know I'm probably being stupid here but where am I supposed to type in this thing you gave me? Creation code or should I make an event with "Create" or something? I'm lost here...

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #7 on: January 16, 2016, 02:40:51 PM »
That code should go in the step event of the bullet object.

PanKarmelek

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Re: Making a save blocker
« Reply #8 on: January 16, 2016, 02:46:18 PM »
Whew, I got it working now. Thank you very much for help, you're the boss! <3