move_square.py

Created by julien-bernon

Created on June 14, 2020

1.12 KB


import kandinsky as k

import time as t

import ion



position=[160,120] 

vitesse=[0,0] 

color=(255,255,255)

k.fill_rect(0,0,320,240,color)



def touches():

    down=[]

    for i in range(4):

        if ion.keydown(i):

            down.append(i)

    return down



def move():

    down=touches()

    for touche in down:

        if touche==0:

            position[0]-=5

            if position[0]<0:

                position[0]+=320

        if touche==3:

            position[0]+=5

            position[0]%=320

        if touche==1:

            position[1]-=5

            if position[1]<0:

                position[1]+=240

        if touche==2:

            position[1]+=5

            position[1]%=240

   

def trace_before():

    color=(255,255,255)

    k.fill_rect(0,0,320,240,color)

    color=(64,64,64)

    k.fill_rect(position[0]-5,position[1]+5,10,10,color)



def trace_after():

    color=(255,0,0)

    k.fill_rect(position[0]-5,position[1]+5,10,10,color)



def main():

    while True :

        trace_before()

        move()        

        trace_after()

        t.sleep(0.033)



main()