Hey all!
Im new at programmering and needed some help with it! I have made/got help about this code and wonder what image. code means here
http://pastebin.com/CxJa99Ph


1 | GreenfootImage image = new GreenfootImage( "picture.png" ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class ShieldPercent extends Actor { GreenfootImage image = getImage(); private String procent = ( int ) Rocket.shieldAmmount + "%" ; private int length = procent.length(); public ShieldPercent() { image.clear(); image.scale( 40 , image.getHeight()); image.setColor(Color.GREEN); image.drawString(procent, (image.getWidth() / 2 ) - (procent.length() * 3 ), image.getHeight()); } /** * Act - do whatever the FuelIndicator wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { updateImage(); procent = ( int ) Rocket.shieldAmmount + " %" ; } private void updateImage() { if (Rocket.shieldAmmount <= 101 ) { image.clear(); image.setColor(Color.GREEN); image.drawString(procent, (image.getWidth() / 2 ) - (procent.length() * 3 ), image.getHeight()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import greenfoot.*; public class Bar extends Actor { private int value; private int maxValue; private String uom; private GreenfootImage titleImage; public Bar(String title, String suffix, int val, int max) { uom = suffix; maxValue = max; value = val; titleImage = new GreenfootImage( " " +title+ " " , 20 , java.awt.Color.black, null ); updateImage(); } public void setValue( int val) { if (val < 0 || val > maxValue || value == val) return ; value = val; updateImage(); } private void updateImage() { GreenfootImage frame = new GreenfootImage( 104 , 14 ); frame.drawRect( 0 , 0 , 103 , 13 ); GreenfootImage bar = new GreenfootImage( 100 , 10 ); bar.setColor(java.awt.Color.green); bar.fillRect( 0 , 0 , 100 *value/maxValue, 10 ); frame.drawImage(bar, 2 , 2 ); GreenfootImage valueImage = new GreenfootImage( " " +value+ " " +uom+ " " , 20 , java.awt.Color.black, null ); int greaterWidth = titleImage.getWidth(); if (valueImage.getWidth() > greaterWidth) greaterWidth = valueImage.getWidth(); GreenfootImage main = new GreenfootImage( 2 *greaterWidth+ 104 , 16 ); main.drawImage(frame, main.getWidth()/ 2 - 52 , 2 ); main.drawImage(titleImage, main.getWidth()/ 2 - 52 -titleImage.getWidth(), 8 -titleImage.getHeight()/ 2 ); main.drawImage(valueImage, main.getWidth()/ 2 + 52 , 8 -valueImage.getHeight()/ 2 ); setImage(main); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import greenfoot.*; public class TestWorld extends World { int maxShieldStrength = 100 ; int shieldStrength = maxShieldStrength; Bar shieldBar; public TestWorld() { super ( 300 , 100 , 1 ); addObject(shieldBar = new Bar( "Shield" , "%" , 100 , 100 ), 150 , 50 ); } public void act() { // use the space bar to trigger hit and lose of shield strength for testing if (shieldStrength > 0 && Greenfoot.isKeyDown( "space" )) { shieldStrength--; shieldBar.setValue( 100 *shieldStrength/maxShieldStrength); } } } |