Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

891157 Posts in 33525 Topics- by 24767 Members - Latest Member: Stome

June 19, 2013, 04:12:44 AM
TIGSource ForumsDeveloperTutorialsGame Maker Tuts
Pages: 1 ... 19 20 [21] 22 23 ... 29
Print
Author Topic: Game Maker Tuts  (Read 130040 times)
dangerousday
Level 1
*


iacedrom


View Profile
« Reply #300 on: December 19, 2010, 08:18:26 PM »

At the start of game execution, I declare three variables for all the "buttons" that the game uses: pressWhatever, holdWhatever, releaseWhatever, where Whatever is replaced by whatever function I want the button to be. For instance, pressJump, holdShoot, and so on. That way it's easier to allow the player to remap the keys. Instead of asking "Has the space bar been pressed?" we ask "Has the 'jump' button, whichever button that may be, been pressed?"

In each step, the holdWhatever variable still has the last step's value, so we can compare it to the current step's state via keyboard_check_direct(whateverKey).

Code:
//If holdWhatever is false, but the keyboard reports it's pressed,
//it must have been pressed just now
pressWhatever = keyboard_check_direct(whateverKey) and !holdWhatever;

//If holdWhatever is true, but the keyboard reports it's not pressed,
//it must have just been released now
releaseWhatever = !keyboard_check_direct(whateverKey) and holdWhatever;

//Now update the holdWhatever variable, so we may compare it
//in the next step
holdWhatever = keyboard_check_direct(whateverKey);

Does that make sense? Can anyone offer improvements on this idea?
Logged
GZ
Level 1
*



View Profile WWW Email
« Reply #301 on: December 19, 2010, 08:49:50 PM »

If it works, do you need improvements on it? Basically, do you feel you are being limited by this? What kind of functionality do you need?

I'm not sure how you do things, but all input should be handled by a script, and that's where you can toss all that code. Then use the script to check for key presses. You may be already doing that, but just throwing it out there in case. Also, the only improvements I see are on an array level, but they will make the code harder to read. Example:

pressedKey[0]
pressedKey[1]
etc.

holdKey[0]
holdKey[1]
etc.

releaseKey[0]
releaseKey[1]
etc.

So you can then loop through the array to do functions such as checking the status of a key. Then, your keys would become numbers. So releaseKey[0] would be jump, and releaseKey[1] would be action, and so on.
Logged

sandcrab
Level 0
***


Buzzing!


View Profile WWW
« Reply #302 on: January 07, 2011, 12:44:57 PM »



So, Tiny Barbarian is almost done!  The one thing I really want to take care of is this bug in my collision which causes the player to stick into corners and (rarely) whole tiles.  I have uploaded a stripped down build of the game that only has a couple rooms in it so you can replicate the bug easily.  But this is what it looks like:



On the left, he has run off an edge and landed "in" the corner of the next block.  You can jump up to get out of this one, or sometimes run back, away from the sticking block.

In the middle, he has lodged himself in the lower corner of a block.  Sometimes you can "walk" out of this one, other times, you're screwed.

On the right, he was stuck in a corner and then someone shot him, causing him to "bounce" into the block, further in with each hit.  In this example, he could jump out, but sometimes he can get pushed into the block at a lower height (I have difficulty replicating this) and then there's no way out at all.

One thing I tried to do to fix this was make a check to see if the player should be on the ground and then force his position to line up with the tile grid, but it didn't seem to work well and also caused weird complications with some of his other movements (like bouncing off of spikes got really weird).  I also tried rounding X or Y to whole numbers before colliding, and that didn't have any effect at all.

It seems like I used to see this "corner sticking" in a lot of Game Maker games, but I think these days I only play the good ones or maybe the method for avoiding this sort of thing is better documented and people avoid it.  At any rate, my code for movement and collisions is all in the oBarbarian Step event, and it should be pretty easy to follow for anyone who has done this sort of thing before.  Any help would be super appreciated! Beg

Code:

//setting horizontal movement

move = false;


if (keyboard_check_direct(vk_left)) && (!hit) && (hp > 0) && (!oGame.playerFreeze)
    {
    if (!climb)
        {
        if (scale = 1)
            {
            hspeed = 0;
            }
        if (jump) hspeed = -playerSpeed
            else hspeed -= accel;
        move = true;
        if (hspeed < -playerSpeed) hspeed = -playerSpeed;
        }
    scale = -1;
    }
    else if (keyboard_check_direct(vk_right)) && (!hit) && (hp > 0) && (!oGame.playerFreeze)
        {
        if (!climb)
            {
            if (scale = -1)
                {
                hspeed = 0;
                }
            if (jump) hspeed = playerSpeed
                else hspeed += accel;
            move = true;
            if (hspeed > playerSpeed) hspeed = playerSpeed;
            }
        scale = 1;
        }
    else if (!hit)  
        {
        if (hspeed < 0)
            {
            hspeed += drag;
            if (hspeed >= 0) hspeed = 0;
            }
        if (hspeed > 0)
            {
            hspeed -= drag;
            if (hspeed <= 0) hspeed = 0;
            }
        }



//vertical collisions

if (!climb)
    {
    gravity = myGravity;
    if (vspeed <= 0)
        if (place_meeting(x,y+vspeed - 1,oWall))
            {
            while (!place_meeting(x,y-1,oWall))
                y-=1;
            vspeed = 0;
            }

    if (vspeed >=0)
        {
        if (place_meeting(x,y+vspeed+1,oWall)) || (place_meeting(x,y+vspeed + 1 ,oJumpThru)) && (!place_meeting(x,y,oJumpThru))
            {
            if (jump || hit)
                while (!place_meeting(x,y+1,oWall) && !place_meeting(x,y+1,oJumpThru))
                    y+=1;
            jump = false;
            gravity = 0;
            vspeed = 0;

            
            if (hit)
               {
               hit = false;
               invincibleTimer = invincibleTime;
               }
            }
        else
            {
            if (!hit)
                jump = true;
            gravity = myGravity;
            if (vspeed > maxFall)
                vspeed = maxFall;
            
            }
        }
    }

//jumping
    
if (!jump) && (keyboard_check_pressed(ord('Z'))) && (!hit) && (hp > 0) && (!place_meeting(x,y-4,oWall)) && (!oGame.playerFreeze) //&& (swing < 2)
    {
    jump = true;
    chargeJump = true;
    climb = false;
    vspeed = -maxJump;//-jumpSpeed;
    }


if (chargeJump) && (keyboard_check_direct(ord('Z'))) && (!place_meeting(x,y-4,oWall)) && (!oGame.playerFreeze) && (!hit)
    {
    vspeed = -jumpSpeed;
    jumpHeight += jumpSpeed;
    if (jumpHeight < maxJumpHeight)
        gravity = 0;
        else
            {
            gravity = myGravity;
            chargeJump = false;
            jumpHeight = 0;
            keyboard_clear(ord('Z'));
            }
    }
    else
        {
        chargeJump = false;
        jumpHeight = 0;
        }

        
//horizontal collisions
if (move || hit) && (place_meeting(x+hspeed+1*sign(hspeed), y, oWall))
    {
    move = false;
    x = xprevious;
    while (!place_meeting(x+1*sign(hspeed),y,oWall))
        {
        x += 1*sign(hspeed);
        }
    hspeed = 0;
    }



Test Build
GMK File
« Last Edit: January 07, 2011, 01:05:07 PM by sandcrab » Logged

sandcrab
Level 0
***


Buzzing!


View Profile WWW
« Reply #303 on: January 08, 2011, 01:20:44 PM »

So an update, I fixed the problem, but my question "why doesn't this work?" still stands, but the answer is more narrowed down (I think?) 

I went back into the Grandma Engine and--after a lot of careful dissection--was able to pull out what I needed to change my collision.  I started with horizontal, and now it looks like this:

Code:
//horizontal collisions

h_counter += hspd;
h = round( h_counter );
h_counter -= h;

repeat (abs(h))
    {
    if (place_meeting(x + sign(h), y, oWall))
        {
            {
            hspd = 0;
            break;
            }
        }
    else
        {
        x += sign(h); 
        }

    }

That made a noticeable improvement.  Sticking on top of ledges became harder to do, and sticking to the bottom corners became impossible, but there was still a slight drag around the corner, like a one-frame snag.  Then I put this code above my vertical collision, to match Matt's code sequence, and boom, everything worked perfectly, didn't have to change my vertical at all. 

So I can release the game in a less shameful state, but I still want to know what was wrong and why this solution worked.
Logged

Droqen
Level 10
*****


aka nick fury


View Profile WWW Email
« Reply #304 on: January 16, 2011, 10:57:22 AM »

Posted this in sandcrab's thread, but I figure it might be useful to answer the question here, too, in case anyone else is having this same problem:
So basically our problem here is that
X and Y are checked separately, say
'all clear!', but x+hspeed and y+vspeed
is never actually checked! So the
Barbarian merrily slides himself into
the block and... wait, that's not what
we wanted at all ):

Lesson learned: Check X, then Move X.
Only after finishing with all X-
movement,
Check Y, then Move Y. Of
course, this order really doesn't matter.
It has effects, but the collision will
work fine either way.
(can switch X and Y in the above.)

Enjoy!
Logged

ryanelittlefield
Level 0
*


DevNoob

apolloskeywork78
View Profile WWW Email
« Reply #305 on: January 19, 2011, 04:59:43 PM »

So I know it's been like 2 or 3 years since this tutorial was released, but you're still helping people. I know there are are far more advanced things like Unity and XNA now, but I'm a noob to programming and game creation alike. I had a couple difficulties with my coding throughout some parts of this, but the road is rocky. I fixed them though, and I plan to continue through this! Thanks again for the tutorials, and for the potential coding experience!
Logged

Once a noob, not always a noob.
Pencerkoff
CCCP
Level 4
*


Hello I am Pencerkoff


View Profile
« Reply #306 on: February 11, 2011, 06:12:55 PM »

Hello this is Pencerkoff

I don't know if it would really be a tutorial, but I would love some advice concerning adding sound to a game.

For instance, what file types should I try to have and which commands are the more efficient.  Back in my MMF days I remember having trouble with too many overlapping sounds, so I wouldn't mind a few pointers if that's a problem with game maker as well.

Wouldn't say no to any advice concerning how you gather your sound resources... Once upon a time I would use freesound.org and some recordings from a friend for music.  I have the Assemblee library now, but are there other things I should know?

-PENCERKOFF

Logged

Desert Dog
Level 4
****



View Profile
« Reply #307 on: February 11, 2011, 07:01:38 PM »

Hi Pencerkoff,

.wav's for sound effects. There the only sound type you can play multiple instances off.

You can only load .midi's and .mp3 sound types natively, using GM, for your music.

However, if you want to load .ogg's, there are some good DLL's you can use. SuperSound.DLL is a good one.

.midi formats can have their volume controlled, etc, via GM's functions, but .mp3's aren't. [.mp3's are played through the systems media player]

In that regard, I'd also suggest if you were using .mp3's, maybe check out the SuperSound.DLL(or FMOD, or whatever) if you want to have things like in-game volume control. SuperSound.DLL adds a lot of sound functuality, and is pretty easy to use, too.

Size wise, .midi's are pretty much tiny, .mp3's and .ogg's are a sizeable amount bigger than .midi's. If your trying to keep the file size down, and don't mind sacrificing the music quality, then go for .midi's.

.wav's are uncompressed sound files, which means that they are comparitively huge compared to .midi's, mp3's, etc. That's fine for short, sound effects, but don't even think of having a song saved in .wav format. :p

sfxr is a good, freeware sound fx program which I use to at least give me quick place-holder sounds. I'm sorry, I'm not very good at sfx gathering, either!
Logged

John Sandoval
Level 10
*****


tantric suicide


View Profile WWW
« Reply #308 on: February 11, 2011, 07:54:37 PM »

@Pencerkoff: GM's built in sound system is useless. Download SuperSound.dll and have all your sound files be .oggs or .wavs (though .wavs take way too much space).
Logged

Pencerkoff
CCCP
Level 4
*


Hello I am Pencerkoff


View Profile
« Reply #309 on: February 11, 2011, 08:30:09 PM »

Hello this is Pencerkoff

Alright... .oggs it is.  You guys know a program to convert files into that format?

More importantly, I have the supersound.dll and don't really know how to include that in game maker.

Thanks for being very responsive, you guys

-PENCERKOFF
Logged

John Sandoval
Level 10
*****


tantric suicide


View Profile WWW
« Reply #310 on: February 11, 2011, 08:35:19 PM »

@Pencerkoff: Here's an example I made for someone else in the forums. It has all the necessary scripts to fully utilize supersound, as well as an object that shows you loading/unloading/looping songs.

http://www.host-a.net/u/jtsandoval/FIX.zip

(this was made with gm8; if you need an earlier version, just post)
Logged

Desert Dog
Level 4
****



View Profile
« Reply #311 on: February 11, 2011, 10:24:15 PM »

Looks like John's got you covered. If his example doesn't work for you, simply merge the SuperSound .gmk (actually, I think it's a .gmd.. from GM5) with your current project (make sure you backup first!) And you should be good to go.

Merging .gmk's is usually the easiest way to include a .DLL into your game.

I'm afraid that I don't have a mp3-to-ogg converter that I use, so you'll have to google unless someone else posts their favourite.



Logged

im9today
Guest
« Reply #312 on: February 13, 2011, 01:21:37 AM »

@chevy: i'm using your scripts to draw the screen as a surface but i'm still getting a few doubled pixels, missing pixels etc. is this to be expected or did i do something wrong?
Logged
Evan Balster
Level 10
*****


dreaming close to metal


View Profile WWW Email
« Reply #313 on: February 13, 2011, 05:41:54 AM »

im9: try drawing your sprites at rounded coordinates.
Logged

Infinite Blank, SoundSelf, Cave Story+, Wreath
voice, accordion, mandolin, oboe (?!)
Game audio programming consultant.
<plaid/audio> 0.2: opensource audio framework
Pencerkoff
CCCP
Level 4
*


Hello I am Pencerkoff


View Profile
« Reply #314 on: February 13, 2011, 06:58:25 AM »

Hello this is Pencerkoff

im9: try drawing your sprites at rounded coordinates.

That's not automatic?  I can see why surfaces wouldn't be but sprites?  There a reason for that?

@Pencerkoff: Here's an example I made for someone else in the forums. It has all the necessary scripts to fully utilize supersound, as well as an object that shows you loading/unloading/looping songs.

http://www.host-a.net/u/jtsandoval/FIX.zip

(this was made with gm8; if you need an earlier version, just post)

Maybe I'm just to new to this extension stuff but I seriously don't know what any of this is getting at.  I need to add these scripts to my game in order to use them, but where does the .dll file come in?  And is there an easy way to put those scripts into my game?  Desert Dog's merging idea strikes me as being very scary.

So everyone in "the know" goes through all of this just to add sound to a game?  If this is all so great how come is isn't just a part of GM?

-PENCERKOFF
Logged

Pages: 1 ... 19 20 [21] 22 23 ... 29
Print
Jump to:  

Theme orange-lt created by panic