This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

neezee
neezee presents ...

2013/7/9

Wolf_und_Schaf (Wolf and Sheep)

A little game based on the throwing engine of this scenario: http://www.greenfoot.org/scenarios/5940

1861 views / 25 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
Was bedeutet die blaue Wurfmarkierung?
neezeeneezee

2013/7/9

Die soll den letzten Wurf anzeigen, allerdings scheint es nicht der letzte eigene zu sein, sondern der des Gegners. Hab den Fehler bisher nicht finden können - eigentlich hat jeder Spieler sein eigenes Visier-Objekt...
achso
Max-FelixMax-Felix

2014/12/12

also Herr Lehrer: das Problem ist, dass nicht zwischen dem Wurf vom Linken und Rechten unterschieden wird, sondern einfach nur der letzte Wurf, eben der vom Gegner, angezeigt wird.
Max-FelixMax-Felix

2014/12/12

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.RadialGradientPaint; import java.awt.Graphics2D; /** * Write a description of class AimDisplay here. * * @author (your name) * @version (a version number or a date) */ public class AimDisplay extends Actor { private HumanPlayer player; private int radius; private static int prevX; private static int prevY; private static int prevX2; private static int prevY2; int pl=1; private static boolean prevValid = false; private static boolean prevValid2 = false; private int curX; private int curY; public static final double MIN_PROP = ProjectileWorld.MIN_FORCE / ProjectileWorld.MAX_FORCE; public AimDisplay(HumanPlayer player, int radius, boolean showTarget) { this.player = player; this.radius = radius; redraw(0, 0); } /** * Act - do whatever the AimDisplay wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { MouseInfo info = Greenfoot.getMouseInfo(); if (info != null) { int xDir = info.getX() - getX(); int yDir = info.getY() - getY(); if (yDir >= -1) { yDir = -1; } double angle = Math.atan2(yDir, xDir); if (angle >= -Math.toRadians(ProjectileWorld.LOWEST_ANGLE)) { angle = -Math.toRadians(ProjectileWorld.LOWEST_ANGLE); } if (angle <= -Math.toRadians(180 - ProjectileWorld.LOWEST_ANGLE)) { angle = -Math.toRadians(180 - ProjectileWorld.LOWEST_ANGLE); } double distProp = Math.hypot(xDir, yDir) / (double)radius; if (distProp > 1) { distProp = 1; } else if (distProp < MIN_PROP) { distProp = MIN_PROP; } double forceFactor = (distProp - MIN_PROP) / (1 - MIN_PROP); redraw(angle, forceFactor); if (Greenfoot.mouseClicked(null) && pl == 1) { prevX = curX; prevY = curY; prevValid = true; player.fire(angle, forceFactor); getWorld().removeObject(this); } else if (Greenfoot.mouseClicked(null) && pl == 2) { prevX2 = curX; prevY2 = curY; prevValid2 = true; player.fire(angle, forceFactor); getWorld().removeObject(this); } } } private void redraw(double radianAngle, double forceFactor) { float[] spacing = {0.0f, (float)(MIN_PROP - 0.001f), (float)MIN_PROP, 1.0f}; Color[] colors = {new Color(0.0f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), new Color(1.0f, 0.0f, 0.0f, 0.1f), new Color(1.0f, 0.0f, 0.0f, 0.5f)}; RadialGradientPaint p = new RadialGradientPaint(radius, radius, radius, spacing, colors); double dist = (MIN_PROP + (forceFactor * (1 - MIN_PROP))) * (double)radius; GreenfootImage img = new GreenfootImage(radius*2, radius*2); Graphics2D g = img.getAwtImage().createGraphics(); g.setPaint(p); g.fillArc(0, 0, radius * 2, radius * 2, ProjectileWorld.LOWEST_ANGLE, 180 - 2 * ProjectileWorld.LOWEST_ANGLE); g.dispose(); img.setColor(new Color(1.0f, 0.0f, 0.0f, 0.8f)); curX = radius + (int)(dist * Math.cos(radianAngle)); curY = radius + (int)(dist * Math.sin(radianAngle)); img.drawLine(radius, radius, curX, curY); img.drawLine(curX - 5, curY - 5, curX + 5, curY + 5); img.drawLine(curX - 5, curY + 5, curX + 5, curY - 5); if (prevValid && pl == 1) { img.setColor(new Color(0.0f, 0.0f, 1.0f, 0.8f)); img.drawLine(radius, radius, prevX, prevY); img.drawLine(prevX - 5, prevY - 5, prevX + 5, prevY + 5); img.drawLine(prevX - 5, prevY + 5, prevX + 5, prevY - 5); pl = 2; } else if (prevValid2 && pl == 2) { img.setColor(new Color(0.0f, 0.0f, 1.0f, 0.8f)); img.drawLine(radius, radius, prevX2, prevY2); img.drawLine(prevX2 - 5, prevY2 - 5, prevX2 + 5, prevY2 + 5); img.drawLine(prevX2 - 5, prevY2 + 5, prevX2 + 5, prevY2 - 5); pl = 1; } setImage(img); } } wenn man den code hier für das aimdisplay einsetzt, blinkt der vorherige vom Gegner abwechselnd mit dem eigenen vorherigen. ich hab schon versucht den vom gegner auszublenden, aber bin zu faul es fertig zu stellen :) was hier anders ist, ist dass eine zweite Vorher-Koordinate dabei ist, die immer abwechselnd beschrieben werden
Max-FelixMax-Felix

2014/12/13

Ok ich glaub pl = 1; bzw pl = 2; muss man in act ändern und nicht unten

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.