From b447353891599b46fedf63432575c55484198a05 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Tue, 7 Jul 2015 14:38:00 +0200 Subject: [PATCH] Fixed a few bugs --- core/src/logic/Creature.java | 46 +++++++++++++++++++++++------------ core/src/logic/World.java | 4 +++ desktop/src/gui/GUI.form | 32 ++++++++++++++++++++++-- desktop/src/gui/GUI.java | 47 ++++++++++++++++++++++++++++++++++-- 4 files changed, 109 insertions(+), 20 deletions(-) diff --git a/core/src/logic/Creature.java b/core/src/logic/Creature.java index 32af051..03bea5d 100644 --- a/core/src/logic/Creature.java +++ b/core/src/logic/Creature.java @@ -164,18 +164,20 @@ public class Creature extends Element implements Runnable { double relX = Math.cos(dir), relY = Math.sin(dir); float c = 0; float eyeX = (float) (relX * getSize() * 0.6f), eyeY = (float) (relY * getSize() * 0.6f); - for (Sight sight : sights) { - if (sight != null) { - c = sight.getDistance() / sightRange * 2 + sightRange; - } else { - } - if (sight != null) { - if (sight.getElement() instanceof Creature) { - s.setColor(c, 0, 0, 1); - } else if (sight.getElement() instanceof Vegetable) { - s.setColor(0, c, 0, 1); + if (Game.get().getWorld().getOptions().getOrDefault("draw_sight_lines", 0f) > 0) { + for (Sight sight : sights) { + if (sight != null) { + c = sight.getDistance() / sightRange * 2 + sightRange; + } else { + } + if (sight != null) { + if (sight.getElement() instanceof Creature) { + s.setColor(c, 0, 0, 1); + } else if (sight.getElement() instanceof Vegetable) { + s.setColor(0, c, 0, 1); + } + s.line(eyeX + getX(), getY() + eyeY, sight.getElement().getX(), sight.getElement().getY()); } - s.line(eyeX + getX(), getY() + eyeY, sight.getElement().getX(), sight.getElement().getY()); } } if (sights[0] == null && sights[1] == null) { @@ -187,8 +189,10 @@ public class Creature extends Element implements Runnable { //FOV float degrees = fov * 360f / (float) Math.PI; float orient = dir * 180f / (float) Math.PI - degrees / 2; - s.setColor(0.3f, 0.3f, 0.3f, 1); - s.arc((float) eyeX + getX(), (float) eyeY + getY(), sightRange, orient, degrees); + if (Game.get().getWorld().getOptions().getOrDefault("draw_view_cones", 0f) > 0) { + s.setColor(0.3f, 0.3f, 0.3f, 1); + s.arc((float) eyeX + getX(), (float) eyeY + getY(), sightRange, orient, degrees); + } if (hp < prevHp) { // Damage mark s.set(ShapeRenderer.ShapeType.Filled); @@ -274,14 +278,16 @@ public class Creature extends Element implements Runnable { // Check if attackable if (beak > beak / 2 && tempDist < beak * 1.5f && tempAngle < fov / 2) { // Attacking! - hp++; - fitness++; + float damage = beak; + hp += damage / 2; + fitness += 2; if (hp > max_hp) { hp = max_hp; } killing = true; Creature c = (Creature) e; - c.setHp(c.getHp() - 0.2f); + c.heal(-damage); + //c.praise(-1); } } //Log.log(Log.DEBUG,"RelAngle "+relAngle+" Dir "+ndir); @@ -311,6 +317,14 @@ public class Creature extends Element implements Runnable { } } + private void heal(float amount) { + hp += amount; + } + + private void praise(float amount) { + fitness += amount; + } + /** * Check if the Worker thread has finished its current iteration * diff --git a/core/src/logic/World.java b/core/src/logic/World.java index e70e8f9..c91e070 100644 --- a/core/src/logic/World.java +++ b/core/src/logic/World.java @@ -376,6 +376,10 @@ public class World implements Runnable { return fps; } + public Map getOptions() { + return options; + } + public Creature getSelectedCreature() { return selected; } diff --git a/desktop/src/gui/GUI.form b/desktop/src/gui/GUI.form index 15e47b9..2d36eb5 100644 --- a/desktop/src/gui/GUI.form +++ b/desktop/src/gui/GUI.form @@ -269,9 +269,15 @@ - + + + + + + + @@ -429,7 +435,12 @@ - + + + + + + @@ -600,6 +611,7 @@ + @@ -656,6 +668,22 @@ + + + + + + + + + + + + + + + + diff --git a/desktop/src/gui/GUI.java b/desktop/src/gui/GUI.java index 8041b78..ac098dc 100644 --- a/desktop/src/gui/GUI.java +++ b/desktop/src/gui/GUI.java @@ -115,6 +115,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { currentHpDecay = new javax.swing.JLabel(); currentMaxTicks = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); + drawViewCones = new javax.swing.JCheckBox(); + drawSightLines = new javax.swing.JCheckBox(); status = new javax.swing.JLabel(); menuBar = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); @@ -298,6 +300,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { sightRangeSlider.setMaximum(1000); sightRangeSlider.setMinimum(20); + sightRangeSlider.setValue(100); sightRangeSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { sightRangeSliderStateChanged(evt); @@ -337,6 +340,20 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { } }); + drawViewCones.setText("Draw view cones"); + drawViewCones.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + drawViewConesStateChanged(evt); + } + }); + + drawSightLines.setText("Draw sight lines"); + drawSightLines.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + drawSightLinesStateChanged(evt); + } + }); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -344,6 +361,11 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(drawViewCones) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(drawSightLines) + .addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -470,7 +492,11 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(maxTicksSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentMaxTicks, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(drawViewCones) + .addComponent(drawSightLines)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(pauseButton) .addComponent(jButton1)) @@ -648,9 +674,14 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { worldSizeSlider.setValue(2000); corpseDecaySlider.setValue(0); topSizeSlider.setValue(0); - sightRangeSlider.setValue(50); + sightRangeSlider.setValue(100); hpDecaySlider.setValue(500); maxTicksSlider.setValue(0); + toggleFPSLimitCheckbox.setSelected(false); + multithreadingCheckbox.setSelected(true); + enableCorpsesCheckbox.setSelected(false); + drawSightLines.setSelected(false); + drawViewCones.setSelected(false); updateSettings(); } @@ -678,6 +709,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { options.put("creature_sight_range", (float) sightRangeSlider.getValue()); options.put("creature_hp_decay", (float) hpDecaySlider.getValue() / 1000); options.put("max_ticks", (float) maxTicksSlider.getValue()); + options.put("draw_view_cones",drawViewCones.isSelected()?1f:0); + options.put("draw_sight_lines",drawSightLines.isSelected()?1f:0); currentMaxTicks.setText(maxTicksSlider.getValue() + ""); currentHpDecay.setText(hpDecaySlider.getValue() / 1000f + ""); currentSightRange.setText(sightRangeSlider.getValue() + ""); @@ -790,6 +823,14 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { resetDefaultSettings(); }//GEN-LAST:event_jButton1ActionPerformed + private void drawViewConesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_drawViewConesStateChanged + updateSettings(); + }//GEN-LAST:event_drawViewConesStateChanged + + private void drawSightLinesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_drawSightLinesStateChanged + updateSettings(); + }//GEN-LAST:event_drawSightLinesStateChanged + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel container; private javax.swing.JSlider corpseDecaySlider; @@ -803,6 +844,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener { private javax.swing.JLabel currentSightRange; private javax.swing.JLabel currentTopSize; private javax.swing.JLabel currentWorldSize; + private javax.swing.JCheckBox drawSightLines; + private javax.swing.JCheckBox drawViewCones; private javax.swing.JCheckBox enableCorpsesCheckbox; private javax.swing.JMenuItem exitButton; private javax.swing.JSlider fpsLimitSlider;