def rect_to_screen(self, rect, coords): """ Convert a rectangle into screen coordinates. """ if coords == Renderer.COORDS_SCREEN: return rect else: tl = self.world_to_screen(rect.topleft) br = self.world_to_screen(rect.bottomright) ret = Rect() ret.topleft = tl ret.bottomright = br return ret
def test_bottomright(self): """Changing the bottomright attribute moves the rect and does not change the rect's size """ r = Rect(1, 2, 3, 4) new_bottomright = (r.right + 20, r.bottom + 30) expected_topleft = (r.left + 20, r.top + 30) old_size = r.size r.bottomright = new_bottomright self.assertEqual(new_bottomright, r.bottomright) self.assertEqual(expected_topleft, r.topleft) self.assertEqual(old_size, r.size)
def test_bottomright( self ): """Changing the bottomright attribute moves the rect and does not change the rect's size """ r = Rect( 1, 2, 3, 4 ) new_bottomright = (r.right+20,r.bottom+30) expected_topleft = (r.left+20,r.top+30) old_size = r.size r.bottomright = new_bottomright self.assertEqual( new_bottomright, r.bottomright ) self.assertEqual( expected_topleft, r.topleft ) self.assertEqual( old_size, r.size )
MOVESPEED = 500. # for the ship moving sideways BOLTLENGTH = SHIPSIZE // 2 BOLTWIDTH = 3 BOLTSPEED = 500. # pixels per second ALIENBOLT = 1 SHIPBOLT = 2 SCOREBOARD = Rect(0, 0, VIEWWIDTH, SHIPSIZE) SCOREBOARD.midbottom = VIEWPORT.midtop STATUSBAR = Rect(0, 0, VIEWWIDTH, SHIPSIZE) STATUSBAR.midtop = VIEWPORT.midbottom DEBUGWINDOW = Rect(0, 0, (SCREENSIZE[0] - VIEWWIDTH) // 2, SCREENSIZE[1]) DEBUGWINDOW.bottomright = SCREENSIZE NR_OF_STARS = 50 # at what score, the player receives an extra life EXTRA_LIVES = [30000, 100000] # key mapping. # how to check whether keyboard is azerty or qwerty? LEFT_KEYS = [K_LEFT, K_q] RIGHT_KEYS = [K_RIGHT, K_d] FIRE_KEYS = [K_SPACE, K_j, K_UP]