Move first steps scripts to their own directory
This commit is contained in:
		
							parent
							
								
									1244c97493
								
							
						
					
					
						commit
						cc6c701c59
					
				
					 2 changed files with 0 additions and 0 deletions
				
			
		
							
								
								
									
										40
									
								
								first_steps/01_fixed_size_console.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								first_steps/01_fixed_size_console.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,40 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
# Make sure 'dejavu10x10_gs_tc.png' is in the same directory as this script.
 | 
			
		||||
import tcod
 | 
			
		||||
 | 
			
		||||
WIDTH, HEIGHT = 80, 60  # Console width and height in tiles.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> None:
 | 
			
		||||
    """Script entry point."""
 | 
			
		||||
 | 
			
		||||
    # Load the font, a 32 by 8 tile font with libtcod's old character layout.
 | 
			
		||||
    tileset = tcod.tileset.load_tilesheet(
 | 
			
		||||
        "fonts/terminal16x16_gs_ro.png", 16, 16, tcod.tileset.CHARMAP_CP437,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # Create the main console.
 | 
			
		||||
    console = tcod.Console(WIDTH, HEIGHT, order="F")
 | 
			
		||||
 | 
			
		||||
    # Create a window based on this console and tileset.
 | 
			
		||||
    # New window for a console of size columns×rows.
 | 
			
		||||
    with tcod.context.new(columns=console.width, rows=console.height, tileset=tileset) as context:
 | 
			
		||||
        # Main loop, runs until SystemExit is raised.
 | 
			
		||||
        while True:
 | 
			
		||||
            console.clear()
 | 
			
		||||
            console.print(x=0, y=0, string="Hello World!")
 | 
			
		||||
            context.present(console)  # Show the console.
 | 
			
		||||
 | 
			
		||||
            # This event loop will wait until at least one event is processed before exiting.
 | 
			
		||||
            # For a non-blocking event loop replace  with .
 | 
			
		||||
            for event in tcod.event.wait():
 | 
			
		||||
                context.convert_event(event)  # Sets tile coordinates for mouse events.
 | 
			
		||||
                print(event)  # Print event names and attributes.
 | 
			
		||||
                if isinstance(event, tcod.event.Quit):
 | 
			
		||||
                    raise SystemExit()
 | 
			
		||||
 | 
			
		||||
        # The window will be closed after the above with-block exits.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
							
								
								
									
										30
									
								
								first_steps/02_dynamically_sized_console.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								first_steps/02_dynamically_sized_console.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
import tcod
 | 
			
		||||
 | 
			
		||||
WIDTH, HEIGHT = 720, 480  # Window pixel resolution (when not maximized.)
 | 
			
		||||
FLAGS = tcod.context.SDL_WINDOW_RESIZABLE | tcod.context.SDL_WINDOW_MAXIMIZED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> None:
 | 
			
		||||
    """Script entry point."""
 | 
			
		||||
	# New window with pixel resolution of width×height.
 | 
			
		||||
    with tcod.context.new(width=WIDTH, height=HEIGHT, sdl_window_flags=FLAGS) as context:
 | 
			
		||||
        while True:
 | 
			
		||||
			# Console size based on window resolution and tile size.
 | 
			
		||||
            console = context.new_console(order="F")
 | 
			
		||||
            console.print(0, 0, "Hello World")
 | 
			
		||||
            context.present(console, integer_scaling=True)
 | 
			
		||||
 | 
			
		||||
            for event in tcod.event.wait():
 | 
			
		||||
				# Sets tile coordinates for mouse events.
 | 
			
		||||
                context.convert_event(event)  
 | 
			
		||||
                print(event)
 | 
			
		||||
 | 
			
		||||
                if isinstance(event, tcod.event.Quit):
 | 
			
		||||
                    raise SystemExit()
 | 
			
		||||
                elif isinstance(event, tcod.event.WindowResized) and event.type == "WINDOWRESIZED":
 | 
			
		||||
                    pass  # The next call to context.new_console may return a different size.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue