def execute(self, game): self.image = game.graphics['ship'] self.x, self.y = 500.0, 300.0 self.z = -512 while True: if Game.keyboard_key_down(K_LEFT): self.x -= 10.0 if Game.keyboard_key_down(K_RIGHT): self.x += 10.0 if Game.keyboard_key_down(K_UP): self.y -= 10.0 if Game.keyboard_key_down(K_DOWN): self.y += 10.0 yield
def pattern_vortex(self, x, y, type=0): _range = 0 if Game.keyboard_key_down(K_SPACE): _range = 10 if random.random() > 0.9: _range = 1 for c in range(_range): Shot(self, x, y)
def execute(self): # We want this entity to check for the escape key every frame, so we use a loop. while True: # Check for the escape key being pressed. if Game.keyboard_key_down(K_ESCAPE): # We can safely use the typical Python system method for quitting. sys.exit() # Each tick we leave the entity at the yield statement and will return here # in the next tick. If we returned instead of yielded our Entity would be # considered finished and would be destroyed. yield
def pattern_vortex(self, x, y, type = 0): _range = 1 amount = 10.0 if Game.keyboard_key_down(K_SPACE): _range = 10 amount = 5.0 for c in range(_range): if type: self.cur2 -= amount else: self.cur += amount if type: if self.cur2 < -360.0: self.cur2 = 0.0 else: if self.cur > 360.0: self.cur = 0.0 Shot(self, x, y, self.cur2 if type else self.cur)
def pattern_vortex(self, x, y, type=0): _range = 1 amount = 10.0 if Game.keyboard_key_down(K_SPACE): _range = 10 amount = 5.0 for c in range(_range): if type: self.cur2 -= amount else: self.cur += amount if type: if self.cur2 < -360.0: self.cur2 = 0.0 else: if self.cur > 360.0: self.cur = 0.0 Shot(self, x, y, self.cur2 if type else self.cur)
def execute(self): self._load_media() self._create_tests(TestNormal, TestImage, TestRotation, TestScaling, TestFlipHoriz, TestFlipVert, TestFlipBoth, TestAlpha, TestYellow, TestCyan, TestMagenta, TestZSort, TestPosition, TestBlend, TestHideShow, TestPriority, TestImageSequence, TestDrawCentrePoint, TestRotateCentrePoint, TestScaleCentrePoint, TestFlipCentrePoint, TestStopExecuting, TestClip, TestColourAndAlpha, TestTextPosition, TestTextRotation, TestTextScaling, TestTextXFlip, TestTextYFlip, TestTextXAndYFlip, TestTextAlpha, TestTextYellow, TestTextCyan, TestTextMagenta, TestTextBlend, TestTextShowAndHide, TestTextCentrePoint, TestTextAlignment, TestTextClip, TestTextShadow, TestMousePos, TestMouseButton, TestMouseWheel ) while True: if Game.keyboard_key_down(K_ESCAPE): sys.exit() yield
def execute(self): self.graphics = { "ship": Game.load_image(os.path.join("media", "ship.png")), "shot": Game.load_image(os.path.join("media", "shot.png")) } self.font = Game.load_font(size=50) Ship(self) self.fps_text = Game.write_text(0.0, 0.0, font=self.font, text=0) self.entity_text = Game.write_text(0.0, 40.0, font=self.font, text=0) Game.write_text(512.0, 730.0, font=self.font, text="Hold space to produce more entities", alignment=ALIGN_CENTRE) while True: if Game.keyboard_key_down(K_ESCAPE): sys.exit() self.pattern_vortex(300.0, 300.0, 1) self.pattern_vortex(700.0, 300.0) self.fps_text.text = "FPS " + str(Game.fps) self.entity_text.text = str(len(Game.entity_list)) + " entities" yield
def execute(self): self.graphics = { "ship" : Game.load_image(os.path.join("media", "ship.png")), "shot" : Game.load_image(os.path.join("media", "shot.png")) } self.font = Game.load_font(size = 50) Ship(self) self.fps_text = Game.write_text(0.0, 0.0, font = self.font, text = 0) self.entity_text = Game.write_text(0.0, 40.0, font = self.font, text = 0) Game.write_text( 512.0, 730.0, font = self.font, text = "Hold space to produce more entities", alignment = ALIGN_CENTRE ) while True: if Game.keyboard_key_down(K_ESCAPE): sys.exit() self.pattern_vortex(300.0, 300.0, 1) self.pattern_vortex(700.0, 300.0) self.fps_text.text = "FPS " + str(Game.fps) self.entity_text.text = str(len(Game.entity_list)) + " entities" yield
def execute(self): self.graphics = { "ship": Game.load_image(os.path.join("media", "ship.png")), "shot": Game.load_image(os.path.join("media", "shot.png")), } self.font = Game.load_font(size=50) # Ship(self) self.fps_text = Game.write_text(0.0, 0.0, font=self.font, text=0) self.entity_text = Game.write_text(0.0, 40.0, font=self.font, text=0) Game.write_text( 512.0, 730.0, font=self.font, text="Hold space to produce more entities", alignment=ALIGN_CENTRE ) # add bounds sx = Game.screen_resolution[0] sy = Game.screen_resolution[1] seg1 = Segment(space.static_body, Vec2d(0, 0), Vec2d(0, sy), 0) seg1.elasticity = 1.0 seg1.friction = 1.0 seg2 = Segment(space.static_body, Vec2d(0, sy), Vec2d(sx, sy), 0) seg2.elasticity = 1.0 seg2.friction = 1.0 seg3 = Segment(space.static_body, Vec2d(sx, sx), Vec2d(sx, 0), 0) seg3.elasticity = 1.0 seg3.friction = 1.0 # add everything into space space.add_static(seg1, seg2, seg3) while True: if Game.keyboard_key_down(K_ESCAPE): sys.exit() space.step(0.1) # TODO - use actual time delta self.pattern_vortex(300.0, 300.0, 1) self.fps_text.text = "FPS " + str(Game.current_fps) self.entity_text.text = str(len(Game.entity_list)) + " entities" yield