- '''
- 1. Create an image in paint or something with aspect ratio 4:3.
- 2. Make a billboard with it using: File > Make Billboard... in Alice.
- 3. Move and resize it so it covers the whole screen.
- 4. Place the script "main(<billboard name>)" in world.my_first_method. If the name starts with a number, place an underscore before it.
- 5. Create a new world method, handleMouseClick
- 6. Create a "When mouse is clicked on" event with the billboard and world.handleMouseClick
- 7. Create the world variables mouseX and mouseY.
- 8. In the handleMouseClick method, set these to the mouse position, then call the script "handleMouseClick()".
- '''
- # import core classes
- from edu.cmu.cs.stage3.alice.core import *
- from edu.cmu.cs.stage3.alice.core.event import *
- from edu.cmu.cs.stage3.alice.core.response import *
- from edu.cmu.cs.stage3.alice.core.property import *
- from edu.cmu.cs.stage3.alice.core.question import *
- # import constants
- from edu.cmu.cs.stage3.alice.core.Direction import *
- from edu.cmu.cs.stage3.alice.core.style.TraditionalAnimationStyle import *
- # import image
- from java.awt.image import *
- # import misc
- from edu.cmu.cs.stage3.alice.authoringtool import *
- from edu.cmu.cs.stage3.alice.authoringtool.util import *
- # classes
- class Generic:
- pass
- # variables
- screenObj = None # the Billboard object that represents the screen
- images = {} # holds BufferedImage's and Graphics2D's
- dims = Generic()
- # images
- def makeImage(name, width, height):
- '''
- adds an empty BufferedImage and its Graphics2D to images
- '''
- images[name] = AuthoringTool.getHack().getJAliceFrame().getGraphicsConfiguration().createCompatibleImage(width, height)
- images['m' + name.title()] = images[name].createGraphics()
- # textures
- def setTexture(object, image):
- '''
- takes java.awt.Image, makes it texture of object
- '''
- texture = TextureMap()
- texture.propertyChanged(PropertyEvent(texture.image, image))
- object.propertyChanged(PropertyEvent(object._diffuseColorMap, texture))
- def getTextureImage(object):
- '''
- returns java.awt.Image
- '''
- return object.diffuseColorMap.image
- #mouse
- def handleMouseClick():
- pass
- #misc
- def onScreen(obj):
- world.bool = camera.canSee(obj, false)
- def main(screen):
- global screenObj
- screenObj = screen
- # dimension constants
- _size = world.camera.renderTarget.getAWTComponent().getSize()
- dims.WIDTH = _size.width
- dims.HEIGHT = _size.height
- dims.GRID_WIDTH = dims.HEIGHT # make a square grid
- dims.CELL_WIDTH = dims.HEIGHT / round(dims.HEIGHT / 20) # get as close to 20 px per cell as possible, is a float
- dims.MENU_WIDTH = dims.WIDTH - dims.GRID_WIDTH
- # store images
- makeImage('main', dims.WIDTH, dims.HEIGHT)
- makeImage('grid1', dims.GRID_WIDTH, dims.HEIGHT)
- makeImage('grid2', dims.GRID_WIDTH, dims.HEIGHT)
- makeImage('menu', dims.MENU_WIDTH, dims.HEIGHT)
- setTexture(screen, images['main'])
ueoa
Posted by Anonymous on Sun 12th Dec 2010 21:05
raw | new post
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.