Can't change a variable in CMU CS academy

19 Views Asked by At

I'm making a simple plant growing game in the CMU CS academy thing and I can't figure out how to make this work. If I click up it makes it work as usual one time but does nothing whenever I click up again.

Code:

app.background = 'skyBlue'

import time

def increaseHeight(height):
    Rect(225, 0, 120, 250, fill='skyBlue')
    planta = Rect(250, 150, 10, 100, fill='forestGreen')
    planta.height += height
    planta.centerY -= height
    plantb = Rect(270, 150 - height, 10, 100 + height, fill='forestGreen'),
    plantc = Rect(290, 150 - height, 10, 100 + height, fill='forestGreen'),
    plantd = Rect(310, 150 - height, 10, 100 + height, fill='forestGreen'),
    plante = Rect(330, 150 - height, 10, 100 + height, fill='forestGreen')

def Reset():
    Rect(225, 0, 120, 250, fill='skyBlue')
    planta = Rect(250, 240, 10, 10, fill='forestGreen'),
    plantb = Rect(270, 240, 10, 10, fill='forestGreen'),
    plantc = Rect(290, 240, 10, 10, fill='forestGreen'),
    plantd = Rect(310, 240, 10, 10, fill='forestGreen'),
    plante = Rect(330, 240, 10, 10, fill='forestGreen')

def decreaseWater(height):
    Rect(0, 145, 80, 105, fill=gradient('dimGrey', 'silver', start = 'bottom-left'))
    Rect(5, 150, 70, 95, fill='grey')
    Rect(5, 150 + height, 70, 95 - height, fill=gradient('lightBlue', 'teal', start = 'top-right'))

def Start():
    planta = Rect(250, 150, 10, 100, fill='forestGreen')
    plantb = Rect(270, 150, 10, 100, fill='forestGreen')
    plantc = Rect(290, 150, 10, 100, fill='forestGreen')
    plantd = Rect(310, 150, 10, 100, fill='forestGreen')
    plante = Rect(330, 150, 10, 100, fill='forestGreen')

def onKeyPress(key):
    print(key)
    if key == 'up':
        increaseHeight(5)
        decreaseWater(2)

Rect(0, 250, 400, 150, fill = 'saddleBrown')
Circle(100, 60, 30, fill='yellow')
Circle(100, 60, 40, fill='yellow', opacity = 50)
Circle(100, 60, 50, fill='yellow', opacity = 25)
Circle(100, 60, 75, fill='yellow', opacity = 10)

waterTank = Rect(0, 145, 80, 105, fill=gradient('dimGrey', 'silver', start = 'bottom-left'))
Rect(5, 150, 70, 95, fill='grey')
Rect(5, 150, 70, 95, fill=gradient('lightBlue', 'teal', start = 'top-right'))
Label('Press UpArrow to grow', 200, 375, fill='white', font='cinzel', size = 15)

Start()

Resources - https://academy.cs.cmu.edu/docs

I tried using global variables but I couldn't edit them.

0

There are 0 best solutions below