Question
Arrow Key help i need help making it so that arrow keys move my mallet up left right and down by 80 when pressed. when
Arrow Key help
i need help making it so that arrow keys move my mallet up left right and down by 80 when pressed. when i press right it rotates and i just want it to move left on the x axis by 80 pixels and for right to move right 80 pixels to the right. i want to use the arrow keys.
import random import turtle
moles = [] mallet = ()
def rand_cord(): r1 = random.randrange(-160, 160, 80) r2 = random.randrange(-160, 160, 80) return [r1, r2]
def makemole(t): global mallet global moles l = 1 while l == 1: l = 0 coor = rand_cord() for i in moles: if i == coor: l = 1 if mallet == coor: l = 1 moles.append(coor) t.goto(coor[0], coor[1]) t.dot(20, 'red')
def creategame(): global mallet t = turtle.Turtle() t.hideturtle() t.up() t.speed(0) dots = (-160, -80, 0, 80, 160) for x in dots: for y in dots: t.goto(x, y) t.dot(20, 'black') mallet = rand_cord() t.goto(mallet[0], mallet[1]) t.dot(20, 'blue') for i in range(9): makemole(t) return(t)
def wm(): turtle.Screen()
def h1(): t.forward(30) def h2(): t.left(45) def h3(): t.right(45) def h4(): wn.bye() wm.onkey(h1, "Up") wm.onkey(h2, "Left") wm.onkey(h3, "Right") wm.onkey(h4, "q") wm.listen() wm.mainloop()
t = creategame
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started