Beispiel #1
0
    def test_scaledcirclecollision(self):
        s1 = Sprite(self.circ, (100, 80))
        s2 = Sprite(self.rect, (161, 100))
        c = s1.collidingWith(s2)
        self.assertFalse(c, msg="circle not colliding with rect")
        s1.x = 101
        c = s1.collidingWith(s2)
        self.assertTrue(c, msg="circle colliding with rect")
        s1.x = 170
        c = s1.collidingWith(s2)
        self.assertTrue(c, msg="circle colliding with rect on right side")
        s1.x = 172
        c = s1.collidingWith(s2)
        self.assertFalse(c, msg="circle not colliding with rect on right side")
        # Now scale at 2x
        s1.scale = 2
        s1.x = 40
        c = s1.collidingWith(s2)
        self.assertFalse(c, msg="2x scaled circle not colliding with rect")
        s1.x = 41
        c = s1.collidingWith(s2)
        self.assertTrue(c, msg="2x scaled circle colliding with rect")
        s1.x = 170
        c = s1.collidingWith(s2)
        self.assertTrue(
            c, msg="2x scaled circle colliding with rect on right side")
        s1.x = 172
        c = s1.collidingWith(s2)
        self.assertFalse(
            c, msg="2x scaled circle not colliding with rect on right side")

        s1.destroy()
        s2.destroy()
Beispiel #2
0
 def test_spritecollision(self):
   s1 = Sprite(self.image, (51,52))
   s2 = Sprite(self.image, (51, 52))
   cl = s2.collidingWithSprites()
   self.assertEqual(len(cl), 1)
   self.assertEqual(s2.collidingWith(cl[0]), True)
   s2.x = 125
   self.assertEqual(s2.collidingWith(cl[0]), False)
   s1.destroy()
   s2.destroy()    
Beispiel #3
0
 def test_spritecollision(self):
     s1 = Sprite(self.image, (51, 52))
     s2 = Sprite(self.image, (51, 52))
     cl = s2.collidingWithSprites()
     self.assertEqual(len(cl), 1)
     self.assertEqual(s2.collidingWith(cl[0]), True)
     s2.x = 125
     self.assertEqual(s2.collidingWith(cl[0]), False)
     s1.destroy()
     s2.destroy()
Beispiel #4
0
 def test_sprite(self):
   s = Sprite(self.image, (51,52))
   self.assertEqual(s.x, 51)
   self.assertEqual(s.y, 52)
   self.assertEqual(s.width, 71)
   self.assertEqual(s.height, 100)
   self.assertEqual(s.position, (51,52))
   self.assertEqual(s.fxcenter, 0.0)
   s.x = 41
   self.assertEqual(s.x, 41)
   self.assertEqual(s.width, 71)
   s.destroy()
Beispiel #5
0
 def test_sprite(self):
     s = Sprite(self.image, (51, 52))
     self.assertEqual(s.x, 51)
     self.assertEqual(s.y, 52)
     self.assertEqual(s.width, 71)
     self.assertEqual(s.height, 100)
     self.assertEqual(s.position, (51, 52))
     self.assertEqual(s.fxcenter, 0.0)
     s.x = 41
     self.assertEqual(s.x, 41)
     self.assertEqual(s.width, 71)
     s.destroy()
https://github.com/HHS-IntroProgramming/Spacewar

"""
from ggame import App, RectangleAsset, ImageAsset, Sprite, LineStyle, Color, Frame
from math import sin, cos

SCREEN_WIDTH = 1423
SCREEN_HEIGHT = 788

asset1 = ImageAsset("images/starfield.jpg")
width = 512
height = 512
 
stars = Sprite(asset1)
stars1 = Sprite(asset1)
stars1.x = 512
stars1.y = 0
stars2 = Sprite(asset1)
stars2.x = 1024
stars2.y = 0
stars3 = Sprite(asset1)
stars3.x = 0
stars3.y = 512
stars4 = Sprite(asset1)
stars4.x = 512
stars4.y = 512
stars5 = Sprite(asset1)
stars5.x = 1024
stars5.y = 512

asset2 = ImageAsset("images/sun.png")