# Wonky code - Numworks game

I am very new to coding in python and I am attempting to create the viral “Suika game” on my calculator. The physics, collision (both not made by me) and a few other parts of my code seem to be having some errors that I cannot for the life of my figure out, any help is greatly appreciated.

To see a visual representation of the game so far here is the link
1epauletteshark/watermellon.py — Python — NumWorks

``````from kandinsky import *
from random import *
from time import *
from ion import *

SCREEN_W=320
SCREEN_H=222
sel=1
sel_x=SCREEN_W/2-5
FRUIT=[#for example:(1(fruit number 1),50(x poition),50(y position)
]

def clear_screen(c):
fill_rect(0,0,SCREEN_W,SCREEN_H,c)

def circle(x,y,rank):

COLORS=[color(246,17,14),color(251,109,72),
color(166,108,255),color(255,185,4),
color(254,138,40),color(247,20,17),
color(254,240,132),color(132,204,18),
color(15,108,8)]

if rank<2:
scale=3
elif rank<=4:
scale=2
else:
scale=1.65

rank+=1

for y2 in range(int(rank**scale+10)):
for x2 in range(int(rank**scale+10)):
distance=(x2-rank**scale/2)**2+(y2-rank**scale/2)**2
if distance<=(rank**scale/2)**2:
set_pixel(int(x+x2),int(y+y2),COLORS[rank-2])

def check_collision(fruit1, fruit2):
x1, y1, r1 = fruit1
x2, y2, r2 = fruit2
# Check if the centers are within a certain distance
distance = ((x2 - x1)**2 + (y2 - y1)**2)**0.5
return distance < max(r1, r2)

def update_positions():
for i in range(len(FRUIT)):
FRUIT[i] = list(FRUIT[i])
if FRUIT[i][2] < SCREEN_H / 4 * 3 - 10:
FRUIT[i][2] += 7
FRUIT[i] = tuple(FRUIT[i])

def handle_collisions():
global FRUIT
updated_fruits = list(FRUIT)
fruits_to_remove = set()

for i in range(len(updated_fruits)):
for j in range(i + 1, len(updated_fruits)):
if check_collision(updated_fruits[i], updated_fruits[j]) and updated_fruits[i][0] == updated_fruits[j][0]:
# Check if fruits are of the same type and colliding

# Create a new fruit with higher rank at the average position
new_rank = updated_fruits[i][0] + 1
new_x = (updated_fruits[i][1] + updated_fruits[j][1]) / 2
new_y = (updated_fruits[i][2] + updated_fruits[j][2]) / 2
updated_fruits.append((new_rank, new_x, new_y))

FRUIT = [fruit for i, fruit in enumerate(updated_fruits) if i not in fruits_to_remove]

def tick():
global sel_x,sel

clear_screen(color(197,143,86))

#Draw container
fill_rect(int(SCREEN_W/4-5),int(SCREEN_H/4-5),int(SCREEN_W/2+10),int(SCREEN_H/2+10),color(248,216,135))
fill_rect(int(SCREEN_W/4),int(SCREEN_H/4),int(SCREEN_W/2),int(SCREEN_H/2),color(233,217,174))

if keydown(KEY_RIGHT) and sel_x<SCREEN_W/4*3-10:
sel_x+=7
if keydown(KEY_LEFT) and sel_x>SCREEN_W/4:
sel_x-=7
fill_rect(int(sel_x+5),25,1,int(SCREEN_H/4*3-25),"white")
circle(int(sel_x),20,sel)
if keydown(KEY_DOWN):
FRUIT.append((sel,sel_x,25))
sel=choice([1,1,1,1,2,2,3])

handle_collisions()
update_positions()

for fruit in FRUIT:
circle(int(fruit[1]),int(fruit[2]),int(fruit[0]))

while True:
tick()
sleep(0.05)
``````

If you don’t tell us what these errors are, it’s going to be a lot harder to help

nonetheless, I’ll be you’ll get some code review – I"ll start: you probably don’t want to use global – google will tell you why, and how to avoid it.