def saddle(): colors = [ 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b' ] saddle = [ Magnet(np.array([1, 1, 0]), Magnet.radius, np.array([0, 0, 0]), colors[0]), Magnet(np.array([1, -1, 0]), Magnet.radius, np.array([Magnet.radius * 2, 0, 0]), colors[1]), Magnet(np.array([-1, -1, 0]), Magnet.radius, np.array([Magnet.radius * 2, Magnet.radius * 2, 0]), colors[2]), Magnet(np.array([-1, 1, 0]), Magnet.radius, np.array([0, Magnet.radius * 2, 0]), colors[3]) ] return saddle
def __init__(self): self.magnets = {} """ This is the configuration for AMOR. As this is so special, it is hardcoded. But the thing can take up to 6 magnets if pushed. Change this to another configuration scheme if this is used any where else then AMOR """ self.magnets['1'] = Magnet(-40.,40.) self.magnets['2'] = Magnet(-100.,100.) self.magnets['3'] = Magnet(-40.,40.) self.magnets['4'] = Magnet(0.,0.) self.magnets['5'] = Magnet(0.,0.) self.magnets['6'] = Magnet(0.,0.)
def loop(num, counterclockwise): colors = [ 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b' ] loop = [] for i in range(num): #OFF BY ONE ERROR HERE theta = (i * 2 * np.pi) / (num) print(theta) magnetDirection = np.array([-np.sin(theta), np.cos(theta), 0]) if counterclockwise == False: magnetDirection *= -1 # posVecMag = Magnet.radius/(np.cos(theta/2)) posVecMag = Magnet.radius / (np.sin(np.pi / num)) magnetPosition = np.array( [posVecMag * np.cos(theta), posVecMag * np.sin(theta), 0]) loop.append( Magnet(magnetDirection, Magnet.radius, magnetPosition, colors[i])) return loop
def grid(x, y, z, momentDir): colors = [ 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b' ] ret = [] for i in range(x): for j in range(y): for k in range(z): ret.append( Magnet( np.array([ 1 if 'x' in momentDir else 0, 1 if 'y' in momentDir else 0, 1 if 'z' in momentDir else 0 ]), Magnet.radius, np.array([ Magnet.radius * 2 * i, Magnet.radius * 2 * j, Magnet.radius * 2 * k ]), colors[i])) return ret
def line(num, ldir, momentDir): colors = [ 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b', 'g', 'b' ] ret = [] for i in range(num): ret.append( Magnet( np.array([ 1 if 'x' in momentDir else 0, 1 if 'y' in momentDir else 0, 1 if 'z' in momentDir else 0 ]), Magnet.radius, np.array([ Magnet.radius * 2 * i if 'x' in ldir else 0, Magnet.radius * 2 * i if 'y' in ldir else 0, Magnet.radius * 2 * i if 'z' in ldir else 0 ]), colors[i])) return ret
def __init__(self): self.__clock = pygame.time.Clock() self.__screen = pygame.display.set_mode(GameConstants.SCREEN_SIZE) self.__Magnet = Magnet( (GameConstants.SCREEN_SIZE[0] / 2, GameConstants.SCREEN_SIZE[1] / 2), pygame.image.load(GameConstants.SPRITE_MAGNET).convert_alpha()) self.__Ball = Ball( (0, 0), pygame.image.load(GameConstants.SPRITE_BALL).convert_alpha(), self) self.__Target = Target( (400, 600), pygame.image.load(GameConstants.SPRITE_TARGET).convert_alpha(), self) pygame.mouse.set_visible(0) pygame.init() pygame.display.set_caption("Simple Game Test") self.__scenes = (PlayingGameScene(self), MenuScene(self), HitTargetScene(self)) self.__currentScene = 2
obj_board.matrix_set( obj_scenery.create_ground(rows, 500, obj_board.matrix_get())) obj_board.matrix_set(obj_scenery.create_sky(rows, 500, obj_board.matrix_get())) obj_board.matrix_set(obj_scenery.create_clouds(obj_board.matrix_get())) obj_board.matrix_set( obj_scenery.create_coins(rows, 500, obj_board.matrix_get())) obj_board.matrix_set( obj_scenery.create_powerup(rows, 500, obj_board.matrix_get())) obj_board.matrix_set(obj_scenery.create_obstacles(obj_board.matrix_get())) obj_board.matrix_set(obj_scenery.create_deadwall(obj_board.matrix_get())) obj_dragon = Dragon(rows, 500) obj_board.matrix_set(obj_dragon.place_dragon(rows, 500, obj_board.matrix_get())) y = random.randint(10, rows - 15) x = random.randint(60, 300) obj_magnet = Magnet(x, 20) obj_board.matrix_set(obj_magnet.print(obj_board.matrix_get())) stage = -1 obj_dragon_ball = Dragon_ball(10, 10) obj_board.matrix_set(obj_dragon_ball.print(obj_board.matrix_get())) game_time = 100 game_strt_time = time.time() power_time = 0 mando_check_roar = 0 boss_fight_start = time.time() def mag_force(x, y, stage, board): dist = 19 mag_x, mag_y = obj_magnet.get_x_y() if x < mag_x and mag_x - x < dist and mag_y - y < dist and mag_y - y > -dist:
# zs.append(m.getPotentialEnergy([magnet1, magnet2])) # print(zs) # ax.scatter(xs, ys, zs) # ax.set_xlabel('Magnet 2 X Position') # ax.set_ylabel('Magnet 2 Y Position') # ax.set_zlabel('System Potential Energy') # plt.show() t = np.linspace(-20,20,100) s = np.zeros(len(t)) magnet1 = Magnet(np.array([1, 0, 0]), 0.003175, np.array([0, 0, 0])) print(s.shape) for i in range(len(t)): magnet2 = Magnet(np.array([1, 0, 0]), 0.003175, np.array([0, 0, t[i]])) s[i] = m.getPotentialEnergy([magnet1, magnet2]) fig, ax = plt.subplots() ax.plot(t, s) t2 = np.linspace(-20,20,100) s2 = np.zeros(len(t)) magnet1 = Magnet(np.array([1, 0, 0]), 0.003175, np.array([0, 0, 0])) print(s.shape)
t = u.move() if t != 0 and t != 1: u.fall() bl.new_bullet(t) elif t == 0: u.fall() u.printer(sc) sc.add(c.rem(u.get_centre())) sc.set_nxt(0) if m == None and sc.get_no() > sc.get_beams() / 2 and sc.get_timer() > 10 and sc.get_m_no() < 1: m = Magnet() sc.set_timer(0) sc.set_m_no(1) for i in range(len(b)): if b[i].get_immersed() == 0 and (m == None or m.get_immersed()): sc.set_nxt(1) if sc.get_timer() > 10 and sc.get_no() < sc.get_beams(): b.append(Beam()) sc.set_timer(0) sc.inc_no() elif sc.get_nxt() == 0: sc.inc_timer()
def timerFired(self, dt): if self.player.mode == "invincible": self.scrollSpeed = 5 * self.oriScrollSpeed else: self.scrollSpeed = self.oriScrollSpeed if not self.playerGroup.sprite.isAlive or (self.mode != "game") or self.isPaused: return self.count += 1 if self.count % 5 == 0: self.score += 1 if len(self.obstacles) != 0: for obstacle in self.obstacles: obstacle.scroll += self.scrollSpeed if len(self.coins) != 0: for coin in self.coins: coin.scroll += self.scrollSpeed if len(self.rockets) != 0: for rocket in self.rockets: rocket.scroll += self.scrollSpeed if len(self.itemBoxes) != 0: for itemBox in self.itemBoxes: itemBox.scroll += self.scrollSpeed if self.player.mode != "invincible": self.scrollSpeed += 1 / 500 self.oriScrollSpeed = self.scrollSpeed # modified code inspired by: https://www.youtube.com/watch?v=PjgLeP0G5Yw self.bgX -= self.scrollSpeed self.bgX2 -= self.scrollSpeed self.player.scroll += self.scrollSpeed if self.bgX < (self.bgWidth * -1): self.bgX = self.bgWidth elif self.bgX2 < (self.bgWidth * -1): self.bgX2 = self.bgWidth for obstacle in self.obstacles: obstacle.x -= self.scrollSpeed for coin in self.coins: coin.x -= self.scrollSpeed for itemBox in self.itemBoxes: itemBox.x -= self.scrollSpeed self.obstacles.update(self.width, self.height, self.player.x, self.player.y) self.playerGroup.update(dt, self.isKeyPressed, self.width, self.height) self.coins.update(self.width, self.height, self.player.x, self.player.y, self.player.mode) self.itemBoxes.update(self.width, self.height, self.player.x, self.player.y) self.warningSigns.update(self.width, self.height) self.rockets.update(self.width, self.height, self.player.x, self.player.y) self.lasersPrep.update(self.width, self.height, self.player.x, self.player.y) self.lasers.update(self.width, self.height, self.player.x, self.player.y) if self.player.bullets != None and len(self.player.bullets) != 0: self.bulletGroup.add(self.player.bullets[-1]) self.bulletGroup.update(self.width, self.height, self.player) if self.player.magnet != None: self.magnetGroup = pygame.sprite.GroupSingle(self.player.magnet) self.player.magnet.update(self.width, self.height, self.player.x, self.player.y) (boolObstacle, obstacle) = self.player.collide(self.obstacles) if self.player.mode != "invincible" and obstacle != None: self.moneyRecorded = False # modified code from: https://nerdparadise.com/programming/pygame/part3 pygame.mixer.Channel(0).play(pygame.mixer.Sound( self.collisionSound), maxtime=600) pygame.mixer.music.stop() self.player.isAlive = False self.isPaused = True obstacle.kill() (boolCoin, coins) = self.player.collideCoins(self.coins) if coins != None: for coin in coins: if not coin.hit: # modified code from: https://nerdparadise.com/programming/pygame/part3 pygame.mixer.Channel(2).play(pygame.mixer.Sound( self.coinSound), maxtime=600) self.score += 20 coin.hit = True coin.count = 0 (boolItemBox, itemBox) = self.player.collide(self.itemBoxes) if self.player.mode != "invincible" and self.player.mode != "magnet suit" and itemBox != None: self.player.mode = itemBox.itemType self.player.count = 0 itemBox.hit = True itemBox.kill() if self.player.mode == "magnet suit": # modified code from: https://nerdparadise.com/programming/pygame/part3 pygame.mixer.Channel(4).play(pygame.mixer.Sound( self.magnetSound), maxtime=2000) self.player.magnet = Magnet(self.player.x, self.player.y) elif self.player.mode == "invincible": pygame.mixer.Channel(4).play(pygame.mixer.Sound( self.invincibleSound), maxtime=2000) (boolRocket, rocket) = self.player.collide(self.rockets) if self.player.mode != "invincible" and rocket != None: self.moneyRecorded = False # modified code from: https://nerdparadise.com/programming/pygame/part3 pygame.mixer.Channel(0).play(pygame.mixer.Sound( self.collisionSound), maxtime=600) pygame.mixer.music.stop() self.player.isAlive = False self.isPaused = True rocket.kill() (boolLaser, laser) = self.player.collide(self.lasers) if self.player.mode != "invincible" and laser != None and laser.laserOn: self.moneyRecorded = False # modified code from: https://nerdparadise.com/programming/pygame/part3 pygame.mixer.Channel(0).play(pygame.mixer.Sound( self.collisionSound), maxtime=600) pygame.mixer.music.stop() self.player.isAlive = False self.isPaused = True laser.kill() if len(self.player.bullets) != 0: for bullet in self.player.bullets: for rocket in self.rockets: bullet.hitItem(rocket) for obstacle in self.obstacles: bullet.hitItem(obstacle)
def timerFired(self, dt): if self.mode == "Play": self.timer += 1 if self.timer % 4 == 0: self.roadTimer += 1 if self.timer % 4 == 0: self.runningManTimer += 1 if not (self.isMerge): self.powerupTimer += 1 #POWERUP TIMING if self.powerupTimer % 700 == 0: powerupChoice = random.choice(["magnet", "invinc"]) self.powerupTime = random.randint(550, 700) if powerupChoice == "magnet": self.isMakingMagnets = True self.isMakingInvincs = False else: self.isMakingMagnets = False self.isMakingInvincs = True #AI TIMING if self.powerupTimer % 1000 == 0: self.AITime = random.randint(900, 1000) #COIN WORK if self.timer > 50: if self.isMakingCoins and not (self.isMerge): if len(self.coins) < 1: self.coinLoc = random.choice( ["middle", "left", "right"]) if self.coinLoc == "middle" and not (self.isMerge): initialX = self.middleApex[0] initialY = self.middleApex[1] + 10 dx = 0 dy = 2 for i in range(5): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) elif self.coinLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = -1.1547005 dy = 2 numCoins = random.randint(5, 8) for i in range(numCoins): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) elif self.coinLoc == "right" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = 1.1547005 dy = 2 numCoins = random.randint(5, 8) for i in range(numCoins): self.coins.add( Coin(initialX + i * dx, initialY + i * dy)) #dilate the coins for coin in self.coins: if self.coinLoc == "middle": Coin.dilate(coin, self.middleApex) elif self.coinLoc == "left": Coin.dilate(coin, self.leftApex) elif self.coinLoc == "right": Coin.dilate(coin, self.rightApex) #check if it goes out of bounds if coin.y > self.height: if self.isMagnetic: self.score += 1 self.coins.remove(coin) if not self.man.isJump: #can't collect coins while jumping coinsHit = pygame.sprite.spritecollide(self.playerGroup.sprite, self.coins, True) for coin in coinsHit: self.coinSound.play() self.score += 1 #MAGNET WORK if self.timer > 170: if self.isMakingMagnets and not (self.isMerge): if len(self.magnets) < 1: if self.timer % 700 == self.powerupTime: self.magnetLoc = random.choice(["left", "right"]) if self.magnetLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = -1.1547005 dy = 2 self.magnets.add(Magnet(initialX, initialY)) elif self.magnetLoc == "right" and not ( self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 dx = 1.1547005 dy = 2 self.magnets.add(Magnet(initialX, initialY)) #dilate the magnet for magnet in self.magnets: if self.magnetLoc == "left": Magnet.dilate(magnet, self.leftApex) elif self.magnetLoc == "right": Magnet.dilate(magnet, self.rightApex) #check if it goes out of bounds if magnet.y > self.height: self.magnets.remove(magnet) if not self.man.isJump: #can't collect magnets while jumping magnetsHit = pygame.sprite.spritecollide( self.playerGroup.sprite, self.magnets, True) if len(magnetsHit) == 1: self.magnetSound.play() self.isMagnetic = True self.road.color = (0, 0, 200) #magnetic timer if self.isMagnetic: self.magneticTimer += 1 if self.magneticTimer == 250: self.isMagnetic = False self.magneticTimer = 0 self.road.color = (200, 200, 0) #INVINCIBILITY WORK if self.timer > 250: if self.isMakingInvincs and not (self.isMerge): if len(self.invincs) < 1: if self.powerupTimer % 700 == self.powerupTime: self.invincLoc = random.choice(["left", "right"]) if self.invincLoc == "left" and not (self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 self.invincs.add(Invinc(initialX, initialY)) elif self.invincLoc == "right" and not ( self.isMerge): initialX = 477 initialY = 169.207843193097 + 25 self.invincs.add(Invinc(initialX, initialY)) #dilate the invinc for invinc in self.invincs: if self.invincLoc == "left": Invinc.dilate(invinc, self.leftApex) elif self.invincLoc == "right": Invinc.dilate(invinc, self.rightApex) #check if it goes out of bounds if invinc.y > self.height: self.invincs.remove(invinc) if not self.man.isJump: #can't collect invincs while jumping invincsHit = pygame.sprite.spritecollide( self.playerGroup.sprite, self.invincs, True) if len(invincsHit) == 1: self.invincSound.play() self.isInvinc = True self.road.color = (200, 0, 0) #invinc timer if self.isInvinc: print(self.invincTimer) self.invincTimer += 1 if self.invincTimer == 250: self.isInvinc = False self.invincTimer = 0 self.invincTime = None self.road.color = (200, 200, 0) #AI WORK if self.timer > 200: if self.isMakingAIs: if len(self.AIs) < 1: if self.powerupTimer % 1000 == self.AITime: self.AILoc = random.choice(["left", "right"]) if self.AILoc == "left": initialX = 477 initialY = 169.207843193097 + 25 self.AIs.add(AI(initialX, initialY)) elif self.AILoc == "right": initialX = 477 initialY = 169.207843193097 + 25 self.AIs.add(AI(initialX, initialY)) #dilate the AI for ai in self.AIs: if self.AILoc == "left": AI.dilate(ai, self.leftApex) elif self.AILoc == "right": AI.dilate(ai, self.rightApex) #check if it goes out of bounds if ai.y > self.height: self.AIs.remove(ai) if not self.man.isJump: #can't collect AIs while jumping AIsHit = pygame.sprite.spritecollide(self.playerGroup.sprite, self.AIs, True) if len(AIsHit) == 1: self.AISound.play() self.isAI = True self.road.color = (124, 252, 0) #AI timer if self.isAI: self.road.color = (124, 252, 0) self.AITimer += 1 if self.AITimer == 1000: self.isAI = False self.AITimer = 0 self.AITime = None self.road.color = (200, 200, 0) #HOLES #generate a hole if self.timer % 500 == 0: self.holeTime = random.randint(300, 499) if self.timer % 500 == self.holeTime and self.isMakingHoles: self.isHolePresent = True self.holes.append(Hole(412, 250)) #dilate the hole if self.isHolePresent: for hole in self.holes: Hole.dilate(hole, self.middleApex) if hole.centerY - hole.height // 2 > self.height: self.isHolePresent = False self.holes = [] #how to die for hole in self.holes: bottom = hole.centerY + hole.height // 2 if self.isAI: if hole.centerY >= self.man.y - 35: #MAYBE STILL USE BOTTOM if not (self.man.shouldJump): self.man.shouldJump = True self.man.shouldJumpIndex = 0 if hole.centerY >= self.man.y and not (self.isAI) and not ( self.isInvinc) and not ( self.man.isJump): #if there's no merge if not (self.isMerge): self.mode = "GameOverNoJump" self.isMagnetic = False self.isInvinc = False self.isAI = False self.holes = [] pygame.mixer.music.stop() elif self.isMerge: if hole.centerY - self.man.y < 60: self.mode = "GameOverNoJump" self.isMagnetic = False self.isInvinc = False self.isAI = False self.holes = [] pygame.mixer.music.stop() #MAKE MERGE if self.timer % 500 == 0: self.mergeTime = random.randint(300, 499) if self.timer % 500 == self.mergeTime: self.isMerge = True if self.isMerge: self.isMakingCoins = False self.isMakingMagnets = False self.isMakingInvincs = False self.isMakingHoles = False if self.road.k == self.height // 4: if self.man.y < 140: self.mode = "GameOverFell" pygame.mixer.music.stop() #reset self.isMerge = False self.isMakingCoins = True self.isMagnetic = False self.isInvinc = False self.isAI = False self.road.k = 5 self.man.x = self.width // 2 self.man.y = 8 * self.height // 10 self.man.updateRect() powerupChoice = random.choice(["magnet", "invinc"]) Game.pickPowerup(self, powerupChoice) elif self.man.y > self.height // 4 - 50: self.man.y -= 5 self.man.updateRect() elif self.road.k < self.height // 4: self.road.k += 1 #MOVE LEFT AND RIGHT if self.isKeyPressed(pygame.K_LEFT) and self.man.left: self.playerGroup.sprite.moveLeft(self.width) #move left if self.isKeyPressed(pygame.K_RIGHT) and self.man.right: self.playerGroup.sprite.moveRight(self.width) #move left #MAKE JUMP if self.man.isJump and not (self.man.left) and not ( self.man.right ): #GLITCH when you click arrow keys too fast if self.man.jumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[self.man.jumpIndex] self.man.updateRect() self.man.jumpIndex += 1 elif self.man.jumpIndex >= len(self.jumpAdd): self.man.isJump = False self.gruntJumpLandSound.play() self.man.jumpIndex = 0 self.man.left = True self.man.right = True #AI WORK if self.isAI: if self.isMerge: if self.man.shouldJump: #DON'T click arrow keys too fast/simultaneously if self.man.shouldJumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[ self.man.shouldJumpIndex] self.man.shouldJumpIndex += 1 self.man.updateRect() elif self.man.shouldJumpIndex >= len(self.jumpAdd): self.man.shouldJump = False self.man.shouldJumpIndex = 0 self.man.left = True self.man.right = True #get to the middle if 350 < self.man.y < 566: Player.AIgetCoins(self.man, "middle", self.width) elif 140 < self.man.y < 222: self.resetPlay() self.mode = "Play" elif not (self.isMerge): if self.man.shouldJump: #DON'T click arrow keys too fast/simultaneously if self.man.shouldJumpIndex < len(self.jumpAdd): self.man.y += self.jumpAdd[ self.man.shouldJumpIndex] self.man.shouldJumpIndex += 1 self.man.updateRect() elif self.man.shouldJumpIndex >= len(self.jumpAdd): self.man.shouldJump = False self.man.shouldJumpIndex = 0 self.man.left = True self.man.right = True Player.AIgetCoins(self.man, self.coinLoc, self.width)
def init(self): pygame.mixer.init() self.timer = 0 self.score = 0 self.splash = pygame.image.load('images/splash.png') self.bg2 = pygame.transform.scale( pygame.image.load('images/base2.jpg'), (954, 720)) self.helpScreens = [ pygame.image.load('images/help/help1.png'), pygame.image.load('images/help/help2.png') ] self.rightRail = pygame.image.load('images/rightrail2.png') self.leftRail = pygame.image.load('images/leftrail2.png') self.topRail = pygame.transform.scale( pygame.image.load('images/toprail.png'), (954, 720)) self.fog = pygame.transform.scale( pygame.image.load('images/fog3.png').convert_alpha(), (960, 200)) self.mode = "Splash" #see redrawAll for possible modes self.enteredName = "" self.leaderboard = Leaderboard() #has path, enterNameBase, leaderboardBase #jumping action self.jumpAdd = [ -40, -35, -30, -25, -20, -15, -10, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 20, 25, 30, 35, 40 ] #MERGING ACTION self.isMerge = False self.mergeTime = None #ROAD self.road = Road((self.width, self.height), self.screen) self.roadTimer = 0 self.apex = (self.width // 2, self.height - self.width * math.tan(math.pi / 6)) self.middleApex = (self.width // 2, self.height - self.width * math.tan(math.pi / 6)) self.leftApex = (483.25, 180.033160740402) self.rightApex = (470.75, 180.033160740402) #CHARACTER Player.init() player = Player(self.width // 2, 8 * self.height // 10) self.playerGroup = pygame.sprite.GroupSingle(player) self.man = self.playerGroup.sprite self.runningManTimer = 0 #COINS Coin.init() self.coins = pygame.sprite.Group() self.coinLoc = None self.isMakingCoins = True #GENERAL POWERUPS self.powerupTime = random.randint(550, 700) self.powerupChoices = ["magnets", "invincs"] self.powerupTimer = 0 #MAGNETS Magnet.init() self.magnets = pygame.sprite.Group() self.magnetLoc = None self.isMakingMagnets = True self.isMagnetic = False self.magneticTimer = 0 self.isMagnetPresent = (len(self.magnets) > 0) #INVINCS Invinc.init() self.invincs = pygame.sprite.Group() self.invincLoc = None self.isMakingInvincs = False self.isInvinc = False self.invincTimer = 0 self.isInvincPresent = (len(self.invincs) > 0) #AI AI.init() self.AIs = pygame.sprite.Group() self.AILoc = None self.isMakingAIs = False self.isAI = False self.AITimer = 0 self.isAIPresent = (len(self.AIs) > 0) self.AITime = random.randint(900, 1000) #HOLES self.holes = [] self.isHolePresent = False self.isMakingHoles = True self.holeTime = None #DEATH self.deadScreens = [ pygame.image.load('images/dead/burnt.png'), pygame.image.load('images/dead/crevice.png'), pygame.image.load('images/dead/didntSlide.png'), pygame.image.load('images/dead/ranOff.png') ] #SOUNDS #https://www.youtube.com/watch?v=WzQEbRAZJRE pygame.mixer.music.load('sounds/soundtrack.mp3') pygame.mixer.music.set_volume(0.1) #https://www.sounds-resource.com/mobile/templerun/sound/6075/ self.invincSound = pygame.mixer.Sound('sounds/angelWings.wav') self.coinSound = pygame.mixer.Sound('sounds/coin.wav') self.gruntJumpSound = pygame.mixer.Sound('sounds/gruntJump.wav') self.gruntJumpLandSound = pygame.mixer.Sound( 'sounds/gruntJumpLand.wav') self.magnetSound = pygame.mixer.Sound('sounds/magnet.wav') self.AISound = pygame.mixer.Sound('sounds/shimmer.wav') self.splashSound = pygame.mixer.Sound('sounds/splash.wav') self.splatSound = pygame.mixer.Sound('sounds/splat.wav') self.turnSound = pygame.mixer.Sound('sounds/footstepsTurn.wav') self.mouseClick = pygame.mixer.Sound('sounds/mouseClick.wav')
def genDrivingBfield(self): Driver = Magnet(self.thickness, self.diameter, self.inner_armLength, self.magnetization, self.xlim, self.ylim, self.zlim, self.resolution, self.step) phi = 0 for i in range( int((2 * np.pi / self.driving_angular_velocity) / self.timesres)): Driver.genBfield(phi, i) phi = phi + i * self.timesres * self.driving_angular_velocity for i in range( int((2 * np.pi / self.driving_angular_velocity) / self.timesres)): Bfield_list = [] for k in range(self.inner_num_of_teeth): j = int((int((2 * np.pi / self.driving_angular_velocity) / self.timesres) / self.inner_num_of_teeth) * k) if i + j < int((2 * np.pi / self.driving_angular_velocity) / self.timesres): Bfield_list.append(Driver.getBfield(i + j)) else: reducediplusj = i + j while reducediplusj >= int( (2 * np.pi / self.driving_angular_velocity) / self.timesres): reducediplusj -= int( (2 * np.pi / self.driving_angular_velocity) / self.timesres) Bfield_list.append(Driver.getBfield(reducediplusj)) Bx_field = np.zeros((int(2 * self.xlim / self.resolution), int(2 * self.ylim / self.resolution), int(2 * self.zlim / self.resolution))) By_field = np.zeros((int(2 * self.xlim / self.resolution), int(2 * self.ylim / self.resolution), int(2 * self.zlim / self.resolution))) Bz_field = np.zeros((int(2 * self.xlim / self.resolution), int(2 * self.ylim / self.resolution), int(2 * self.zlim / self.resolution))) while Bfield_list: B_field = Bfield_list.pop() Bx_field = np.add(Bx_field, B_field[0]) By_field = np.add(Bx_field, B_field[1]) Bz_field = np.add(Bx_field, B_field[2]) current_path = os.getcwd() if "driver_Bfielddata" not in os.listdir(current_path): os.mkdir("driver_Bfielddata") os.chdir("driver_Bfielddata") file = open("driver_Bfielddata" + str(i) + ".txt", 'w+') for u in range(int(2 * self.xlim / self.resolution)): for v in range(int(2 * self.ylim / self.resolution)): for w in range(int(2 * self.zlim / self.resolution)): file.write("(" + str(u * self.resolution - self.xlim) + "," + str(v * self.resolution - self.ylim) + "," + str(w * self.resolution - self.zlim) + ") " + "(" + str(Bx_field[u][v][w]) + "," + str(By_field[u][v][w]) + "," + str(Bz_field[u][v][w]) + ")\r\n") os.chdir(current_path)
Magnet(np.array([1, 1, 0]), Magnet.radius, np.array([0, 0, 0]), colors[0]), Magnet(np.array([1, -1, 0]), Magnet.radius, np.array([Magnet.radius * 2, 0, 0]), colors[1]), Magnet(np.array([-1, -1, 0]), Magnet.radius, np.array([Magnet.radius * 2, Magnet.radius * 2, 0]), colors[2]), Magnet(np.array([-1, 1, 0]), Magnet.radius, np.array([0, Magnet.radius * 2, 0]), colors[3]) ] return saddle if __name__ == "__main__": mag1 = Magnet(np.array([1, 0, 0]), Magnet.radius, np.array([Magnet.radius * 2, 0, 0]), 'b') mag2 = Magnet(np.array([1, 1, 0]), Magnet.radius, np.array([0, 0, 0]), 'b') # magnets = line(2, ldir='z', momentDir='x') # magnets = MagnetSimulator.line(3,'x','x') # magnets[0].moment = -magnets[0].moment # magnets[1].moment = -magnets[1].moment # magnets = MagnetSimulator.saddle() magnets = MagnetSimulator.loop(3, True) # magnets[4].moment = np.array([-1,-1,0]) # magnets = [mag1, mag2] # magnets = [mag1, mag2] sim = MagnetSimulator(magnets) sim.run()