Floating balloons that the player catches and floating with them

sensodyne

Member
Hello,

Tries to get the effect as shown in the image below

clown and balloons.png


For example, I have an object that is a clown.
The clown moves left and right and holds balloons in his left hand.
Every now and then he takes a red balloon from his left hand to his right hand and releases it upwards ..
The balloons go up ... and after a few seconds they explode ...also when they touch a hard surface, e.g. ceiling walls, they will also explode ..
when the player grabs the string attached to the balloon, he will be able to float with the balloon up ...
how to do something like that?
skipping the drawing of the clown sprite ... because it's understandable ... I guess the red balloon must be a separate object ...
can someone help me put this together? I would be very grateful for any help ..
 

Xer0botXer0

Senpai
Create the red balloon relative to the clown
give the red balloon to the player when he's within range of the clown
set the players y coordinate equal to the balloon
increment the red balloons y coordinate
use a timer to decide when the balloon changes to an exploding sprite
if the balloons sprite is an exploding sprite then kill the player and destroy the balloon
 

sensodyne

Member
I can handle the clown sprite ... The same with the balloon sprite and I'll make a object obj_ balloon and that's it ...
I could use the code for vertical platform traffic here .. but it's not enough to achieve the effect I described
 

Xer0botXer0

Senpai
Just animate a sprite where the clown hands the balloon over to the player and the player receiving it.
You can code that by making sure the player is within range, then hide the player sprite and play the clown passing the balloon sprite, which includes a player sprite receiving it.

Or you can split it and have the player receive it, trick is to make sure they're close enough.

Not sure which part you're struggling with.

Do you like toothpaste ? xD
 

sensodyne

Member
I can only paint an animated clown with balloons and a separate red balloon ... And set it as a separate object. I Write a code for vertical movement and that's all I can do myself

Do i like toothpaste
what do you work in a dental company and want to sell me a wholesale quantity :)?
 
P

ParodyKnaveBob

Guest
Toothpaste. $F^ J

It sounds like what you seek is to know how to get the player instance and balloon instance to "stick together" while moving? If so, one way to do this is to move one instance the way you like, then set the other instance's x,y accordingly. You might have the moving instance set the other's x,y -- or have the other follow the mover's x,y in its own End Step. Now, how to sync them easily? One easyish way could be to have the player object change sprite once it connects with the balloon object -- and have this other sprite's origin set at the hand (assuming the balloon's sprite's origin would be near the base of the string); this way, you don't even have to finagle math anywhere -- you just tell one instance's x,y to match the other instance's x,y -- and you can even have the clown's sprite's origin match if you wanted. $:^ }

I hope this helps,
 

FoxyOfJungle

Kazan Games
I think what was mentioned is extra work, all you need to do is: When colliding with the balloon, activate the variable flying = true. On the player's step, if this variable is true, it will cause the player to go up in the y axis (depending on how you did the player's gravity, just reverse the gravity in reverse). When taking the balloon and the variable is true, just draw the balloon in the character's hand. (When the balloon collides with the player, destroy the balloon).
 

sensodyne

Member
As I mentioned .. I only made the balloon obj_balon move upwards .. I set the balloon collision on a string ...


obj_balloon

create

GML:
hspeed = 0;
vspeed = -1;
image_speed = 2;

GML:
///Vertical Collision balloon

if (place_meeting(x,y+vspeed,obj_ceiling))
{
    while(!place_meeting(x,y+sign(vspeed),obj_ceiling))
    {
        y += sign(vspeed);
    }
    vspeed = 0;
  
    }
end step

GML:
with o_player
    {
    if place_meeting(x,y+2,other)
        {
      
          x+=other.x-other.xprevious
          y+=other.y-other.yprevious
        }
    }
outside room

GML:
instance_destroy();
collision obj_ballon with the ground


GML:
instance_destroy();
collision obj_ballon with the ceiling

GML:
instance_destroy();
ok i don't know how to do:


point 1

A balloon explodes when it rises and breaks down after 4 seconds, for example


point 2

How to set a number on a balloon that will count down the 4 seconds after which the balloon will explode and destroyed


point 3

The balloon should explode and destroy itself when it touches the hard ground, i.e. the ground and the ceiling obj_ground and obj_ceiling


point 4

The hero should automatically grab the balloon string, because that is where the collision mask is set. And when he presses the jump button, e.g. "x", he will be able to release the balloon string and jump to another balloon or platform


point 5

I already have a clown drawn ... has two animation states ...
- when he goes left and right with the balloons
- when he is standing still with the balloons

The clown should take a few steps left and right and then stand ... and in his right hand generate a balloon sprite and then the balloon should start to rise


clown and balloons.png
 
Last edited:

sensodyne

Member
now tries to make point 4 from these four points

I added a variable flying when the balloon collides with the player in the event step ...
Unfortunately, the player does not grab the balloon string (I have a collision mask already set there) I inverted gravity, I understand that if I have gravity set to grav = 1, I should set it here to grav = -1
The player should grab the string of the balloon and go up with the balloon ... when I press the x button he should release the string and if I press the x button and the left or right arrow, it will jump in the right direction

I must have mixed up something ... the code looks like this ..
I do not have such experience with GMS yet


o_player

create

GML:
flying = false;
grav = 1;

step


GML:
if place_meeting(x+0,y+0,obj_balloon) and flying = true
{
grav = -1

}

if flying=true
sprite_index=spr_hero_grab
 

sensodyne

Member
I will present it in the video below about what effect I mean ...



I have already done point 1 ,point 2 and point 3
point 4 and point 5 remain to be done



point 4

The hero should automatically grab the balloon string, because that is where the collision mask is set. And when he presses the jump button, e.g. "x", he will be able to release the balloon string and jump to another balloon or platform


point 5

I already have a clown drawn ... has two animation states ...
- when he goes left and right with the balloons
- when he is standing still with the balloons

The clown should take a few steps left and right, then stop and change the sprite to idle, and with his empty right hand, he should generate an obj_balloon object and then release it to make the ballon floating.
and again the clown will do the same cyclically ... he will walk, stop and generate another balloon in a random place ... When he generates, for example, 4 balloons, he will stop generating more balloons until the others disappear from the room..

I am not entirely convinced that this code is correct ... although the balloon is up floating, but it is a code for a moving platform ... Ballon is supposed to be this moving platform, but the player has to grab the string (where the sprite collision mask is set) and not stand on the balloon

this is what my code looks like now ..

obj_balloon

create

GML:
hspeed = 0;
vspeed = -1;
image_speed = 2;
sprite_index = spr_balloon

s = 4;
alarm[0] = room_speed;

alarm[0]

GML:
s -= 1;

if (s == 0) {

   instance_destroy();
//this is where I will create a sprite explosion balloon

}



else {
    alarm[0] = room_speed;
}

step


GML:
///Vertical Collision balloon

if (place_meeting(x,y+vspeed,obj_ceiling))
{
    while(!place_meeting(x,y+sign(vspeed),obj_ceiling))
    {
        y += sign(vspeed);
    }
    vspeed = 0;

    }


draw

GML:
draw_set_font(font_balloon);
draw_set_color(c_white);
draw_sprite(spr_balloon, 0, x, y);
draw_text(x , y-20, string(s) + "");

outside room



GML:
       instance_destroy();
          // this is where I will create a sprite explosion balloon




collision obj_ballon with the ground



GML:
       instance_destroy();
           //this is where I will create a sprite explosion balloon





collision obj_ballon with the ceiling


GML:
       instance_destroy();
        //this is where I will create a sprite explosion balloon


This code to point 4 does not work. The player does not grab the balloon string

o_player

create

GML:
flying = false;
grav = 1;

step

GML:
if place_meeting(x+0,y+0,obj_balloon) and flying = true
{
grav = -1

}

if flying=true
sprite_index=spr_hero_grab // here the player sprite should change to a sprite that grabs a balloon string
 

sensodyne

Member
I don't know how to solve this issue further


point 4

The hero should automatically grab the balloon string, because that is where the collision mask is set. And when he presses the jump button, e.g. "x", he will be able to release the balloon string and jump to another balloon or platform


point 5

I already have a clown drawn ... has two animation states ...
- when he goes left and right with the balloons
- when he is standing still with the balloons

The clown should take a few steps left and right, then stop and change the sprite to idle, and with his empty right hand, he should generate an obj_balloon object and then release it to make the ballon floating.
and again the clown will do the same cyclically ... he will walk, stop and generate another balloon in a random place ... When he generates, for example, 4 balloons, he will stop generating more balloons until the others disappear from the room..
 

Xer0botXer0

Senpai
For some reason your sentences make me lose train of thought.

I tried to watch the video you posted so I can understand what you're talking about, but the video doesn't load.

I don't see you setting flying to true.
 
Last edited:

sensodyne

Member
For some reason your sentences make me lose train of thought.

I tried to watch the video you posted so I can understand what you're talking about, but the video doesn't load.
https://drive.google.com/file/d/1cmMhjg9yP5iEOl6GUsetStmQOgW8DjTs/view

I don't see you setting flying to true.
After all, the movie works ... I checked it on another computer and it works ... my friend also checked ...

and here I do not set flying to true?

GML:
if place_meeting(x+0,y+0,obj_balloon) and flying = true
{
grav = -1

}

if flying=true
sprite_index=spr_hero_grab // here the player sprite should change to a sprite that grabs a balloon string
 

Xer0botXer0

Senpai
GML:
if (place_meeting(x+0,y+0,obj_balloon) && flying == true) //here you have an if statement with two conditions
{
      grav = -1; //Here - you assign a value
}

if (flying== true) //here you have an if statement with a single condition
{
      sprite_index=spr_hero_grab; // here the sprite index is updated when a single condition is met
}
Neither of the two if statements contains a variable named flying that's assigned the value of true.
 

sensodyne

Member
GML:
if (place_meeting(x+0,y+0,obj_balloon) && flying == true) //here you have an if statement with two conditions
{
      grav = -1; //Here - you assign a value
}

if (flying== true) //here you have an if statement with a single condition
{
      sprite_index=spr_hero_grab; // here the sprite index is updated when a single condition is met
}
Neither of the two if statements contains a variable named flying that's assigned the value of true.

This code does not help ... I know I forgot to give the clamps there ... but it still doesn't work ...
The player still does not grasp the balloon string and does not float with it
 

Nidoking

Member
What is the line of code where you SET the "flying" variable to be true? Please quote exactly that line of code, with or without a bit of context so we can see how it's used. None of the lines of code you've posted so far do that.
 

sensodyne

Member
What is the line of code where you SET the "flying" variable to be true? Please quote exactly that line of code, with or without a bit of context so we can see how it's used. None of the lines of code you've posted so far do that.

Of course that no line of code does this..I gave it as an example ... I have a problem with this..I described it above in the post..I wrote two points with which I have a problem and posted a video ...
which illustrates what I wanted to get ...


I will present it in the video below about what effect I mean ...



I have already done point 1 ,point 2 and point 3
point 4 and point 5 remain to be done



point 4

The hero should automatically grab the balloon string, because that is where the collision mask is set. And when he presses the jump button, e.g. "x", he will be able to release the balloon string and jump to another balloon or platform


point 5

I already have a clown drawn ... has two animation states ...
- when he goes left and right with the balloons
- when he is standing still with the balloons

The clown should take a few steps left and right, then stop and change the sprite to idle, and with his empty right hand, he should generate an obj_balloon object and then release it to make the ballon floating.
and again the clown will do the same cyclically ... he will walk, stop and generate another balloon in a random place ... When he generates, for example, 4 balloons, he will stop generating more balloons until the others disappear from the room..

I am not entirely convinced that this code is correct ... although the balloon is up floating, but it is a code for a moving platform ... Ballon is supposed to be this moving platform, but the player has to grab the string (where the sprite collision mask is set) and not stand on the balloon

this is what my code looks like now ..

obj_balloon

create

GML:
hspeed = 0;
vspeed = -1;
image_speed = 2;
sprite_index = spr_balloon

s = 4;
alarm[0] = room_speed;

alarm[0]

GML:
s -= 1;

if (s == 0) {

   instance_destroy();
//this is where I will create a sprite explosion balloon

}



else {
    alarm[0] = room_speed;
}

step


GML:
///Vertical Collision balloon

if (place_meeting(x,y+vspeed,obj_ceiling))
{
    while(!place_meeting(x,y+sign(vspeed),obj_ceiling))
    {
        y += sign(vspeed);
    }
    vspeed = 0;

    }


draw

GML:
draw_set_font(font_balloon);
draw_set_color(c_white);
draw_sprite(spr_balloon, 0, x, y);
draw_text(x , y-20, string(s) + "");

outside room



GML:
       instance_destroy();
          // this is where I will create a sprite explosion balloon




collision obj_ballon with the ground



GML:
       instance_destroy();
           //this is where I will create a sprite explosion balloon





collision obj_ballon with the ceiling


GML:
       instance_destroy();
        //this is where I will create a sprite explosion balloon


This code to point 4 does not work. The player does not grab the balloon string

o_player

create

GML:
flying = false;
grav = 1;

step

GML:
if place_meeting(x+0,y+0,obj_balloon) and flying = true
{
grav = -1

}

if flying=true
sprite_index=spr_hero_grab // here the player sprite should change to a sprite that grabs a balloon string
 
I see you added the flying variable and made it false, your error is that you are never setting it to true if you are inexperienced with game maker, instead of position_meeting you could just make a new event with your player that counts for collisions (I like to use these ;) ) and make sure that you are trying to collide with the object of the balloon when your game is compiled, and not your sprite balloon.
 

Nidoking

Member
Of course that no line of code does this..I gave it as an example ...
Well, you've also posted code from obj_player, in CODE blocks, that checks to see whether flying is true. If you never set flying to true, then flying will never be true, so the check will always fail. Your comment here:
sprite_index=spr_hero_grab // here the player sprite should change to a sprite that grabs a balloon string
points to a line of code that will never execute. If the line never executes, then what it says will never happen. If I tell you to write the word "false" on a piece of paper, and then I tell you that when the word "true" is written on the paper, you can eat a cookie, will you ever be able to eat the cookie? Of course not, unless someone changes what's written on the paper. I see that you have said this:
The hero should automatically grab the balloon string,
By "automatically", did you mean "this should happen without me writing anything to make it happen"? Because that's not possible. If you want it to happen - if you want flying to be true - you must, at some time, at least once in the course of running the game, set flying to be true. If what you're posting here is not your actual code but merely an example, then you're confusing everyone by posting it, and we'll need to see how you're actually doing things. But if, as I suspect, what you're posting is your actual code, then the problem continues to be that you have not set flying to true, and I think you should probably not do anything else until you have tried the effect of setting flying to true at some point in your game.
 

sensodyne

Member
Well, you've also posted code from obj_player, in CODE blocks, that checks to see whether flying is true. If you never set flying to true, then flying will never be true, so the check will always fail. Your comment here:


points to a line of code that will never execute. If the line never executes, then what it says will never happen. If I tell you to write the word "false" on a piece of paper, and then I tell you that when the word "true" is written on the paper, you can eat a cookie, will you ever be able to eat the cookie? Of course not, unless someone changes what's written on the paper. I see that you have said this:


By "automatically", did you mean "this should happen without me writing anything to make it happen"? Because that's not possible. If you want it to happen - if you want flying to be true - you must, at some time, at least once in the course of running the game, set flying to be true. If what you're posting here is not your actual code but merely an example, then you're confusing everyone by posting it, and we'll need to see how you're actually doing things. But if, as I suspect, what you're posting is your actual code, then the problem continues to be that you have not set flying to true, and I think you should probably not do anything else until you have tried the effect of setting flying to true at some point in your game.
In the create event, should I set the flying variable to true?
this is my code, but I just started to create it..and it bugs the solutions ..
 

Nidoking

Member
In the create event, should I set the flying variable to true?
Is the obj_player flying when you create it? I assume not. You should set flying to true when the obj_player is flying, and to false when the obj_player is not flying. That will not be in the create event, but when you find the condition that determines that the player should be flying or not flying. The line we've been talking about looks like what you want. I think you tried to set flying by putting "and flying = true", but that is not how and works.
 
P

ParodyKnaveBob

Guest
(started typing this around 12 hours ago ... got sick ... I'll try to finish now)

--

It seems to me that the language barrier might be the problem. BOTH language barriers, actually:

1. English does not seem to be sensodyne's first conversational language. This is fine of course, but it can lead to confusion.

2. GML does not seem to be sensodyne's first programming language. This is fine of course, but it can lead to confusion.

and here I do not set flying to true?
GML:
if place_meeting(x+0,y+0,obj_balloon) and flying = true
{
grav = -1
}

if flying=true
sprite_index=spr_hero_grab // here the player sprite should change to a sprite that grabs a balloon string
sensodyne believes these two places set flying = true; in code.

GML:
if (place_meeting(x+0,y+0,obj_balloon) && flying == true) //here you have an if statement with two conditions
{
      grav = -1; //Here - you assign a value
}

if (flying== true) //here you have an if statement with a single condition
{
      sprite_index=spr_hero_grab; // here the sprite index is updated when a single condition is met
}
Neither of the two if statements contains a variable named flying that's assigned the value of true.
Xer0botXer0 attempts to show sensodyne the problem, the difference, but changes sensodyne's code to show it.

(okay, back from being sick ... let's see if I can finish this with any clarity ... sorry)

To sensodyne, GML allows a programmer to use .. nonstandard syntax. Despite languages like PHP allowing one to assign variables in the middle of if conditions, GML does not. At the same time, = is supposed to assign in GML, and == is supposed to compare, but GML also secretly allows a coder to use = for comparison. Which is sad. $:^ (

if (flying = true)
is actually in GML translated internally to
if (flying == true)
and it only compares and does not assign here.

I hope this helps,
 

TailBit

Member
An alternative way using a grab variable

Where you store the id of the balloon in grab

And the step end event tries to move you to the balloon's position
GML:
// player create event
grab = noone;

// Collission with balloon
// only if falling and if about the
// same height as the balloon
if vspeed>0
&& abs(y-other.y)<5{
    grab = other.id;
}

// step end event
// Move player to the grabbed balloon
with(grab){
    other.x = x;
    other.y = y;
}
// You could use instance_exist instead anf position yourself with
// x = grab.x instead

// Jump button pressed
// When you jump you set vspeed and clear grab
vspeed = -7;
grab = noone;

// At the top of your step event you can stop the rest of the event from triggering if grab targets s balloon
if instance_exists(grab) exit;
 
Top