Author Topic: Invincibility Frames  (Read 7442 times)

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • 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 #15 on: August 03, 2015, 08:16:35 AM »
Make a sprite for the health bar which is 1 pixel, and then draw it with the length of the maximum length / max HP * HP.
(click to show/hide)

smoke weed everyday

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 #16 on: August 03, 2015, 12:40:17 PM »
How do you change the length of the sprite?

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • 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 #17 on: August 03, 2015, 12:45:50 PM »
image_xscale = x

it's multiplicative, so if you choose 1, it'll show the sprite, if you choose 2, it'll double the length, -1 will reverse the sprite, etc.

EDIT: Or actually, you'd probably rather just wanna put in the draw event:

draw_sprite_ext(spr_healthbar,0,x,y,image_xscale,1,0,c_white,1)

Replace the variables with whatever.
(click to show/hide)

smoke weed everyday

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 #18 on: August 03, 2015, 12:52:16 PM »
Alright, I tried using the draw event, which I've never used before, and ran into some problems

I only wrote this:

draw_sprite(HPBar,0,10,10)

and neither the sprite nor the boss appears.

also, just now, i tried

hpbar=draw_sprite(HPBar,0,10,10);
hpbar.image_xscale=500/20*hp

the boss and hp bar did not show, and the players sprite got stretched instead.

EDIT: Oops, didn't see your edit. Tried it, and it still didn't work. what should I put for the image scaling if the max hp is 20 and I want the length to be 500? I think the fact that I put "500/20*hp" is what screwed everything up.

EDIT2: Wow, I'm incredibly stupid. I replaced spr_healthbar with my sprite name, and that fixed it. But the boss still doesn't seem to want to exist. By that I mean it's invisible. It's still shootable if you can guess where he is.

EDIT3: Once again, I'm terrible. I just put in draw_self(); before the other line and everything worked perfectly.
« Last Edit: August 03, 2015, 01:15:35 PM by LoneTree_tv »

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • 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 #19 on: August 03, 2015, 02:04:29 PM »
Yeah, maybe I should have also said that you should put in draw_self() when using the draw event, but otherwise, there you go!
(click to show/hide)

smoke weed everyday

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 #20 on: August 03, 2015, 03:19:25 PM »
Thanks  :atkHappy:

I also wanted to know how to make cherries rotate around the boss, but I scratched the idea as a whole. It'd still be nice to know how, if you know.

Katz

  • Cherry Eater
  • Posts: 71
  • 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 #21 on: August 03, 2015, 03:22:41 PM »
Thanks  :atkHappy:

I also wanted to know how to make cherries rotate around the boss, but I scratched the idea as a whole. It'd still be nice to know how, if you know.

I would do either paths or move_towards_point code(s) with a 360 rotation

I guess the first one works better if math is hard :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 #22 on: August 03, 2015, 03:24:51 PM »
Math is ezpz, and I don't know how to use paths :P

But how would that work in code?

with deliciousFruit {
move_towards_point(boss.x,boss.y,90) }

?

Derf

  • Guest
Re: Invincibility Frames
« Reply #23 on: August 03, 2015, 03:57:27 PM »
off the top of my head something like this

make a special fruit object:

Code: [Select]
CREATE EVENT:
cx = boss.x
cy = boss.y
rad = 12; //or whatever you want the radius to be
spd = 8;//or whatever you want the rotational speed to be
ang = 90;//or whatever you want the starting ang of the object to be

Code: [Select]
STEP EVENT:
ang = ang mod 360;//this makes it so that the ang is always between 0 & 360

if(ang < 0) {
     ang += 360;
}

x = cx + rad * cos(degtorad(ang)); //make sure cherry is at correct point in rotation
y = cy - rad * sin(degtorad(ang));

ang += spd; //rotate cherry

cx = boss.x;
cy = boss.y; //update the centre points so that if your boss is moving, the cherries move with it
« Last Edit: August 03, 2015, 04:00:01 PM by Derf »

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 #24 on: August 03, 2015, 04:01:22 PM »
That looks incredibly complicated.
Also, you didn't use the move_towards_point thing, telling me there's probably a different method? I'd like to know just in case. Thanks :atkHappy:

Katz

  • Cherry Eater
  • Posts: 71
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 44.0.2403.125 Chrome 44.0.2403.125
    • View Profile
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #25 on: August 03, 2015, 04:11:52 PM »
I 100% recommend derf's method in this instance. move_towards_point would just be simple and shitty imo.

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 #26 on: August 03, 2015, 04:12:29 PM »
alright then. Thanks  :atkHappy:

Derf

  • Guest
Re: Invincibility Frames
« Reply #27 on: August 03, 2015, 04:19:30 PM »
You only really need to mess with the create event variables to tweak it to fit your game so it shouldn't matter if you don't understand it 100%.

Generally there are more than one way of doing most things in Game Maker and it's just up to personal preference and optimization really.

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 44.0.2403.125 Chrome 44.0.2403.125
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Invincibility Frames
« Reply #28 on: August 03, 2015, 04:49:28 PM »
A while back sand wrote this script for orbiting, I hope he won't mind I put it here:


Code: (orbit) [Select]
argument0=centerX; //the center x-coordinate for the orbit
argument1=centerY; //the center y-coordinate for the orbit
argument2=radius;
argument3=spinSpeed; //the speed the projectile is moving in the orbit
argument4=direction;
argument5=radiusSpeed; //the speed the projectile is moving along the radius (a speed of -1 would make the projectile move inwards)



x=centerX+lengthdir_x(radius+rad,direction+dir);
y=centerY+lengthdir_y(radius+rad,direction+dir);
dir+=spinSpeed;
rad+=radiusSpeed;


And in the projectile's step event:


Code: [Select]
orbit(centerX,centerY,radius,spinSpeed,direction,radiusSpeed);


You could set the defaults in the projectile's step event, but for me, when I set the spinSpeed in the step event, the projectiles will just speed up until it hits a certain speed, then slow back down, as if it were a sine wave. To avoid this, I usually just put in either a spawning object's alarm[_] event or the boss's alarm[_] event:


Code: [Select]
for(i=0;i<360;i+=360/[number]){
  a=instance_create([x value],[y value],cherry);
  a.centerX=a.xstart;
  a.centerY=a.ystart;
  a.radius=[number];
  a.spinSpeed=[number];
  a.direction=i;
  a.radiusSpeed=[number];
}


If you don't want the projectiles to move in towards the orbit's center, you can remove rad and radiusSpeed from each code or just set it radiusSpeed to 0.
« Last Edit: August 03, 2015, 04:52:22 PM by infern0man1 »