Skip to content

Commit c6a729e

Browse files
committed
No longer need to pass FPS into Boid update. Updated Example.
1 parent 74506c5 commit c6a729e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

example_layered.py renamed to example_scene.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python3
22
from pynboids import Boid
33
from random import randint
4+
from math import cos
45
import pygame as pg
56
'''
6-
Boid Import Example w/ layered groups.
7+
Boid Import Example, Fish Tank Scene.
78
Copyright (c) 2021 Nikolaus Stromberg
89
'''
9-
BPL = 48 # How many boids per layer
10+
BPL = 42 # How many boids per layer
1011
FLLSCRN = True # True for Fullscreen, or False for Window.
1112
WRAP = False # False avoids edges, True wraps boids to other side.
1213
BGCOLOR = (0, 0, 48) # Background color in RGB.
@@ -19,7 +20,7 @@ def main():
1920
if FLLSCRN:
2021
screen = pg.display.set_mode(currentRez, pg.SCALED)
2122
pg.mouse.set_visible(False)
22-
else: screen = pg.display.set_mode(currentRez, pg.RESIZABLE)
23+
else: screen = pg.display.set_mode((int(currentRez[0]*0.99),int(currentRez[1]*0.94)), pg.SCALED | pg.RESIZABLE)
2324

2425
bg_surf = pg.Surface((screen.get_width()*1.1, screen.get_height()*1.1))
2526
bg_surf.set_colorkey(0)
@@ -34,6 +35,10 @@ def main():
3435
bgBoids = bg_Boids.sprites()
3536
frontBoids = front_Boids.sprites()
3637

38+
#Bubbles = pg.sprite.Group()
39+
#for b in range(10):
40+
# Bubbles.add(Bubble(top_surf))
41+
3742
clock = pg.time.Clock()
3843
while True:
3944
for e in pg.event.get():
@@ -46,17 +51,18 @@ def main():
4651
top_surf.fill(0)
4752
screen.fill(BGCOLOR)
4853

49-
bg_Boids.update(bgBoids, dt, FPS, WRAP)
50-
front_Boids.update(frontBoids, dt, FPS, WRAP)
54+
bg_Boids.update(bgBoids, dt, WRAP)
55+
#Bubbles.update(dt, FPS)
56+
front_Boids.update(frontBoids, dt, WRAP)
5157

5258
bg_Boids.draw(bg_surf)
5359
bg_surf2 = pg.transform.scale(bg_surf,screen.get_size())
54-
screen.blit(bg_surf2, (0,0))
55-
60+
#screen.blit(bg_surf2, (0,0))
61+
#Bubbles.draw(top_surf)
5662
front_Boids.draw(top_surf)
5763
top_surf2 = pg.transform.scale(top_surf,screen.get_size())
58-
screen.blit(top_surf2, (0,0))
59-
64+
#screen.blit(top_surf2, (0,0))
65+
screen.blits([(bg_surf2, (0,0)), (top_surf2, (0,0))])
6066
pg.display.update()
6167

6268
if __name__ == '__main__':

pynboids.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Copyright (c) 2021 Nikolaus Stromberg [email protected]
88
'''
99
FLLSCRN = False # True for Fullscreen, or False for Window.
10-
BOIDZ = 85 # How many boids to spawn, may slow after 200ish.
10+
BOIDZ = 88 # How many boids to spawn, may slow after 200ish.
1111
WRAP = False # False avoids edges, True wraps boids to other side.
1212
FISH = False # True here will turn boids into fish.
1313
BGCOLOR = (0, 0, 0) # Background color in RGB.
@@ -35,7 +35,7 @@ def __init__(self, drawSurf, isFish=False, cHSV=None):
3535
self.angle = randint(0, 360) # random start angle, and position ^
3636
self.pos = pg.Vector2(self.rect.center)
3737

38-
def update(self, allBoids, dt, fps, ejWrap=False): # boid behavior
38+
def update(self, allBoids, dt, ejWrap=False): # boid behavior
3939
selfCenter = pg.Vector2(self.rect.center)
4040
curW, curH = self.drawSurf.get_size()
4141
turnDir = xvt = yvt = yat = xat = 0
@@ -118,7 +118,7 @@ def main():
118118

119119
dt = clock.tick(FPS) / 1000
120120
screen.fill(BGCOLOR)
121-
nBoids.update(allBoids, dt, FPS, WRAP)
121+
nBoids.update(allBoids, dt, WRAP)
122122
nBoids.draw(screen)
123123
pg.display.update()
124124

0 commit comments

Comments
 (0)