Author Topic: Invincibility Frames  (Read 7437 times)

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Invincibility Frames
« on: July 27, 2015, 12:31:38 AM »
I know how I could easily do invincibility frames(but describe how anyway, my way's probably wrong), but how do you make the boss toggle invisibility when it's invincible?

EDIT:

Also, how do I make an object rotate around another object?
Thanks in advance   :atkHappy:
« Last Edit: August 02, 2015, 04:10:12 PM by LoneTree_tv »

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.107 Chrome 44.0.2403.107
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #1 on: July 27, 2015, 12:50:48 AM »
You would create a timer (a variable in the creation code, a variable -= 1 in the step) and then set image_alpha = 0 until the timer runs out. If you already have the code for invincibility just stick the image_alpha 0 into that one. You can also make it image_alpha = .5 for half-visible, and so on.

To be more specific, I would make invincibility frames with the following

In the Create section:
IFrame = 0;
BossHP = 100 (or whatever value you want)

In the Collide with Bullet section:
if IFrame = 0 {
BossHP -= 1;
IFrame = 20}

In the Step section:
if IFrame > 0 {
IFrame -= 1;}

I'm pretty sure that should do what you want after you change the variables to your liking, but someone else might know better than me.
« Last Edit: July 27, 2015, 12:57:05 AM by Kyir »

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #2 on: July 27, 2015, 01:03:42 AM »
Thanks for the help.
There's just one thing:
when I said toggling, i meant it keeps on switching between visibility and invisibility even while invincible.
Do you know how to do that?

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #3 on: July 27, 2015, 01:13:40 AM »
I got it working with the flashing by using an inconvenient way where
I have a bunch of lines saying

if (IFrame=x) {
image_alpha=x }

or something like that, but would it work if I triggered an alarm or something that says

if (image_alpha=0) {
image_alpha=1 }

if (image_alpha=1) {
image_alpha = 0 }

if (IFrame = 0) {
image_alpha = 1
}else{
alarm[11]=20

?

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #4 on: July 27, 2015, 01:25:09 AM »
I got it working that way. Thanks for the help  :atkLove:

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 40.0.2214.94 Chrome 40.0.2214.94
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #5 on: July 27, 2015, 01:54:10 AM »
In the future, use the edit button instead of the post feature; it's against the rules to triple post unless each post is spread far enough away from each other in time or the content in it is too large to fit into one post (which really shouldn't happen either).

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #6 on: July 27, 2015, 06:04:43 PM »
In the future, use the edit button instead of the post feature; it's against the rules to triple post unless each post is spread far enough away from each other in time or the content in it is too large to fit into one post (which really shouldn't happen either).

Sorry.  :atkCry:
I didn't want to post so many times,
but I forgot that editing existed.

Derf

  • Guest
Re: Invincibility Frames
« Reply #7 on: July 27, 2015, 06:12:44 PM »
I'm not sure it makes much of a difference to the speed of the code but it's probably better to use the in-built function for visibility than image_alpha since you're just using 0 & 1 anyway. e.g. "visible = 1" or "visible = 0".

Also when you're just using boolean data (a value that is either 1 or 0/true or false) you can just do the following:

Code: [Select]
visible = !visible;
instead of

Code: [Select]
if (visible = 0) {
     visible = 1;
}
else if (visible = 1) {
     visible = 0;
}

Again, it's not a big enough thing to cause slowdown in the game but it is quicker for GM to process and is a good habit simply because it requires you to type less.

HAEGOE

  • Spike Dodger
  • Posts: 101
  • Why the *beep* they're not in puyo tetris?????????
  • OS:
  • Windows 8/Server 2012 Windows 8/Server 2012
  • Browser:
  • Chrome 44.0.2403.107 Chrome 44.0.2403.107
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #8 on: July 27, 2015, 09:12:49 PM »
Well, I'm using this code to toggle a couple of frames later

Code: [Select]
if IFrame>0 and IFrame mod 4 <2{
//the former is to make sure invisibility toggling works only when invincible, and the latter is for setting toggle interval
visible = 0;
}else{//when the boss is not invincible or when toggled from invisible to visible
visible = 1;
}

in the code above, I setted the interval to 2, means boss' invisibility changes each 2 frames.

If you want to increase it(decreasing would means setting it to 1, in which case It's better to use what derf said), you can write it this way

Code: [Select]
if IFrame>0 and IFrame mod (interval X2) <(interval){
//same as above. I suggest writing value as natural number
visible = 0;
}else{
visible = 1;
}
a.k.a. tasteisgone
pronounciaton of HAEGOE is HAEGWE, not HAEGO.

I MAEK MBOILE GEAMS!
https://play.google.com/store/apps/details?id=com.Haegoe.MostPop


LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #9 on: July 27, 2015, 11:13:28 PM »
Wow. Thanks so much!
But one more thing, can you break down the first lines of code for both of the segments?
I don't understand "mod 4 <2" and "mod (interval X2) <(interval)" very well.
Just for future usage, I'd like to know what they do.
Thanks in advance  :atkHappy:

HAEGOE

  • Spike Dodger
  • Posts: 101
  • Why the *beep* they're not in puyo tetris?????????
  • OS:
  • Windows 8/Server 2012 Windows 8/Server 2012
  • Browser:
  • Chrome 44.0.2403.107 Chrome 44.0.2403.107
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #10 on: July 28, 2015, 04:38:30 AM »
first, here 'mod' means 'modulo operation' or 'remainder'.

so, if you say IFrame mod 4 < 2, it means if you divide 4 into the value 'IFrame' and you get a remainder less than 2.

and since the IFrame is dropping every frame, the remainder of the calculation will also be changed.
as the IFrame goes down, the remainder(IFrame mod 4) will take a cycle of 3->2->1->0->3->2->1->0->3->.. and so on.
now, when remainder is 1 or 0, then the IFrame mod 4 < 2 will be true, which means visible = 0 and boss will be invisible.
and when remainder is 2 or 3, then it will be false, visible = 1 and boss will be visible.

same goes with mod (interval X2) <(interval).
As the IFrame drops, IFrame mod (interval X2), or remainder will take a cycle from interval X2-1 to zero, then back to interval X2-1.
and if the remainder is smaller than interval, then the code will be true, and I believe you'll get the picture.

Of course, interval X2 means twice the interval. By setting it that way, half the remainder will be same or higher than the interval(which means false), and the other half will be lower than that(true), so that you can control the number of frames of invisibility toggle.

hope this is simple enough.. I'm not good at explaining things  :atkCry:
a.k.a. tasteisgone
pronounciaton of HAEGOE is HAEGWE, not HAEGO.

I MAEK MBOILE GEAMS!
https://play.google.com/store/apps/details?id=com.Haegoe.MostPop


LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.89 Chrome 44.0.2403.89
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #11 on: July 28, 2015, 08:23:26 PM »
Alright, thanks. I understood most of it, except for the interval and interval X2 stuff.
No need to explain. But if someone does know how to explain it to an absolute beginner like me, please do.

In the case that I do use the interval code, and just copy paste it,
what do I need to change to make the interval longer or shorter, and how many frames longer will it make it?

HAEGOE

  • Spike Dodger
  • Posts: 101
  • Why the *beep* they're not in puyo tetris?????????
  • OS:
  • Windows 8/Server 2012 Windows 8/Server 2012
  • Browser:
  • Chrome 44.0.2403.125 Chrome 44.0.2403.125
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #12 on: July 29, 2015, 06:50:14 AM »
uhh.. you see, that's where the interval and interval X2 comes in.

for example, if you want to set interval as 5 frame, do this :

if IFrame>0 and IFrame mod 10 < 5 {
//the former is to make sure invisibility toggling works only when invincible, and the latter is for setting toggle interval
visible = 0;
}else{//when the boss is not invincible or when toggled from invisible to visible
visible = 1;
}
basically the same, but there interval is 5 and interval X2 is 10.
a.k.a. tasteisgone
pronounciaton of HAEGOE is HAEGWE, not HAEGO.

I MAEK MBOILE GEAMS!
https://play.google.com/store/apps/details?id=com.Haegoe.MostPop


LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 43.0.2357.93 Chrome 43.0.2357.93
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #13 on: July 29, 2015, 04:41:00 PM »
So interval isn't a constant or any thing, it'd just the number of frames that it takes before toggling?
Oops.
I thought it was some sort of built in function to gm.
Also, if I wanted the boss to stay visible twice as long as it stays invisible, I could put something like
mod 8 < 3
right?
finally, to clear up some confusion, MY idea wag up at the top of the thread that I said worked was in a form of an alarm. It didn't flash at every frame. I put alarm [11]=20 at the end of it.
sorry if my grammar or something sucks, I wrote this all on my phone :P

LoneTree_tv

  • Wannabe
  • Posts: 32
  • Bad Fangamer and Fangame Dev
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 44.0.2403.125 Chrome 44.0.2403.125
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #14 on: August 02, 2015, 11:40:25 PM »
One more thing, hopefully the last,
How do you make a health bar appear?