-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,7 @@ def getavgpos(self): | |
| avgx += b.xc | ||
| avgy += b.yc | ||
| bcount += 1 | ||
|
|
||
| avgx = avgx/bcount | ||
| avgy = avgy/bcount | ||
| if bcount <= 2: | ||
|
|
@@ -112,19 +112,15 @@ def getavgdir(self): | |
| if b.withinrange(self): | ||
| avgd += b.rot | ||
| bcount += 1 | ||
|
|
||
| avgd = avgd/bcount | ||
| return avgd | ||
|
|
||
| return avgd/bcount | ||
|
Comment on lines
-115
to
+116
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def cohesion(self): | ||
| ax, ay = self.getavgpos() # average x and y | ||
| if self.alone: | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) | ||
| else: | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) # just draws a rectangle at where the average position is | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) | ||
| relx = ax - self.x | ||
| rely = ay - self.y | ||
|
|
||
|
Comment on lines
-121
to
+123
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| rota, l = getVectorfromXY(relx, rely) | ||
| print(rota) | ||
| rotc = ((rota - self.rot) * 0.3) # change in rotation needed: change 0.5 to other values to increase/decrease sensitivity | ||
|
|
@@ -144,15 +140,11 @@ def separate(self): | |
| ox, oy = getXYFromVector(b.rot, 10) | ||
| rx = x - ox | ||
| ry = y - oy | ||
| if rx > 0 and ry > 0: | ||
|
|
||
| if rx > 0 and ry > 0 or (rx <= 0 or ry >= 0) and (rx >= 0 or ry >= 0): | ||
| self.rot += tcs | ||
| elif rx > 0 and ry < 0: | ||
| self.rot -= tcs | ||
| elif rx < 0 and ry < 0: | ||
| self.rot -= tcs | ||
| else: | ||
| self.rot += tcs | ||
|
Comment on lines
-147
to
-155
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.rot -= tcs | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -206,22 +198,28 @@ def getVectorfromXY(xc, yc): | |
| center = Object(0, 0, 5, 5, (0, 0, 255)) | ||
| backg = Object(0, 0, width, height, (0, 0, 0)) | ||
|
|
||
| boids = [] | ||
| boids = [ | ||
| Boid( | ||
| randint(0, width), | ||
| randint(0, height), | ||
| pygame.image.load("boid.png"), | ||
| 150, | ||
| ) | ||
| for _ in range(100) | ||
| ] | ||
|
|
||
|
|
||
|
Comment on lines
-209
to
211
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| # add boids | ||
| for i in range(100): | ||
| boids.append(Boid(randint(0, width), randint(0, height), pygame.image.load("boid.png"), 150)) | ||
| playerquit = False | ||
| main = True | ||
|
|
||
| while not playerquit: | ||
| backg.draw() | ||
| for i in boids: | ||
| i.update() | ||
|
|
||
| center.x, center.y = boids[0].getavgpos() | ||
| #center.draw() | ||
|
|
||
| for event in pygame.event.get(): | ||
| if event.type == QUIT: | ||
| main = False | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ def getavgpos(self, dist): | |
| avgx += b.x | ||
| avgy += b.y | ||
| bcount += 1 | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the following improvement in Function |
||
| avgx = avgx/bcount | ||
| avgy = avgy/bcount | ||
| print(avgx, avgy) | ||
|
|
@@ -117,10 +117,12 @@ def getVectorfromXY(xc, yc): | |
|
|
||
| center = Object(0, 0, 5, 5, (0, 0, 255)) | ||
| backg = Object(0, 0, 1920, 1080, (0, 0, 0)) | ||
| boids = [] | ||
| boid = Boid(100, 100, pygame.image.load("boid.png")) | ||
|
|
||
| boids.append(Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png"))) | ||
| boids = [ | ||
| Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png")) | ||
| ] | ||
|
|
||
|
Comment on lines
-120
to
+125
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| playerquit = False | ||
| main = True | ||
| while not playerquit: | ||
|
|
@@ -131,7 +133,7 @@ def getVectorfromXY(xc, yc): | |
| for i in boids: | ||
| i.update() | ||
| i.draw() | ||
|
|
||
| center.x, center.y = boids[0].getavgpos(500) | ||
| center.draw() | ||
| #print(pygame.mouse.get_pos()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function
Boid.getavgpos: