Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions examples/imageBounceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ def create_circle():
circle.goto(0,0)
return circle
circle1, circle2, circle3 = create_circle(), create_circle(), create_circle()

circle4 = create_circle()
circle4.goto(400,300)
circle4.debug = True
slither.slitherStage.bgcolor = (255, 255, 255)

def run_a_frame():
circle1.xpos += 1
circle1.ypos += 1
circle1.xpos += 0.5
circle1.ypos += 0.5
circle1.direction += 1

circle2.xpos += 1
circle2.xpos += 0.5
circle2.direction += 1

circle3.ypos += 1
circle3.ypos += 0.5
circle3.direction += 1

circle4.direction += 1

slither.setup()
slither.runMainLoop(run_a_frame)
14 changes: 8 additions & 6 deletions slither/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import pygame
import sys, os
# import time # For future timer

WIDTH, HEIGHT = (800, 600)
SCREEN_SIZE = (WIDTH, HEIGHT)

sprites = [] # List of all sprites
clock = pygame.time.Clock() # Used to control framerate
Expand All @@ -28,9 +30,7 @@
# This function is broken, issue #9 remains
def rotateCenter(image, angle):
"""rotate a Surface, maintaining position."""
loc = image.get_rect().center #rot_image is not defined
rot_sprite = pygame.transform.rotate(image, angle)
rot_sprite.get_rect().center = loc
return rot_sprite

# Stage class
Expand Down Expand Up @@ -145,7 +145,7 @@ def setup(caption=sys.argv[0]):
'''Sets up PyGame and returns a screen object that can be used with blit().'''
global globalscreen
pygame.init()
screen = pygame.display.set_mode((800, 600))
screen = pygame.display.set_mode(SCREEN_SIZE)
caption = pygame.display.set_caption(caption)
globalscreen = screen
return screen
Expand All @@ -166,7 +166,7 @@ def blit(screen):
screen.fill(slitherStage.bgColor)

if slitherStage.currentCostume:
screen.blit(pygame.transform.scale(slitherStage.currentCostume, (800,600)), (0, 0))
screen.blit(pygame.transform.scale(slitherStage.currentCostume, SCREEN_SIZE, (0, 0)))

for obj in sprites:
if obj.isVisible(): # Check if the object is showing before we do anything
Expand All @@ -177,7 +177,9 @@ def blit(screen):
image = pygame.transform.scale(image, (int(imageSize[0] * obj.scale), int(imageSize[1] * obj.scale)))
if not obj.direction == 0:
image = rotateCenter(image, obj.direction)
screen.blit(image, (obj.xpos, obj.ypos))
new_rect = image.get_rect()
new_rect.center = (obj.xpos, obj.ypos)
screen.blit(image, new_rect)

pygame.display.flip()

Expand Down