FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Scratch-To-Python/scratch_py at main · MengruCui/Scratch-To-Python · GitHub

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

List

Classes Links
Game Manager Link
Sprite Link

Game Manager

The Game Manager is basically the CPU of this library. Initially started the Pygame application, it manages and updates all sprites until the user quit the application.

  • Make new Game Manager object
'''
Arguments
----------
width : int
  width of screen
height : int
  height of screen
game_directory: str
  path directory to game folder. os.getcwd() is sufficient.
  
Returns
-------
game    : GameManger
'''
from scratch_py import manager
import os

game = manager.GameManager(800, 600, os.getcwd())
  • Add new background (But doesn't change to it)
Arguments
----------
image_link : str
  name of new background
  
game.add_background_image("background1.png")
  • Change background
Arguments
----------
image_link : str
  name of new background
  
game.change_background_image("background1.png")
  • Change game title
Arguments
----------
game_title : str
  new name of game
  
game.change_title("Game Title")
  • Change if user has quit or not
Returns
-------
result    : bool
  tell user if it has quit or not
  
result = game.check_quit()
  • Get current background name
Returns
-------
name    : str
  background's name
  
name = game.get_background_name()
  • Get user event
game.get_user_events()
  • Get current timer
Returns
-------
timer    : int
  current time
  
timer = game.get_timer()
  • Check if certain key is hold
Arguments
---------
key: str
  certain key to hold

Returns
-------
result    : bool
  tell if that key is hold or not
  
result = game.key_hold('a')
  • Check if certain key is pressed but not hold
Arguments
---------
key: str
  certain key to press

Returns
-------
result    : bool
  tell if that key is pressed or not
  
result = game.key_pressed('a')
  • Check if certain key is released
Arguments
---------
key: str
  certain key to release

Returns
-------
result    : bool
  tell if that key is released or not
  
result = game.key_released('a')
  • Switch to next background image (similar to Scratch backdrop)
game.next_background_image()
  • Play background music
Arguments
---------
link    : bool
  link to new background music
loop_num: int
  number of loops to play the new background music
  infinite if loop_num == 0
  
game.play_background_music('music.mp3', 0)
  • Set background volume
Arguments
---------
volume  : int
  new volume
  
game.set_background_music_volume(100)
  • Stop all game and sprite sounds
game.stop_all_sound()
  • Stop background music
game.stop_background_music()
  • Update game per frame (FPS)
game.update()

Sprite

Sprite is basically the same Sprite from Scratch. You can move it, transform it and many more!

Modules Links
Motion Link
Looks Link
Sound Link
Control Link
Sensing Link
  • Create new sprite
Arguments
---------
image_link  : bool
  name of the image for the new sprite
scale       : float
  size of image
  
Returns
-------
new_sprite  : Sprite
  the new sprite
  
new_sprite = game.new_sprite("image.png", 30)

Motion

  • Move 10 steps
sprite.move(10)
  • Turn right 15 degrees
sprite.turn_right(10)
  • Turn left 15 degrees
sprite.turn_left(10)
  • Go to a specific position
sprite.go_to(0,0)

sprite.go_to_random_position()
  • Glide to a particular position
sprite.glide(100, 100, 1)

sprite.glide_to_mouse_pointer(1)

sprite.glide_to_random_position(1)

sprite.glide_to_sprite(other_Sprite, 1)
  • Point in direction
sprite.set_direction(100)

sprite.point_toward_mouse()

sprite.point_toward_sprite(other_Sprite)
  • Change x by 10
sprite.change_x(10)
  • Set x to 100
sprite.set_x(100)
  • Change y by 10
sprite.change_y(10)
  • Set y to 100
sprite.set_y(100)
  • If on edge, bounce
sprite.bounce_on_edge()
  • Set rotation style
# All-Around, Left-Right, None
sprite.set_rotation_style("None")
  • Get x position
x = sprite.get_x()
  • Get y position
y = sprite.get_y()
  • Get direction
dir = sprite.get_direction()

Looks

  • say "Hello"
sprite.say("Hello")

sprite.say("Hello", 2)

sprite.set_costume_after_say("image2.png")
  • think "Hello"
#TODO
  • Switch costume
sprite.add_costume("image2.png")

sprite.next_costume()

sprite.switch_costume("image2.png")
  • Change size
sprite.change_size(10)
  • Show
sprite.show()
  • Hide
sprite.hide()
  • Get costume number
name = sprite.get_costume_name()

num = sprite.get_costume_number()
  • Get size
size = sprite.get_size()

Sound

  • Play sound
sprite.play_sound("music.wav")
  • Stop sound
sprite.stop_sound()
  • Change volume by 10
sprite.change_volume(10)
  • Set volume to 100
sprite.set_volume(100)

Control

  • Wait 1 second
sprite.wait(1)
  • Clone
new_clone = sprite.clone()

Sensing

  • Check if sprite touch something
result = sprite.touch(other_sprite)

result = sprite.touch_edge()
  • Check if mouse clicked on sprite
result = sprite.mouse_clicked()

result = sprite.mouse_hovered()
  • Check Key 'Space' pressed
result = game.key_hold('space')

result = game.key_pressed('space')

result - game.key_released('space')

Sensing

  • Show collision box
sprite.show_box()

sprite.hide_box()

Back | FazBrowse Home | New Git URL