Skip to content

Latest commit

 

History

History
104 lines (83 loc) · 2.3 KB

pgzero-cheatsheet.md

File metadata and controls

104 lines (83 loc) · 2.3 KB

PGZero

Minimal example

code
    # images/actorname.png 
    actorname = Actor('actorname')
    actorname.pos = 100, 56
    WIDTH = 500
    HEIGHT = actorname.height + 20
    def draw():
        screen.clear()
        actorname.draw()
    
    def update():
        actorname.left += 2
        if actorname.left > WIDTH:
            actorname.right = 0

Text

code
    screen.draw.text("hello gamedev", (x_pos, y_pos),fontname="helvetica", fontsize=40, color=(red,green,blue), shadow=(2,2), scolor=(red,green,blue))
code
    def on_mouse_down():
    print("Mouse button clicked")

    def on_mouse_down(pos):
        print("Mouse button clicked at", pos)

    def on_mouse_down(button):
        print("Mouse button", button, "clicked")

    def on_mouse_down(pos, button):
        print("Mouse button", button, "clicked at", pos)

    def on_mouse_move(pos):
        print(pos)
    
   def update():
	if (keyboard.right):
		print("right") 
	
	if (keyboard.space):
		print("space") 
 

Collisions

code
    collidable = Actor('actorname')
    collidable.pos = 100, 56

    def update():
        if actorname.collidepoint(collidable.pos):
            print("Ouch")

Sounds

code
    # sounds/soundname.wav 
    sounds.soundname.play() # plays 1ce 
    sounds.soundname.play(7) # plays seven times   
    sounds.soundname.play(-1) # loops forever 
    sounds.soundname.stop()
    sounds.soundname.get_length() # duration in seconds 

    # music/track.mp3 
    music.play('track') 
    music.play_once('track') # can use on_music_end() hook 
    music.queue('track') 
    music.stop() 
    music.pause() 
    music.unpause()
    music.is_playing() # returns true if music is playing 
    music.fadeout(0.5) # where 0.5 is the duration 
    music.set_volume(0.5) # 0 being no volume & 1 being full volume 
    music.get_volume() 

    tonename = tone.create('C1', 0.8)
    tonename.play()