示例#1
0
	def __init__(self):
		self.screenSize = (800,800)
		self.running = False
		self.spawn = Spawn([self.screenSize[0]/2, self.screenSize[1]/2])
		self.foragers = []
		self.food = []
		self.frame_num = 0
		self.draw_sensors = True
示例#2
0
pygame.display.set_caption("2D shooting game")
shot = pygame.mixer.Sound('sounds/shot.wav')
bruh = pygame.mixer.Sound('sounds/bruh.wav')
ploo = pygame.mixer.Sound('sounds/ploo.wav')
konichiwa = pygame.mixer.Sound('sounds/konichiwa.wav')
brk = pygame.mixer.Sound('sounds/brk.wav')
pygame.mixer_music.load('sounds/bg_music.wav')
enemy_shot = pygame.mixer.Sound('sounds/enemy_shot.wav')
hit_sound = pygame.mixer.Sound('sounds/hit_sound.wav')
coin_sound = pygame.mixer.Sound('sounds/coin_sound.wav')
laugh = pygame.mixer.Sound('sounds/laugh.wav')
sneeze_sound = pygame.mixer.Sound('sounds/sneeze.wav')
pygame.mixer_music.play(-1)

# //////////////////////////////////////////////// create objects //////////////////////////////////////
maor = Spawn(590, 300, 'images/faces/maor.png', 'images/faces/maor2.png', 5, konichiwa, 'images/bullets/asian.png',
             time.perf_counter(), random.randint(2, 7), t_spawn_created_list, displayed_score_counter, -1)
ido = Spawn(590, 300, 'images/faces/ido.png', 'images/faces/ido2.png', 5, ploo, 'images/bullets/shnitzel.png',
            time.perf_counter(), random.randint(2, 7), t_spawn_created_list, displayed_score_counter, -1)
tom = Spawn(590, 300, 'images/faces/tom.png', 'images/faces/tom2.png', 5, bruh, 'images/bullets/chains.png',
            time.perf_counter(), random.randint(2, 7), t_spawn_created_list, displayed_score_counter, -1)
bar = Spawn(590, 300, 'images/faces/bar.png', 'images/faces/bar2.png', 5, brk, 'images/bullets/penisr.png',
            time.perf_counter(), random.randint(2, 7), t_spawn_created_list, displayed_score_counter, -1)
maors_girl_object = CheeringObject(500, 400, maors_girl, laugh)
lose_button = Lose()
dror_char = player.Player()
play_button = Button(535, 0, 'images/others/play_button.png')

childs_list = [[maor, 'images/bullets/asian.png', konichiwa, 'images/faces/maor.png', 'images/faces/maor2.png'],
               [ido, 'images/bullets/shnitzel.png', ploo, 'images/faces/ido.png', 'images/faces/ido2.png'],
               [tom, 'images/bullets/chains.png', bruh, 'images/faces/tom.png', 'images/faces/tom2.png'],
               [bar, 'images/bullets/penisr.png', brk, 'images/faces/bar.png', 'images/faces/bar2.png']]
示例#3
0
文件: data.py 项目: jonzxz/BDOBot
from Spawn import Spawn
import datetime as dt
"""
This file contains data that will be used by other classes/functions
week - contains Spawn data for the week with the keys being days of week
failstack - still a work in progress, to be redone
"""

week = {
    0: [  #MONDAY
        Spawn(dt.time(hour=1, minute=30, second=0), 'Kutum'),
        Spawn(dt.time(hour=11, minute=0, second=0), ['Kzarka', 'Nouver']),
        Spawn(dt.time(hour=15, minute=0, second=0), ['Kutum', 'Nouver']),
        Spawn(dt.time(hour=20, minute=0, second=0), ['Karanda', 'Kzarka']),
        Spawn(dt.time(hour=23, minute=59, second=59), 'Offin')
    ],
    1: [  #TUESDAY
        Spawn(dt.time(hour=1, minute=30, second=0), 'Nouver'),
        Spawn(dt.time(hour=11, minute=0, second=0), ['Karanda', 'Kutum']),
        Spawn(dt.time(hour=15, minute=0, second=0), ['Kutum', 'Kzarka']),
        Spawn(dt.time(hour=20, minute=0, second=0), ['Muraka', 'Quint']),
        Spawn(dt.time(hour=23, minute=59, second=59), 'Garmoth')
    ],
    2: [  #WEDNESDAY
        Spawn(dt.time(hour=1, minute=30, second=0), ['Kzarka', 'Offin']),
        Spawn(dt.time(hour=11, minute=0, second=0), ['Nouver', 'Kutum']),
        Spawn(dt.time(hour=15, minute=0, second=0), ['Karanda', 'Kzarka']),
        Spawn(dt.time(hour=20, minute=0, second=0), ['Kutum', 'Nouver']),
        Spawn(dt.time(hour=23, minute=59, second=59), 'Vell')
    ],
    3: [  #THURSDAY
示例#4
0
class Simulation:
	drawing       = True
	lighting_mode = True
	food_respawn  = False

	def __init__(self):
		self.screenSize = (800,800)
		self.running = False
		self.spawn = Spawn([self.screenSize[0]/2, self.screenSize[1]/2])
		self.foragers = []
		self.food = []
		self.frame_num = 0
		self.draw_sensors = True
		
	
	def init(self):
		# Pygame init
		pygame.init()
		self.screen = pygame.display.set_mode(self.screenSize)
		self.font = pygame.font.SysFont("monospace", 15)
		

	def copy(self):
		new_sim = Simulation()
		new_sim.foragers = deepcopy(self.foragers)
		new_sim.food = deepcopy(self.food)
		return new_sim


	def startLoop(self):
		self.running = True
		while self.running:
			self.nextFrame()

	def nextFrame(self):
		self.__checkEvents()
		if Simulation.drawing: self.__draw()
		self.__checkCollisions()
		self.__move()

		self.frame_num += 1
		if not Simulation.lighting_mode: time.sleep(1.0/100.0)

	def spawnForager(self):
		pos = self.spawn.pos[:]
		pos[0] += randint(-1*self.spawn.radius, self.spawn.radius)
		pos[1] += randint(-1*self.spawn.radius, self.spawn.radius)
		theta = randint(0,3)*math.pi/2
		self.foragers.append(Forager(pos, theta))
	
	def spawnFood(self):
		pos = self.spawn.pos[:]
		dx = randint(self.spawn.radius, self.screenSize[0]/2)
		dy = randint(self.spawn.radius, self.screenSize[1]/2)
		pos[0] += dx * (-1 if randint(0,1) == 0 else 1)
		pos[1] += dy * (-1 if randint(0,1) == 0 else 1)
		self.food.append(Food(pos))

	def __checkEvents(self):
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				self.running = False
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_SPACE:
					Simulation.drawing = (False if Simulation.drawing else True)
					print "Toggled drawing to %s" % Simulation.drawing
				if event.key == pygame.K_l:
					Simulation.lighting_mode = (False if Simulation.lighting_mode else True)
					print "Toggled lighting_mode to %s" % Simulation.lighting_mode

	def __draw(self):
		self.screen.fill((255,255,255))
		self.spawn.draw(self.screen)

		# Draw foragers
		total_food = 0
		for forager in self.foragers:
			forager.draw(self.screen)
			if self.draw_sensors: forager.drawSensor(self.screen)
			total_food += forager.food_collected

		# Draw score
		label = self.font.render("Food Collected: %s" % total_food, 1, (0,0,0))
		self.screen.blit(label, (20, 20))

		# Draw food
		for food in self.food:
			food.draw(self.screen)
		pygame.display.flip()

	def __move(self):
		for forager in self.foragers:
			forager.move()

	def __checkCollisions(self):
		for forager in self.foragers:
			collissions = forager.checkCollisions(self.food, self.spawn)
			for i in range(0,collissions):
				if Simulation.food_respawn: self.spawnFood()

	def allOffScreen(self):
		on_screen = False
		for forager in self.foragers:
			if (forager.pos[0] > forager.radius) and (forager.pos[0] - forager.radius < self.screenSize[0]) and (forager.pos[1] > forager.radius) and (forager.pos[1] - forager.radius < self.screenSize[1]):
				on_screen = True
				break

		return not on_screen