Pages: [1]
  Print  
Author Topic: Quick Hack - Adding the Basketball - Downloadable Mod  (Read 14823 times)
DariusK
Bulb
*
Posts: 97



View Profile WWW
« on: January 08, 2010, 11:24:46 AM »

I was reading in another thread about the oBasketball object that Derek implemented for Spelunky but never added. I decided to check it out for myself. Here's how I did it (it's like a three-minute hack). If you just want to grab the final basketball mod, go here!

First I wanted to test out the basketball to see what it's like. So I decided to make it so that whenever you break open a jar, you'll get a basketball. (I didn't choose crates because those don't spawn often enough.)

In GameMaker, open up the oJar object. It's under the Objects-->Items directory, or go to Edit-->Find Resource and type "oJar".

We want to affect its behavior when it's broken apart, so we open the Destroy event and open the script in there. You'll see this chunk of code:

Code:
    if (rand(1,3) == 1) instance_create(x, y, oGoldChunk);
    else if (rand(1,6) == 1) instance_create(x, y, oGoldNugget);
    else if (rand(1,12) == 1) instance_create(x, y, oEmeraldBig);
    else if (rand(1,12) == 1) instance_create(x, y, oSapphireBig);
    else if (rand(1,12) == 1) instance_create(x, y, oRubyBig);
    else if (rand(1,6) == 1) instance_create(x-8, y-8, oSpider);
    else if (rand(1,12) == 1)
    {
        if (colLeft) instance_create(x, y-8, oSnake);
        else if (colRight) instance_create(x-16, y-8, oSnake);
        else instance_create(x-8, y-8, oSnake);
    }

This code is what determines how often things come out of jars: a 1 in 3 chance of a gold chunk, otherwise a 1 in 6 chance of a nugget, and then different possibilities until you get all the way to spider or snake. What we can do is simply change the first line so it's always true and always generates a basketball.

Code:
    if (rand(1,1) == 1) instance_create(x, y, oBasketball);
    else if (rand(1,6) == 1) instance_create(x, y, oGoldNugget);
    else if (rand(1,12) == 1) instance_create(x, y, oEmeraldBig);
    else if (rand(1,12) == 1) instance_create(x, y, oSapphireBig);
    else if (rand(1,12) == 1) instance_create(x, y, oRubyBig);
    else if (rand(1,6) == 1) instance_create(x-8, y-8, oSpider);
    else if (rand(1,12) == 1)
    {
        if (colLeft) instance_create(x, y-8, oSnake);
        else if (colRight) instance_create(x-16, y-8, oSnake);
        else instance_create(x-8, y-8, oSnake);
    }

What that does is it generates a random integer between 1 and 1, which will of course always equal 1 and spawn a basketball.

Now, this is nice for trying out the basketball, but you might want to mess around with the code to make it spawn like anything else. And probably from a crate. The code for crate spawning is actually inside the oPlayer1 object, so if you open that up and go to the Step event, you want to open the second Action block of code and go down to line 214, where there's this code:

Code:
// open crate
if (kUp and kAttackPressed and collision_point(x, y, oCrate, 0, 0))
{
        if (isRealLevel()) global.totalCrates += 1;
        chest = instance_place(x, y, oCrate);
        if (isRoom("rTutorial")) obj = instance_create(chest.x, chest.y, oBombBag);
        else if (rand(1,500) == 1) obj = instance_create(chest.x, chest.y, oJetpack);
        else if (rand(1,200) == 1) obj = instance_create(chest.x, chest.y, oCapePickup);
        else if (rand(1,100) == 1) obj = instance_create(chest.x, chest.y, oShotgun);
        else if (rand(1,100) == 1) obj = instance_create(chest.x, chest.y, oMattock);
        else if (rand(1,100) == 1) obj = instance_create(chest.x, chest.y, oTeleporter);
        else if (rand(1,90) == 1) obj = instance_create(chest.x, chest.y, oGloves);
        else if (rand(1,90) == 1) obj = instance_create(chest.x, chest.y, oSpectacles);
        else if (rand(1,80) == 1) obj = instance_create(chest.x, chest.y, oWebCannon);
        else if (rand(1,80) == 1) obj = instance_create(chest.x, chest.y, oPistol);
        else if (rand(1,80) == 1) obj = instance_create(chest.x, chest.y, oMitt);
        else if (rand(1,60) == 1) obj = instance_create(chest.x, chest.y, oPaste);
        else if (rand(1,60) == 1) obj = instance_create(chest.x, chest.y, oSpringShoes);
        else if (rand(1,60) == 1) obj = instance_create(chest.x, chest.y, oSpikeShoes);
        else if (rand(1,60) == 1) obj = instance_create(chest.x, chest.y, oMachete);
        else if (rand(1,40) == 1) obj = instance_create(chest.x, chest.y, oBombBox);
        else if (rand(1,40) == 1) obj = instance_create(chest.x, chest.y, oBow);
        else if (rand(1,20) == 1) obj = instance_create(chest.x, chest.y, oCompass);
        else if (rand(1,10) == 1) obj = instance_create(chest.x, chest.y, oParaPickup);
        else if (rand(1,2) == 1) obj = instance_create(chest.x, chest.y, oRopePile);
        else obj = instance_create(chest.x, chest.y, oBombBag);
        obj.cost = 0;
        playSound(global.sndPickup);
        if (chest == holdItem)
        {
            holdItem = 0;
            pickupItemType = "";
        }
        with chest { instance_create(x, y, oPoof); instance_destroy(); }
       
        kAttackPressed = false;
}

If you'd like the basketball to spawn about as often as, say, the parachute, just put insert the following line between oParaPickup and oRopePile:

 
Code:
       else if (rand(1,10) == 1) obj = instance_create(chest.x, chest.y, oParaPickup);
// NEW LINE HERE
        else if (rand(1,10) == 1) obj = instance_create(chest.x, chest.y, oBasketball);
        else if (rand(1,2) == 1) obj = instance_create(chest.x, chest.y, oRopePile);

I decided to release this as a mod, because hey, why not!

http://tinysubversions.com/spelunkybball/
Logged

marsgreekgod
Big Bossy
Mossy
*
Posts: 9806


The will of the Galaxy.


View Profile WWW Email
« Reply #1 on: January 08, 2010, 11:37:31 AM »

the thing I like about the basketball is that you dribble it.
Logged

Show your power, Gun Del Hell! Show them their fate! Yes! Yes! Yes! Yes! Yes! Here we go! Let's go, go, go, go, Django! Light and Dark! It comes down to this! Be afraid, Sun!
Sudonimus
Mossy
*
Posts: 2743


Stop staring.


View Profile
« Reply #2 on: January 08, 2010, 02:29:12 PM »

When I click the link, it says
"You 404'd it. Gnarly, dude" or something like that.

What does that mean?
Logged

How is there no such thing as non-existence?!
DariusK
Bulb
*
Posts: 97



View Profile WWW
« Reply #3 on: January 08, 2010, 02:30:02 PM »

When I click the link, it says
"You 404'd it. Gnarly, dude" or something like that.

What does that mean?
I *just* fixed that a second ago. Try it again! Or this direct link:

http://tinysubversions.com/spelunky/bball/spelunkybball.zip
Logged

Sudonimus
Mossy
*
Posts: 2743


Stop staring.


View Profile
« Reply #4 on: January 08, 2010, 02:36:11 PM »

Awesome!
Downloading...
Logged

How is there no such thing as non-existence?!
gummybears123
Mossy
*
Posts: 5785


Yummy Gummy!


View Profile
« Reply #5 on: January 08, 2010, 02:45:58 PM »

Wow great!  THanks darius!
Logged

I made a rap.
It sounds dumb, like reading a map
I really should stop this thing before it goes too far
But I don't really car as long as I stay below the radar
Those big companies won't get me no
I'll get away before the fuzz show

-Most famous rapper of Mossmouth
Kirbylord
Sudonimus
Mossy
*
Posts: 2743


Stop staring.


View Profile
« Reply #6 on: January 08, 2010, 02:52:29 PM »

I haven't found the Basketball yet...
Maybe I haven't tried 10 crates.
Logged

How is there no such thing as non-existence?!
gummybears123
Mossy
*
Posts: 5785


Yummy Gummy!


View Profile
« Reply #7 on: January 08, 2010, 02:57:16 PM »

I haven't found one either...
Logged

I made a rap.
It sounds dumb, like reading a map
I really should stop this thing before it goes too far
But I don't really car as long as I stay below the radar
Those big companies won't get me no
I'll get away before the fuzz show

-Most famous rapper of Mossmouth
Kirbylord
Sudonimus
Mossy
*
Posts: 2743


Stop staring.


View Profile
« Reply #8 on: January 08, 2010, 02:58:48 PM »

Let's go look for one!!
Logged

How is there no such thing as non-existence?!
gummybears123
Mossy
*
Posts: 5785


Yummy Gummy!


View Profile
« Reply #9 on: January 08, 2010, 03:00:00 PM »

I can't find one anywhere...
Logged

I made a rap.
It sounds dumb, like reading a map
I really should stop this thing before it goes too far
But I don't really car as long as I stay below the radar
Those big companies won't get me no
I'll get away before the fuzz show

-Most famous rapper of Mossmouth
Kirbylord
Sudonimus
Mossy
*
Posts: 2743


Stop staring.


View Profile
« Reply #10 on: January 08, 2010, 03:02:31 PM »

This calls for DariusK!!!
Logged

How is there no such thing as non-existence?!
gummybears123
Mossy
*
Posts: 5785


Yummy Gummy!


View Profile
« Reply #11 on: January 08, 2010, 03:04:13 PM »

I still haven't found one... I think this might be a bug...

Or we're both very unlucky
Logged

I made a rap.
It sounds dumb, like reading a map
I really should stop this thing before it goes too far
But I don't really car as long as I stay below the radar
Those big companies won't get me no
I'll get away before the fuzz show

-Most famous rapper of Mossmouth
Kirbylord
DariusK
Bulb
*
Posts: 97



View Profile WWW
« Reply #12 on: January 08, 2010, 03:05:12 PM »

It's about as rare as the parachute. If you want to see a basketball, you can go to the in-game level editor and create a whole bunch of crates and open them.

Also, I just uploaded a version that spawns a basketball when you press "backspace." Download the file again, it will have a new .exe in there and you can play around with spawning lots of basketballs.
Logged

marsgreekgod
Big Bossy
Mossy
*
Posts: 9806


The will of the Galaxy.


View Profile WWW Email
« Reply #13 on: January 08, 2010, 11:26:46 PM »

Never tested, do basketballs hurt baddys?
Logged

Show your power, Gun Del Hell! Show them their fate! Yes! Yes! Yes! Yes! Yes! Here we go! Let's go, go, go, go, Django! Light and Dark! It comes down to this! Be afraid, Sun!
gummybears123
Mossy
*
Posts: 5785


Yummy Gummy!


View Profile
« Reply #14 on: January 09, 2010, 07:08:36 PM »

Test it yourself.. it would take like 5 secs!

Downloading right now...
Logged

I made a rap.
It sounds dumb, like reading a map
I really should stop this thing before it goes too far
But I don't really car as long as I stay below the radar
Those big companies won't get me no
I'll get away before the fuzz show

-Most famous rapper of Mossmouth
Kirbylord
Pages: [1]
  Print  
 
Jump to: