예제 #1
0
 def update_confined(self):
     World.remove(self.mouse_confined_button)
     if Settings.mouse_confined:
         self.mouse_confined_button.texts[0].set_text('Mouse confined')
     else:
         self.mouse_confined_button.texts[0].set_text('Mouse unconfined')
     World.add(self.mouse_confined_button)
예제 #2
0
 def spawn(coordinates, main_character=None):
     if main_character is None:
         main_character = Settings.main_character_name
     mc = eval('%s()' % main_character)
     mc.coordinates = coordinates
     World.promote_main(mc)
     World.add(mc)
예제 #3
0
 def add_buttons(self, arr, starting_index, finishing_index):
     g = self.generate_buttons(arr, starting_index, finishing_index)
     i = next(g)
     while i:
         self.buttons.append(i)
         World.add(i)
         i = next(g)
예제 #4
0
 def load(self):
     for obj in self.world:
         World.add(obj)
         if 'spawn' in obj.type:
             self.spawn = obj
         if 'target' in obj.type:
             self.targets.append(obj)
     GameStates.spawn(self.spawn.get_coordinates())
예제 #5
0
 def click_rename(self):
     name = input('New name: ')
     p = Level.default_path + '\\' + name + '.txt'
     os.rename(self.path, p)
     self.path = p
     World.remove(self.name_label)
     self.display_name()
     print('Saved as: ' + p)
예제 #6
0
 def add_characters(self, arr, starting_index, finishing_index):
     g = self.generate_characters(arr, starting_index, finishing_index)
     i = next(g)
     while i[0]:
         self.characters.append(i[0])
         World.add(i[0])
         self.buttons.append(i[1])
         World.add(i[1])
         i = next(g)
예제 #7
0
 def create_gravity_field(self):
     if World.main_character is not None:
         if KeyLogger.bindings['gravity'].check():
             gf = NormalGravityField()
             gf.coordinates = Mouse.get_real_coordinates() - Coordinates(
                 gf.width / 2, gf.height / 2)
             gf.type.append('unmovable')
             World.add(gf)
             return True
     return False
예제 #8
0
 def change_submenu(self, new_submenu):
     if self.state in [self.GAME, self.BUILDER]:
         thread_lock.pause_main = True
         World.pause()
         pygame.event.set_grab(False)
     else:
         self.menu_library.menus[self.submenu].end()
         self.menu_library.menus[self.submenu].empty()
     self.submenu = new_submenu
     self.menu_library.menus[self.submenu].begin()
     self.menu_library.menus[self.submenu].load()
     self.state = self.MENU
     self.sleep()
예제 #9
0
 def back(self):
     if self.back_number == 0:
         event = pygame.event.Event(pygame.QUIT, {})
         pygame.event.post(event)
     elif self.back_number == 1:
         thread_lock.pause_main = False
         World.resume()
         self.gamestates.state = self.gamestates.BUILDER
         self.empty()
         self.gamestates.sleep()
     elif self.back_number == 2:
         thread_lock.pause_main = False
         World.resume()
         self.gamestates.state = self.gamestates.GAME
         self.empty()
         self.gamestates.sleep()
     else:
         self.change_to(self.back_number)
예제 #10
0
 def run(self):
     for game_object in World.get_display():
         c = game_object.get_coordinates()
         scale = Frame.scale
         if 'fixed' not in game_object.type:
             c += Frame.default_coordinates
             c *= Settings.frame_additional_scale
         for animation in game_object.animations:
             self.blit(animation.get_texture(),
                       c + animation.get_coordinates(), scale)
         for text in game_object.texts:
             self.blit(text.get_texture(), c + text.get_coordinates(),
                       scale)
     self.fps_counter.set_text(str(int(self.fps_clock.get_fps())))
     self.blit(self.fps_counter.get_texture(), Coordinates(10, 0),
               Frame.scale)
     self.fps_clock.tick(Frame.max_fps)
     try:
         pygame.display.update()
     except pygame.error:
         pass
예제 #11
0
 def click_play(self):
     self.end()
     self.empty()
     bck = Background('resources\\test_images\\white_background.png')
     World.add(bck)
     level = Level(self.gamestates, self.path.split('\\')[-1][:-4])
     World.setup_level(level)
     World.add(self.gamestates.target_label)
     thread_lock.pause_main = False
     self.gamestates.state = self.gamestates.GAME
     Frame.default_coordinates = Coordinates(0, 0)
     if Borders.focus_object is None:
         Borders.gain_focus(World.main_character)
     Borders.lock()
     pygame.event.set_grab(Settings.mouse_confined)
     self.gamestates.sleep()
예제 #12
0
 def click_build(self):
     self.empty()
     bck = Background('resources\\test_images\\white_background.png')
     World.add(bck)
     save_button = SaveButton()
     save_button.coordinates = Coordinates(650, 500)
     World.add(save_button)
     level = Level(self.gamestates, '')
     World.setup_level(level)
     thread_lock.pause_main = False
     self.gamestates.state = self.gamestates.BUILDER
     Frame.default_coordinates = Coordinates(0, 0)
     if Borders.focus_object is None:
         Borders.gain_focus(World.main_character)
     Borders.lock()
     pygame.event.set_grab(Settings.mouse_confined)
     self.gamestates.sleep()
예제 #13
0
 def end(self):
     World.remove(self.name_label)
예제 #14
0
 def remove_characters(self):
     for i in self.characters:
         World.remove(i)
     for i in self.buttons:
         World.remove(i)
예제 #15
0
 def display_name(self):
     name = Settings.main_character_name
     lname = LevelName('Character selected:   ' + name, 30,
                       Coordinates(200, 50))
     self.name_label = lname
     World.add(lname)
예제 #16
0
 def end(self):
     World.remove(self.name_label)
     self.remove_characters()
예제 #17
0
 def f():
     Settings.main_character_name = name
     Settings.write_settings()
     World.remove(self.name_label)
     self.display_name()
예제 #18
0
 def begin(self):
     World.full_clear()
예제 #19
0
 def remove_buttons(self):
     for i in self.buttons:
         World.remove(i)
예제 #20
0
 def world_remove(self):
     World.remove(self)
예제 #21
0
 def load(self):
     for obj in self.world:
         World.add(obj)
 def click(self):
     World.write()
예제 #23
0
 def end(self):
     World.full_clear()
예제 #24
0
 def click_main_menu(self):
     World.full_clear()
     self.change_to(4)
예제 #25
0
from main_game.game_states import GameStates
from objects.images.animation_library import AnimationLibrary
from physics.coordinates import Coordinates
from frame.settings import Settings
from objects.game_object.dinamic.obstacles.blocks.grey_block import GreyBlock
from objects.game_object.dinamic.obstacles.targets.classic_target import ClassicTarget
from frame.borders import Borders
from main_game.level import Level
from objects.widgets.buttons.save_button import SaveButton

Settings()
ImageLibrary()
frame = Frame()
AnimationLibrary(frame)
Borders()
World()
KeyLogger()
Mouse()

Borders.lock()
game_states = GameStates()
game_states.change_submenu(4)
game_states.state = GameStates.MENU

if __name__ == '__main__':
    running = True

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                Settings.write_settings()
예제 #26
0
 def hover():
     for world in World.get_selectable():
         for obj in world:
             if Mouse.hovering(obj):
                 return obj
     return None
예제 #27
0
 def fire_normal_bullet(self, direction):
     bullet = NormalBullet(direction)
     bullet.coordinates = self.get_firing_coordinates()
     World.add(bullet)
예제 #28
0
 def display_name(self):
     name = self.path.split('\\')[-1][:-4]
     lname = LevelName(name, 50, Coordinates(100, 100))
     self.name_label = lname
     World.add(lname)
예제 #29
0
 def end(self):
     World.remove(self.mouse_confined_button)