-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (67 loc) · 2.54 KB
/
main.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import math
import pygame
import numpy
from Classes.PicObj import PicObj # you can also import *
from Classes.Robot import Robot # you can also import *
from Classes.Goal import Goal # you can also import *
from Classes.Ball import Ball # you can also import *
from Classes.Globals import * # to import all global variables
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
if __name__ == '__main__':
pygame.init()
SPEED = 5
RADIUS = 20
GOALWIDTH = 30
GOALHEIGHT = 100
robot_list = []
gameObjs = []
ball = Ball(400, 400)
ball.resetToMiddle()
redGoal = Goal(100, 400,GOALWIDTH,GOALHEIGHT,"red",RED)
blueGoal = Goal(WIDTH -100, 400,GOALWIDTH,GOALHEIGHT,"blue", BLUE)
run = True
moving = False
robot1 = Robot(SPEED, 10, 300,300, RED, RADIUS)
robot2 = Robot(SPEED, 10, 600,500, BLUE, RADIUS)
# robot3 = Robot(SPEED, 10, 200,200, RED, RADIUS)
#robotv2 = Robot2([50,50], [10,10,5])
robot_list.append(robot1)
robot_list.append(robot2)
# robot_list.append(robot3)
gameObjs.append(ball)
gameObjs.append(redGoal)
gameObjs.append(blueGoal)
gameObjs.append(robot1)
gameObjs.append(robot2)
# gameObjs.append(robot3)
while run:
draw(WIN, gameObjs)
#this works
# if robot.xpos>0 and robot.ypos>0:
# robot.upLeft()
for event in pygame.event.get():
#print(event)
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
moving = True
if event.key == pygame.K_f:
print(get_distance(robot1, robot2))
# elif event.key == pygame.K_s:
# robot.down()
#
# if event.key == pygame.K_a:
# robot.left()
# elif event.key == pygame.K_d:
# robot.right()
control(robot2, event, ball)
if not robot1.hasball and (ball.getSpeed()[0] != 0):
if WIDTH>ball.xpos+ball.radius and ball.xpos-ball.radius>0 and HEIGHT>ball.ypos+ball.radius and ball.ypos-ball.radius>0:
ball.move()
redGoal.scoreGoal(ball)
blueGoal.scoreGoal(ball)
else:#get it to bounce off walls
ball.setSpeed([0,0])
algorithm(robot1, robot2,ball, blueGoal)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/