Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pygame.init()
pygame.display.init()
pygame.mouse.set_visible(0)
PGoJoyHandler = joystick()
get_config()
# VARIABLES
state_up = 0
state_down = 0
state_left = 0
state_right = 0
threshold = 1000 # Analogic middle to debounce
joystick = 0 # 0 is the 1sf joystick
# FF files
wait = pygame.image.load('/opt/retropie/configs/all/CRT/bin/ScreenUtilityFiles/resources/media/skin_automount_rotated/wait_%s.png'%RotationCurrentMode)
waitPos = wait.get_rect()
waitPos.center = ((x_screen/2), (y_screen/2))
extract = pygame.image.load('/opt/retropie/configs/all/CRT/bin/ScreenUtilityFiles/resources/media/skin_automount_rotated/extract_%s.png'%RotationCurrentMode)
extractPos = extract.get_rect()
extractPos.center = ((x_screen/2), (y_screen/2))
enabled = pygame.image.load('/opt/retropie/configs/all/CRT/bin/ScreenUtilityFiles/resources/media/skin_automount_rotated/enabled_%s.png'%RotationCurrentMode)
enabledPos = enabled.get_rect()
enabledPos.center = ((x_screen/2), (y_screen/2))
disabled = pygame.image.load('/opt/retropie/configs/all/CRT/bin/ScreenUtilityFiles/resources/media/skin_automount_rotated/disabled_%s.png'%RotationCurrentMode)
disabledPos = disabled.get_rect()
disabledPos.center = ((x_screen/2), (y_screen/2))
cancel = pygame.image.load('/opt/retropie/configs/all/CRT/bin/ScreenUtilityFiles/resources/media/skin_automount_rotated/cancel_%s.png'%RotationCurrentMode)
async def agent_loop(server_address="localhost:8000", agent_name="student"):
async with websockets.connect(f"ws://{server_address}/player") as websocket:
# Receive information about static game properties
await websocket.send(json.dumps({"cmd": "join", "name": agent_name}))
msg = await websocket.recv()
game_properties = json.loads(msg)
# You can create your own map representation or use the game representation:
mapa = Map(size=game_properties["size"], mapa=game_properties["map"])
# Next 3 lines are not needed for AI agent
SCREEN = pygame.display.set_mode((299, 123))
SPRITES = pygame.image.load("data/pad.png").convert_alpha()
SCREEN.blit(SPRITES, (0, 0))
while True:
try:
state = json.loads(
await websocket.recv()
) # receive game state, this must be called timely or your game will get out of sync with the server
# Next lines are only for the Human Agent, the key values are nonetheless the correct ones!
key = ""
for event in pygame.event.get():
if event.type == pygame.QUIT or not state["lives"]:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
pygame.font.init()
basicfont = pygame.font.SysFont(None, 30)
oldkps, oldkp, oldtrim, oldgyro = str(0),str(0),str(0), str(0)
pygame.init()
clock = pygame.time.Clock()
size = width, height = 1200, 500
screen=pygame.display.set_mode(size)
############ Load art work ##############################
joytop = pygame.image.load('images/joytopglow.png')
joybase = pygame.image.load('images/joybase.png')
minus = pygame.image.load('images/minus.png')
plus = pygame.image.load('images/plus.png')
pluslight = pygame.image.load('images/pluslight.png')
minuslight = pygame.image.load('images/minuslight.png')
gTrim = pygame.image.load('images/Trim.png')
gTrimlight = pygame.image.load('images/Trimlight.png')
record = pygame.image.load('images/record.png')
pause = pygame.image.load('images/pause.png')
stop = pygame.image.load('images/stop.png')
play = pygame.image.load('images/play.png')
cmdpause = pygame.image.load('images/cmdpause.png')
cmdrecord = pygame.image.load('images/cmdrecord.png')
trash = pygame.image.load('images/trash.png')
trashlight = pygame.image.load('images/trashlight.png')
######################## initialize variables #################
timestart = time()
cmdwrite = 0
button1,button2,button3,button4,button5,button6,button7, button8, button9 ,button10, button11 ,button12 , toggle, toggle2, toggle3 = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
x,y = 0,0
for event in pygame.event.get():
if event.type == pygame.QUIT:
if QuitMessage not in [type(obj) for obj in self.persistent_guis]: # stops recalling when active
self.quit_message()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE or (event.key == pygame.K_F4 and event.mod == pygame.KMOD_ALT):
self.state = "quit"
elif event.key == pygame.K_m:
self.state = "menu"
elif event.key == pygame.K_s: # Screenshot (saves view_surface and game_surface)
pygame.image.save(self.game_view.game_surface.main_surface,
self.model_link.game_name + str(time.time()) + ".png")
pygame.image.save(self.display,
self.model_link.game_name + str(time.time()) + "display" + ".png")
elif event.type == pygame.MOUSEBUTTONDOWN:
self.handle_click(mouse_x, mouse_y)
# Drawing
self.draw()
pygame.display.update()
# Here has been game quit, returns to controller call, where save and new state are processed.
return self.state
def main():
# Global Variables (They aren't so evil after all)
global DISPLAYSURF, FPSCLOCK, FPS, PLAYER_LIST, LIST_OF_OBJECTS, LIST_OF_ENEMIES, IMAGE_LIBRARY, WINDOWWIDTH, WINDOWHEIGHT, scale_X, scale_Y
# A Library for all the graphics
IMAGE_LIBRARY = { 'Fumiko': pygame.image.load("Fumiko.png"),
'empty': pygame.image.load("charempty.png"),
'Chipset_1': pygame.image.load("Chipset_1.png"),
'BG_1': pygame.image.load("BG_2.jpg"),
'Object_Rock': pygame.image.load("rock_smaller.png"),
'Object_Rock_2': pygame.image.load("rock.png"),
'Object_Grass': pygame.image.load("grass.png"),
'Object_Grass_2': pygame.image.load("grass_2.png"),
'Boss_A': pygame.image.load("mons6.png"),
'Monsters': pygame.image.load("Monster_Charset.png"),
'Monsters_Bigger': pygame.image.load("Monster_Charset_Bigger.png")
}
PLAYER_LIST = []
LIST_OF_OBJECTS = []
LIST_OF_ENEMIES = []
FPS = 30
def __init__(self,x,y):
Maproom.__init__(self,x,y)
self.background = pygame.image.load('./pics/room-bginn1_3.bmp').convert()
self.gameobjects.append(Tree2(10,20))
self.gameobjects.append(Tree2(200,70))
self.gameobjects.append(Tree2(400,10))
self.guardian = InnGuardian(160,320)
self.gameobjects.append(self.guardian)
self.gameobjects.append(Dungeonwall(0,0,100,500))
self.gameobjects.append(Dungeonwall(200,0,100,500))
# Inn walls
self.gameobjects.append(Dungeonwall(0,175,150,400))
self.gameobjects.append(Dungeonwall(250,250,250,250))
reset_bodies(space)
selected = None
if not is_interactive:
pygame.time.set_timer(USEREVENT+1, 70000) # apply force
pygame.time.set_timer(USEREVENT+2, 120000) # reset
pygame.event.post(pygame.event.Event(USEREVENT+1))
pygame.mouse.set_visible(False)
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
elif event.type == KEYDOWN and event.key == K_p:
pygame.image.save(screen, "newtons_cradle.png")
if event.type == pygame.USEREVENT+1:
r = random.randint(1,4)
for body in bodies[0:r]:
body.apply_impulse_at_local_point((-6000,0))
if event.type == pygame.USEREVENT+2:
reset_bodies(space)
elif event.type == KEYDOWN and event.key == K_r and is_interactive:
reset_bodies(space)
elif event.type == KEYDOWN and event.key == K_f and is_interactive:
r = random.randint(1,4)
for body in bodies[0:r]:
body.apply_impulse_at_local_point((-6000,0))
elif event.type == MOUSEBUTTONDOWN and is_interactive:
img.set_colorkey(BLACK)
## resize the explosion
img_lg = pygame.transform.scale(img, (75, 75))
explosion_anim['lg'].append(img_lg)
img_sm = pygame.transform.scale(img, (32, 32))
explosion_anim['sm'].append(img_sm)
## player explosion
filename = 'sonicExplosion0{}.png'.format(i)
img = pygame.image.load(path.join(img_dir, filename)).convert()
img.set_colorkey(BLACK)
explosion_anim['player'].append(img)
## load power ups
powerup_images = {}
powerup_images['shield'] = pygame.image.load(path.join(img_dir, 'shield_gold.png')).convert()
powerup_images['gun'] = pygame.image.load(path.join(img_dir, 'bolt_gold.png')).convert()
###################################################
###################################################
### Load all game sounds
shooting_sound = pygame.mixer.Sound(path.join(sound_folder, 'pew.wav'))
missile_sound = pygame.mixer.Sound(path.join(sound_folder, 'rocket.ogg'))
expl_sounds = []
for sound in ['expl3.wav', 'expl6.wav']:
expl_sounds.append(pygame.mixer.Sound(path.join(sound_folder, sound)))
## main background music
#pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg'))
pygame.mixer.music.set_volume(0.2) ## simmered the sound down a little
def __init__(self, position, **data):
self.path = ""
self.originalSurface = None
self.transparent = True
if "path" in data:
self.path = data["path"]
else:
self.path = "surface"
if "surface" not in data:
data["surface"] = pygame.image.load(data["path"])
self.originalSurface = data["surface"]
super(GUI.Image, self).__init__(position, **data)
def __init__(self, desc="4x4", save=False, reward_func="sparse"):
# new health counter
# gets reduced when we touch fire
self.health0 = self.health = 100.0
self.orientation0 = self.orientation = 90 # 0=look up, 90=look right, 180=look down, 270=look left
super().__init__(desc, save, "sparse")
self.reward_func = reward_func
# create the pygame-render data structures
self.pyg_field_size = 25
self.surface = pygame.Surface((self.pyg_field_size*self.n_col, self.pyg_field_size*self.n_row), flags=pygame.SRCALPHA)
self.surface_pix = pygame.surfarray.pixels3d(self.surface) # fixed ndarray link into the surface pixel values
# load the images
self._img_pawn = pygame.image.load("images/mario.png").convert_alpha()
self._img_wall = pygame.image.load("images/wall.png").convert_alpha()
self._img_goal = pygame.image.load("images/goal.png").convert_alpha()
self._img_fire = pygame.image.load("images/fire.png").convert_alpha()