| Scratch | Python |
 |
import simplegame as sg
def cat_start(self: sg.Sprite):
while True:
self.move(10)
game.wait(0.2)
game = sg.Game(900, 500)
cat = game.create_sprite(150, 250, ['C:\\Path\\cat.png'])
cat.add_event(sg.Events.START, cat_start)
game.run()
|
 |
|
 |
|
 |
cat.change_direction(-15)
|
 |
|
 |
|
 |
|
 |
cat.set_x(0)
cat.set_y(0)
|
 |
x = random.randint(0, game.width)
y = random.randint(0, game.height)
cat.glide_to(1, x, y)
|
 |
x = game.mouse_x
y = game.mouse_y
cat.glide_to(1, x, y)
|
 |
x = sprite.x
y = sprite.y
cat.glide_to(1, x, y)
|
 |
|
 |
|
 |
x = game.mouse_x
y = game.mouse_y
cat.set_direction_to_xy(x, y)
|
 |
x = sprite.x
y = sprite.y
cat.set_direction_to_xy(x, y)
|
 |
|
 |
|
 |
|
 |
|
 |
cat.bounce_if_on_edge(10)
|
 |
cat.set_rotation_style(sg.RotationStyles.LEFT_RIGHT)
cat.set_rotation_style(sg.RotationStyles.DONT_ROTATE)
cat.set_rotation_style(sg.RotationStyles.ALL_AROUND)
|
 |
a = cat.x
b = cat.y
c = cat.direction
|
 |
cat.say("Hello!")
game.wait(2)
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
cat.go_forward()
cat.go_backward()
|
 |
cat.play_sound_until_done('C:\\Path\\meow.wav')
|
 |
cat.play_sound('C:\\Path\\meow.wav')
|
 |
|
 |
|
 |
|
 |
def cat_start(self: sg.Sprite):
#...
cat.add_event(sg.Events.START, cat_start)
|
 |
def my_func(self: sg.Sprite):
#...
cat.add_event(sg.Events.SPACE, my_func)
|
 |
def my_func(self: sg.Sprite):
#...
cat.add_event(sg.Events.MOUSE_LEFT, my_func)
|
 |
def my_func(self: sg.Sprite):
#...
cat.add_event(sg.Events.BACKDROP_SWITCHES_TO, my_func, 1)
|
 |
def my_func(self: sg.Sprite):
#...
cat.add_event(sg.Events.RECEIVE_MESSAGE, my_func, "my_msg")
|
 |
cat.broadcast_message("my_msg")
|
 |
|
 |
for i in range(10):
#...
game.wait(0.03)
|
 |
while True:
#...
game.wait(0.03)
|
 |
|
 |
if a == 50:
#...
else:
#...
|
 |
while a != 50:
game.wait(0.03)
|
 |
while a != 50:
#...
game.wait(0.03)
|
 |
|
 |
def my_func(self: sg.Sprite):
#...
clone.add_event(sg.Events.START, my_func)
|
 |
|
 |
|
 |
|
 |
|
 |
cat.is_touching_sprite(sprite)
|
 |
cat.is_touching_color((0, 0, 0))
|
 |
game.are_colors_touching((0, 0, 0), (255, 255, 255))
|
 |
cat.get_distance_to_mouse()
|
 |
cat.get_distance_to_sprite(sprite)
|
 |
a = cat.ask("What's your name?")
|
 |
game.is_key_pressed(sg.Keys.SPACE)
|
 |
|
 |
|
 |
|
 |
cat.is_draggable = True
cat.is_draggable = False
|
 |
|
 |
|
 |
game.current_backdrop_idx
|
 |
|
 |
import datetime
today = datetime.date.today()
year = today.year
|
 |
from datetime import date
today = date.today()
d = date(2000, 1, 1)
delta = today - d
print(delta.days)
|
 |
|
 |
|
 |
|
 |
|
 |
import random
random.randint(1, 10)
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
|
 |
def my_block(steps):
cat.move(steps)
|
 |
|