pastebin - collaborative debugging tool
alicesucks.kpaste.net RSS


ueoa
Posted by Anonymous on Sun 12th Dec 2010 21:05
raw | new post

  1. '''
  2. 1. Create an image in paint or something with aspect ratio 4:3.
  3. 2. Make a billboard with it using: File > Make Billboard... in Alice.
  4. 3. Move and resize it so it covers the whole screen.
  5. 4. Place the script "main(<billboard name>)" in world.my_first_method. If the name starts with a number, place an underscore before it.
  6. 5. Create a new world method, handleMouseClick
  7. 6. Create a "When mouse is clicked on" event with the billboard and world.handleMouseClick
  8. 7. Create the world variables mouseX and mouseY.
  9. 8. In the handleMouseClick method, set these to the mouse position, then call the script "handleMouseClick()".
  10. '''
  11.  
  12. # import core classes
  13. from edu.cmu.cs.stage3.alice.core import *
  14. from edu.cmu.cs.stage3.alice.core.event import *
  15. from edu.cmu.cs.stage3.alice.core.response import *
  16. from edu.cmu.cs.stage3.alice.core.property import *
  17. from edu.cmu.cs.stage3.alice.core.question import *
  18.  
  19. # import constants
  20. from edu.cmu.cs.stage3.alice.core.Direction import *
  21. from edu.cmu.cs.stage3.alice.core.style.TraditionalAnimationStyle import *
  22.  
  23. # import image
  24. from java.awt.image import *
  25.  
  26. # import misc
  27. from edu.cmu.cs.stage3.alice.authoringtool import *
  28. from edu.cmu.cs.stage3.alice.authoringtool.util import *
  29.  
  30. # classes
  31.  
  32. class Generic:
  33.         pass
  34.  
  35. # variables
  36.  
  37. screenObj = None        # the Billboard object that represents the screen
  38.  
  39. images = {}             # holds BufferedImage's and Graphics2D's
  40.  
  41. dims = Generic()
  42.  
  43. # images
  44. def makeImage(name, width, height):
  45.         '''
  46.         adds an empty BufferedImage and its Graphics2D to images
  47.         '''
  48.         images[name] = AuthoringTool.getHack().getJAliceFrame().getGraphicsConfiguration().createCompatibleImage(width, height)
  49.         images['m' + name.title()] = images[name].createGraphics()
  50.  
  51. # textures
  52. def setTexture(object, image):
  53.         '''
  54.         takes java.awt.Image, makes it texture of object
  55.         '''
  56.         texture = TextureMap()
  57.         texture.propertyChanged(PropertyEvent(texture.image, image))
  58.         object.propertyChanged(PropertyEvent(object._diffuseColorMap, texture))
  59.  
  60. def getTextureImage(object):
  61.         '''
  62.         returns java.awt.Image
  63.         '''
  64.         return object.diffuseColorMap.image
  65.  
  66. #mouse
  67. def handleMouseClick():
  68.         pass
  69.  
  70. #misc
  71. def onScreen(obj):
  72.         world.bool = camera.canSee(obj, false)
  73.  
  74. def main(screen):
  75.         global screenObj
  76.  
  77.         screenObj = screen
  78.  
  79.         # dimension constants
  80.         _size = world.camera.renderTarget.getAWTComponent().getSize()
  81.  
  82.         dims.WIDTH = _size.width
  83.         dims.HEIGHT = _size.height
  84.  
  85.         dims.GRID_WIDTH = dims.HEIGHT   # make a square grid
  86.  
  87.         dims.CELL_WIDTH = dims.HEIGHT / round(dims.HEIGHT / 20) # get as close to 20 px per cell as possible, is a float
  88.  
  89.         dims.MENU_WIDTH = dims.WIDTH - dims.GRID_WIDTH
  90.  
  91.         # store images
  92.         makeImage('main', dims.WIDTH, dims.HEIGHT)
  93.         makeImage('grid1', dims.GRID_WIDTH, dims.HEIGHT)
  94.         makeImage('grid2', dims.GRID_WIDTH, dims.HEIGHT)
  95.         makeImage('menu', dims.MENU_WIDTH, dims.HEIGHT)
  96.  
  97.         setTexture(screen, images['main'])

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at