Exemplo n.º 1
0
 def test_load_twice(self, inp, pr, cor):
     print("DICT")
     print(editor.frame_dict)
     with mock.patch('editor.print') as my_print:
         editor.load('some/path', 'name1')
         my_print.assert_any_call(red_start + 'фрагмент с именем ' +
                                  'name1' +
                                  ' уже существует, попробуйте снова' +
                                  red_end)
Exemplo n.º 2
0
	def __init__(self, connection):
		self.name = editor.load('username.txt',errors=True,cf=True)
		self.curdata = ""; self.prevdata = ""
		self.root = pepper.d2GameScreen(rootgeo=(500,400),roottitle="Wizards Alpha 0.1")
		self.root.clear(pepper.GameSquare('lime green'))
		self.root.root.bind("<Key>", self.keyPress)
		self.root.root.bind("<Button>", self.buttonPress)
		self.server = SERVER.Server()
		self.data = "Login from '"+self.name+"';"; self.update()
Exemplo n.º 3
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((800,600))

    player = Ball()

    clock = pygame.time.Clock()

    c =  PlatformCamera(player,screen)

    # Set up the scenes
    winScene = Scene([WinScene()],c,name="WinScene")
    startScreen = Scene([StartScreen("tut1")],c,name="StartScene")
    gameOverScene = Scene([GameOver()],c,name="GameOver")

    tut1 = Scene(editor.load("levels/tutorial/01.lvl")+[player],c,name="tut1")
    tut2 = Scene(editor.load("levels/tutorial/02.lvl")+[player],c,name="tut2")
    tut3 = Scene(editor.load("levels/tutorial/03.lvl")+[player],c,name="tut3")
    tut4 = Scene(editor.load("levels/tutorial/04.lvl")+[player],c,name="tut4")

    lvl1 = Scene(editor.load("levels/lvl1.lvl")+[player],c,name="lvl1")

    test = Scene(editor.load("levels/foo.lvl")+[player],c,name="foo")


    # Start the game
    Game.start([test
               ,startScreen
               ,gameOverScene
               ,winScene
               ,tut1
               ,tut2
               ,tut3
               ,tut4
               ,lvl1],screen)
Exemplo n.º 4
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))

    player = Ball()

    clock = pygame.time.Clock()

    c = PlatformCamera(player, screen)

    # Set up the scenes
    winScene = Scene([WinScene()], c, name="WinScene")
    startScreen = Scene([StartScreen("tut1")], c, name="StartScene")
    gameOverScene = Scene([GameOver()], c, name="GameOver")

    tut1 = Scene(editor.load("levels/tutorial/01.lvl") + [player],
                 c,
                 name="tut1")
    tut2 = Scene(editor.load("levels/tutorial/02.lvl") + [player],
                 c,
                 name="tut2")
    tut3 = Scene(editor.load("levels/tutorial/03.lvl") + [player],
                 c,
                 name="tut3")
    tut4 = Scene(editor.load("levels/tutorial/04.lvl") + [player],
                 c,
                 name="tut4")

    lvl1 = Scene(editor.load("levels/lvl1.lvl") + [player], c, name="lvl1")

    test = Scene(editor.load("levels/foo.lvl") + [player], c, name="foo")

    # Start the game
    Game.start([
        test, startScreen, gameOverScene, winScene, tut1, tut2, tut3, tut4,
        lvl1
    ], screen)
Exemplo n.º 5
0
def main(mapFilepath):

	# Pygame set up
	# -----------------------------------------------------------
	screen=pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT), 0, 32)
	pygame.display.set_caption('Simple pygame example')
	clock=pygame.time.Clock()
	rd.seed()

	terrainGroup.empty()

	bigmap = pygame.Surface((g.BIGMAP_WIDTH+SCREEN_WIDTH, g.BIGMAP_HEIGHT+SCREEN_HEIGHT))
	bigmap.fill(WHITE)
		# ------- create background ---------------- subsurface of bigmap (what will be on the screen)
	background = pygame.Surface(screen.get_size()) #surface the size of the screen
	backgroundRect = background.get_rect() #create rectangle the size of background/the screen
	background = bigmap.subsurface((g.CORNERPOINT[0], g.CORNERPOINT[1], SCREEN_WIDTH, SCREEN_HEIGHT)) #take snapshot of bigmap
	background = background.convert()



	# --- pybox2d world setup -----------------------------------
	# Create the world
	_world = world(gravity=(0,-10),doSleep=True)

	# And a static body to hold the ground shape
	ground= StaticObject(_world, (0, g.BIGMAP_HEIGHT - 25), (g.BIGMAP_WIDTH,25))
	createEdges(_world, (g.BIGMAP_WIDTH,g.BIGMAP_HEIGHT))

	# add a crate
	# for i in xrange(200):
	# 	Crate(_world, (rd.randint(0, 700), rd.randint(0, 400)))
	# ledge = Ledge(_world, ground, leftpoint = (800,600), width = 400)
	# Ledge(_world, ground, leftpoint = (200,200), width = 500)
	# Ledge(_world, ground, leftpoint = (500,250), width = 500)


	# --------------------------------------------------------
	# --- Game setup -----------------------------------------
	mainLoop = True


	spawnPos = editor.load(mapFilepath, _world, ground)
	player = Player(_world, spawnPos)

	vampire1 = Vampire(_world, (800, 400), target = player)
	zombie = Zombie(_world, (800,400), target =player)
	Zombie(_world, (900,300), target =player)
	Zombie(_world, (1100,400), target =player)
	Zombie(_world, (1000,200), target =player)
	Skull(_world, (600,600))
	MonsterSpawn(_world, (700,700), Skull, monster_cooldown = 4, duration = -1, online = True)
	scrollx = 0
	scrolly = 0

	weapons1 = [Rifle(player), Hadouken(player), BaseballBat(player), megaBall(player),GrapplingHook(player), Grenade(player), BouncingBall(player), FragmentedBall(player), MiniBouncingBall(player)]
	weapons2 = [megaBall(player),GrapplingHook(player), Grenade(player)]
	weapon1_index = 0
	weapon2_index = 0
	player.weapon1 = weapons1[0]
	player.weapon2 = weapons2[2]

	gui = GUI.GameGUI(_world, ground, player)




	while mainLoop :
 		milliseconds = clock.tick(TARGET_FPS)
		seconds = milliseconds / 1000.0


		for event in pygame.event.get():
			if event.type==QUIT or (event.type==KEYDOWN and event.key==K_ESCAPE):
				mainLoop = False

			elif event.type == KEYDOWN :
				if event.key == K_d :
					g.K_RIGHT = True

				elif event.key == K_a :
					g.K_LEFT = True

				if event.key == K_SPACE :
					player.jump()
				elif event.key == K_s :
					g.K_DOWN = True
				# elif event.key == K_z :
				# 	player.stand()

			elif event.type == KEYUP:
				if event.key == K_d :
					g.K_RIGHT = False
					#player.stop()
					player.go(0,player.accel)
				elif event.key == K_a :
					g.K_LEFT = False
					#player.stop()
					player.go(0,player.accel)
				elif event.key == K_s :
					g.K_DOWN = False
				elif event.key == K_x :
					weapon1_index = (weapon1_index +1) % len(weapons1)
					player.weapon1 = weapons1[weapon1_index]
				elif event.key == K_z :
					weapon2_index = (weapon2_index +1) % len(weapons2)
					player.weapon2 = weapons2[weapon2_index]




			if event.type == MOUSEMOTION :
				cursor.update()

			if event.type == MOUSEBUTTONDOWN :
				if event.button == 1:
					g.LEFT_CLICK = True
					if geo.distance(player.pos, cursor.pos) <= player.weapon1.weapon_range :
						player.left_click(cursor.rect.topleft)
				if event.button == 3:
					g.RIGHT_CLICK = True
					if geo.distance(player.pos, cursor.pos) <= player.weapon2.weapon_range :
						player.right_click(cursor.rect.topleft)
				elif event.button == 4 :
					player.rotateLeft()
				elif event.button == 5 :
					player.rotateRight()
			elif event.type == MOUSEBUTTONUP :
				if event.button == 1:
					g.LEFT_CLICK = False
					player.weapon1.deactivate(cursor.rect.topleft)
				if event.button == 3:
					g.RIGHT_CLICK = False
					player.weapon2.deactivate()
		if g.K_RIGHT :
			if g.TIMEON:
				player.goRight()


		if g.K_LEFT:
			if g.TIMEON:
				player.goLeft()

		# if pygame.sprite.spritecollideany(player.feet, ledgeGroup):
		# 	player.onLedge = True
		# else :
		# 	player.onLedge = False






		# -------- Scrolling  with keyboard------------------

		pressedKeys = pygame.key.get_pressed()
		# what happens when u press an arrow to move screen
		if pressedKeys[K_LEFT]:
			scrollx -= g.scrollStepx
		if pressedKeys[K_RIGHT]:
			scrollx += g.scrollStepx
		if pressedKeys[K_DOWN]:
			scrolly += g.scrollStepy
		if pressedKeys[K_UP]:
			scrolly -= g.scrollStepy
		# ---- scroll the screen --------
		g.CORNERPOINT[0] += scrollx
		g.CORNERPOINT[1] += scrolly

		#----- prevent scrolling out of the map
		if g.CORNERPOINT[0] < 0:
			g.CORNERPOINT[0]=0
			scrollx = 0
		elif g.CORNERPOINT[0] > g.BIGMAP_WIDTH - SCREEN_WIDTH :
			g.CORNERPOINT[0] = g.BIGMAP_WIDTH - SCREEN_WIDTH
			scrollx = 0
		if g.CORNERPOINT[1] < 0:
			g.CORNERPOINT[1] = 0
			scrolly = 0
		elif g.CORNERPOINT[1] > g.BIGMAP_HEIGHT - SCREEN_HEIGHT :
			g.CORNERPOINT[1] = g.BIGMAP_HEIGHT - SCREEN_HEIGHT
			scrolly =0
		# making sure charcater is in middle of screen
		g.CORNERPOINT[0] = geo.maximum(player.pos[0] - SCREEN_WIDTH/2, 0)
		g.CORNERPOINT[1] = geo.maximum(player.pos[1] - SCREEN_HEIGHT/2, 0)

		scrollx = 0
		scrolly = 0



		# ---- update shit and draw allGroup ----------------
		background = bigmap.subsurface((g.CORNERPOINT[0], g.CORNERPOINT[1], SCREEN_WIDTH, SCREEN_HEIGHT))
		screen.blit(background, (0,0))
		allGroup.update(seconds)

		# destroy bodies out of the time step else issues
		for body in g.TO_DESTROY :
			_world.DestroyBody(body)
			g.TO_DESTROY.remove(body)
		g.TO_DESTROY = []

		for timer in g.TIMERS :
			timer.update(seconds)
		# take a time step in box2d engine
		_world.Step(TIME_STEP, 10, 10)
		gui.update()
		allGroup.draw(screen)
		pygame.display.flip()
Exemplo n.º 6
0
 def test_load(self, inp, pr, cor):
     print(editor.frame_dict)
     with mock.patch('editor.print') as my_print:
         editor.load('some/path', 'name1')
         my_print.assert_any_call(red_start + "CREATE" + red_end)