Example #1
0
# usr/bin/env python3
# keysDownTest.py - Test slither.keysDown()

import slither


def run_a_frame():
    print(slither.keysDown())


slither.setup()
slither.runMainLoop(run_a_frame)
Example #2
0
#! usr/bin/env python3
# fullScreenTest.py

import slither, pygame

snakey = slither.Sprite()
snakey.costumeName = "costume0" # You can set the default costume (costume0) by name...
snakey.goto(400, 300)

slither.slitherStage.bgColor = (40, 222, 40)

slither.setup() # Begin slither

def run_a_frame():
    snakey.direction += 1

@slither.registerCallback(pygame.MOUSEBUTTONUP)
def handle_mousedown(event):
    slither.toggleFullScreen()

slither.runMainLoop(run_a_frame)
import slither, time  # Get slither and time functions

slither.setup(
    'Press S for sound', 400, 400
)  # Setup slither with the caption 'Press S for sound' and resolution 400px by 400px


def loop():  # Define main loop
    try:  # Error handling wrapper
        if slither.keysDown()[0] == 's':  # Run if key s is pressed...
            sound = slither.slitherSound.loadSound(
                'boom.wav')  # Load the sound 'boom.wav'
            sound.play()  # Play the sound
            time.sleep(2)  # Wait 2 seconds
    except:  # Run code if there's an error
        pass  # Do nothing


slither.runMainLoop(loop)  # Run main loop
Example #4
0
import slither, random  # Get functions from slither and random

doge = [None] * 30  # Initialize array 'doge'
dogecount = 1  # Initialize iterator 'dogecount'

while dogecount != 30:  # Produce 30 doges
    doge[dogecount] = slither.Sprite()  # Make each doge a sprite
    doge[dogecount].addCostume('doge.png',
                               'doge')  # Give them the costume 'doge'
    doge[dogecount].costumeName = 'doge'  # Set the doges costume to 'doge'
    doge[dogecount].ypos = random.randint(
        0, 400)  # Make the doges go to a random y position
    doge[dogecount].xpos = random.randint(
        0, 400)  # Make the doges go to a random x position
    dogecount += 1  # Increase the iterator for reiteration

slither.setup(
    'Doge invasion!', 400, 400
)  # Setup slither, set caption to 'Doge invasion!' and set resolution to 400px by 400px


def loop():  # Define main game loop called 'loop'
    pass  # Do nothing...


slither.runMainLoop(loop)  # Run main game loop
Example #5
0
import slither  # Get slither functions

background = slither.slitherStage  # Make 'background' the stage
background.addCostume('./assets/grass.png',
                      'grass')  # Add costume 'grass' to background
background.costumeName = 'grass'  # Set the costume to grass

snakey = slither.Sprite()  # Make a sprite named snakey (default)
snakey.goto(700, 200)  # Make snakey go to xpos 700 and ypos 200

slither.setup(
    'Run Snakey!', 800, 400
)  # Setup slither, set the caption to 'Run Snakey!' and set the resolution to 800px by 400px


def myloop():  # Make a main loop named 'myloop'
    slither.blitText(
        'Run snakey, Run!', 300, 20, 32
    )  # Add the text 'Run snakey, Run!' to the screen on xpos 300, ypos 20 with font size 32
    snakey.xpos -= 10  # Make snakey run forward
    if snakey.xpos == 100:  # Trigger code if snakey is about to exit screen
        snakey.goto(700, 200)  # Make snakey restart


slither.runMainLoop(myloop)  # Run the main game loop
Example #6
0
import slither  # Get slither functions

snakey = slither.Sprite()  # Make a sprite called snakey
snakey.costumeName = "costume0"  # Set snakey's costume to costume0

snakey.goto(200, 200)  # Make snakey go to x 200 and y 200

slither.setup(
    'Hello World!', 400, 400
)  # Setup slither with caption 'Hello World!' and resolution 400px by 400px


def run_a_frame():  # Define main game loop
    pass  # Do nothing. This is only a simple project


slither.runMainLoop(run_a_frame)  # Start main game loop
Example #7
0
import slither # Get slither functions

background = slither.slitherStage # Make 'background' the stage
background.addCostume('./assets/grass.png', 'grass') # Add costume 'grass' to background
background.costumeName = 'grass' # Set the costume to grass

snakey = slither.Sprite() # Make a sprite named snakey (default)
snakey.goto(700, 200) # Make snakey go to xpos 700 and ypos 200

slither.setup('Run Snakey!', 800, 400) # Setup slither, set the caption to 'Run Snakey!' and set the resolution to 800px by 400px

def myloop(): # Make a main loop named 'myloop'
    slither.blitText('Run snakey, Run!', 300, 20, 32) # Add the text 'Run snakey, Run!' to the screen on xpos 300, ypos 20 with font size 32
    snakey.xpos -= 10 # Make snakey run forward
    if snakey.xpos == 100: # Trigger code if snakey is about to exit screen
        snakey.goto(700, 200) # Make snakey restart
   
slither.runMainLoop(myloop) # Run the main game loop
Example #8
0
import slither, time # Get slither and time functions

slither.setup('Press S for sound', 400, 400) # Setup slither with the caption 'Press S for sound' and resolution 400px by 400px

def loop(): # Define main loop
    try: # Error handling wrapper
        if slither.keysDown()[0] == 's': # Run if key s is pressed...
            sound = slither.slitherSound.loadSound('./assets/boom.wav') # Load the sound 'boom.wav'
            sound.play() # Play the sound
            time.sleep(2) # Wait 2 seconds
    except: # Run code if there's an error
        pass # Do nothing

slither.runMainLoop(loop) # Run main loop
Example #9
0
import slither, random # Get functions from slither and random

doge = [None]* 30 # Initialize array 'doge'
dogecount = 1 # Initialize iterator 'dogecount'

while dogecount != 30: # Produce 30 doges
    doge[dogecount] = slither.Sprite() # Make each doge a sprite
    doge[dogecount].addCostume('./assets/doge.png', 'doge') # Give them the costume 'doge'
    doge[dogecount].costumeName = 'doge' # Set the doges costume to 'doge'
    doge[dogecount].ypos = random.randint(0, 400) # Make the doges go to a random y position
    doge[dogecount].xpos = random.randint(0, 400) # Make the doges go to a random x position
    dogecount += 1 # Increase the iterator for reiteration

slither.setup('Doge invasion!', 400, 400) # Setup slither, set caption to 'Doge invasion!' and set resolution to 400px by 400px

def loop(): # Define main game loop called 'loop'
    pass # Do nothing...

slither.runMainLoop(loop) # Run main game loop