1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-10 09:34:20 +01:00

Fixed a few bugs

This commit is contained in:
Enrico Fasoli 2015-07-07 14:38:00 +02:00
parent fcd1e540e6
commit b447353891
4 changed files with 109 additions and 20 deletions

View File

@ -164,6 +164,7 @@ 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);
if (Game.get().getWorld().getOptions().getOrDefault("draw_sight_lines", 0f) > 0) {
for (Sight sight : sights) {
if (sight != null) {
c = sight.getDistance() / sightRange * 2 + sightRange;
@ -178,6 +179,7 @@ public class Creature extends Element implements Runnable {
s.line(eyeX + getX(), getY() + eyeY, sight.getElement().getX(), sight.getElement().getY());
}
}
}
if (sights[0] == null && sights[1] == null) {
s.setColor(1, 1, 1, 1);
} else {
@ -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;
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
*

View File

@ -376,6 +376,10 @@ public class World implements Runnable {
return fps;
}
public Map<String, Float> getOptions() {
return options;
}
public Creature getSelectedCreature() {
return selected;
}

View File

@ -269,9 +269,15 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="drawViewCones" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="drawSightLines" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@ -429,7 +435,12 @@
<Component id="maxTicksSlider" min="-2" max="-2" attributes="0"/>
<Component id="currentMaxTicks" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="44" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="drawViewCones" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="drawSightLines" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="19" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="pauseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
@ -600,6 +611,7 @@
<Properties>
<Property name="maximum" type="int" value="1000"/>
<Property name="minimum" type="int" value="20"/>
<Property name="value" type="int" value="100"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="sightRangeSliderStateChanged"/>
@ -656,6 +668,22 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="drawViewCones">
<Properties>
<Property name="text" type="java.lang.String" value="Draw view cones"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="drawViewConesStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="drawSightLines">
<Properties>
<Property name="text" type="java.lang.String" value="Draw sight lines"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="drawSightLinesStateChanged"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

@ -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;