Viele weitere Beispielprojekt für verschiedene Anwendungen
53
examples/zm_aquarium/Aquarium.java
Normal file
@@ -0,0 +1,53 @@
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
import schule.ngb.zm.util.ImageLoader;
|
||||
|
||||
public class Aquarium extends Zeichenmaschine {
|
||||
|
||||
public static final int N_FISHES = 25;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new Aquarium();
|
||||
}
|
||||
|
||||
private Fish[] fish;
|
||||
|
||||
public Aquarium() {
|
||||
super(800, 600, "Aquarium");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
canvas.addLayer(1, new Background());
|
||||
|
||||
fish = new Fish[N_FISHES];
|
||||
|
||||
for( int i = 1; i <= 7; i++ ) {
|
||||
ImageLoader.preloadImage("fish"+i, "tiles/fish"+i+"gs.png");
|
||||
}
|
||||
|
||||
for( int i = 0; i < N_FISHES; i++ ) {
|
||||
fish[i] = new Fish();
|
||||
shapes.add(fish[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
for( int i = 0; i < fish.length; i++ ) {
|
||||
fish[i].update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked() {
|
||||
for( int i = 0; i < fish.length; i++ ) {
|
||||
fish[i].randomize();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
59
examples/zm_aquarium/Background.java
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
import schule.ngb.zm.Layer;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
|
||||
public class Background extends Layer {
|
||||
|
||||
private static final int TILE_SIZE = 64;
|
||||
|
||||
private int tile_width;
|
||||
|
||||
private Image[] floor, plants;
|
||||
|
||||
private Image water;
|
||||
|
||||
public Background() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Background( int width, int height ) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize( int width, int height ) {
|
||||
super.setSize(width, height);
|
||||
generateBackground();
|
||||
}
|
||||
|
||||
public void generateBackground() {
|
||||
tile_width = (int)(ceil(getWidth()/(double)TILE_SIZE));
|
||||
floor = new Image[tile_width];
|
||||
plants = new Image[tile_width];
|
||||
|
||||
for ( int i = 0; i < tile_width; i++ ) {
|
||||
floor[i] = loadImage("tiles/floor"+random(1,8)+".png");
|
||||
if( random(1,10) < 4 ) {
|
||||
plants[i] = loadImage("tiles/plant"+random(1,14)+".png");
|
||||
}
|
||||
}
|
||||
|
||||
water = loadImage("tiles/water.png");
|
||||
|
||||
for ( int i = 0; i < getHeight(); i += TILE_SIZE ) {
|
||||
for ( int j = 0; j < getWidth(); j += TILE_SIZE ) {
|
||||
drawing.drawImage(water, j, i, null);
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < tile_width; i++ ) {
|
||||
if( plants[i] != null ) {
|
||||
drawing.drawImage(plants[i], i*TILE_SIZE, getHeight() - (2*TILE_SIZE) + 10,TILE_SIZE,TILE_SIZE, null);
|
||||
}
|
||||
drawing.drawImage(floor[i], i*TILE_SIZE, getHeight() - TILE_SIZE,TILE_SIZE,TILE_SIZE, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
examples/zm_aquarium/Fish.java
Normal file
@@ -0,0 +1,72 @@
|
||||
import schule.ngb.zm.*;
|
||||
import schule.ngb.zm.shapes.Picture;
|
||||
import schule.ngb.zm.shapes.Shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
public class Fish extends Shape implements Updatable {
|
||||
|
||||
private int speed;
|
||||
|
||||
private Picture img;
|
||||
|
||||
public Fish() {
|
||||
randomize();
|
||||
}
|
||||
|
||||
public void randomize() {
|
||||
int i = random(1, 7);
|
||||
speed = random(-2, 2);
|
||||
img = new Picture("fish" + i);
|
||||
img.setAnchor(NORTHWEST);
|
||||
img.scale(random(0.8, 1.0));
|
||||
img.tint(randomNiceColor());
|
||||
//img.scale(0.5);
|
||||
if( speed < 0 ) {
|
||||
img.flip(LEFT);
|
||||
}
|
||||
img.moveTo(random(10, width-img.getWidth()), random(30, height-120));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
img.move(speed, .5 * sin(tick / (speed * 10.0)));
|
||||
|
||||
if( img.getX() <= 0 || img.getX()+img.getWidth() >= 800 ) {
|
||||
speed *= -1;
|
||||
img.flip(LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw( Graphics2D graphics, AffineTransform transform ) {
|
||||
img.draw(graphics, transform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return img.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return img.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape copy() {
|
||||
return img.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.awt.Shape getShape() {
|
||||
return img.getShape();
|
||||
}
|
||||
|
||||
}
|
||||
55
examples/zm_aquarium/package.bluej
Normal file
@@ -0,0 +1,55 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Attractor
|
||||
dependency1.to=Gravity
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Gravity
|
||||
dependency2.to=Mover
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Gravity
|
||||
dependency3.to=Attractor
|
||||
dependency3.type=UsesDependency
|
||||
editor.fx.0.height=728
|
||||
editor.fx.0.width=1037
|
||||
editor.fx.0.x=95
|
||||
editor.fx.0.y=53
|
||||
objectbench.height=94
|
||||
objectbench.width=776
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8305369127516778
|
||||
package.editor.height=488
|
||||
package.editor.width=661
|
||||
package.editor.x=374
|
||||
package.editor.y=158
|
||||
package.frame.height=660
|
||||
package.frame.width=800
|
||||
package.numDependencies=3
|
||||
package.numTargets=3
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=48
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=Mover
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=380
|
||||
target1.y=220
|
||||
target2.height=70
|
||||
target2.name=Attractor
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=380
|
||||
target2.y=350
|
||||
target3.height=70
|
||||
target3.name=Gravity
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=120
|
||||
target3.y=120
|
||||
BIN
examples/zm_aquarium/tiles/fish1.png
Executable file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
examples/zm_aquarium/tiles/fish1gs.png
Executable file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
examples/zm_aquarium/tiles/fish2.png
Executable file
|
After Width: | Height: | Size: 785 B |
BIN
examples/zm_aquarium/tiles/fish2gs.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
examples/zm_aquarium/tiles/fish3.png
Executable file
|
After Width: | Height: | Size: 982 B |
BIN
examples/zm_aquarium/tiles/fish3gs.png
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
examples/zm_aquarium/tiles/fish4.png
Executable file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
examples/zm_aquarium/tiles/fish4gs.png
Executable file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
examples/zm_aquarium/tiles/fish5.png
Executable file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
examples/zm_aquarium/tiles/fish5gs.png
Executable file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
examples/zm_aquarium/tiles/fish6.png
Executable file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
examples/zm_aquarium/tiles/fish6gs.png
Executable file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
examples/zm_aquarium/tiles/fish7.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
examples/zm_aquarium/tiles/fish7gs.png
Executable file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
examples/zm_aquarium/tiles/floor1.png
Executable file
|
After Width: | Height: | Size: 817 B |
BIN
examples/zm_aquarium/tiles/floor2.png
Executable file
|
After Width: | Height: | Size: 821 B |
BIN
examples/zm_aquarium/tiles/floor3.png
Executable file
|
After Width: | Height: | Size: 886 B |
BIN
examples/zm_aquarium/tiles/floor4.png
Executable file
|
After Width: | Height: | Size: 904 B |
BIN
examples/zm_aquarium/tiles/floor5.png
Executable file
|
After Width: | Height: | Size: 757 B |
BIN
examples/zm_aquarium/tiles/floor6.png
Executable file
|
After Width: | Height: | Size: 861 B |
BIN
examples/zm_aquarium/tiles/floor7.png
Executable file
|
After Width: | Height: | Size: 732 B |
BIN
examples/zm_aquarium/tiles/floor8.png
Executable file
|
After Width: | Height: | Size: 798 B |
BIN
examples/zm_aquarium/tiles/plant1.png
Executable file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
examples/zm_aquarium/tiles/plant10.png
Executable file
|
After Width: | Height: | Size: 769 B |
BIN
examples/zm_aquarium/tiles/plant11.png
Executable file
|
After Width: | Height: | Size: 1012 B |
BIN
examples/zm_aquarium/tiles/plant12.png
Executable file
|
After Width: | Height: | Size: 689 B |
BIN
examples/zm_aquarium/tiles/plant13.png
Executable file
|
After Width: | Height: | Size: 1013 B |
BIN
examples/zm_aquarium/tiles/plant14.png
Executable file
|
After Width: | Height: | Size: 1012 B |
BIN
examples/zm_aquarium/tiles/plant2.png
Executable file
|
After Width: | Height: | Size: 890 B |
BIN
examples/zm_aquarium/tiles/plant3.png
Executable file
|
After Width: | Height: | Size: 930 B |
BIN
examples/zm_aquarium/tiles/plant4.png
Executable file
|
After Width: | Height: | Size: 752 B |
BIN
examples/zm_aquarium/tiles/plant5.png
Executable file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
examples/zm_aquarium/tiles/plant6.png
Executable file
|
After Width: | Height: | Size: 886 B |
BIN
examples/zm_aquarium/tiles/plant7.png
Executable file
|
After Width: | Height: | Size: 925 B |
BIN
examples/zm_aquarium/tiles/plant8.png
Executable file
|
After Width: | Height: | Size: 741 B |
BIN
examples/zm_aquarium/tiles/plant9.png
Executable file
|
After Width: | Height: | Size: 653 B |
BIN
examples/zm_aquarium/tiles/shark.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
examples/zm_aquarium/tiles/skeleton1.png
Executable file
|
After Width: | Height: | Size: 711 B |
BIN
examples/zm_aquarium/tiles/skeleton10.png
Executable file
|
After Width: | Height: | Size: 821 B |
BIN
examples/zm_aquarium/tiles/skeleton2.png
Executable file
|
After Width: | Height: | Size: 941 B |
BIN
examples/zm_aquarium/tiles/skeleton3.png
Executable file
|
After Width: | Height: | Size: 581 B |
BIN
examples/zm_aquarium/tiles/skeleton4.png
Executable file
|
After Width: | Height: | Size: 729 B |
BIN
examples/zm_aquarium/tiles/skeleton5.png
Executable file
|
After Width: | Height: | Size: 624 B |
BIN
examples/zm_aquarium/tiles/skeleton6.png
Executable file
|
After Width: | Height: | Size: 848 B |
BIN
examples/zm_aquarium/tiles/skeleton7.png
Executable file
|
After Width: | Height: | Size: 745 B |
BIN
examples/zm_aquarium/tiles/skeleton8.png
Executable file
|
After Width: | Height: | Size: 1014 B |
BIN
examples/zm_aquarium/tiles/skeleton9.png
Executable file
|
After Width: | Height: | Size: 629 B |
BIN
examples/zm_aquarium/tiles/water.png
Executable file
|
After Width: | Height: | Size: 103 B |