From b2373dc0c577f9052b51484ec8d3ca41769b3ddd Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 31 Mar 2016 10:42:38 -0400 Subject: [PATCH 1/3] Fix issue #9 --- examples/circle.png | Bin 411 -> 404 bytes examples/imageBounceTest.py | 14 +++++++++----- slither/__init__.py | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/circle.png b/examples/circle.png index 9fea960d9cbe721102e8d0afd7fae54639860007..f5d8b4da30528fb50e83fb21bbfbd91a8922c795 100644 GIT binary patch delta 321 zcmV-H0lxm51C#@hB#|)~3c>&Y4#EKyC`y2lQzw5CNklKbOq?E$<&k&UfAvCFt%0zmoL=C#9(1SGWrRyX;KwBxI6LjH~N@(t; zi~eCNr=2u>gl8Of(7=%%vAauyEV#$LgU|p=5}PU=wCEbQL9#VJD{8iE&9b6K4;E$+ zD;9s=U)12q8N`~O47}-3EP51+9>tC=us^C^ESUIGl(IVAQ@`# zU||NaV&VIhphnBq+%rgq4p?-}wvwQOmL#~EpaE7S+y&WVeJMtT32cCd(JdbpHSZH*^6$^2*w{kO0v6G9kL8C8$PoW2CILlNgJwRJ2 zq7J(7OeG9g(?wS}O1F}R-(int1r5B@7S&T4WWgHGUW5i%k~pN)Xwf}x7fF` z-bD<#Es~%D4`$v)teE-zicq0tOP;w%f*LHk=a@vO(UJtG5gK4c!rdY@>L(Ezbf+!a zrx6->hdufgD>VEnM;KltL6@AV1X*>2E<8gi@{Sd{T*F!BJ0lC|K@v64nNmOxC3RVr Y4}Saz*%|J{vj6}907*qoM6N<$f;F3q2><{9 diff --git a/examples/imageBounceTest.py b/examples/imageBounceTest.py index 333b989..bb21cab 100644 --- a/examples/imageBounceTest.py +++ b/examples/imageBounceTest.py @@ -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) diff --git a/slither/__init__.py b/slither/__init__.py index f571fb8..6f5a337 100644 --- a/slither/__init__.py +++ b/slither/__init__.py @@ -28,9 +28,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 @@ -171,13 +169,16 @@ def blit(screen): for obj in sprites: if obj.isVisible(): # Check if the object is showing before we do anything image = obj.currentCostume # So we can modify it and blit the modified version easily + orig_rect = image.get_rect() # These next few blocks of code check if the object has the defaults before doing anything. if not obj.scale == 1: imageSize = image.get_size() 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() From b609735a4cb080b7e5475d3c0f28cfc9dd84903b Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 31 Mar 2016 10:55:13 -0400 Subject: [PATCH 2/3] Removed an unused line of code --- slither/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/slither/__init__.py b/slither/__init__.py index 6f5a337..5ec8805 100644 --- a/slither/__init__.py +++ b/slither/__init__.py @@ -169,7 +169,6 @@ def blit(screen): for obj in sprites: if obj.isVisible(): # Check if the object is showing before we do anything image = obj.currentCostume # So we can modify it and blit the modified version easily - orig_rect = image.get_rect() # These next few blocks of code check if the object has the defaults before doing anything. if not obj.scale == 1: imageSize = image.get_size() From 55d07e9d6adfe0bc1be7f85b469cfd8421e69897 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 31 Mar 2016 11:19:17 -0400 Subject: [PATCH 3/3] Made the screen size tuple a constant, so that it is easier to change --- slither/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/slither/__init__.py b/slither/__init__.py index 5ec8805..d94c165 100644 --- a/slither/__init__.py +++ b/slither/__init__.py @@ -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 @@ -143,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 @@ -164,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