Code documentation: Buildings

This is a page about how the buildings work in both Classic and Definitive Edition.

Since in Definitive Edition there are two buildings, it'll be normal and use buildings as a word.

## How they give CpS

### Scratch Edition

Essentially, buildings give CpS due to code that looks something like this:

Wait 1 second

If (building) is at least 1, then:

Change cookies and all-time cookies by (CpS given by building).

Else, then:

Do nothing

### Definitive Edition

*Directory in GitHub: where the magic happens*

Buildings give CpS from code that looks like this:

CpS = (round((building) \* crsrLvl) / 10);

There is also some other stuff about buildingTime.

The stuff about buildingTime ~~looks like~~ is this:

if (buildingTime >= (10 / (building))){

                if ((building) >= 1){

                    cookies += 1;

                    allTimeCookies += 1;

                }

                buildingTime = 0;

            } else {

                buildingTime += (1 / fpsCap);

            }

If you want to cheat and modify your CpS, then change the 10 in "if (buildingTime >= (10 / (building)))" to something else. To make your CpS higher, change the 10 to 9.999recursive or less. The 10 also seems to be the amount of seconds it takes.

As for the second line, that just checks if you have 1 or more (building).

The third line gives you 1 cookie for every time the number in the first line gets reached.

Fun fact break: The highest number Javascript can store to the first 60 digits is 1.79769313486231580793728971405303415079934132710037826936173e+308.

The fourth line modifies the statistics page to give you more all time cookies. Pretty obvious stuff.

The fifth line is just a bracket what do you want me to do with that information

The sixth line resets the building time back to 0 when the number at the first line gets reached.

The seventh line says if otherwise, do the next line which is

The eighth line says add 1 out of 30 (because the fps cap is 30) to the buildingTime before the number from the first line gets reached. However, grandmas and cursors don't have the same CpS. That's because instead, it says add 0.04 \* grandmas instead.

The ninth line is just a bracket what do you want me to do with that information seriously

else if (mouseX > buy2HBX1 && mouseX < buy2HBX2 && mouseY > buy2HBY1 && mouseY < buy2HBY2 && cookies >= gMaPrice) {

                gMas += 1;

                cookies -= gMaPrice;

                gMaPrice = 100 + (gMas \* 15);

            }

        };

The first line checks if you've clicked the buy icon for the grandma and if so do the second line.

The second line unblocks all of your blocked people on Gmail.

The third line allows cookies on every single website you've ever visited.

The fourth line hacks into Gmail and makes it a subscription service and makes you have to pay 15 times the price for every gMail you get.

## How buying buildings works:

### Scratch version

Buying buildings works from this code:

When (the buy icon) is clicked

If cookies are greater than or equal to (building price), then:

Play sound tick

Change (building) by 1

Set (cookies) to (cookies) - (building price)

### Definitive Edition

*Directory: where the magic happens*

The code for buying (building) is this:

}else if (mouseX > buyHBX1 && mouseX < buyHBX2 && mouseY > buyHBY1 && mouseY < buyHBY2 && cookies >= buildingPrice){

                (building) += 1;

                cookies -= buildingPrice; //takes away cookies

                buildingPrice = 15 + ((building) \* 2); //changes the price

                buildings += 1;

            }

        };

For the first line, this basically says: If you click me, then the second line will happen!

The second line says if the first line happens, you'll have 1 more building. Obviously, you can get more (building) by changing the 1 to something else. Alternatively, if you want to lose (building) for whatever reason, change the += to a -=. Also, assuming you don't have any (building), if you change the 1 to for example 1.4 then the price of a building will be 16.8. If you do that, then it will show as two (building) under the big cookie. In fact, if you do something like 1.0001 cursors, it'll show as 1.000 cursors on the buy text while you'll still see 2 cursors under the big cookie.

The third line is explained by the little thing after the two slashes.

The fourth line is also explained by the two slashes but they fail to mention that it changes the price by 2, so from 15 cookies to 17 cookies.

The fifth line changes the buildings statistic in the stats page to 1 more than originally.

The sixth and seventh line are just brackets I mean seriously

## How prices increase:

### Scratch version

Set (building price) to (initial price) plus (price increase) times (amount of buildings of the same type owned).

### Definitive Edition

Umm, I'm pretty sure the third line in the last chapter explained that.

## How the buy icon works

### Scratch Edition

This isn't about how buying works, but about how the popups work.

The building count code looks like this, using the Grandma as an example:

When [buy icon] hovered over:

Say "Grandmas: (# of Grandmas)" for 0.1 seconds

Switch sprite to (buy icon + info)

Else:

Switch sprite to (buy icon w/o info)

### Definitive Edition

That does happen in Definitive Edition but since laziness is a thing it's not here.

## Cursor Exclusive Code

### Scratch Edition

The cursor has some exclusive code.

The first important part is what makes the cursor appear underneath the cookie. It looks like this:

If (# of (building) owned) = at least 1, then:

Broadcast message (make cursor appear)

Else:

Do nothing.

The broadcast block starts this line of code in the cursor that appears underneath the cursor:

When message (make cursor appear) is received, then:

Show cursor.

The CpS giving code is also modified in that

It waits 10 (divided by # of (building)) seconds, instead of just 1 second.

### Definitive Edition

*Directory: variables and stuff*

The only building isn't the cursor but since that doesn't really matter, we'll just use this space to find the other code related to the cursor.

var drawCrsr = function(crsrX, crsrY, crsrHue1, crsrHue2, crsrHue3) {

    fill(crsrHue1, crsrHue2, crsrHue3);

    ellipse(crsrX, crsrY, 72, 45);

    rect((crsrX + 13) - 45, (crsrY + 48) - (45 \* 2), 20, 32);

    rect((crsrX + 33) - 45, (crsrY + 39) - (45 \* 2), 20, 32);

    rect((crsrX + 51) - 45, (crsrY + 45) - (45 \* 2), 20, 32);

    rect((crsrX + 65) - 45, (crsrY + 53) - (45 \* 2), 20, 32);

};

This code is related to drawing the cursor since instead of using pictures, this game uses other things that have no name at all.

The first line basically says that this is what happens when you say drawCrsr.

The second line says that the cursor is white because the crsrHue's are white.

The third line allows the palm of the hand to exist. The last 2 numbers are how wide and tall the palm is, respectively.

The fourth, fifth, sixth, and seventh lines are the fingers. They go left to right. This also means it has 4 fingers.

The eighth line is a bracket and a semicolon is this some kind of code for americas secret alien plans or something

### Grandma exclusive code

*Directory: variables and stuff*

var drawGMa = function(gMaX, gMaY, gMaH1, gMaH2, gMaH3) {

    fill(gMaH1, gMaH2, gMaH3);

    ellipse(gMaX, gMaY, 65, 65);

    fill(191, 242, 239);

    ellipse(gMaX - 13, gMaY - 11.5, 15, 15);

    ellipse(gMaX + 13, gMaY - 11.5, 15, 15);

    fill(0, 0, 0);

    arc(gMaX, gMaY - 10, 15, 0, 0, 180);

};

The first 2 lines are basically the same as in the cursor drawings except with grandma stuff.

The third line makes a pink ellipse with an eccentricity of 0 (a circle).
The fourth line makes the glasses the color #bff2ef.

The fifth line makes the left glass where it should be.

The sixth line makes the right glass where it should be.

The seventh line makes the line inbetween the left and right glass what it should be.

## Where the values come from:

The values of the prices and price increases come from the real version of Cookie Clicker.