Go to page Previous  1 ... 37, 38, 39, 40, 41  Next  [ 816 posts ]  Reply to topicPost new topic 
Coding Help, Questions and Issues relating to coding
Author Message
 [us]
 Post subject: Re: Coding Help
PostPosted: Wed Jan 25, 2017 10:59 pm 
User avatar
"I am one valuable card"
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
Well, I feel like I'm the one who explains the problems mostly. But , I seriously need help when it comes to a ladder like this.
Image

Everything on climbing code seems so smooth until the sprite speed isn't responding on movement.

Here's my code:

Step {OBJ_PLAYER}

Code:
if (collision_line(x, bbox_top, x, bbox_bottom - 8, obj_ladder, false, false)) &&  keyboard_check_pressed(vk_up) // This is what triggers the player to be in the ladder
{
climb = true
}

if (climb)
{
    hsp = 0;
    vsp = 0;
    jumpable = false

if keyboard_check(vk_up)
{
if place_free(x,y-2)
vsp-=2
}

if keyboard_check(vk_down)
{
if place_free(x,y+2)
vsp+=2
}

   if (key_up and !collision_line(x, bbox_top, x, bbox_bottom - 8, obj_ladder, false, false))
    or (!collision_line(x, bbox_top, x, bbox_bottom, obj_ladder, false, false))
    {
        climb = false;
        jumpable = true;
    }
   
    if (key_left or key_right)
        climb = false;

}


+ the "Animation" phase

Code:
if (place_meeting(x,y,obj_ladder)) && climb = true && (!place_meeting(x,y,obj_wall))
{
sprite_index = spr_pclimb
if keyboard_check(vk_down) or keyboard_check(vk_up)
{
if speed = 0
            image_speed = 0
        else
            image_speed = 0.15
        sprite_index = spr_pclimb
}
}

_________________
Image
Image

Image
NNID: SonicZetrex
User: SonicZetrx


Old Drawing Banners

Spoiler:

Things I support/others

Spoiler:


My favorite theme:

 
Top
Offline 
 User page at mfgg.net
 
 [es]
 Post subject: Re: Coding Help
PostPosted: Thu Jan 26, 2017 6:33 am 
User avatar
I'm just a little adorable kitty :3
Member
[*]
[*]
[*]
[*]
[*]

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

Try this

Syntax: [ Download ] [ Hide ]
Using gml Syntax Highlighting
if ((place_meeting(x,y,obj_ladder)) && climb)
{
    sprite_index = spr_pclimb;
    if (vspeed == 0)
    {
        image_speed = 0;
        image_index = 0;
    }
    else
        image_speed = 0.15;
}

_________________
Image ImageImageImageImageImageImage Image
~ Supernova / Drawerkirby (2) / Gato / Neweegee (2) (3) ~
"shy guys are wall plugs confirmed" - Vitiman on Club Saturn Ex
Image
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Jan 26, 2017 7:01 am 
User avatar
Marle's my waifu
Member
[*]
[*]
[*]
I wouldn't directly compare vspeed using == because you get floating point imprecision that way. Try if (abs(vspeed) < 0.01) instead of if (vspeed == 0)

I also wouldn't use magic numbers for the image speed but that's a mistake in Sonic's original code so shrug.

_________________
더 빠르게 더 빠르게
더 멋지게 더 멋지게
더 신나게 더 신나게
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Thu Jan 26, 2017 9:09 am 
User avatar
"I am one valuable card"
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
What I honestly don't get is that my character animates when on ground, but not when going up or down the ladders.

_________________
Image
Image

Image
NNID: SonicZetrex
User: SonicZetrx


Old Drawing Banners

Spoiler:

Things I support/others

Spoiler:


My favorite theme:

 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Thu Jan 26, 2017 10:09 am 
User avatar
Kootie Patootie
Member
[*]
[*]
[*]
[*]
[*]

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

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

[*]
[*]
Why do you have a custom speed variable 'vsp' in the first code block, but you test for the built-in constant 'speed' in the second block?

EDIT: Disregard above, I figured out why you did that. You should remove the first
Code:
sprite_index = spr_pclimb
, because then you'll be able to see if the code block the second one is functional at all. After that debugging, you'll know for sure whether the issue is with the speed test itself, or if something else somewhere is over riding the image_speed.

_________________
Image
My mains
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Fri Jan 27, 2017 10:54 pm 
User avatar
"I am one valuable card"
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
It honestly took me a while but I've done it!

I don't think it's purposeful to put the code I've changed . All I did was put few of "climb" variables within it and it worked success. But honestly, thanks. Sometimes I even figure it out myself when I explained what the problem is (eventually)...

_________________
Image
Image

Image
NNID: SonicZetrex
User: SonicZetrx


Old Drawing Banners

Spoiler:

Things I support/others

Spoiler:


My favorite theme:

 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Sun Jan 29, 2017 5:28 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Hello again,
so there's a problem I have: When I hit an invincibility monitor and then hit a speed sneaker monitor while being invincible, the invincibility theme just restarts instead of playing the speed sneakers theme.
And the speed sneakers theme wont play even when the invincibility wears off, as it plays the level theme instead.
And when the speed sneakers wear off like that, the level theme restarts as if the speed sneakers theme did play (even though it didn't).
Here's the code (inside the Step Event of the object that handles all music and jingles):
Code:
/* Speed Sneaker */
if(instance_exists(par_player))
{
 if(instance_exists(global.main_player))
 {
 if(global.main_player.speed_sneakers_timer > 1)
  {
   if not(FMODInstanceIsPlaying(sneakersong)) and sneaker_already_played = false
    {
     //caster_stop(caster_handle);
     //caster_play(speed_sneaker_jingle,caster_volume,caster_pitch)
     FMODInstanceStop(caster_handle);
     FMODInstanceStop(invincibilitysong);
     FMODInstanceStop(invincibility_jingle);
     sneakersong = FMODSoundPlay(speed_sneaker_jingle);
     sneaker_already_played = true;
     break;
    };
   if not(FMODInstanceIsPlaying(speed_sneaker_jingle)) and sneaker_already_played = false
    {
     //caster_stop(caster_handle);
     //caster_play(speed_sneaker_jingle,caster_volume,caster_pitch)
     FMODInstanceStop(caster_handle);
     FMODInstanceStop(invincibilitysong);
     FMODInstanceStop(invincibility_jingle);
     sneakersong = FMODSoundPlay(speed_sneaker_jingle);
     sneaker_already_played = true;
     break;
    };
  };
  else if(global.main_player.speed_sneakers_timer == 1)
   {
    //if(FMODInstanceIsPlaying(sneakersong))
     //{
      //caster_stop(speed_sneaker_jingle)
      FMODInstanceStop(sneakersong);
      FMODInstanceStop(speed_sneaker_jingle);
      sneaker_already_played = false;
      //caster_loop(caster_handle,caster_volume,caster_pitch)
      current_song = FMODSoundLoop(caster_handle);
     //};
   };
  };
};

/* Invincibility */
if(instance_exists(par_player))
{
 if(instance_exists(global.main_player))
 {
 if(global.main_player.invincibility_timer != 0 && global.main_player.invincibility = 1 && global.main_player.super_state == false)
  {
   if not(FMODInstanceIsPlaying(invincibilitysong))
    {
     //caster_stop(caster_handle);
     //caster_stop(speed_sneaker_jingle);
     //caster_loop(invincibility_jingle,caster_volume,caster_pitch)
     FMODInstanceStop(caster_handle);
     FMODInstanceStop(sneakersong);
     FMODInstanceStop(speed_sneaker_jingle);
     invincibilitysong = FMODSoundLoop(invincibility_jingle);
     break;
    };
  };
  else if(global.main_player.invincibility_timer == 0)
   {
    if(FMODInstanceIsPlaying(invincibilitysong))
     {
      //caster_stop(invincibility_jingle)
      //caster_loop(caster_handle,caster_volume,caster_pitch)
      FMODInstanceStop(invincibilitysong);
      current_song = FMODSoundLoop(caster_handle);
     };
   };
  };
};

Just so you know, just hitting the speed sneaker monitor while not being invincible does produce the speed sneaker theme, just as it should.
So yeah, I would be glad if someone could help me out on that nutcracker...

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Sun Jan 29, 2017 3:05 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

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

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

[*]
[*]
Don't you already have a topic for this issue?

_________________
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
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Sun Jan 29, 2017 11:01 pm 
User avatar
Member
[*]
I'm trying to make an enemy who throws hammers in GMS' Hello Engine based on how far Mario is from his x-position (for example, if Mario is over him exactly, the hammer does not move, if he is 30 pixels from the enemy, the hammer is twice as fast as 15 pixels from the enemy). I did hspeed=direct*0.5*distance_from_object(obj_mario). This works as intended if the bro is on the same y-level as Mario, but not if he is above the bro, since it calculates based on y-distance as well as x-distance. Is it possible to make it so that only x-distance counts?

Edit: Trying absolute value obj_bro.x - obj_mario.x ... let's see if it works.
Edit2: It seems to! ...How regretful that I posted this.

 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Jan 30, 2017 2:05 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
DJ Coco wrote:
Don't you already have a topic for this issue?

Yeah, but nobody ever answered to the topic, so I'm trying my luck here.
Because yes, I really need to solve this problem THAT bad!

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Tue Jan 31, 2017 5:28 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

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

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

[*]
[*]
Perhaps show a little bit of incentive to fix it yourself then?
I'm pretty sure the reason you didn't get replies wasn't a lack of visibility, and rather just a lack of willing to help you out - which frankly, isn't really surprising given you have a new issue every month or so and wait for weeks to get it fixed.

I know you claim that you're trying to get it fixed, but it's a bit hard to believe that.

_________________
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
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 01, 2017 1:16 pm 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Yeah, but how I can possibly prove that I'm trying to fix it myself?

EDIT: Managed to fix it myself, though my attempt at fixing it was pretty...hacky, to say the least.

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Feb 06, 2017 1:19 am 
User avatar
Member
[*]
General programming question:
What is the fastest way to z-layer onscreen sprites in a top-down game? Every time I look this up, I find engine-specific solutions for Unity and GM. I'm making a roguelike from scratch with 24x16 tiles but the characters can be any arbitrary size.

At first, I just looped through onscreen tiles left-to-right, top-to-bottom and rendered any sprites on them. That worked, but once I introduced animation I had an issue: The onscreen position of sprites might not be the in-game position. A character switches tiles in a single frame, but it takes them about 12 to walk from one tile to another. In the meantime, they might be incorrectly layered with other entities.

My current solutions is this: Loop through all onscreen sprites and add them to a sprite_que. Run C's qsort on the sprite_que to order everything from lowest-to-highest y coordinate. Finally, iterate through sprite_que and draw everything in the proper z-order. This is done every frame, starting from scratch. I'm considering maintaining a global list of sprites ordered by z-depth and only updating it when sprites move. The issue is, that'll introduce more complexity to my engine because I'll have to remember to remove sprites every time I remove an entity.

For some context, here is how the game looks:

Spoiler:

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Mon Feb 06, 2017 4:08 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

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

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

[*]
[*]
DragonDePlatino wrote:
That worked, but once I introduced animation I had an issue: The onscreen position of sprites might not be the in-game position.
If that's the issue, can't you just use the onscreen position to calculate the correct z-depth?

I heavily agree though that this artificial z-depth thing is very hard to pull off and often uses a lot of trickery. The easiest approach would probably be to use real 3D with an ortographic projection.

_________________
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
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Mon Feb 06, 2017 6:21 am 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
I would sort the list of objects by their bottom vertical positions, then iterate through that list:

Syntax: [ Download ] [ Hide ]
Using python Syntax Highlighting
objects.sort(key=lambda o: o.y + o.height)
for o in objects:
    blit(o) # or whatever is used to draw the object
 


Quote:
I'm considering maintaining a global list of sprites ordered by z-depth and only updating it when sprites move.

Yeah, that's another way to do it. Probably not necessary, though, and it might not even result in substantial performance gains.

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Mon Feb 06, 2017 3:40 pm 
User avatar
C# Programmer
Member
[*]
[*]
[*]
[*]
Ignore what I just wrote below. If your method works without animation, then why not let the animated coords affect your sorting?

_

I've already done the 3D way that DJ Coco mentioned. It's overkill if only one game object can be at the same world position at a time.

An easy solution would be to use 3D coords for you game world and do all your game logic and animation using 3D coords. When drawing, you convert the 3D coords to screen space. You can use the world Z coord for depth sorting.

So for the image you showed, if we let the world XY coords be 1:1 with screen space and the world Z coord be down in screen space, then all objects would be at the same world height, but have different world XZ coords. All objects in the same screen-space row would share the same world YZ coords.

_________________
MFGG TKO (scrapped) - Animations
Image
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Mon Feb 06, 2017 4:52 pm 
User avatar
Member
[*]
After playing around with a few different solutions I've stuck with my existing one but optimized it a great deal. I was already determining z-depth by a sprite's y-position, the issue was that I was recalculating a sprite's onscreen position before and after adding it to the queue. My current solution was trimmed from 80 LOC to 40 and looks like this in pseudocode:
Code:
render_sprites:
   empty sprite queue
   
   for all y coordinates in-camera:
      for all x coordinates in-camera:
         if this coordinate is a wall:
            add the wall to the sprite_queue
            ++queue_size
            continue
         if this coordinate has an entity:
            if this entity is visible:
               add the entity to the sprite_queue
               ++queue_size
   
   sort sprite_queue with qsort
   
   for all sprites in sprite_queue:
      render sprite_queue[sprite]

@DJ Coco
@onpon4
@TheShyGuy
Yup, that's what I've been doing. The tricky part is that I'm using an Entity Component System where gameplay is heavily decoupled from rendering. Therefore I can't sort actual in-game entities. Just the sprite objects based on those entities.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 15, 2017 2:58 pm 
User avatar
Member
So I've created a pretty short bit of code that handles slopes in almost the same way as Yoshi's Island. the only problem is that the game now thinks that ledges are slopes too and warps the player down almost halfway, and by halfway I mean a couple hundred pixels? (I think it's whatever I set my maximum slope variable too.)

Here's the code:
EDIT: Sorry I forgot to explain some of the variables in the code. I've used cd and cu to describe how many pixels to move down or up respectively, and Hsp is horizontal speed. Solid is a constant I made to reference the collision object. I think that's it...
Code:
slope_max = 10
if !place_meeting(x+sign(Hsp),y,Solid)
{

 for (cd=0; !place_meeting(x+Hsp,y+cd,Solid) && cd<=abs(slope_max); cd+=1;)
 {
   if !place_meeting(x+Hsp,y+cd,Solid) and place_meeting(x,y+slope_max,Solid)
   y+=cd;
 }
 
 //while ((!place_meeting(x+Hsp,y+cd,Solid) && cd <= abs(slope_max))) cd += 1;
 

}
if place_meeting(x+Hsp,y,Solid)
{
    cu = 0;
    while ((place_meeting(x+Hsp,y-cu,Solid) && cu <= abs(slope_max)))
            //or
          //((place_meeting(x+Hsp,y+c,Solid) && c <= abs(slope_max)))
            cu += 1;
    if place_meeting(x+Hsp,y-cu,Solid)
    {
        while (!place_meeting(x+sign(Hsp),y,Solid)) x+=sign(Hsp);
        Hsp = 0;
    }
    else
    {
        y-=cu;
    }
}

x += Hsp;


This is the entire collision code. it's inside of a script so I can call it whenever an object needs to.
It's also loosely based off of Shaun Spalding's collision code from his platformer tutorial.

if anyone could help with this I would greatly appreciate it. I am still working on it so I guess if I fix it before I get a reply I'll just, idk reply to this? (This is the first time I've used this site in years)

 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 15, 2017 3:33 pm 
User avatar
Member
[*]
As good of a learning experience it is, I highly recommend you don't write slope collision code yourself. It's very hard to get right and if you try reinventing the wheel you will inevitably tweak it for weeks as you find weird little edge cases.

TheShyGuy wrote a nice GMS 1.2 script that handles slope collisions for you. If you don't end up using that, at least use it as a reference. Its much longer than your code so I imagine it's a lot more stable in most cases.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Wed Feb 15, 2017 3:54 pm 
User avatar
Member
Thanks for the reply!

I've actually been scouring the internet, trying to make a sort of Frankenstein's monster of collision detection, taking things from code other people have written. I've learned quite a lot from it, so thank you for adding to the "collection"

I'll definitely take a look at the code from there. As for your suggestion to not write my own slope code, I really am looking to understand how it works and what I can do to make it my own.

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


Who is online

Users browsing this topic: No registered users and 0 guests


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