I'm learning python through a course called CMU CS acamdemy and I'm making a little fish game where you play as a shark.
Im running a code using onstep where every 30 frames (stepsPerSecond = 30)
a counter counting in game seconds goes up by 1. When 10 seconds have passed the first wave starts which spawns a certain amount of fish:
(here is the fish spawn code that also spawns a hitbox for each fish)
fishys = Group()
fishHitboxes = Group()
def spawnfish():
y=randrange(100,400)
fishHitbox = Oval (400,y,110,40, fill = 'red')
fish = Image('cmu://744624/30765862/Screenshot_2024-05-06_at_8.50.42_AM-removebg-preview.png',400,y)
fish.width = 90
fish.height = 60
fish.speed = randrange(-6,-1)
fishHitbox.speed = 0
fishHitboxes.add(fishHitbox)
fishys.add(fish)
app.fishtotal += 1
(here is the control for each fish movement and each hitbox movement, it also interacts with the shark hitbox (shonkHitbox))
for fish in fishys:
for fishHitbox in fishHitboxes:
fishHitbox.opacity = 100
fish.centerX += fish.speed
fishHitbox.centerX = fish.centerX
fishHitbox.centerY = fish.centerY
if (fish.centerX < 0):
del fish
if (fishHitbox.hitsShape(shonkHitbox)):
del fish
(here is the wave and seconds counter, this also has a limiter so infinite fish don't spawn because this line of code is in the onstep.)
if app.counter % 30 == 0:
app.seconds += 1
if (app.seconds == app.waveinterval):
app.waveinterval += 10
app.wave += 1
if (app.wave ==1):
app.fishlimit = 12
if (app.fishtotal < app.fishlimit):
spawnfish()
(when wave 1 starts I receive this error message)
"line 214:
fish.centerX += fish.speed
Exception: <Javascript TypeError>: Cannot read properties of undefined (reading 'js_getattribute')"