Skip to content

Commit

Permalink
Fixes Issue 38. Bonuses in levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyacheslav Mishcheryakov committed Jan 9, 2013
1 parent 29f7fcf commit 1fe67ad
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 40 deletions.
1 change: 0 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<property name="native.dir" value="${basedir}/native" />
<property name="data.dir" value="${basedir}/data"/>
<property name="launchers.dir" value="${basedir}/launchers" />
<!-- <property name="gui.dir" value="${basedir}/gui" /> -->

<property name="readme.file" value="${basedir}/README.txt" />
<property name="qatasks.file" value="${basedir}/QATASKS.txt" />
Expand Down
Binary file modified data/epochs/test_epoch/level1.dps
Binary file not shown.
Binary file modified data/epochs/test_epoch/level2.dps
Binary file not shown.
Binary file modified data/epochs/test_epoch/level3.dps
Binary file not shown.
Binary file modified data/epochs/test_epoch2/level2.dps
Binary file not shown.
28 changes: 14 additions & 14 deletions junit/lamao/soh/core/bonuses/SHDecBallSpeedBonusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void testBonuOnce()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);
Expand All @@ -55,10 +55,10 @@ public void testBonuOnce()
assertNotNull(bonus);
bonus.apply(scene);
assertTrue(Math.abs(Math.abs(ball1.getVelocity().length() /
new Vector3f(-1, -1, 0).length()) -
new Vector3f(-1, 0, 1).length()) -
(1 - SHDecBallSpeedBonus.DEC_PERCENT)) < 0.001f);
assertTrue(Math.abs(Math.abs(ball2.getVelocity().length() /
new Vector3f(1, 1, 0).length()) -
new Vector3f(1, 0, -1).length()) -
(1 - SHDecBallSpeedBonus.DEC_PERCENT)) < 0.001f);
}

Expand All @@ -67,9 +67,9 @@ public void testBonusTwice()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);
Expand All @@ -79,11 +79,11 @@ public void testBonusTwice()
bonus.apply(scene);

assertTrue(Math.abs(Math.abs(ball1.getVelocity().length() /
new Vector3f(-1, -1, 0).length()) -
new Vector3f(-1, 0, 1).length()) -
(1 - SHDecBallSpeedBonus.DEC_PERCENT) *
(1 - SHDecBallSpeedBonus.DEC_PERCENT)) < 0.001f);
assertTrue(Math.abs(Math.abs(ball2.getVelocity().length() /
new Vector3f(1, 1, 0).length()) -
new Vector3f(1, 0, -1).length()) -
(1 - SHDecBallSpeedBonus.DEC_PERCENT) *
(1 - SHDecBallSpeedBonus.DEC_PERCENT)) < 0.001f);
}
Expand All @@ -93,9 +93,9 @@ public void testBonusCleanup()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);
Expand All @@ -104,16 +104,16 @@ public void testBonusCleanup()
bonus.apply(scene);

SHBall ball3 = SHEntityCreator.createDefaultBall();
ball3.setVelocity(1, -1, 0);
ball3.setVelocity(1, 0, 1);
balls.add(ball3);
when(scene.get("ball")).thenReturn(balls);

bonus.cleanup(scene);
assertTrue(Math.abs(ball1.getVelocity().length() -
new Vector3f(-1, -1, 0).length()) < 0.001f);
new Vector3f(-1, 0, 1).length()) < 0.001f);
assertTrue(Math.abs(ball2.getVelocity().length() -
new Vector3f(1, 1, 0).length()) < 0.001f);
new Vector3f(1, 0, -1).length()) < 0.001f);
assertTrue(Math.abs(ball3.getVelocity().length() -
new Vector3f(1, -1, 0).length()) < 0.001f);
new Vector3f(1, 0, 1).length()) < 0.001f);
}
}
6 changes: 3 additions & 3 deletions junit/lamao/soh/core/bonuses/SHDefaultMoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void testContstructors()
SHDefaultMover mover = new SHDefaultMover(box);

assertNotNull(mover.getModel());
assertTrue(SHUtils.areEqual(new Vector3f(0, -1, 0), mover.getVelocity(),
assertTrue(SHUtils.areEqual(new Vector3f(0, 0, 1), mover.getVelocity(),
0.001f));

mover = new SHDefaultMover();
assertNull(mover.getModel());
assertTrue(SHUtils.areEqual(new Vector3f(0, -1, 0), mover.getVelocity(),
assertTrue(SHUtils.areEqual(new Vector3f(0, 0, 1), mover.getVelocity(),
0.001f));
}

Expand All @@ -48,7 +48,7 @@ public void testMoving()
SHDefaultMover mover = new SHDefaultMover(box);

mover.update(0.5f);
assertTrue(SHUtils.areEqual(new Vector3f(0, -0.5f, 0),
assertTrue(SHUtils.areEqual(new Vector3f(0, 0, 0.5f),
box.getLocalTranslation(), 0.001f));
}
}
26 changes: 13 additions & 13 deletions junit/lamao/soh/core/bonuses/SHIncBallSpeedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void testBonuOnce()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);
Expand All @@ -61,10 +61,10 @@ public void testBonuOnce()
assertNotNull(bonus);
bonus.apply(scene);
assertTrue(Math.abs(Math.abs(ball1.getVelocity().length() /
new Vector3f(-1, -1, 0).length()) -
new Vector3f(-1, 0, 1).length()) -
(1 + SHIncBallSpeedBonus.INC_PERCENT)) < 0.001f);
assertTrue(Math.abs(Math.abs(ball2.getVelocity().length() /
new Vector3f(1, 1, 0).length()) -
new Vector3f(1, 0, -1).length()) -
(1 + SHIncBallSpeedBonus.INC_PERCENT)) < 0.001f);
}

Expand All @@ -73,9 +73,9 @@ public void testBonusTwice()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);
Expand All @@ -84,11 +84,11 @@ public void testBonusTwice()
bonus.apply(scene);

assertTrue(Math.abs(Math.abs(ball1.getVelocity().length() /
new Vector3f(-1, -1, 0).length()) -
new Vector3f(-1, 0, 1).length()) -
(1 + SHIncBallSpeedBonus.INC_PERCENT) *
(1 + SHIncBallSpeedBonus.INC_PERCENT)) < 0.001f);
assertTrue(Math.abs(Math.abs(ball2.getVelocity().length() /
new Vector3f(1, 1, 0).length()) -
new Vector3f(1, 0, -1).length()) -
(1 + SHIncBallSpeedBonus.INC_PERCENT) *
(1 + SHIncBallSpeedBonus.INC_PERCENT)) < 0.001f);
}
Expand All @@ -98,25 +98,25 @@ public void testBonusCleanup()
{
List<Spatial> balls = new ArrayList<Spatial>();
SHBall ball1 = SHEntityCreator.createDefaultBall();
ball1.setVelocity(-1, -1, 0);
ball1.setVelocity(-1, 0, 1);
SHBall ball2 = SHEntityCreator.createDefaultBall();
ball2.setVelocity(1, 1, 0);
ball2.setVelocity(1, 0, -1);
balls.add(ball1);
balls.add(ball2);
when(scene.get("ball")).thenReturn(balls);

bonus.apply(scene);

SHBall ball3 = SHEntityCreator.createDefaultBall();
ball3.setVelocity(1, -1, 0);
ball3.setVelocity(1, 0, 1);
balls.add(ball3);
when(scene.get("ball")).thenReturn(balls);

bonus.cleanup(scene);
assertTrue(Math.abs(ball1.getVelocity().length() -
new Vector3f(-1, -1, 0).length()) < 0.001f);
new Vector3f(-1, 0, 1).length()) < 0.001f);
assertTrue(Math.abs(ball2.getVelocity().length() -
new Vector3f(1, 1, 0).length()) < 0.001f);
new Vector3f(1, 0, -1).length()) < 0.001f);
assertTrue(Math.abs(ball3.getVelocity().length() -
new Vector3f(1, -1, 0).length()) < 0.001f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testHandlerWallIsActive()
SHBall ball = SHEntityCreator.createDefaultBall("ball", "ball");
SHBottomWall wall = new SHBottomWall("wall", "bottom-wall", null);
wall.setActive(true);
ball.setVelocity(1, 1, 1);
ball.setVelocity(1, 0, 1);

when(event.getParameter("src", SHBall.class)).thenReturn(ball);
when(event.getParameter("dst", SHBottomWall.class)).thenReturn(wall);
Expand All @@ -68,7 +68,7 @@ public void testHandlerWallIsActive()

verify(event).getParameter("src", SHBall.class);
verify(event).getParameter("dst", SHBottomWall.class);
assertTrue(SHUtils.areEqual(ball.getVelocity(), new Vector3f(1, -1, 1), 0.001f));
assertTrue(SHUtils.areEqual(ball.getVelocity(), new Vector3f(1, 0, -1), 0.001f));
verify(dispatcher).addEvent("level-wall-hit", handler);
}

Expand Down
2 changes: 1 addition & 1 deletion session.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<session>
<last-selected-profile>profile</last-selected-profile>
<last-selected-profile>test</last-selected-profile>
</session>
6 changes: 3 additions & 3 deletions src/lamao/soh/core/bonuses/SHDecBallSpeedBonus.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void apply(SHScene scene)
angle = SHUtils.angle(ball.getVelocity());

ball.getVelocity().x = (float)Math.cos(angle) * speed * (1 - DEC_PERCENT);
ball.getVelocity().y = (float)Math.sin(angle) * speed * (1 - DEC_PERCENT);
ball.getVelocity().z = -(float)Math.sin(angle) * speed * (1 - DEC_PERCENT);

_balls.add(ball);
}
Expand All @@ -67,13 +67,13 @@ public void cleanup(SHScene scene)
{
speed = ball.getVelocity().length();
angle = Math.acos(ball.getVelocity().x / Math.abs(speed));
if (ball.getVelocity().y < 0)
if (ball.getVelocity().z > 0)
{
angle = 2 * Math.PI - angle;
}

ball.getVelocity().x = (float)Math.cos(angle) * speed / (1 - DEC_PERCENT);
ball.getVelocity().y = (float)Math.sin(angle) * speed / (1 - DEC_PERCENT);
ball.getVelocity().z = -(float)Math.sin(angle) * speed / (1 - DEC_PERCENT);
}
_balls.clear();
}
Expand Down
6 changes: 3 additions & 3 deletions src/lamao/soh/core/bonuses/SHIncBallSpeedBonus.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void apply(SHScene scene)
angle = SHUtils.angle(ball.getVelocity());

ball.getVelocity().x = (float)Math.cos(angle) * speed * (1 + INC_PERCENT);
ball.getVelocity().y = (float)Math.sin(angle) * speed * (1 + INC_PERCENT);
ball.getVelocity().z = -(float)Math.sin(angle) * speed * (1 + INC_PERCENT);

_balls.add(ball);
}
Expand All @@ -67,13 +67,13 @@ public void cleanup(SHScene scene)
{
speed = ball.getVelocity().length();
angle = Math.acos(ball.getVelocity().x / Math.abs(speed));
if (ball.getVelocity().y < 0)
if (ball.getVelocity().z > 0)
{
angle = 2 * Math.PI - angle;
}

ball.getVelocity().x = (float)Math.cos(angle) * speed / (1 + INC_PERCENT);
ball.getVelocity().y = (float)Math.sin(angle) * speed / (1 + INC_PERCENT);
ball.getVelocity().z = (float)Math.sin(angle) * speed / (1 + INC_PERCENT);
}
_balls.clear();
}
Expand Down

0 comments on commit 1fe67ad

Please sign in to comment.