Skip to content

szotms/simplegame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

simplegame

Python package for creating simple games.

installation

pip install simplegame

or

py -m pip install simplegame

quick start

from simplegame import sg

def cat_start(self: sg.Sprite):
    for x in range(30):
        self.move(10)
        game.wait(0.03)

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()

scratch - python comparision

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.move(10)
cat.change_direction(15)
cat.change_direction(-15)
cat.go_to_random()
cat.go_to_mouse()
cat.go_to_sprite(sprite)
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)
cat.glide_to(1, 0, 0)
cat.set_direction(90)
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.change_x(10)
cat.set_x(0)
cat.change_y(10)
cat.set_y(0)
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.say("Hello!")
cat.set_costume(1)
cat.next_costume()
game.set_backdrop_idx(1)
game.next_backdrop()
cat.change_size(10)
cat.set_size(100)
cat.show()
cat.hide()
cat.go_forward()
cat.go_backward()
cat.play_sound_until_done('C:\\Path\\meow.wav')
cat.play_sound('C:\\Path\\meow.wav')
cat.change_volume(-10)
cat.set_volume(100)
a = cat.volume
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")
game.wait(1)
for i in range(10):
    #...
    game.wait(0.03)
while True:
    #...
    game.wait(0.03)
if a == 50:
    #...
if a == 50:
    #...
else:
    #...
while a != 50:
    game.wait(0.03)
while a != 50:
    #...
    game.wait(0.03)
game.stop_all()
def my_func(self: sg.Sprite):
    #...
clone.add_event(sg.Events.START, my_func)
clone = cat.clone()
clone.delete()
cat.is_touching_mouse()
cat.is_touching_edge()
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)
game.is_mouse_down
game.mouse_x
game.mouse_y
cat.is_draggable = True
cat.is_draggable = False
game.timer()
game.reset_timer()
game.current_backdrop_idx
cat.x
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)
a + 2
a - 2
a * 2
a / 2
import random
random.randint(1, 10)
a > 50
a < 50
a == 50
a > 1 and b > 1
a > 1 or b > 1
not a > 1 
"apple" + "banana"
"apple"[0]
len("apple")
"a" in "apple"
a % 2
round(a)
abs(a)
a = 0
a += 1
def my_block(steps):
    cat.move(steps)
my_block(10)

About

Python package for creating simple games

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages