Permalink
Browse files

- AI improvements

- Acceleration used instead of speed for changing directions
  • Loading branch information...
1 parent 020a699 commit b3762c94c87a945e1459ec59b92034baf26e249d @austinhallock austinhallock committed Mar 20, 2012
View
Binary file not shown.
@@ -90,7 +90,7 @@ class SlimeVolleyball extends Scene
ball.y += ball.velocity.y * Constants.FPS_RATIO
ball.velocity.y += ball.acceleration.y * Constants.FPS_RATIO
- p2Pos = @p2.x + @p2.width / 2 - 14
+ p2Pos = @p2.x + @p2.width / 2
pastP1 = @ball.x > @p1.x + @p1.width / 2 + @ball.radius
pastPole = ball.x > @pole.x
ballPos = @ball.x + @ball.radius
@@ -102,16 +102,17 @@ class SlimeVolleyball extends Scene
# Where he wants to be to hit it (based on the angle of the ball and distance from pole)
# More weight is on the angle than the distance
# the randomness makes him stupider
- sweetSpot = p2Pos - Constants.AI_DIFFICULTY * ( 1 - ( 1 / Constants.AI_DIFFICULTY ) * Math.random() ) * .8 * ( 2 * ( ( ( p2Pos - @pole.x ) / ( @width / 2 ) ) + 8 * ( 1.57 - Math.abs ballAngle ) ) )
+ randomOffset = ( 1 - Constants.AI_DIFFICULTY ) * 50 * ( Math.random() - .5 ) # -50 to 50
+ sweetSpot = p2Pos - 14 - randomOffset - Constants.AI_DIFFICULTY * .8 * ( 2 * ( ( ( p2Pos - @pole.x ) / ( @width / 2 ) ) + 8 * ( 1.57 - Math.abs ballAngle ) * ( 1.57 - Math.abs ballAngle ) ) )
# jump only if angle is steep enough, or ball will land past
if ( Math.abs( ballPos - sweetSpot ) <= 5 || ballPos - sweetSpot > 5 ) && @ball.y < 200 && @ball.y > 100 && @p2.velocity.y == 0 && ( ( ballAngle > -.8 && ballAngle < 0.8 ) )
@p2.velocity.y = -8 # jump
# ball will pass p2
- if ballLand > sweetSpot + 5 # have him shoot at a lower angle if it's less steep
+ if ballLand - sweetSpot > 5 # have him shoot at a lower angle if it's less steep
@p2.x += (Constants.MOVEMENT_SPEED*.55) + (Constants.MOVEMENT_SPEED*Constants.AI_DIFFICULTY)
# Ball past 1 and will land past net OR ball heading toward p1 from our side
- else if ( ( pastP1 && pastPole ) || ( @ball.velocity.x < 0 && @ball.x > @pole.x ) ) && ballLand < sweetSpot - 5
+ else if ( ( pastP1 && pastPole ) || ( @ball.velocity.x < 0 && @ball.x > @pole.x ) ) && ballLand - sweetSpot < -5
@p2.x -= (Constants.MOVEMENT_SPEED*.55) + (Constants.MOVEMENT_SPEED*Constants.AI_DIFFICULTY)
draw: ->
@@ -22,7 +22,7 @@ class Player
playerID = obj.playerID
# Store the unique identifier for this player
- secret = 'SECRETKEYHERE' # Secret key for this game
+ secret = 'amAiFpm3mFYEsF2TDbWgHtmcPdajVM' # Secret key for this game
@clay = new Clay( playerID, secret )
@room.stopGame if @room
@@ -16,10 +16,19 @@ class Slime extends Sprite
# check for up, left, right
pNum = if @isP2 then 1 else 0
if input.left(pNum)
- @velocity.x = -Constants.MOVEMENT_SPEED
+ if @velocity.x > -Constants.MOVEMENT_SPEED
+ @acceleration.x = -Constants.MOVEMENT_SPEED / 15
+ else
+ @acceleration.x = 0
+ @velocity.x = -Constants.MOVEMENT_SPEED
else if input.right(pNum)
- @velocity.x = Constants.MOVEMENT_SPEED
+ if @velocity.x < Constants.MOVEMENT_SPEED
+ @acceleration.x = Constants.MOVEMENT_SPEED / 15
+ else
+ @acceleration.x = 0
+ @velocity.x = Constants.MOVEMENT_SPEED
else
+ @acceleration.x = 0
@velocity.x = 0
if input.up(pNum)
@velocity.y = -Constants.SLIME_JUMP if @y >= Constants.BASE_HEIGHT - Constants.BOTTOM - @height

0 comments on commit b3762c9

Please sign in to comment.