Go to page Previous  1 ... 34, 35, 36, 37, 38, 39, 40, 41  Next  [ 816 posts ]  Reply to topicPost new topic 
Coding Help, Questions and Issues relating to coding
Author Message
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 24, 2016 1:44 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, so there's a projectile that doesn't want to coorperate. However, since that's merely a single projectile, I'll post my problem here instead of making a seperate thread.
So I want my projectile to split in two. I have that.
Now I also want to change the split depending on whenever the projectile has hit the wall or the ground.
While the wall detection is fine, the ground detection isn't.
Sometimes, the projectile will hit the ground far away from any wall and still think that it has hit a wall, and I'm trying to fix that.
Here's the collision detection (inside the Step Event):
Code:
if hspeed > 0
and collision_rectangle(bbox_right+hspeed,bbox_top,bbox_right+hspeed,bbox_bottom-1,obj_solid,0,0) //I have hit the right wall
{
    fire1 = (instance_create(self.x+8,self.y+8,obj_autobomb_firevert))
    fire1.vspeed = 3
    fire2 = (instance_create(self.x+8,self.y+8,obj_autobomb_firevert))
    fire2.vspeed = -3
    sound_play(snd_flames)
    instance_destroy()
}
else if hspeed < 0
and collision_rectangle(bbox_left+hspeed,bbox_top,bbox_left+hspeed,bbox_bottom-1,obj_solid,0,0) //I have hit the left wall
{
    fire1 = (instance_create(self.x,self.y+8,obj_autobomb_firevert))
    fire1.vspeed = 3
    fire2 = (instance_create(self.x,self.y+8,obj_autobomb_firevert))
    fire2.vspeed = -3
    sound_play(snd_flames)
    instance_destroy()
}
else if collision_rectangle(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1,obj_solidtop,0,0) //I have hit the ground
{
    fire1 = (instance_create(self.x,self.y+8,obj_autobomb_fire))
    fire1.hspeed = 3
    fire2 = (instance_create(self.x,self.y+8,obj_autobomb_fire))
    fire2.hspeed = -3
    sound_play(snd_flames)
    instance_destroy()
}

Would be glad if someone could help me there, because that's the last tidbit that needs to be corrected before another boss in my fangame is finally finished.
Thanks in advance!

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 24, 2016 1:58 pm 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
^ If your projectile is low enough to the ground, the wall check is going to return true because of how you set the collision boxes up and the fact that it's the first thing being checked. Run through your code in your head, in order, assuming your projectile is at a y where bbox_bottom-1 is overlapping the ground. The first check, right wall, would return true (or second check if the thing is going left) because the collision bounds you specified go pretty low and as a result the floor check never gets a chance to run.

Now does it make sense why it's doing what it's doing? Try and fix it based on this information.

 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 24, 2016 6:33 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, so I changed the order of the if triggers, and now, the complete opposite happens.
Now, the projectile always detects the ground correctly, but sometimes detects a wall as ground, and that's not good either.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Thu Feb 25, 2016 7:10 pm 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
I figured that would happen. You only tackled half of the problem, though. You can probably try something like raising the Ys of the wall checkers to "bbox_top minus maximum fall speed, bbox_bottom minus maximum fall speed". Disregard that, that was still with the original order in mind. Either way, you need to make sure the collision boxes don't overlap, or there will be derpery no matter what.

Here's what GM probably sees: (the lines are the detectors as you defined them, as shown on a nonspecific projectile hitting a floor)
Spoiler:


Last edited by Miles on Thu Feb 25, 2016 8:38 pm, edited 4 times in total.
Updated.

 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Fri Feb 26, 2016 5:25 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
After some tinkering, it finally worked. Thanks.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 07, 2016 1:45 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, so now I'm trying out something new. I want that after the flagpole has been reached and the victory fanfare has played, the results theme starts to play.
I have this in the step event:
Code:
if not sound_isplaying(snd_flagsong)
    sound_loop(snd_result)
if not sound_isplaying(snd_flagsong)
and global.time = 0
{
    canskip = 1
}

Now the thing is: The results theme only starts to play when I'm closing the game window (since I have one second of it during the closing). And now, I'm not kidding. It really does, even if I wait 5 minutes for the results theme to play.
I would be glad if somebody could help me. Thanks in advance!

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [tr]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 07, 2016 3:48 pm 
User avatar
Thanks DonnieTheGuy!
Administrator
[A]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Code:
if not sound_isplaying(snd_result)
    sound_loop(snd_result)
if not sound_isplaying(snd_result)
and global.time = 0
{
    canskip = 1
}

_________________
Image
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 07, 2016 4:16 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Mors wrote:
Code:
if not sound_isplaying(snd_result)
    sound_loop(snd_result)
if not sound_isplaying(snd_result)
and global.time = 0
{
    canskip = 1
}

Eh? I don't have such code snippet, and I'm pretty sure this will not get the result that I actually want.
If it helps, both songs are MP3.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [tr]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 07, 2016 5:59 pm 
User avatar
Thanks DonnieTheGuy!
Administrator
[A]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Sorry, I misunderstood your problem
Code:
if (!sound_isplaying(snd_flagsong)) && (!sound_isplaying(snd_result)) {
    sound_loop(snd_result)
    results = 1
}
if ((!sound_isplaying(snd_result)) && (global.time = 0) && (results))
    canskip = 1

Here. I'm surprised how you had a problem on something as simple as that. I'm not sure if this would work tho, because I know nothing about how everything else in your game works.

_________________
Image
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Tue Mar 08, 2016 3:46 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Wait, I think I understand now. It tries to loop the song over and over again, hence why it never starts until the window loses focus.
Okay, now I know how to fix it. Thanks.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 10, 2016 9:40 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, new problem.
So I want to add special hit reactions to whenever Mario gets hit by spiked things. Right now, I'm trying to implement it on a Spiny.
Here is the "Collision with obj_mario" code:
Code:
if instance_exists(obj_invincibility)
    exit
if other.y < y-27
and obj_mario.stompstyle = 1 //Does Mario a spinjump?
{
    if global.yoshi = 2
    {
        obj_mario.vspeed = 0
        instance_create(x-8,y,obj_spinsmoke)
        instance_destroy()
        exit
    }
    with other event_user(1)
    sound_play(snd_stomp)
    instance_create(obj_mario.x,obj_mario.y+32,obj_spinthump)
    exit
}
if other.invincible = 0 //Does Mario still have post-hit invincibility frames?
{
    with other event_user(0)
    with other spikehit = 1 //Mario got hit by spikes
}


Here is the relevant part of Event User 0 of the player object (uses obj_mario as a parent):
Code:
if global.health >= 1
{
    global.health -= 1
    invincible = 1
    sound_play(snd_warp)
    if vspeed = 0
        y = y-2
    ID = instance_create(x,y,obj_playerknockback)
    ID.spikehit = spikehit
    //sound_play(snd_ow)
}


And here is the Create Event of obj_playerknockback:
Code:
gravity = 0.2
vspeed = -6
if obj_mario.invincible = 0
    yayaya = 1
hspeed = -2*obj_mario.direct
obj_mario.invincible = 1
obj_mario.visible = 0
obj_mario.ishurt = 1
if global.state > 0
    mask_index = spr_bigmask
if spikehit = 1
    scr_mariospike()
else
    scr_mariohurt()
direct = obj_mario.direct


Now here is the problem: the player object does get spikehit set to 1 properly, but obj_playerknockback never sets spikehit to 1 for some reasons...
Anyone knows why this is happening? Thanks in advance!

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 10, 2016 11:09 am 
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
in this block:
Code:
if other.invincible = 0 //Does Mario still have post-hit invincibility frames?
{
    with other event_user(0)
    with other spikehit = 1 //Mario got hit by spikes
}
try putting "with other spikehit = 1" first, so
Code:
if other.invincible = 0 //Does Mario still have post-hit invincibility frames?
{
    with other spikehit = 1 //Mario got hit by spikes
    with other event_user(0)
}


Otherwise the player will get the spikehit set too late. Event_user0 wouldn't have spikehit be 1 during its execution, therefore causing your problem. Probably.

_________________
"talk about dang ol' this ain't scientific rockets, man"
Spoiler:
Bibby Team - Nice little place. Give it a try.
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 10, 2016 11:53 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Thanks, now spikehit in obj_playerknockback gets set to 1 properly.
However, that didn't fix the problem.
Thankfully, I could fix the problem nonetheless by relocating the if-else branch for the reaction to alarm[1].
So thank you very much.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 21, 2016 7:57 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, now here is something more finicky. This is what I have in scr_mario_snowboard (handles the animations):
Code:
if sprite_index = spr_mario_snowboard
{
    if vspeed < 0
        image_index = 2
    else if vspeed > 0
        image_index = 0
    else
        image_index = 1
}

While this piece of code does work when Mario is in the air, it simply wont work when Mario is sliding down or up the slopes, and I have no idea why, since technically, Mario's vspeed should change, but the code thinks it does not. What am I missing?

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 21, 2016 8:43 am 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Hm, when Mario goes up/down in a slope, is his vspeed set to go up/down, or is he changing his y position to a higher/lower position? If it is the latter, then changing his vspeed when he goes in a slope should fix your problem, since changing the y position won't count as speed at all.

_________________
Image
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 21, 2016 10:21 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Q-Nova wrote:
Hm, when Mario goes up/down in a slope, is his vspeed set to go up/down, or is he changing his y position to a higher/lower position? If it is the latter, then changing his vspeed when he goes in a slope should fix your problem, since changing the y position won't count as speed at all.


It's the later, but I fear that changing into the former could possibly screw up the slopes completely (since the slope object is already highly instable to begin with).
So...are there any alternatives I could use? I was thinking about comparing the current y position with the previous y position, but I don't know how I could possibly save the previous y position...

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 21, 2016 10:39 am 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Hm, perhaps maybe you could have a variable, which has a value that depends on whenever Mario goes up/down in a slope or not, and then you would have the script check the variable values when it is setting the image_index.

_________________
Image
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Mar 21, 2016 11:13 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Okay, so I added this to the Step Event of the player object:
Code:
if collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_slope_r,1,0)
or collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_slope_sr,1,0)
    ydirect = -1
else if collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_slope_l,1,0)
or collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_slope_sl,1,0)
    ydirect = 1
else
    ydirect = 0


And this to scr_mario_snowboard:
Code:
if sprite_index = spr_mario_snowboard
{
    if vspeed < 0
        image_index = 2
    else if vspeed > 0
        image_index = 0
    else if ydirect = -1
        image_index = 2
    else if ydirect = 1
        image_index = 0
    else
        image_index = 1
}


Yet the animation still doesn't work like it should on slopes. Seriously, this is so aggrivating.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Mar 23, 2016 3:15 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
So...anyone can help me?

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Wed Mar 23, 2016 5:39 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
"can" and "want to" are two different things
______________________________________
that code is a pain to read, so I scrolled up a bit to see what you need.
If you need to figure out whether Mario is going upwards / downwards without using vspeed, just use the position variables y and yprevious.

y_distance_moved = (y - yprevious);
Might want to use the sign function if needed

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
Go to page Previous  1 ... 34, 35, 36, 37, 38, 39, 40, 41  Next  [ 816 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group