-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurtleTarget.py
More file actions
64 lines (54 loc) · 1.65 KB
/
TurtleTarget.py
File metadata and controls
64 lines (54 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# HIT THE TARGET GAME
import turtle
# NAMED CONSTANTS
SCREEN_WIDTH = 600 # screen width
SCREEN_HEIGHT = 600 # screen height
TARGET_LLEFT_X = 100 # TARGETS LOWER LEFT X
TARGET_LLEFT_Y = 200 # TARGETS LOWER LEFT Y
TARGET_WIDTH = 25 # TARGETS WIDTH
FORCE_FACTOR = 30 # ARBITRARY FORCE FACTOR
PROJECTILE_SPEED = 1 # ANIMATION SPEED
NORTH = 90 # ANGLE OF NORTH DIRECTION
SOUTH = 270 # ANGLE OF SOUTH DIRECTION
EAST = 0 # ANGLE OF EAST DIRECTION
WEST = 180 # ANGLE OF WEST DIRECTION
#SET UP WINDOW
turtle.setup(SCREEN_WIDTH,SCREEN_HEIGHT)
#DRAW TARGET
turtle.hideturtle()
turtle.speed(0)
turtle.penup()
turtle.goto(TARGET_LLEFT_X,TARGET_LLEFT_Y)
turtle.pendown()
turtle.setheading(EAST)
turtle.forward(TARGET_WIDTH)
turtle.setheading(NORTH)
turtle.forward(TARGET_WIDTH)
turtle.setheading(WEST)
turtle.forward(TARGET_WIDTH)
turtle.setheading(SOUTH)
turtle.forward(TARGET_WIDTH)
turtle.penup()
#Center turtle
turtle.goto(0,0)
turtle.setheading(EAST)
turtle.showturtle()
turtle.speed(PROJECTILE_SPEED)
# Get the angle and force from the user
angle = float(input('Enter the projectile\'s\' angle: '))
force=float(input('Enter the launch force (1-10): '))
# Calculate the distance
distance = force * FORCE_FACTOR
# Set the turtle heading
turtle.setheading(angle)
# Launch the projectile
turtle.pendown
turtle.forward(distance)
# Did you hit the target
if (turtle.xcor() >= TARGET_LLEFT_X and
turtle.xcor() <=(TARGET_LLEFT_X + TARGET_WIDTH) and
turtle.ycor() >= TARGET_LLEFT_Y and
turtle.ycor() <= (TARGET_LLEFT_Y + TARGET_WIDTH)):
print('Target Hit')
else:
print('You missed the target')