def createHurdles(self, window): for rowGround in self.squares: for colGround in rowGround: chanceRock = random.randint(1, 4) # a ajouter : function qui permet de checker qu'un obsctacle ne soit pas dans un coin if (chanceRock == 1): colGround = rock.Rock(colGround.x, colGround.y, window)
def create_album(self, genre): if genre == 'C': return classical.Classical() elif genre == 'R': return rock.Rock() elif genre == 'M': return metal.Metal()
def __init__(self, name, screen_x, screen_y, frames_per_second): self.name=config.TITLE self.screen_x=config.SCREEN_X self.screen_y=config.SCREEN_Y self.frames_per_second=config.FRAMES_PER_SECOND game.Game.__init__(self, config.TITLE,config.SCREEN_X,config.SCREEN_Y) self.shipshape=[point.Point(400, 300), point.Point(360,290), point.Point(360,310)] self.center=point.Point(self.screen_x/2, self.screen_y/2) self.rotation=config.SHIP_INITIAL_DIRECTION self.color=config.SHIP_COLOR self.ship=Ship(self.center, self.rotation, self.color) self.rocks=[] for i in range(config.ROCK_COUNT): self.rockspeed=random.uniform(config.ROCK_MIN_SPEED,config.ROCK_MAX_SPEED) self.rotationspeed=random.uniform(config.ROCK_MIN_ROTATION_SPEED,config.ROCK_MAX_ROTATION_SPEED) * random.randrange(-1, 2, 2) self.rockplace=point.Point(random.randint(0,config.SCREEN_X),random.randint(0,config.SCREEN_Y)) self.rock=rock.Rock(self.rockplace,random.uniform(0.0,359.99),config.ROCK_COLOR,self.rotationspeed, self.rockspeed) self.rocks.append(self.rock) self.bposition=self.ship.getPoints()[0] self.brotation=self.ship.get_rotation() self.bradius=config.BULLET_RADIUS self.bcolor=config.BULLET_COLOR self.bullet=Bullet(self.bposition, self.bradius, self.brotation, self.bcolor) self.stars=[] for i in range(config.STAR_COUNT): self.sposition=point.Point(random.randint(0,config.SCREEN_X),random.randint(0,config.SCREEN_Y)) self.sradius=config.STAR_RADIUS self.srotation=0.0 self.scolornum=random.uniform(0,255) self.scolor=(self.scolornum, self.scolornum, self.scolornum) self.star=Star(self.sposition, self.sradius, self.srotation, self.scolor) self.stars.append(self.star)
def __init__(self, width=640, height=480): ''' Description: The main controller class that handles the images Parameters: self, width, height - self is the default class parameter, width is the screen width, height is the screen height Return:none ''' pygame.init() self.width = width self.height = height self.screen = pygame.display.set_mode((self.width,self.height)) self.background = pygame.Surface(self.screen.get_size()).convert() self.textfont = pygame.font.SysFont("helvetica", 15) self.titlefont = pygame.font.SysFont("helvetica", 90) self.startRect = pygame.Rect(180,320,80,30) self.quitRect = pygame.Rect(380,320,80,30) self.cannon = cannon.Cannon(0, 420, "cannon.jpg") self.castle = castle.Castle(450, 310, "castle.png") self.rock = rock.Rock(105,420, "rocky.jpg") self.castlerect = self.castle.rect self.cannonSprite = pygame.sprite.Group(self.cannon) ##Used for drawing the cannon sprite self.castleSprite = pygame.sprite.Group(self.castle) ##Used for drawing the castle sprite self.rockSprite = pygame.sprite.Group(self.rock) ##Used for drawing the rock sprite self.shot = 0 self.angle = 0 self.velocity = 0 self.ixvelocity =0 self.iyvelocity = 0 self.rocktime = 0 self.bullets = 5
def __init__(self, world_width, world_height): self.mWorldWidth = world_width self.mWorldHeight = world_height shipX = self.mWorldWidth / 2 shipY = self.mWorldHeight / 2 self.mShip = ship.Ship(shipX, shipY, self.mWorldWidth, self.mWorldHeight) self.mRocks = [] self.mObjects = [self.mShip] # rocks for x in range(10): rockX = random.randrange(0, self.mWorldWidth) rockY = random.randrange(0 , self.mWorldHeight) rock1 = rock.Rock(rockX, rockY, world_width, world_height) self.mRocks.append(rock1) self.mObjects.append(rock1) #stars self.mStars = [] for x in range(20): starX = random.randrange(0, self.mWorldWidth) starY = random.randrange(0, self.mWorldHeight) star1 = star.Star(starX, starY, self.mWorldWidth, self.mWorldHeight ) self.mStars.append(star1) self.mObjects.append(star1) self.mBullets = [] self.mGameLost = False self.mGameWon = False
def __init__(self, width, height): self.mWorldWidth = width self.mWorldHeight = height shipx = random.randint(0, self.mWorldWidth) shipy = random.randint(0, self.mWorldHeight) self.mShip = ship.Ship(shipx, shipy, self.mWorldWidth, self.mWorldHeight) self.mBullet = [] NUM_ROCKS = random.randint(10, 20) self.mRocks = [] for i in range(NUM_ROCKS): rockx = random.randint(0, self.mWorldWidth) rocky = random.randint(0, self.mWorldHeight) rocks = rock.Rock(rockx, rocky, self.mWorldWidth, self.mWorldHeight) self.mRocks.append(rocks) NUM_STARS = 20 self.mStars = [] for i in range(NUM_STARS): starsx = random.randint(0, self.mWorldWidth) starsy = random.randint(0, self.mWorldHeight) stars = star.Star(starsx, starsy, self.mWorldWidth, self.mWorldHeight) self.mStars.append(stars) self.mObjects = self.mRocks[:] + [self.mShip] + self.mStars[:]
def main(): pygame.init() fpsClock = pygame.time.Clock() surf = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32) my_launcher = launcher.Launcher(0, HEIGHT - 20) my_rock = rock.Rock(0, HEIGHT - 20) #TODO while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: my_launcher.changeAngle(3) if event.key == pygame.K_DOWN: my_launcher.changeAngle(-3) if event.key == pygame.K_RIGHT: my_launcher.changeMagnitude(5) if event.key == pygame.K_LEFT: my_launcher.changeMagnitude(-5) if (event.key == pygame.K_SPACE) and (not my_rock.ismoving()): my_launcher.fire(my_rock) if event.type == QUIT: pygame.quit() sys.exit() #2. Do game logic my_rock.move(1.0 / FPS) # 3. Draw everything draw_world(surf) my_launcher.draw_launcher(surf) my_rock.draw(surf) pygame.display.update() fpsClock.tick(FPS)
def __init__(self, world_width, world_height): self.mWorldWidth = world_width self.mWorldHeight = world_height self.mRocks = [] self.mStars = [] self.mBullets = [] self.mObjects = [] self.mShip = ship.Ship(world_width / 2, world_height / 2, self.mWorldWidth, self.mWorldHeight) for i in range(20): self.mStars.append( star.Star(random.randrange(0, 700), random.randrange(0, 700), self.mWorldWidth, self.mWorldHeight)) for s in self.mStars: self.mObjects.append(s) for i in range(10): self.mRocks.append( rock.Rock(random.randrange(0, 700), random.randrange(0, 700), self.mWorldWidth, self.mWorldHeight)) for r in self.mRocks: self.mObjects.append(r) self.mObjects.append(self.mShip) return
def blitBreakableWalls(self, window): x = y = 0 for i in range(11): for j in range(11): if self.breakableWallPosition[j][i] == 1: rock.Rock(x, y, window) x += 40 y += 40 x = 0
def init_entities(self): self.diver = diver.Diver( (self.dimensions[0] / 2, self.dimensions[1] / 2)) self.bg = background.Background(self.dimensions) self.rocks = rock.Rock(self.dimensions) rock.create_rocks(self.rocks) self.entities = [self.bg, self.diver, self.rocks]
def setUp( self ): self.expected_x = 100 self.expected_y = 200 self.expected_dx = 0.0 self.expected_dy = 0.0 self.expected_rotation = 0 self.expected_world_width = 600 self.expected_world_height = 400 self.constructed_obj = rock.Rock( self.expected_x, self.expected_y, self.expected_world_width, self.expected_world_height ) return
def setUp( self ): self.expected_x = 100 self.expected_y = 200 self.expected_min_rotation = 0 self.expected_max_rotation = 359.9 self.expected_min_spin_rate = -90 self.expected_max_spin_rate = 90 self.expected_world_width = 600 self.expected_world_height = 400 self.expected_minimum_velocity = 10 self.expected_maximum_velocity = 20 self.constructed_obj = rock.Rock( self.expected_x, self.expected_y, self.expected_world_width, self.expected_world_height ) return
def main(): pygame.init() fpsClock = pygame.time.Clock() my_serial = serial.Serial("/dev/ttyACM0") my_launcher = launcher.Launcher(0, 400) my_rock = rock.Rock(0, 400) my_target = target.Target(random.random() * 280 + 100, 390) window = pygame.display.set_mode((500, 400)) pygame.display.set_caption('Lab 2 Stone') while (True): draw_world(window) mag_alt = read_arduino(my_serial) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: my_launcher.changeAngle(.05236) elif event.key == pygame.K_DOWN: my_launcher.changeAngle(-.05236) elif event.key == pygame.K_LEFT: my_launcher.changeMagnitude(-3) elif event.key == pygame.K_RIGHT: my_launcher.changeMagnitude(3) elif event.key == pygame.K_SPACE and not my_rock.isMoving( ) and not my_target.hit(my_rock, window): my_launcher.fire(my_rock) elif event.key == pygame.K_r: my_serial.write('r') elif event.key == pygame.K_g: my_serial.write('g') if event.type == QUIT: pygame.quit() sys.exit() my_rock.move(1.0 / FPS) my_launcher.Alt_Mag(mag_alt) if (my_rock.y > 400): my_rock.moveto(0, 400, window) displaytxt("You Missed!!", window) if my_target.hit == True: my_rock.moveto(0, 400, window) displaytxt("Good Hit!!", window) my_target.moveTo(random.random() * 280 + 100, 390) my_launcher.draw(window) my_rock.draw(window) my_target.draw(window) pygame.display.update() fpsClock.tick(FPS)
def __init__(self, world_width, world_height): self.mWorldWidth = world_width self.mWorldHeight = world_height shipX = self.mWorldWidth / 2 shipY = self.mWorldHeight / 2 self.mShip = ship.Ship(shipX, shipY, self.mWorldWidth, self.mWorldHeight) self.mRocks = [] self.mObjects = [self.mShip] # drawing the rocks for x in range(10): rockX = random.randrange(0, self.mWorldWidth) rockY = random.randrange(0, self.mWorldHeight) rock1 = rock.Rock(rockX, rockY, world_width, world_height) self.mRocks.append(rock1) self.mObjects.append(rock1)
def main(): pygame.init() pygame.display.init() fpsClock = pygame.time.Clock() # clock object SURF = pygame.display.set_mode((WIDTH, HEIGHT)) # creates game box pygame.display.set_caption('Launchr') # window title my_launcher = launcher.Launcher(0, (HEIGHT - 20)) my_rock = rock.Rock(0, (HEIGHT - 20)) my_target = target.Target(100 + (random.random() * WIDTH - 100), HEIGHT - 20, TARGET_WIDTH) while True: # main game loop for event in pygame.event.get(KEYUP): if event.key == pygame.K_UP: my_launcher.changeAngle(3) if event.key == pygame.K_DOWN: my_launcher.changeAngle(-3) if event.key == pygame.K_RIGHT: my_launcher.changeMagnitude(5) if event.key == pygame.K_LEFT: my_launcher.changeMagnitude(-5) if (event.key == pygame.K_SPACE) and (my_rock.isMoving() == False): my_launcher.fire(my_rock) if event.type == QUIT: pygame.quit() sys.exit() # game logic my_rock.move(1.0 / FPS) if (my_rock.y > HEIGHT - 19): my_rock.moveTo(0, HEIGHT - 20) displayText("You missed!", SURF) if my_target.hitBy(my_rock): my_rock.moveTo(0, HEIGHT - 20) displayText("Got eeeem", SURF) # Updates game screen draw_world(SURF) my_launcher.draw_launcher(SURF) my_target.draw_target(SURF) my_rock.draw_rock(SURF) pygame.display.update() fpsClock.tick(FPS)
def __init__(self,width,height): self.mWorldWidth = width self.mWorldHeight = height shipx = random.randint(0,self.mWorldWidth) shipy = random.randint(0,self.mWorldHeight) self.mColorObject = (255,255,255) self.mShip = ship.Ship(shipx,shipy,self.mWorldWidth,self.mWorldHeight) NUM_ROCKS = random.randint(10,20) self.mRocks = [] for i in range(NUM_ROCKS): rockx = random.randint(0,self.mWorldWidth) rocky = random.randint(0,self.mWorldHeight) rocks = rock.Rock(rockx,rocky,self.mWorldWidth,self.mWorldHeight) self.mRocks.append(rocks) self.mObjects = self.mRocks + [self.mShip]
def __init__(self, world_width, world_height): self.mWorldWidth = world_width self.mWorldHeight = world_height self.mShip = ship.Ship(300, 300, world_width, world_height) self.mRocks = [] self.mObjects = [] self.mBullets = [] self.mStars = [] for i in range(20): x = random.randint(0, self.mWorldWidth) y = random.randint(0, self.mWorldHeight) self.mStars.append(star.Star(x, y, world_width, world_height)) #add randrange for x and y for i in range(10): x = random.randint(0, self.mWorldWidth) y = random.randint(0, self.mWorldHeight) self.mRocks.append(rock.Rock(x, y, world_width, world_height)) self.mObjects = self.mRocks + self.mStars + [self.mShip] return
def sketch(): pygame.init() pywindow = pygame.display.set_mode((int(width), int(height))) WHITE = (255, 255, 255) BLUE = (0, 0, 255) pywindow.fill(WHITE) radius = 1 color = (0, 0, 255) new_texture = texture.Texture() while True: #main game loop for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: #This checks for the mouse press event center = pygame.mouse.get_pos() #Gets the mouse position new_rock = rock.Rock(center, radius, color) if new_texture.add(new_rock): pygame.draw.circle( pywindow, color, new_rock.center, radius) #Draws a circle at the mouse position if event.type == pygame.KEYDOWN: if int(event.key) == ord('b'): color = (0, 0, 255) if int(event.key) == ord('r'): color = (255, 0, 0) if int(event.key) == ord('g'): color = (0, 255, 0) if 48 < int(event.key) <= 57: radius = (int(event.key) - 48) * 5 if event.type == QUIT: pygame.quit() return new_texture pygame.display.update()
import sys import launcher import rock pygame.init() SURF = pygame.display.set_mode((500, 400)) Black = (0, 0, 0) Green = (0, 128, 0) Sky_Blue = (135, 206, 235) FPS = 30 fpsClock = pygame.time.Clock() x = 0 y = 380 my_launcher = launcher.Launcher(x, y) my_rock = rock.Rock(x, y) def main(): while (True): #1. Pygame events for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: my_launcher.changeAngle(3) if event.key == pygame.K_DOWN: my_launcher.changeAngle(-3) if event.key == pygame.K_LEFT: my_launcher.changeMagnitude(-5) if event.key == pygame.K_RIGHT: my_launcher.changeMagnitude(5)
def main(): # start up pygame and build a game window pygame.init() fpsClock=pygame.time.Clock() window = pygame.display.set_mode((WIDTH,HEIGHT),0,32) pygame.display.set_caption('Launchr') s = serial.Serial("/dev/ttyACM1",timeout=0.5) # create custom objects my_launcher = launcher.Launcher(0,HEIGHT-20) my_rock = rock.Rock(0,HEIGHT-20) my_target = target.Target((random.random()*280)+50, HEIGHT-20, TARGET_WIDTH) objs = [my_launcher, my_rock, my_target] # Main game loop while(True): # 1 Process Events for event in pygame.event.get(): if event.type == pygame.KEYDOWN: """arduino controls launcher mag/angle if event.key == pygame.K_UP: my_launcher.changeAngle(3) if event.key == pygame.K_DOWN: my_launcher.changeAngle(-3) if event.key == pygame.K_RIGHT: my_launcher.changeMag(5) if event.key == pygame.K_LEFT: my_launcher.changeMag(-5) """ if ((event.key == pygame.K_SPACE) and not my_rock.isMoving()): my_launcher.fire(my_rock) if event.type == QUIT: pygame.quit() sys.exit() # 2 Update Game State # read from arduino s.write('p') str_data = s.readline() if(len(str_data)>0): data = [int(x) for x in str_data.split(',')] my_launcher.setAngle((data[0]/1024.0)*90) my_launcher.setMag((data[1]/1024.0)*100) my_rock.move(1.0/FPS) # force floating point division if(my_rock.y>HEIGHT): # rock is below the screen my_rock.moveTo(0,HEIGHT-20) s.write('r') displayMessage(window,"Miss!") if(my_target.hitBy(my_rock.getRect())): # rock hit the target! my_rock.moveTo(0,HEIGHT-20) s.write('g') displayMessage(window,"Hit!") my_target.moveTo((random.random()*280)+50) # 3 Update Display drawWorld(window) for obj in objs: obj.draw(window) pygame.display.update() fpsClock.tick(FPS)
import rock as r from phases import * import fluid as f import insulation as i import pipe as p import well as w rock = r.Rock(temperature_formation_initial=350) gas = gas.Gas(pressure_pseudocritical=46, temperature_pseudocritical=190.5, density_relative=0.56) water = water.Water(salinity=0.001) fluid = f.Fluid(gas=gas, water=water, rate_gas_standard=1000, rate_water_standard=10) cementing = i.Insulation(diameter=0.25, thermal_conductivity=0.7) pipe_casing = p.Pipe(length=1000, diameter_outer=0.2, diameter_inner=0.15, roughness_absolute=None, angle_horizontal=90, thermal_conductivity=0.7, insulation=cementing) pipe_production = p.Pipe(length=1000,
#!/usr/bin/python import pygame, sys, time from pygame.locals import * from launcher import * import rock from colors import * import target pygame.init() DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32) #makes window ground = pygame.Rect(0, 380, 500, 20) #ground obj myLauncher = Launcher(0, 380) myRock = rock.Rock(0, 380) myTarget = target.Target() FPS = 30 fpsClock = pygame.time.Clock() def draw_world(surf): #draws everything for scenery surf.fill(SKY_COLOR) #fills sky background pygame.draw.rect(surf, GRASS_GREEN, ground) fontObj = pygame.font.Font('freesansbold.ttf', 32) #font obj textSurfaceObj = fontObj.render('Launchr 1.0', True, BLACK, SKY_COLOR) #text obj textRectObj = textSurfaceObj.get_rect() #text box textRectObj.center = (250, 25) #text box center surf.blit(textSurfaceObj, textRectObj) #puts text to screen
import pygame, sys, random, time from pygame.locals import * import launcher import rock import target from color import * #Set up Window pygame.init() surf = pygame.display.set_mode((400, 400), 0, 32) #Set up launcher my_launcher = launcher.Launcher(0, 380) my_rock = rock.Rock(0, 380) my_target = target.Target((random.random() * 280) + 100, 380) objs = [my_launcher, my_rock, my_target] #Set up FPS FPS = 120 fpsClock = pygame.time.Clock() #Drawing world def draw_world(surf): surf.fill(BLUE) fontObj = pygame.font.Font('freesansbold.ttf', 32) textSurfaceObj = fontObj.render('Launchr 1.0', True, GREEN, BLUE) textRectObj = textSurfaceObj.get_rect()
BLACK) #white text, black highlight textRectObj = textSurfaceObj.get_rect() textRectObj.center = (250, 20) pygame.draw.rect(surf, SKY_COLOR, (0, 0, 500, 380)) #sky pygame.draw.rect(surf, (GRASS_COLOR), (0, 380, 500, 20)) #grass surf.blit(textSurfaceObj, textRectObj) #draw title text pygame.init() DISPLAYSURF = pygame.display.set_mode((500, 400)) #main window pygame.display.set_caption('Launcher') #s = serial.Serial("/dev/ttyACM0") #uncomment eventually FPS = 30 #frames/s fpsClock = pygame.time.Clock() Launcher1 = Launcher.launcher(0, 380) rock1 = rock.Rock(0, 380) while (True): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: #rotate up Launcher1.changeAngle(3) if event.key == pygame.K_DOWN: #rotate down Launcher1.changeAngle(-3) if event.key == pygame.K_LEFT: #decrease power Launcher1.changeMagnitude(-5) if event.key == pygame.K_RIGHT: #increase power
def game_loop(): global pause default_font = pygame.font.Font("./fonts/NanumGothic.ttf", 28) background_image = pygame.image.load("./images/background.png") gameover_sound = pygame.mixer.Sound("./sounds/gameover.wav") pygame.mixer.music.load("./sounds/music.wav") pygame.mixer.music.play(-1) # 무한반복 fps_clock = pygame.time.Clock() players = player.Player() missile_group = pygame.sprite.Group() rock_group = pygame.sprite.Group() occur_prob = 40 shot_count = 0 count_missed = 0 done = False while not done: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: players.dx -= 5 elif event.key == pygame.K_RIGHT: players.dx += 5 elif event.key == pygame.K_UP: players.dy -= 5 elif event.key == pygame.K_DOWN: players.dy += 5 elif event.key == pygame.K_SPACE: missiles = missile.Missile(players.rect.centerx, players.rect.y, 10) missiles.launch() missile_group.add(missiles) elif event.key == pygame.K_p: pause = True paused() if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: players.dx = 0 elif event.key == pygame.K_UP or event.key == pygame.K_DOWN: players.dy = 0 screen.blit(background_image, background_image.get_rect()) occur_of_rocks = 1 + int(shot_count / 300) min_rock_speed = 1 + int(shot_count / 200) max_rock_speed = 1 + int(shot_count / 100) if random.randint(1, occur_prob) == 1: for i in range(occur_of_rocks): speed = random.randint(min_rock_speed, max_rock_speed) rocks = rock.Rock(random.randint(0, Window_width - 30), 0, speed) rock_group.add(rocks) draw_text("파괴한 운석: {}".format(shot_count), default_font, screen, 100, 20, YELLOW) draw_text("놓친 운석: {}".format(count_missed), default_font, screen, 400, 20, RED) for missiles in missile_group: rocks = missiles.collide(rock_group) # 미사일과 운석이 충돌한 경우 if rocks: missiles.kill() rocks.kill() occur_explosion(screen, rocks.rect.x, rocks.rect.y) shot_count += 1 for rocks in rock_group: if rocks.out_out_screen(): # 운석이 화면 밖으로 나간 경우 rocks.kill() count_missed += 1 rock_group.update() rock_group.draw(screen) missile_group.update() missile_group.draw(screen) players.update() players.draw(screen) pygame.display.flip() # 게임 종료 조건 if players.collide(rock_group) or count_missed >= 3: pygame.mixer_music.stop() occur_explosion(screen, players.rect.x, players.rect.y) pygame.display.update() gameover_sound.play() sleep(1) done = True fps_clock.tick(FPS) return "game_menu"
import random import pygame from colors import * from pygame.locals import * #needed for QUIT function to work from game_func import * #object modules import launcher import rock import target pygame.init() fpsClock = pygame.time.Clock() window = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) my_launcher = launcher.Launcher(0, WINDOWHEIGHT - 20) my_rock = rock.Rock(0, WINDOWHEIGHT - 20) #my_target = target.Target((random.random()*280)+100, WINDOWHEIGHT-20) my_target = target.Target(150, WINDOWHEIGHT - 20) FIRED = False #and ((my_target.y+5)<my_rock.y and my_rock.y < (my_target.y-5) ) def isHit(): if (((my_target.x - 20) < my_rock.x and my_rock.x < (my_target.x + 20)) and ((my_target.y - 5) > my_rock.y and my_rock.y < (my_target.y + 5))): return True else: return False