def move(): # movement of ball and targets global score global curIncrement global blueBall global yellowBall if randrange(200) == 0: x = randrange(-150, 150) specialBall = vector(x, 200) specialBalls.append(specialBall) if randrange(40) == 0: y = randrange(-150, 150) target = vector(200, y) targets.append(target) for target in targets: target.x -= 0.5 for specialBall in specialBalls: specialBall.y -= 0.5 if (inside(ball)): ball.y -= 0.35 ball.move(speed) dupe = targets.copy() targets.clear() for target in dupe: if (abs(target - ball) > 13): targets.append(target) else: score += 10 blueBall += 1 spDupe = specialBalls.copy() specialBalls.clear() for specialBall in spDupe: if (abs(specialBall - ball) > 13): specialBalls.append(specialBall) else: score += 15 curIncrement += 10 yellowBall += 1 draw() for target in targets: if not inside(target): tt.penup() tt.goto(-80, 0) tt.write( "Your Score {} \n Blue Balls :{} \n Yellow Balls :{}".format( score, blueBall, yellowBall), font=FONT) return tt.ontimer(move, 50)
def move(): global snake global size global food global speed dupe = snake.copy() snake.clear() for piece in dupe: piece.move(speed) if not inside(piece): print('Snake out of boundary') tt.up() tt.goto(0, 0) tt.down() tt.write('Your Score {}'.format(size)) return snake.append(piece) # if check(snake): # print('Snake ate itself') # tt.up() # tt.goto(0, 0) # tt.down() # tt.write('Your Score {}'.format(size)) # return if(len(snake)!=0): head = snake[-1] if(head==food): size+=1 food=vector(value(),value()) newHead=head.copy() newHead.move(speed) snake.append(newHead) draw() tt.ontimer(move,500)
def load(): count = 1 mark = vector(0, 0) for y in range(-200, 200, 100): for x in range(-200, 200, 100): mark = vector(x, y) tiles[mark] = count count += 1 tiles[mark] = None for count in range(50): neighbour = choice(neighbours) spot = mark + neighbour if spot in tiles: number = tiles[spot] tiles[spot] = None tiles[mark] = number mark = spot
def move(): writer.undo() writer.write("score {}".format(state['score'])) clear() if valid(pacman + aim): pacman.move(aim) index = offset(pacman) if tiles[index]==1: tiles[index]=2 state['score']+=1 x = (index %20)*20 - 200 y = 180 - (index//20)*20 square(x,y) up() goto(pacman.x+10,pacman.y+10) dot(20,'yellow') for point,course in ghosts: if valid(point+course): point.move(course) else: options =[ vector (5,0), vector(0,5), vector(-5,0), vector(0,-5) ] plan = choice(options) course.x=plan.x course.y=plan.y up() goto(point.x+10,point.y+10) dot(20,'red') update() for point,course in ghosts: if abs(pacman-point) <20: return ontimer(move,100)
def tap(x, y): x = floor(x, 100) y = floor(y, 100) mark = vector(x, y) for neighbour in neighbours: spot = mark + neighbour if spot in tiles and tiles[spot] is None: number = tiles[mark] tiles[spot] = number square(spot, number) tiles[mark] = None square(mark, None)
def move(): global score global count bird.y -= 5 for ball in balls: ball.x -= 3 for ball in all: ball.x -= 3 if randrange(10) == 0: y = randrange(-199, 199) ball = vector(199, y) balls.append(ball) all.append(ball) dc[count] = 0 count += 1 while len(balls) > 0 and not inside(balls[0]): balls.pop(0) if not inside(bird): draw(False) up() goto(0, 0) down() write('Score {} '.format(score), font=['Arial', 14, 'bold']) return for ball in balls: if (abs(ball - bird) < 15): draw(False) up() goto(0, 0) down() write('Score {} '.format(score), font=['Arial', 14, 'bold']) return else: #print(ball.x,bird.x,ball.x-bird.x) if ball in all: i = all.index(ball) #print("i ",i, ball.x,ball.y) if (dc[i + 1] == 0): if (bird.x - ball.x > 15): score += 1 dc[i + 1] = 1 draw(True) ontimer(move, 50)
from TurtleGames.base import vector from random import * from turtle import * FONT = ["Arial", 14, "bold"] def value(): # [-5,3]->[3,5] return (3 + random() * 2) * choice([-1, 1]) ball = vector(0, 0) aim = vector(value(), value()) state = {1: 0, 2: 0} def move(player, change): state[player] += change def rectangle(x, y, width, height, name): up() goto(x, y) down() color(name) begin_fill() for count in range(2): forward(width)
from random import * import turtle as tt from TurtleGames.base import vector from TurtleGames.base import square snake =[] start = vector(0,0) snake.append(start) size=0 speed = vector(10,0) def change(x,y): speed.x =x speed.y = y def value(): return randrange(-15,15)*10 def draw(): global snake global size tt.clear() # draw food square(food.x,food.y,9,'green') # draw snake for piece in snake: print(piece.x,piece.y) square(piece.x,piece.y,9,'black') print('size ',len(snake))
def change(x,y): if valid(pacman + vector(x,y)): aim.x = x aim.y = y
from random import * from TurtleGames.base import vector,floor from turtle import * state = {'score' : 0} path = Turtle(visible=False) writer = Turtle(visible=False) aim = vector(5, 0) pacman = vector(-40, -80) ghosts = [ [vector(-180, 160), vector(5, 0)], [vector(-180, -160), vector(0, 5)], [vector(100, 160), vector(0, -5)], [vector(100, -160), vector(-5, 0)], ] tiles = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
def tap(x, y): up = vector(0, 30) bird.move(up)
from turtle import * from random import * from TurtleGames.base import floor, vector tiles = {} neighbours = [vector(100, 0), vector(-100, 0), vector(0, 100), vector(0, -100)] def load(): count = 1 mark = vector(0, 0) for y in range(-200, 200, 100): for x in range(-200, 200, 100): mark = vector(x, y) tiles[mark] = count count += 1 tiles[mark] = None for count in range(50): neighbour = choice(neighbours) spot = mark + neighbour if spot in tiles: number = tiles[spot] tiles[spot] = None tiles[mark] = number mark = spot def square(mark, number): up()
from random import * import turtle as tt from TurtleGames.base import vector ball = vector(-200, -200) speed = vector(0, 0) targets = [] specialBalls = [] curIncrement = 200 FONT = ("Arial", 14, "bold") score = 0 blueBall = 0 yellowBall = 0 def inside(xy): return -200 < xy.x < 200 and -200 < xy.y < 200 def tap(x, y): global curIncrement # respond to the screen if not inside(ball): ball.x = -199 ball.y = -199 speed.x = (x + curIncrement) / 25 speed.y = (y + curIncrement) / 25 def move():
from random import * import turtle as tt from TurtleGames.base import vector,square food = vector(0,0) snake = [vector(10,0)] aim = vector(0,-10) score=0 FONT = ("Arial", 14, "bold") def change(x,y): aim.x=x aim.y=y def inside(head): return -200<head.x<190 and -200<head.y<190 def move(): global score head = snake[-1].copy() head.move(aim) if not inside(head) or head in snake: square(head.x,head.y,9,'red') tt.up() tt.goto(0, 0) tt.color('black') tt.down() tt.write('Your Score ={}'.format(score),FONT) tt.update()
import turtle as tt from TurtleGames.base import vector, square p1xy = vector(-100, 0) p1aim = vector(4, 0) p1body = set() p2xy = vector(100, 0) p2aim = vector(-4, 0) p2body = set() def inside(head): return -200 < head.x < 200 and -200 < head.y < 200 def draw(): p1xy.move(p1aim) p1head = p1xy.copy() p2xy.move(p2aim) p2head = p2xy.copy() if not inside(p1head) or p2head in p1body: print('Player Blue is winner') return if not inside(p2head) or p1head in p2body: print('Player Red is winner') return
from random import * import turtle as tt from TurtleGames.base import vector ant = vector(0, 0) aim = vector(2, 0) def wrap(value): return value def draw(): ant.move(aim) ant.x = wrap(ant.x) ant.y = wrap(ant.y) print('ant {}{}'.format(ant.x, ant.y)) print('aim {}{}'.format(aim.x, aim.y)) aim.move(random() - 0.5) aim.rotate(random() * 10 - 5) tt.clear() tt.goto(ant.x, ant.y) tt.dot(10, 'blue') if tt.running: tt.ontimer( draw, 1000 ) # if running is true , draw function is called after each 100 ms
from random import * from turtle import * from TurtleGames.base import vector bird = vector(0, 0) balls = [] all = [] dc = {} count = 1 score = 0 def tap(x, y): up = vector(0, 30) bird.move(up) def inside(point): return -200 < point.x < 200 and -200 < point.y < 200 def draw(alive): # draw screen object clear() up() goto(bird.x, bird.y) down() if (alive): dot(10, 'green') else: