Permalink
Browse files

Update sent_ball.lua

* Rebalanced size and visual size.
* Sound is lower pitch the bigger the ball is
  • Loading branch information...
1 parent 1bd8973 commit 384a484dbb653ab3bd4a5e2594ee873ed731c2e0 @robotboy655 robotboy655 committed Apr 11, 2014
Showing with 21 additions and 25 deletions.
  1. +21 −25 garrysmod/lua/entities/sent_ball.lua
@@ -3,25 +3,22 @@ AddCSLuaFile()
local BounceSound = Sound( "garrysmod/balloon_pop_cute.wav" )
-
DEFINE_BASECLASS( "base_anim" )
-
ENT.PrintName = "Bouncy Ball"
ENT.Author = "Garry Newman"
ENT.Information = "An edible bouncy ball"
ENT.Category = "Fun + Games"
-ENT.Editable = true
-ENT.Spawnable = true
-ENT.AdminOnly = false
-ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
-
+ENT.Editable = true
+ENT.Spawnable = true
+ENT.AdminOnly = false
+ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
function ENT:SetupDataTables()
- self:NetworkVar( "Float", 0, "BallSize", { KeyName = "ballsize", Edit = { type = "Float", min=4, max=128, order = 1 } } );
- self:NetworkVar( "Vector", 0, "BallColor", { KeyName = "ballcolor", Edit = { type = "VectorColor", order = 2 } } );
+ self:NetworkVar( "Float", 0, "BallSize", { KeyName = "ballsize", Edit = { type = "Float", min = 4, max = 128, order = 1 } } )
+ self:NetworkVar( "Vector", 0, "BallColor", { KeyName = "ballcolor", Edit = { type = "VectorColor", order = 2 } } )
end
@@ -39,26 +36,23 @@ function ENT:SpawnFunction( ply, tr, ClassName )
local SpawnPos = tr.HitPos + tr.HitNormal * size
local ent = ents.Create( ClassName )
- ent:SetPos( SpawnPos )
- ent:SetBallSize( size )
+ ent:SetPos( SpawnPos )
+ ent:SetBallSize( size )
ent:Spawn()
ent:Activate()
return ent
end
-
-
-
--[[---------------------------------------------------------
Name: Initialize
-----------------------------------------------------------]]
function ENT:Initialize()
if ( SERVER ) then
- local size = self:GetBallSize() / 2;
+ local size = self:GetBallSize() / 2
-- Use the helibomb model just for the shadow (because it's about the same size)
self:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
@@ -68,7 +62,7 @@ function ENT:Initialize()
-- Wake the physics object up. It's time to have fun!
local phys = self:GetPhysicsObject()
- if (phys:IsValid()) then
+ if ( IsValid( phys ) ) then
phys:Wake()
end
@@ -87,7 +81,7 @@ function ENT:Initialize()
self:SetBallColor( Vector( 0.2, 0.3, 1 ) )
end
- self:NetworkVarNotify( "BallSize", self.OnBallSizeChanged );
+ self:NetworkVarNotify( "BallSize", self.OnBallSizeChanged )
else
@@ -101,8 +95,10 @@ function ENT:OnBallSizeChanged( varname, oldvalue, newvalue )
local delta = oldvalue - newvalue
- local size = self:GetBallSize() / 2;
+ local size = self:GetBallSize() / 2.1
self:PhysicsInitSphere( size, "metal_bouncy" )
+
+ size = self:GetBallSize() / 2.6
self:SetCollisionBounds( Vector( -size, -size, -size ), Vector( size, size, size ) )
self:PhysWake()
@@ -123,10 +119,10 @@ function ENT:Draw()
local lcolor = render.ComputeLighting( self:GetPos(), Vector( 0, 0, 1 ) )
local c = self:GetBallColor()
- lcolor.x = c.r * (math.Clamp( lcolor.x, 0, 1 ) + 0.5) * 255
- lcolor.y = c.g * (math.Clamp( lcolor.y, 0, 1 ) + 0.5) * 255
- lcolor.z = c.b * (math.Clamp( lcolor.z, 0, 1 ) + 0.5) * 255
-
+ lcolor.x = c.r * ( math.Clamp( lcolor.x, 0, 1 ) + 0.5 ) * 255
+ lcolor.y = c.g * ( math.Clamp( lcolor.y, 0, 1 ) + 0.5 ) * 255
+ lcolor.z = c.b * ( math.Clamp( lcolor.z, 0, 1 ) + 0.5 ) * 255
+
render.DrawSprite( pos, self:GetBallSize(), self:GetBallSize(), Color( lcolor.x, lcolor.y, lcolor.z, 255 ) )
end
@@ -142,7 +138,8 @@ function ENT:PhysicsCollide( data, physobj )
-- Play sound on bounce
if ( data.Speed > 60 && data.DeltaTime > 0.2 ) then
- sound.Play( BounceSound, self:GetPos(), 75, math.random( 90, 120 ), math.Clamp( data.Speed / 150, 0, 1 ) )
+ local pitch = 32 + 128 - self:GetBallSize()
+ sound.Play( BounceSound, self:GetPos(), 75, math.random( pitch - 10, pitch + 10 ), math.Clamp( data.Speed / 150, 0, 1 ) )
end
@@ -182,9 +179,8 @@ function ENT:Use( activator, caller )
-- Give the collecting player some free health
local health = activator:Health()
activator:SetHealth( health + 5 )
- activator:SendLua( "achievements.EatBall()" );
+ activator:SendLua( "achievements.EatBall()" )
end
end
-

0 comments on commit 384a484

Please sign in to comment.