This site requires JavaScript, please enable it in your browser!
Greenfoot back
superDumb
superDumb wrote ...

2021/4/7

Issues making cookie clicker

superDumb superDumb

2021/4/7

#
I am making a cookie clicker game in greenfoot and I am trying to check when theCookie is clicked in the world so I can add to the counter. Maybe I can't do it this way but I've been using act() in my world class and trying to check if it's clicked with Greenfoot.mouseClicked(theCookie). If you need any more info than I've given just tell me
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Clicker extends World
{

    /**
     * Constructor for objects of class Clicker.
     * 
     */
        private int cookieCounter = 100;
        private int cookiesPerSecond = 0;
        private int clickValue = 1;
        Cookie theCookie = new Cookie();
        ShopFrame theShopFrame = new ShopFrame();
        Grandma theGrandma = new Grandma();
        
    public Clicker()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 800, 1);
        addObject(theCookie, 280, 480);
        addObject(theShopFrame, 820, 400);
        addObject(theGrandma, 827, 400);
        
    }

    public void act() {
        if(Greenfoot.mouseClicked(theCookie)) {
            cookieCounter += clickValue;
        }
        
        showText("" + cookieCounter, 100, 100);
    }
}
Gbasire Gbasire

2021/4/7

#
you should take the code you've got in your world act method (+ the cookieCounter and clickValue variables) and put it in your cookie act method. Just replace "theCookie" by "this", and add "getWorld()." before "showText("" + cookieCounter, 100, 100);"
superDumb superDumb

2021/4/7

#
Gbasire wrote...
you should take the code you've got in your world act method (+ the cookieCounter and clickValue variables) and put it in your cookie act method. Just replace "theCookie" by "this", and add "getWorld()." before "showText("" + cookieCounter, 100, 100);"
Yeah I had this working in another version but I was trying to get it working like this in the world because I couldn't figure out how to change the cookiespersecond when I buy something from the shop so I thought I could probably check if its clicked in the same place where I check if something is bought --- Also your pokemon game blew my mind xD
Gbasire Gbasire

2021/4/7

#
haha thank you, I'm still trying to improve it and to add new content :)
superDumb superDumb

2021/4/7

#
Answer to my problem : Things are put down in layers I apparently had my cookie behind an invisible wall that was from a png I had put in just put my cookie as the last object added into the game and it works as intended.
You need to login to post a reply.