• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need Help With Idea

C

CheeseOnToast

Guest
Hi and welcome to the forums!

Firstly what you would want to achieve is best done as an optical illusion that gives the player a sense that they're moving but they are really just stationary object moving around the screen dodging certain obstacles that pop in and out through a random generator. You can achieve this optical illusion by using room backgrounds and setting the vertical speed of the background, rest you can use a random chance generator to spawn dodgable objects on demand which you can avoid that scroll downward from top to bottom.
 
If you have a loopable sprite, like spr_tree, then in the create event of the tree object, I would put something like:
Code:
y1=0;
y2=-sprite_height;
In the step event:
Code:
y1+=5;//replace with speed
y2+=5;
if(y1>sprite_height){
    y1-=sprite_height;
}
if(y2>sprite_height){
    y2-=sprite_height;
}
And in the draw event:
Code:
draw_sprite(sprite_index,0,room_width/2,y1);
draw_sprite(sprite_index,0,room_width/2,y2);
For this to work, you'd need the tree sprite to be as tall as the room or taller.

And for the branches, I'd just have an object, obj_branch, that is created in an alarm event of another object that keeps resetting the alarm as well. In this branch object's creation code:
Code:
side=choose(-1,1);//left or right
x=room_width/2+side*(tree_width/2);//replace tree_width with actual width of tree
vspeed=5;//replace with speed you want it to go down (same as tree), probably just use a global variable like global.down_speed
if(side==1){
    sprite_index=spr_branch_right;
}else{
    sprite_index=spr_branch_left;
}
For this to work, you'd need 2 branch sprites. And in the sprite editor, set the origin of the right one at the far left point of the branch. Set the origin of the left branch to the far right point.

If you need anymore help with it, let me know.
 
M

Motivating

Guest
Thanks for the feedback! It's greatly appreciated, will give it a try tonight and troubleshot/mess around
 
M

Motivating

Guest
The only issue i'm having now is to make the branches and background speed increase as time goes on? and to cap it at a certain speed. Any ideas on how I would go about doing that?
 
Last edited by a moderator:
D

DevNorway

Guest
Code:
if speed < maxSpeed {
    //increase branches and background speed
}
 
M

Motivating

Guest
Thanks DevNorway, will try it out! I'm trying to code it so every time I pass an object (the branch) the branch movement increases (the objects) every 10-15 branches passed by like 5% or a set speed. Any idea?
 
Last edited by a moderator:
Have a variable that counts how many branches have passed. Maybe in the create event of a control object:
Code:
global.b_passed=0;
global.down_speed=5;
And in the instance destroy event of the branch (I assume it is destroyed when it leaves the bottom of the screen):
Code:
global.b_passed+=1;
if(global.b_passed mod 10==0){//remainder after division by 10 == 0
    global.down_speed*=1.05;//increase speed by 5%
    with(obj_branch){
        vspeed=global.down_speed;//all current branches speed up
    }
}
For this to work, you need a variable containing the speed of everything going down. I called it global.down_speed. In the create event of the branches, set their vspeed to global.down_speed.
And in the step event of the tree, make the y's add global.down_speed instead of 5, as I put before.
 
M

Motivating

Guest
The issue is it's not being registered as destroyed when it leaves the screen
 
M

Motivating

Guest
Ok I made progress. I made a line (which will be transparent later) but I want it so when the branches hit the line (after lets say every 3 branches) to speed up by 5-10%. Any tweeks to my current code to help? The branches hit the line then only the ones currently on the screen speed up and the freshly spawned branches do not.
 
Last edited by a moderator:
For them to speed up 5% after every 5 branches, use this:
Code:
global.b_passed+=1;
if(global.b_passed mod 5==0){//remainder after division by 5 == 0
  global.down_speed*=1.05;//increase speed by 5%
  with(Left_Branch){
  vspeed=global.down_speed;//all current branches speed up
  }
}
And for each newly spawned branch, you need to put this in the create event:
Code:
vspeed=global.down_speed;
instead of whatever you have setting it's speed.
Let me know if you need any more clarification. If you do, then show me your branch object's code too.

Just read your comment that the branch isn't being destroyed. You would need to create an event in the branch object (outside room), then put
Code:
 instance_destroy()
in there. If that doesn't work, then in the step event, put:
Code:
if(y>room_height){
    instance_destroy();
}
 
M

Motivating

Guest
I really appreciate the help, ill try it out right now. An issue I will have to fix is I have branches spawning outside of the room so it appears like its part of the tree. Meaning it's destroying all the spawned branches. It looks really crappy if they spawn at y=0. Only work around is I could make a cloud cover on y=0
 
Last edited by a moderator:
M

Motivating

Guest
Would there be anyway instead of having the branch be destroyed hitting a line or object to trigger the event?
 
M

Motivating

Guest
Ok so here is a picture of the code of my Branch Spawner. It creates them outside the room so it has a smooth appearance. Having a hard time figuring out how to implament
vspeed=global.down_speed; for the newly spawned branches.
 

Attachments

Last edited by a moderator:
To fix the problem of it being destroyed on creation outside of room, change the outside of room event to the step event and use:
Code:
if y>room_height{
    instance_destroy();
}
 
M

Motivating

Guest
Any idea of how to code the vspeed=global.down_speed; for the newly spawned branches? Once I figure that out I think it might be good
 
M

Motivating

Guest
I did, it's not giving it to the newly spawned branches, just the branches that are currently on the screen
 
That's strange. If you're sure that the code is in the create event of the branch object, then there must be code somewhere else in that object that is setting it to a different speed. Or global.down_speed isn't being changed.
 
M

Motivating

Guest
Maybe this will help you find out what I'm doing wrong, I'm sure I'm making an error somewhere
 

Attachments

Last edited by a moderator:
Yeah, your problem is that your branches are resetting global.down_speed to 1 every time they are created. Take that line out of the branch create code.
 
M

Motivating

Guest
When I take that line of code out I get an error sayin:

FATAL ERROR in
action number 1
of Create Event
for object Left_Branch:

global variable down_speed(100000, -2147483648) not set before reading it.
at gml_Object_Left_Branch_CreateEvent_1 (line 2) - vspeed = global.down_speed
 
Set global.down_speed in the room creation code or create event of he object that spawns the branches. Don't let a branch be created before global.down_speed is set.
 
Top