I'm a new programmer and I'm developing a little Snake Game. In this project I'd like to use Threads, but I literally don't know HOW. I (obviously) looking on the internet for first, but all the codes I found were "already done" code, ready to be used. But what I want is to learn HOW to use the threads.
In my Snake Game I need Threads to make my Snake move: the player press key W, I register the key on a list and then I increase by 50 the playerpos. But, if I just use functions, the Snake moves super fast and it becomes hard to play. For this reason, I'd like to put my "increase by 50 the playerpos" into the Thread and then set a "time.sleep(1)". In this way I'll be able to slow down my snake without influencing the entire program with the "time.sleep".
And here's where my problem begin: I create a Class
import threading, time
class Thread():
now I can add all my functions
def mov_up(self):
playerpos[1]-=50
time.sleep(1)
def mov_sx(self):
playerpos[0]-=50
time.sleep(1)
def mov_down(self):
playerpos[1]+=50
time.sleep(1)
def mov_dx(self):
playerpos[0]+=50
time.sleep(1)
ok, now, what should I do to make this class a thread? Please give me some help >.<