idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
37,900
public static void enterSafeBlock ( ) { if ( inSafe ) { return ; } Renderer . get ( ) . flush ( ) ; lastUsed = TextureImpl . getLastBind ( ) ; TextureImpl . bindNone ( ) ; GL11 . glPushAttrib ( GL11 . GL_ALL_ATTRIB_BITS ) ; GL11 . glPushClientAttrib ( GL11 . GL_ALL_CLIENT_ATTRIB_BITS ) ; GL11 . glMatrixMode ( GL11 . GL...
Enter a safe block ensuring that all the OpenGL state that slick uses is safe before touching the GL state directly .
37,901
public static void leaveSafeBlock ( ) { if ( ! inSafe ) { return ; } GL11 . glMatrixMode ( GL11 . GL_PROJECTION ) ; GL11 . glPopMatrix ( ) ; GL11 . glMatrixMode ( GL11 . GL_MODELVIEW ) ; GL11 . glPopMatrix ( ) ; GL11 . glPopClientAttrib ( ) ; GL11 . glPopAttrib ( ) ; if ( lastUsed != null ) { lastUsed . bind ( ) ; } el...
Leave a safe block ensuring that all of Slick s OpenGL state is restored since the last enter .
37,902
private List createPoints ( int numberOfSegments , float radius , float cx , float cy , float start , float end ) { ArrayList tempPoints = new ArrayList ( ) ; int step = 360 / numberOfSegments ; for ( float a = start ; a <= end + step ; a += step ) { float ang = a ; if ( ang > end ) { ang = end ; } float x = ( float ) ...
Generate the points to fill a corner arc .
37,903
private void fireUpdated ( Object source ) { for ( int i = 0 ; i < listeners . size ( ) ; i ++ ) { ( ( InputPanelListener ) listeners . get ( i ) ) . valueUpdated ( this ) ; } }
Fire notification of updates to all listeners
37,904
private void loadBackground ( ) { JFileChooser chooser = new JFileChooser ( "." ) ; chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { game . setBackgroundImage ( chooser . getSelectedFile ( ) ) ; } }
Load a background image to display behind the particle system
37,905
private void initGraphEditorWindow ( ) { GraphEditorWindow editor = new GraphEditorWindow ( ) ; whiskasPanel . setEditor ( editor ) ; graphEditorFrame = new JFrame ( "Whiskas Gradient Editor" ) ; graphEditorFrame . getContentPane ( ) . add ( editor ) ; graphEditorFrame . setDefaultCloseOperation ( WindowConstants . HID...
init the graph editor window
37,906
public void importEmitter ( ) { chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; File path = file . getParentFile ( ) ; try { final ConfigurableEmitter emitter = ParticleIO . loadEmitter ( file...
Import an emitter XML file
37,907
public void cloneEmitter ( ) { if ( selected == null ) { return ; } try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ParticleIO . saveEmitter ( bout , selected ) ; ByteArrayInputStream bin = new ByteArrayInputStream ( bout . toByteArray ( ) ) ; ConfigurableEmitter emitter = ParticleIO . loadEmitter ( ...
Clone the selected emitter
37,908
public void exportEmitter ( ) { if ( selected == null ) { return ; } chooser . setDialogTitle ( "Save" ) ; int resp = chooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; if ( ! file . getName ( ) . endsWith ( ".xml" ) ) { file = new File ( file ...
Export an emitter XML file
37,909
public void createNewSystem ( ) { game . clearSystem ( additive . isSelected ( ) ) ; pointsEnabled . setSelected ( false ) ; emitters . clear ( ) ; }
Create a completely new particle system
37,910
public void loadSystem ( ) { chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; File path = file . getParentFile ( ) ; try { ParticleSystem system = ParticleIO . loadConfiguredSystem ( file ) ; g...
Load a complete particle system XML description
37,911
public void saveSystem ( ) { int resp = chooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; if ( ! file . getName ( ) . endsWith ( ".xml" ) ) { file = new File ( file . getAbsolutePath ( ) + ".xml" ) ; } try { ParticleIO . saveConfiguredSystem (...
Save a complete particle system XML description
37,912
public void setCurrentEmitter ( ConfigurableEmitter emitter ) { this . selected = emitter ; if ( emitter == null ) { emissionControls . setEnabled ( false ) ; settingsPanel . setEnabled ( false ) ; positionControls . setEnabled ( false ) ; colorPanel . setEnabled ( false ) ; limitPanel . setEnabled ( false ) ; whiskasP...
Set the currently selected and edited particle emitter
37,913
public void updateBlendMode ( ) { if ( additive . isSelected ( ) ) { game . getSystem ( ) . setBlendingMode ( ParticleSystem . BLEND_ADDITIVE ) ; } else { game . getSystem ( ) . setBlendingMode ( ParticleSystem . BLEND_COMBINE ) ; } }
Change the visual indicator for the current particle system blend mode
37,914
public static void main ( String [ ] argv ) { try { UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ; new ParticleEditor ( ) ; } catch ( Exception e ) { Log . error ( e ) ; } }
Entry point in the editor
37,915
public static InputStream getResourceAsStream ( String ref ) { InputStream in = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; in = location . getResourceAsStream ( ref ) ; if ( in != null ) { break ; } } if ( in == null ) { throw ne...
Get a resource
37,916
public static boolean resourceExists ( String ref ) { URL url = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; url = location . getResource ( ref ) ; if ( url != null ) { return true ; } } return false ; }
Check if a resource is available from any given resource loader
37,917
public static URL getResource ( String ref ) { URL url = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; url = location . getResource ( ref ) ; if ( url != null ) { break ; } } if ( url == null ) { throw new RuntimeException ( "Resour...
Get a resource as a URL
37,918
public void setPosition ( float x , float y , boolean moveParticles ) { if ( moveParticles ) { adjust = true ; adjustx -= this . x - x ; adjusty -= this . y - y ; } this . x = x ; this . y = y ; }
Set the position of this particle source
37,919
public boolean completed ( ) { if ( engine == null ) { return false ; } if ( length . isEnabled ( ) ) { if ( timeout > 0 ) { return false ; } return completed ; } if ( emitCount . isEnabled ( ) ) { if ( leftToEmit > 0 ) { return false ; } return completed ; } if ( wrapUp ) { return completed ; } return false ; }
Check if this emitter has completed it s cycle
37,920
public ConfigurableEmitter duplicate ( ) { ConfigurableEmitter theCopy = null ; try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ParticleIO . saveEmitter ( bout , this ) ; ByteArrayInputStream bin = new ByteArrayInputStream ( bout . toByteArray ( ) ) ; theCopy = ParticleIO . loadEmitter ( bin ) ; } ca...
Create a duplicate of this emitter . The duplicate should be added to a ParticleSystem to be used .
37,921
public static void runAsApplication ( Game game , int width , int height , boolean fullscreen ) { try { AppGameContainer container = new AppGameContainer ( game , width , height , fullscreen ) ; container . start ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Start the game as an application
37,922
public void setX ( float x ) { if ( x != this . x ) { float dx = x - this . x ; this . x = x ; if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } for ( int i = 0 ; i < points . length / 2 ; i ++ ) { points [ i * 2 ] += dx ; } center [ 0 ] += dx ; x += dx ; maxX += dx ; minX += dx ; trianglesDirty = t...
Set the x position of the left side this shape .
37,923
public void setY ( float y ) { if ( y != this . y ) { float dy = y - this . y ; this . y = y ; if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } for ( int i = 0 ; i < points . length / 2 ; i ++ ) { points [ ( i * 2 ) + 1 ] += dy ; } center [ 1 ] += dy ; y += dy ; maxY += dy ; minY += dy ; trianglesD...
Set the y position of the top of this shape .
37,924
public void setCenterX ( float centerX ) { if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } float xDiff = centerX - getCenterX ( ) ; setX ( x + xDiff ) ; }
Set the x center of this shape .
37,925
public void setCenterY ( float centerY ) { if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } float yDiff = centerY - getCenterY ( ) ; setY ( y + yDiff ) ; }
Set the y center of this shape .
37,926
public float [ ] getPoint ( int index ) { checkPoints ( ) ; float result [ ] = new float [ 2 ] ; result [ 0 ] = points [ index * 2 ] ; result [ 1 ] = points [ index * 2 + 1 ] ; return result ; }
Get a single point in this polygon
37,927
public float [ ] getNormal ( int index ) { float [ ] current = getPoint ( index ) ; float [ ] prev = getPoint ( index - 1 < 0 ? getPointCount ( ) - 1 : index - 1 ) ; float [ ] next = getPoint ( index + 1 >= getPointCount ( ) ? 0 : index + 1 ) ; float [ ] t1 = getNormal ( prev , current ) ; float [ ] t2 = getNormal ( cu...
Get the combine normal of a given point
37,928
public boolean contains ( Shape other ) { if ( other . intersects ( this ) ) { return false ; } for ( int i = 0 ; i < other . getPointCount ( ) ; i ++ ) { float [ ] pt = other . getPoint ( i ) ; if ( ! contains ( pt [ 0 ] , pt [ 1 ] ) ) { return false ; } } return true ; }
Check if the shape passed is entirely contained within this shape .
37,929
private float [ ] getNormal ( float [ ] start , float [ ] end ) { float dx = start [ 0 ] - end [ 0 ] ; float dy = start [ 1 ] - end [ 1 ] ; float len = ( float ) Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) ; dx /= len ; dy /= len ; return new float [ ] { - dy , dx } ; }
Get the normal of the line between two points
37,930
public boolean includes ( float x , float y ) { if ( points . length == 0 ) { return false ; } checkPoints ( ) ; Line testLine = new Line ( 0 , 0 , 0 , 0 ) ; Vector2f pt = new Vector2f ( x , y ) ; for ( int i = 0 ; i < points . length ; i += 2 ) { int n = i + 2 ; if ( n >= points . length ) { n = 0 ; } testLine . set (...
Check if the given point is part of the path that forms this shape
37,931
public int indexOf ( float x , float y ) { for ( int i = 0 ; i < points . length ; i += 2 ) { if ( ( points [ i ] == x ) && ( points [ i + 1 ] == y ) ) { return i / 2 ; } } return - 1 ; }
Get the index of a given point
37,932
public boolean contains ( float x , float y ) { checkPoints ( ) ; if ( points . length == 0 ) { return false ; } boolean result = false ; float xnew , ynew ; float xold , yold ; float x1 , y1 ; float x2 , y2 ; int npoints = points . length ; xold = points [ npoints - 2 ] ; yold = points [ npoints - 1 ] ; for ( int i = ...
Check if this polygon contains the given point
37,933
public boolean intersects ( Shape shape ) { checkPoints ( ) ; boolean result = false ; float points [ ] = getPoints ( ) ; float thatPoints [ ] = shape . getPoints ( ) ; int length = points . length ; int thatLength = thatPoints . length ; double unknownA ; double unknownB ; if ( ! closed ( ) ) { length -= 2 ; } if ( ! ...
Check if this shape intersects with the shape provided .
37,934
public boolean hasVertex ( float x , float y ) { if ( points . length == 0 ) { return false ; } checkPoints ( ) ; for ( int i = 0 ; i < points . length ; i += 2 ) { if ( ( points [ i ] == x ) && ( points [ i + 1 ] == y ) ) { return true ; } } return false ; }
Check if a particular location is a vertex of this polygon
37,935
protected void findCenter ( ) { center = new float [ ] { 0 , 0 } ; int length = points . length ; for ( int i = 0 ; i < length ; i += 2 ) { center [ 0 ] += points [ i ] ; center [ 1 ] += points [ i + 1 ] ; } center [ 0 ] /= ( length / 2 ) ; center [ 1 ] /= ( length / 2 ) ; }
Get the center of this polygon .
37,936
protected void calculateRadius ( ) { boundingCircleRadius = 0 ; for ( int i = 0 ; i < points . length ; i += 2 ) { float temp = ( ( points [ i ] - center [ 0 ] ) * ( points [ i ] - center [ 0 ] ) ) + ( ( points [ i + 1 ] - center [ 1 ] ) * ( points [ i + 1 ] - center [ 1 ] ) ) ; boundingCircleRadius = ( boundingCircleR...
Calculate the radius of a circle that can completely enclose this shape .
37,937
protected void calculateTriangles ( ) { if ( ( ! trianglesDirty ) && ( tris != null ) ) { return ; } if ( points . length >= 6 ) { boolean clockwise = true ; float area = 0 ; for ( int i = 0 ; i < ( points . length / 2 ) - 1 ; i ++ ) { float x1 = points [ ( i * 2 ) ] ; float y1 = points [ ( i * 2 ) + 1 ] ; float x2 = p...
Calculate the triangles that can fill this shape
37,938
protected final void checkPoints ( ) { if ( pointsDirty ) { createPoints ( ) ; findCenter ( ) ; calculateRadius ( ) ; if ( points . length > 0 ) { maxX = points [ 0 ] ; maxY = points [ 1 ] ; minX = points [ 0 ] ; minY = points [ 1 ] ; for ( int i = 0 ; i < points . length / 2 ; i ++ ) { maxX = Math . max ( points [ i *...
Check the dirty flag and create points as necessary .
37,939
public Shape prune ( ) { Polygon result = new Polygon ( ) ; for ( int i = 0 ; i < getPointCount ( ) ; i ++ ) { int next = i + 1 >= getPointCount ( ) ? 0 : i + 1 ; int prev = i - 1 < 0 ? getPointCount ( ) - 1 : i - 1 ; float dx1 = getPoint ( i ) [ 0 ] - getPoint ( prev ) [ 0 ] ; float dy1 = getPoint ( i ) [ 1 ] - getPoi...
Prune any required points in this shape
37,940
public void setImageColor ( float r , float g , float b ) { setColor ( TOP_LEFT , r , g , b ) ; setColor ( TOP_RIGHT , r , g , b ) ; setColor ( BOTTOM_LEFT , r , g , b ) ; setColor ( BOTTOM_RIGHT , r , g , b ) ; }
Set the filter to apply when drawing this image
37,941
public void setColor ( int corner , float r , float g , float b , float a ) { if ( corners == null ) { corners = new Color [ ] { new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) } ; } corners [ corner ] . r = r ; corners [ corner ] . g = g ; corne...
Set the color of the given corner when this image is rendered . This is useful lots of visual effect but especially light maps
37,942
public void clampTexture ( ) { if ( GL . canTextureMirrorClamp ( ) ) { GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_S , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_T , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; } else { GL . glTexParameteri (...
Clamp the loaded texture to it s edges
37,943
private void load ( InputStream in , String ref , boolean flipped , int f , Color transparent ) throws SlickException { this . filter = f == FILTER_LINEAR ? SGL . GL_LINEAR : SGL . GL_NEAREST ; try { this . ref = ref ; int [ ] trans = null ; if ( transparent != null ) { trans = new int [ 3 ] ; trans [ 0 ] = ( int ) ( t...
Load the image
37,944
protected final void init ( ) { if ( inited ) { return ; } inited = true ; if ( texture != null ) { width = texture . getImageWidth ( ) ; height = texture . getImageHeight ( ) ; textureOffsetX = 0 ; textureOffsetY = 0 ; textureWidth = texture . getWidth ( ) ; textureHeight = texture . getHeight ( ) ; } initImpl ( ) ; c...
Initialise internal data
37,945
public void draw ( float x , float y ) { init ( ) ; draw ( x , y , width , height ) ; }
Draw this image at the specified location
37,946
public void drawEmbedded ( float x , float y , float width , float height ) { init ( ) ; if ( corners == null ) { GL . glTexCoord2f ( textureOffsetX , textureOffsetY ) ; GL . glVertex3f ( x , y , 0 ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x , y + height , 0 ) ; GL . ...
Draw this image as part of a collection of images
37,947
public void draw ( float x , float y , float scale ) { init ( ) ; draw ( x , y , width * scale , height * scale , Color . white ) ; }
Draw the image with a given scale
37,948
public Image getSubImage ( int x , int y , int width , int height ) { init ( ) ; float newTextureOffsetX = ( ( x / ( float ) this . width ) * textureWidth ) + textureOffsetX ; float newTextureOffsetY = ( ( y / ( float ) this . height ) * textureHeight ) + textureOffsetY ; float newTextureWidth = ( ( width / ( float ) t...
Get a sub - part of this image . Note that the create image retains a reference to the image data so should anything change it will affect sub - images too .
37,949
public void drawWarped ( float x1 , float y1 , float x2 , float y2 , float x3 , float y3 , float x4 , float y4 ) { Color . white . bind ( ) ; texture . bind ( ) ; GL . glTranslatef ( x1 , y1 , 0 ) ; if ( angle != 0 ) { GL . glTranslatef ( centerX , centerY , 0.0f ) ; GL . glRotatef ( angle , 0.0f , 0.0f , 1.0f ) ; GL ....
Draw the image in a warper rectangle . The effects this can have are many and varied might be interesting though .
37,950
public Image getFlippedCopy ( boolean flipHorizontal , boolean flipVertical ) { init ( ) ; Image image = copy ( ) ; if ( flipHorizontal ) { image . textureOffsetX = textureOffsetX + textureWidth ; image . textureWidth = - textureWidth ; } if ( flipVertical ) { image . textureOffsetY = textureOffsetY + textureHeight ; i...
Get a copy image flipped on potentially two axis
37,951
public Color getColor ( int x , int y ) { if ( pixelData == null ) { pixelData = texture . getTextureData ( ) ; } int xo = ( int ) ( textureOffsetX * texture . getTextureWidth ( ) ) ; int yo = ( int ) ( textureOffsetY * texture . getTextureHeight ( ) ) ; if ( textureWidth < 0 ) { x = xo - x ; } else { x = xo + x ; } if...
Get the colour of a pixel at a specified location in this image
37,952
public static void drawLeft ( Font font , String s , int x , int y ) { drawString ( font , s , Alignment . LEFT , x , y , 0 , Color . white ) ; }
Draw text left justified
37,953
public static void drawCenter ( Font font , String s , int x , int y , int width ) { drawString ( font , s , Alignment . CENTER , x , y , width , Color . white ) ; }
Draw text center justified
37,954
public static void drawRight ( Font font , String s , int x , int y , int width ) { drawString ( font , s , Alignment . RIGHT , x , y , width , Color . white ) ; }
Draw text right justified
37,955
public void load ( ) { int resp = loadChooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { lastSelected = loadChooser . getSelectedFile ( ) ; saveChooser . setCurrentDirectory ( loadChooser . getCurrentDirectory ( ) ) ; try { BufferedImage image = ImageIO . read ( lastSelected ) ; imagePan...
Load the current image
37,956
public void save ( ) { int resp = saveChooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = saveChooser . getSelectedFile ( ) ; String type = null ; if ( file . getName ( ) . endsWith ( ".png" ) ) { type = "PNG" ; } if ( file . getName ( ) . endsWith ( ".gif" ) ) { type = "GIF" ...
Save the current image
37,957
public String [ ] getAttributeNames ( ) { NamedNodeMap map = dom . getAttributes ( ) ; String [ ] names = new String [ map . getLength ( ) ] ; for ( int i = 0 ; i < names . length ; i ++ ) { names [ i ] = map . item ( i ) . getNodeName ( ) ; } return names ; }
Get the names of the attributes specified on this element
37,958
public String getAttribute ( String name , String def ) { String value = dom . getAttribute ( name ) ; if ( ( value == null ) || ( value . length ( ) == 0 ) ) { return def ; } return value ; }
Get the value specified for a given attribute on this element
37,959
public int getIntAttribute ( String name ) throws SlickXMLException { try { return Integer . parseInt ( getAttribute ( name ) ) ; } catch ( NumberFormatException e ) { throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is not an integer" , e ) ; } }
Get the value specified for a given attribute on this element as an integer .
37,960
public double getDoubleAttribute ( String name ) throws SlickXMLException { try { return Double . parseDouble ( getAttribute ( name ) ) ; } catch ( NumberFormatException e ) { throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is not a double" , e ) ; } }
Get the value specified for a given attribute on this element as an double .
37,961
public boolean getBooleanAttribute ( String name ) throws SlickXMLException { String value = getAttribute ( name ) ; if ( value . equalsIgnoreCase ( "true" ) ) { return true ; } if ( value . equalsIgnoreCase ( "false" ) ) { return false ; } throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is n...
Get the value specified for a given attribute on this element as a boolean .
37,962
public String getContent ( ) { String content = "" ; NodeList list = dom . getChildNodes ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { if ( list . item ( i ) instanceof Text ) { content += ( list . item ( i ) . getNodeValue ( ) ) ; } } return content ; }
Get the text content of the element i . e . the bit between the tags
37,963
public XMLElementList getChildren ( ) { if ( children != null ) { return children ; } NodeList list = dom . getChildNodes ( ) ; children = new XMLElementList ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { if ( list . item ( i ) instanceof Element ) { children . add ( new XMLElement ( ( Element ) list . ite...
Get the complete list of children for this node
37,964
public XMLElementList getChildrenByName ( String name ) { XMLElementList selected = new XMLElementList ( ) ; XMLElementList children = getChildren ( ) ; for ( int i = 0 ; i < children . size ( ) ; i ++ ) { if ( children . get ( i ) . getName ( ) . equals ( name ) ) { selected . add ( children . get ( i ) ) ; } } return...
Get a list of children with a given element name
37,965
protected void createPoints ( ) { ArrayList tempPoints = new ArrayList ( ) ; maxX = - Float . MIN_VALUE ; maxY = - Float . MIN_VALUE ; minX = Float . MAX_VALUE ; minY = Float . MAX_VALUE ; float start = 0 ; float end = 359 ; float cx = x + radius1 ; float cy = y + radius2 ; int step = 360 / segmentCount ; for ( float a...
Generate the points to outline this ellipse .
37,966
public Space findSpace ( float x , float y ) { for ( int i = 0 ; i < spaces . size ( ) ; i ++ ) { Space space = getSpace ( i ) ; if ( space . contains ( x , y ) ) { return space ; } } return null ; }
Find the space at a given location
37,967
public NavPath findPath ( float sx , float sy , float tx , float ty , boolean optimize ) { Space source = findSpace ( sx , sy ) ; Space target = findSpace ( tx , ty ) ; if ( ( source == null ) || ( target == null ) ) { return null ; } for ( int i = 0 ; i < spaces . size ( ) ; i ++ ) { ( ( Space ) spaces . get ( i ) ) ....
Find a path from the source to the target coordinates
37,968
private boolean isClear ( float x1 , float y1 , float x2 , float y2 , float step ) { float dx = ( x2 - x1 ) ; float dy = ( y2 - y1 ) ; float len = ( float ) Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) ; dx *= step ; dx /= len ; dy *= step ; dy /= len ; int steps = ( int ) ( len / step ) ; for ( int i = 0 ; i < steps ; i ...
Check if a particular path is clear
37,969
private void optimize ( NavPath path ) { int pt = 0 ; while ( pt < path . length ( ) - 2 ) { float sx = path . getX ( pt ) ; float sy = path . getY ( pt ) ; float nx = path . getX ( pt + 2 ) ; float ny = path . getY ( pt + 2 ) ; if ( isClear ( sx , sy , nx , ny , 0.1f ) ) { path . remove ( pt + 1 ) ; } else { pt ++ ; }...
Optimize a path by removing segments that arn t required to reach the end point
37,970
public static double sin ( double radians ) { radians = reduceSinAngle ( radians ) ; if ( Math . abs ( radians ) <= Math . PI / 4 ) { return Math . sin ( radians ) ; } else { return Math . cos ( Math . PI / 2 - radians ) ; } }
Get the sine of an angle
37,971
private boolean tryMove ( float x , float y ) { float newx = playerX + x ; float newy = playerY + y ; if ( blocked ( newx , newy ) ) { if ( blocked ( newx , playerY ) ) { if ( blocked ( playerX , newy ) ) { return false ; } else { playerY = newy ; return true ; } } else { playerX = newx ; return true ; } } else { playe...
Try to move in the direction specified . If it s blocked try sliding . If that doesn t work just don t bother
37,972
private void updateMovementVector ( ) { dirX = ( float ) Math . sin ( Math . toRadians ( ang ) ) ; dirY = ( float ) - Math . cos ( Math . toRadians ( ang ) ) ; }
Update the direction that will be moved in based on the current angle of rotation
37,973
public void drawTank ( Graphics g , float xpos , float ypos , float rot ) { int cx = ( int ) ( xpos * 32 ) ; int cy = ( int ) ( ypos * 32 ) ; g . rotate ( cx , cy , rot ) ; player . draw ( cx - 16 , cy - 16 ) ; g . rotate ( cx , cy , - rot ) ; }
Draw a single tank to the game
37,974
public static void main ( String [ ] argv ) { try { AppGameContainer container = new AppGameContainer ( new Scroller ( ) , 800 , 600 , false ) ; container . start ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Entry point to the scroller example
37,975
private void browseForImage ( ) { if ( emitter != null ) { int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; String path = file . getParentFile ( ) . getAbsolutePath ( ) ; String name = file . getName ( ) ; ConfigurableEmitter . set...
Browse for a particle image and set the value into both the emitter and text field on successful completion
37,976
public static final int getMaxSingleImageSize ( ) { IntBuffer buffer = BufferUtils . createIntBuffer ( 16 ) ; GL . glGetInteger ( SGL . GL_MAX_TEXTURE_SIZE , buffer ) ; return buffer . get ( 0 ) ; }
Get the maximum size of an image supported by the underlying hardware .
37,977
private void build ( String ref , int filter , int tileSize ) throws SlickException { try { final LoadableImageData data = ImageDataFactory . getImageDataFor ( ref ) ; final ByteBuffer imageBuffer = data . loadImage ( ResourceLoader . getResourceAsStream ( ref ) , false , null ) ; build ( data , imageBuffer , filter , ...
Create a new big image by loading it from the specified reference
37,978
public void destroy ( ) throws SlickException { for ( int tx = 0 ; tx < xcount ; tx ++ ) { for ( int ty = 0 ; ty < ycount ; ty ++ ) { Image image = images [ tx ] [ ty ] ; image . destroy ( ) ; } } }
Destroy the image and release any native resources . Calls on a destroyed image have undefined results
37,979
private void copyArea ( BufferedImage image , int x , int y , int width , int height , int dx , int dy ) { Graphics2D g = ( Graphics2D ) image . getGraphics ( ) ; g . drawImage ( image . getSubimage ( x , y , width , height ) , x + dx , y + dy , null ) ; }
Implement of transform copy area for 1 . 4
37,980
public static Texture getTexture ( String resourceName , BufferedImage resourceImage ) throws IOException { Texture tex = getTexture ( resourceName , resourceImage , SGL . GL_TEXTURE_2D , SGL . GL_RGBA8 , SGL . GL_LINEAR , SGL . GL_LINEAR ) ; return tex ; }
Load a texture
37,981
public static Texture getTexture ( String resourceName , BufferedImage resourceimage , int target , int dstPixelFormat , int minFilter , int magFilter ) throws IOException { ImageIOImageData data = new ImageIOImageData ( ) ; int srcPixelFormat = 0 ; int textureID = InternalTextureLoader . createTextureID ( ) ; TextureI...
Load a texture into OpenGL from a BufferedImage
37,982
static public BufferedImage getScratchImage ( ) { Graphics2D g = ( Graphics2D ) scratchImage . getGraphics ( ) ; g . setComposite ( AlphaComposite . Clear ) ; g . fillRect ( 0 , 0 , GlyphPage . MAX_GLYPH_SIZE , GlyphPage . MAX_GLYPH_SIZE ) ; g . setComposite ( AlphaComposite . SrcOver ) ; g . setColor ( java . awt . Co...
Returns an image that can be used by effects as a temp image .
37,983
static public Value colorValue ( String name , Color currentValue ) { return new DefaultValue ( name , EffectUtil . toString ( currentValue ) ) { public void showDialog ( ) { Color newColor = JColorChooser . showDialog ( null , "Choose a color" , EffectUtil . fromString ( value ) ) ; if ( newColor != null ) value = Eff...
Prompts the user for a colour value
37,984
static public Value intValue ( String name , final int currentValue , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JSpinner spinner = new JSpinner ( new SpinnerNumberModel ( currentValue , Short . MIN_VALUE , Short . MAX_VALUE , 1 ) ) ;...
Prompts the user for int value
37,985
static public Value floatValue ( String name , final float currentValue , final float min , final float max , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JSpinner spinner = new JSpinner ( new SpinnerNumberModel ( currentValue , min , m...
Prompts the user for float value
37,986
static public Value booleanValue ( String name , final boolean currentValue , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JCheckBox checkBox = new JCheckBox ( ) ; checkBox . setSelected ( currentValue ) ; if ( showValueDialog ( checkBo...
Prompts the user for boolean value
37,987
static public Value optionValue ( String name , final String currentValue , final String [ ] [ ] options , final String description ) { return new DefaultValue ( name , currentValue . toString ( ) ) { public void showDialog ( ) { int selectedIndex = - 1 ; DefaultComboBoxModel model = new DefaultComboBoxModel ( ) ; for ...
Prompts the user for a value that represents a fixed number of options . All options are strings .
37,988
static public Color fromString ( String rgb ) { if ( rgb == null || rgb . length ( ) != 6 ) return Color . white ; return new Color ( Integer . parseInt ( rgb . substring ( 0 , 2 ) , 16 ) , Integer . parseInt ( rgb . substring ( 2 , 4 ) , 16 ) , Integer . parseInt ( rgb . substring ( 4 , 6 ) , 16 ) ) ; }
Converts a string to a color .
37,989
private void addKeyListenerImpl ( KeyListener listener ) { if ( keyListeners . contains ( listener ) ) { return ; } keyListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a key listener to be notified of key input events
37,990
private void addMouseListenerImpl ( MouseListener listener ) { if ( mouseListeners . contains ( listener ) ) { return ; } mouseListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a mouse listener to be notified of mouse input events
37,991
public void addControllerListener ( ControllerListener listener ) { if ( controllerListeners . contains ( listener ) ) { return ; } controllerListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a controller listener to be notified of controller input events
37,992
public void addPrimaryListener ( InputListener listener ) { removeListener ( listener ) ; keyListeners . add ( 0 , listener ) ; mouseListeners . add ( 0 , listener ) ; controllerListeners . add ( 0 , listener ) ; allListeners . add ( listener ) ; }
Add a listener to be notified of input events . This listener will get events before others that are currently registered
37,993
public void removeKeyListener ( KeyListener listener ) { keyListeners . remove ( listener ) ; keyListenersToAdd . remove ( listener ) ; if ( ! mouseListeners . contains ( listener ) && ! controllerListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a key listener that will no longer be notified
37,994
public void removeControllerListener ( ControllerListener listener ) { controllerListeners . remove ( listener ) ; if ( ! mouseListeners . contains ( listener ) && ! keyListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a controller listener that will no longer be notified
37,995
public void removeMouseListener ( MouseListener listener ) { mouseListeners . remove ( listener ) ; mouseListenersToAdd . remove ( listener ) ; if ( ! controllerListeners . contains ( listener ) && ! keyListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a mouse listener that will no longer be notified
37,996
public boolean isControlPressed ( int button , int controller ) { if ( controllerPressed [ controller ] [ button ] ) { controllerPressed [ controller ] [ button ] = false ; return true ; } return false ; }
Check if a controller button has been pressed since last time
37,997
public void clearControlPressedRecord ( ) { for ( int i = 0 ; i < controllers . size ( ) ; i ++ ) { Arrays . fill ( controllerPressed [ i ] , false ) ; } }
Clear the state for isControlPressed method . This will reset all controls to not pressed
37,998
public String getAxisName ( int controller , int axis ) { return ( ( Controller ) controllers . get ( controller ) ) . getAxisName ( axis ) ; }
Get the name of the axis with the given index
37,999
public boolean isControllerLeft ( int controller ) { if ( controller >= getControllerCount ( ) ) { return false ; } if ( controller == ANY_CONTROLLER ) { for ( int i = 0 ; i < controllers . size ( ) ; i ++ ) { if ( isControllerLeft ( i ) ) { return true ; } } return false ; } return ( ( Controller ) controllers . get (...
Check if the controller has the left direction pressed