mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Viele weitere Beispielprojekt für verschiedene Anwendungen
This commit is contained in:
101
examples/zm_cookieclicker/Cookieclicker.java
Normal file
101
examples/zm_cookieclicker/Cookieclicker.java
Normal file
@@ -0,0 +1,101 @@
|
||||
import schule.ngb.zm.GraphicsLayer;
|
||||
import schule.ngb.zm.Options;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
import schule.ngb.zm.shapes.Picture;
|
||||
import schule.ngb.zm.shapes.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Cookieclicker extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new Cookieclicker();
|
||||
}
|
||||
|
||||
private int cookies = 0;
|
||||
|
||||
private int cookiesPerClick = 1;
|
||||
|
||||
private int grandmas = 0;
|
||||
|
||||
private int autoclicker = 12, autoclickerTimer = 0, autoClickerDelay = 600;
|
||||
|
||||
private Text tCookies, tShopGrandma, tShopAutoclicker;
|
||||
|
||||
private Picture pCookie;
|
||||
|
||||
private boolean cookieDown = false;
|
||||
|
||||
public Cookieclicker() {
|
||||
super(1280, 900, "Cookieclicker");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
pCookie = new Picture(width / 2, height / 2, "assets/cookie.png");
|
||||
pCookie.scale(.5);
|
||||
shapes.add(pCookie);
|
||||
|
||||
tCookies = new Text(width - 60, 60, "" + cookies);
|
||||
tCookies.setAnchor(NORTHEAST);
|
||||
tCookies.setStrokeColor(255);
|
||||
tCookies.setFontsize(36);
|
||||
shapes.add(tCookies);
|
||||
|
||||
background.setColor(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
tCookies.setText("" + cookies);
|
||||
|
||||
autoclickerTimer -= (int)(delta * 1000.0);
|
||||
if( autoclickerTimer <= 0 ) {
|
||||
cookies += autoclicker;
|
||||
autoclickerTimer += autoClickerDelay;
|
||||
}
|
||||
|
||||
synchronized( particles ) {
|
||||
ArrayList<NumberParticle> remove = new ArrayList<>();
|
||||
for( NumberParticle p : particles ) {
|
||||
if( p.isActive() ) {
|
||||
p.update(delta);
|
||||
} else {
|
||||
remove.add(p);
|
||||
}
|
||||
}
|
||||
for( NumberParticle p : remove ) {
|
||||
particles.remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
}
|
||||
|
||||
ArrayList<NumberParticle> particles = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void mousePressed() {
|
||||
if( pCookie.getBounds().contains(mouseX, mouseY) ) {
|
||||
cookieDown = true;
|
||||
cookies += cookiesPerClick;
|
||||
pCookie.scale(.95);
|
||||
|
||||
synchronized( particles ) {
|
||||
NumberParticle p = new NumberParticle(mouseX, mouseY, cookiesPerClick);
|
||||
particles.add(p);
|
||||
shapes.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased() {
|
||||
if( cookieDown ) {
|
||||
pCookie.scale(1 / .95);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
examples/zm_cookieclicker/NumberParticle.java
Normal file
33
examples/zm_cookieclicker/NumberParticle.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import schule.ngb.zm.Updatable;
|
||||
import schule.ngb.zm.shapes.Text;
|
||||
|
||||
public class NumberParticle extends Text implements Updatable {
|
||||
|
||||
double sinOffset, life = 0;
|
||||
|
||||
public NumberParticle( double x, double y, int number ) {
|
||||
super(x,y,"+"+number);
|
||||
sinOffset = random(0.0, PI);
|
||||
life = 1.5;
|
||||
setStrokeColor(255);
|
||||
setFontsize(36);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return (life > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
if( isActive() ) {
|
||||
double deltaX = sin(sinOffset + life);
|
||||
x += deltaX;
|
||||
y -= 100*delta;
|
||||
|
||||
life -= delta;
|
||||
setStrokeColor(strokeColor, (int) interpolate(0, 255, life / 1.5));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
111
examples/zm_cookieclicker/NumberParticleEmitter.java
Normal file
111
examples/zm_cookieclicker/NumberParticleEmitter.java
Normal file
@@ -0,0 +1,111 @@
|
||||
import schule.ngb.zm.Drawable;
|
||||
import schule.ngb.zm.Updatable;
|
||||
import schule.ngb.zm.shapes.Text;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class NumberParticleEmitter implements Updatable, Drawable {
|
||||
|
||||
public class NumberParticle extends Text implements Updatable {
|
||||
|
||||
double velX = 0, velY = 0, accX = 0, accY = 0;
|
||||
|
||||
double life = 0;
|
||||
|
||||
public NumberParticle() {
|
||||
super(0, 0, "0");
|
||||
// life = particleLifespan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return (life <= 0);
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
x = emitterX;
|
||||
y = emitterY;
|
||||
life = particleLifespan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
if( isActive() ) {
|
||||
velX += accX;
|
||||
velY += accY;
|
||||
x += velX;
|
||||
y += velY;
|
||||
|
||||
life -= delta;
|
||||
setFillColor(fillColor, (int) interpolate(0, 255, life / particleLifespan));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int particlesPerSecond, maxParticles;
|
||||
|
||||
private double particleLifespan;
|
||||
|
||||
private ArrayList<NumberParticle> particles;
|
||||
|
||||
private int activeParticles = 0;
|
||||
|
||||
private double lastEmit = 0.0;
|
||||
|
||||
private double emitterX, emitterY;
|
||||
|
||||
public NumberParticleEmitter( double x, double y, int particlesPerSecond, double particleLifespan ) {
|
||||
emitterX = x;
|
||||
emitterY = y;
|
||||
|
||||
this.particlesPerSecond = particlesPerSecond;
|
||||
this.particleLifespan = particleLifespan;
|
||||
|
||||
maxParticles = (int) Math.ceil(particlesPerSecond * particleLifespan);
|
||||
particles = new ArrayList<>(maxParticles);
|
||||
|
||||
for( int i = 0; i < maxParticles; i++ ) {
|
||||
particles.add(new NumberParticle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return activeParticles > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw( Graphics2D graphics ) {
|
||||
for( NumberParticle p : particles ) {
|
||||
if( p.isActive() ) {
|
||||
p.draw(graphics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return isVisible();
|
||||
}
|
||||
|
||||
public void emitParticle( int number ) {
|
||||
particles.add(new NumberParticle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
//lastEmit -= delta;
|
||||
|
||||
for( NumberParticle p : particles ) {
|
||||
if( p.isActive() ) {
|
||||
p.update(delta);
|
||||
} /*else if( lastEmit <= 0 ) {
|
||||
p.activate();
|
||||
lastEmit += 1/(double)particlesPerSecond;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
examples/zm_cookieclicker/ParticleTest.java
Normal file
36
examples/zm_cookieclicker/ParticleTest.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import schule.ngb.zm.GraphicsLayer;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class ParticleTest extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new ParticleTest();
|
||||
}
|
||||
|
||||
private NumberParticleEmitter emitter;
|
||||
|
||||
private GraphicsLayer graphics;
|
||||
|
||||
public ParticleTest() {
|
||||
super(800,800, "Particles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
graphics = new GraphicsLayer();
|
||||
canvas.addLayer(graphics);
|
||||
|
||||
emitter = new NumberParticleEmitter(400, 400, 1, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
emitter.update(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
emitter.draw(graphics.getGraphics());
|
||||
}
|
||||
|
||||
}
|
||||
BIN
examples/zm_cookieclicker/assets/Cookie.png
Normal file
BIN
examples/zm_cookieclicker/assets/Cookie.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
55
examples/zm_cookieclicker/package.bluej
Normal file
55
examples/zm_cookieclicker/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
|
||||
Reference in New Issue
Block a user