remoteunit.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import sys
  2. import time
  3. import unittest
  4. import Image
  5. import StringIO
  6. import gameduino.remote
  7. import gameduino.prep as gdprep
  8. gd = gameduino.remote.Gameduino(sys.argv.pop(), 115200)
  9. class TestGameduino(unittest.TestCase):
  10. def setUp(self):
  11. pass
  12. def test_talk(self):
  13. self.assertEqual(gd.rd(gameduino.IDENT), 0x6d)
  14. def test_sprites(self):
  15. ir = gdprep.ImageRAM(StringIO.StringIO())
  16. (rock0, rock1) = gdprep.palettize([Image.open("rock0r.png"), Image.open("rock1r.png")], 16)
  17. ir.addsprites("rock0", (16, 16), rock0, gdprep.PALETTE16A, center = (8,8))
  18. ir.addsprites("rock1", (32, 32), rock1, gdprep.PALETTE16A, center = (16,16))
  19. gd.wr16(gameduino.RAM_PAL, gameduino.RGB(0, 255, 0))
  20. gd.wrstr(gameduino.RAM_SPRIMG, ir.used())
  21. gd.wrstr(gameduino.PALETTE16A, gdprep.getpal(rock0))
  22. for i in range(128):
  23. gd.sprite(i, 200 + 20 * (i & 7), 20 * (i / 8), i / 2, gdprep.PALETTE16A[i&1], 0)
  24. (pic,chr,pal) = gdprep.encode(Image.open("platformer.png"))
  25. gd.wrstr(gameduino.RAM_CHR, chr)
  26. gd.wrstr(gameduino.RAM_PAL, pal)
  27. for y in range(32):
  28. gd.wrstr(gameduino.RAM_PIC + 64 * y, pic[16*y:16*y+16])
  29. def test_ascii(self):
  30. gd.ascii()
  31. gd.putstr(10, 10, "THIS IS A!!")
  32. if __name__ == '__main__':
  33. unittest.main()