#[How to make enemy do small hops instead of moving horizontally?] & [losing lives with collision]

90 messages ยท Page 1 of 1 (latest)

solar gazelle
#

this is the code I've already got for my enemies

livid oracle
#

Try using alarms. For example, if you need your enemy to jump forwards every 1 second (60 frames), you can do something like:

Create Event

hop_distance = 10;
hop_height = -10;
alarm[0] = 60;

Alarm 0 Event

hsp = hop_distance;
vsp = hop_height;
alarm[0] = 60;

Step Event

if (grounded) {
    if (afraidofheights && !place_meeting(x + hop_distance, y+1, [objGrassBlock, objWastelandBlock, objFireBlock])) {
        hop_distance = -hop_distance;
}

    hsp = lerp(hsp, 0, .2);
}
solar gazelle
#

ooooo this seemed to have worked so thank you but the enemy does large and quick jumps whereas I want the hops to be shorter and it also seems to jump off platforms and even jumps in mid air off the screen

#

is there a way to fix this?

#

or should I create an invisible block as a barrier to stop the enemy but have no collision with the player?

#

would that be a good solution?

livid oracle
#

Okkk to make the hops smaller, you can fiddle with the hop_distance and hop_height variables. Smaller numbers make smaller hops

solar gazelle
#

ooo I see, thanks a lot

#

let me try that now

livid oracle
#

To make the jumps take longer, you can set the alarms to a larger number. 60 frames is 1 second, 120 frames is 2 seconds, etc.

#

Remember to set the one in the Create event and the one in the Alarm 0 event

solar gazelle
#

ooo making the jump smaller fixed the issue of him jumping off the platforms

livid oracle
#

Good to hear! Anything else that needs to be fixed?

solar gazelle
#

That's seemed to fix the problem that I had so thank you very much!!!!!!!!!

#

you are a legend

livid oracle
#

Just doing what I can ๐Ÿ˜„

#

Good luck with your project!

solar gazelle
#

thxx

solar gazelle
#

I've setup a lives system for my player so when he collides with the player he loses 1 life

#

but when I collide with the enemy my player loses all the lives in one go super fast

#

I assume to combat this I would have to make a small delay or invulnerability time to my player when colliding with the enemy

#

any idea how I would go about doing this?

#

This is what I've got so far

solar gazelle
#

soo I assume I would create a variable that's always set to false and

#

if I touch the enemy and that variable is false then lose a life then flip that variable to true for the amount of time I wanna be invulnerable?

#

but how would I put this into code?

#

if anyone can help

#

[How to make enemy do small hops instead of moving horizontally?] & [losing lives with collision]

livid oracle
# solar gazelle but how would I put this into code?

Add another variable like this:

Create

invulnerable = false;

Then add a bit into the else statement of your Collision event:

Collide

...
else {
    if (global.life > 0 && ! invulnerable) {
        global.life -= 1;
        invulnerable = true;
        alarm[0] = 60;
    }
}

And finally, use an alarm to reset the invulnerability variable.

Alarm 0

invulnerable = false;
solar gazelle
#

I have added this to my code but my lives still get taken away immediately super fast

livid oracle
#

Oh whoops

solar gazelle
#

ahh I see

livid oracle
#

I added a line into the collision event. Try that ๐Ÿค”

solar gazelle
#

ahhh NICE it works perfectly

#

also if I were to make a powerup that made my character invulnerable for a set amount of time would It would work similar to this expect I would instead change the time for the alarm and take out the life stuff?

#

also I am trying to make it so that when I lose all my lifes my game restarts but it's not letting me use another else statement

#

would this be wrong?

livid oracle
solar gazelle
#

ahh ok I've taken it out of the else statement but

#

when I get done to 0 lives it doesnt restart until I get hit again

#

so I kinda have 4 lives instead of the 3 I set in global life

livid oracle
#

Oh yeah just put it in the Step event instead

#

The last if statement

#

Oh wait

#

nvm

#

You set the lives to check for < 0

#

So your character only dies when the counter reaches -1

#

Set it to <= 0 instead

solar gazelle
#

ok so I've changed it like you said and it did the same thing but changing the 0 to 1 seemed to fix the problem so thank you so much

livid oracle
#

Oh ok that works too cause it's more or less equivalent

#

Cheers! ๐Ÿฅ‚

solar gazelle
#

also your game looks sick af

#

definitely gonna wishlist

livid oracle
#

Ayyy thanks ๐Ÿ˜Ž

#

Much appreciated ๐Ÿ˜Š

solar gazelle
#

I have one more question good sir

#

and after this pls let me send u money for a coffee or something, you've helped me too much

#

I wanna make a pirana plant style enemy that stays stationary and shoots fireballs at the player but cant seem to find any tutorials for this

#

only like

#

enemies that move and shoot the player like a gun but

#

I also wanna make a powerup that lets the player shoot the same projectile

#

wait nvm I think I've found something ima try out

solar gazelle
#

figured it out

livid oracle
#

lmao sorry yeah I fell asleep ๐Ÿ˜‚

#

It was 12 AM where I am

solar gazelle
#

Im trying to make the invulnerability powerup like we talked about before

#

but for some reason it doesnt make me invulnerable

#

is this correct?

solar gazelle
#

nvm I managed to fix it

#

I realised that the alarm thing was for frames so I was basically making myself invincible for a sec so I changed that

#

all working good now

solar gazelle
#

I wanna make it so that

#

I've created an invulnerability power up like we talked about before

#

and this is the code for

#

it

#

but i was wondering

#

how about's would I go around making it so for the duration that the alarm event is active it switches my character sprite to another?

solar gazelle
#

NVM figured it out

livid oracle
#

lmao bro you keep figuring things out while I'm asleep ๐Ÿ˜‚

viral rapids
#

You mean like a frog ?