Project X Forums http://px.worms2d.info/forum/ |
|
[0.6.5] Useful Code Snippets http://px.worms2d.info/forum/viewtopic.php?f=5&t=79 |
Page 1 of 1 |
Author: | Undefined [ Fri Jun 25, 2010 8:29 am ] |
Post subject: | [0.6.5] Useful Code Snippets |
Forbidding the worm to shoot when he's not on his side (fort) : Code: procedure InitHooks; begin RegisterHook('Fire', ON_BEGIN_FIRE); end; function Fire : boolean; var CurW : TWorm; wpns : integer; begin CurW := GetTekWormObj; if CurW = nil then exit; if CurW.SelWeapon = nil then exit; Result := True; // Team 1 : right side // Team 2 : left side if CurW.Team = 2 then begin if ObjInBox(CurW,1154,5,1916,694) then begin // Right side position wpns := CurW.SelWeapon.WN; case wpns of 1,2 : // All the weapons we want to forbid begin Result := False; end; end; end; if CurW.Team = 1 then begin if ObjInBox(CurW,8,14,702,814) then begin // Left side position case wpns of 1,2 : begin Result := False; end; end; end; end; end; end; // So many ends ... Automatic placement for towers, rope races.. Code: procedure Init; var i, wCount : Integer; obj : TWPobj; begin wCount := 0; for i := 1 to GetPObjCount - 1 do begin Obj := GetPObj(i); if Obj = nil then continue; if Obj.ObjType = OBJ_WORM then begin Obj.PosX := 831 + 10 * wCount; // X Pos Obj.PosY := 351 - (wCount div 6); // Y Pos Inc(wCount); end; end; Adding gravity : Code: if (ObjInBox(obj,1115,27,1425,356)) then begin // Position of the gravity
obj.SpY := obj.SpY + 0.7; //0.7 is the force of the gravity end; // Use your brain and you'll understand why I use ObjInBox for gravity |
Author: | anoamas321 [ Fri Jun 25, 2010 9:00 am ] |
Post subject: | Re: [0.6.5] Useful Code Snippets |
nice code with good comments, just on thing it would be really nice if you could indent your code so its easier to see where if's start and end, and stuff. |
Author: | Gran PC [ Fri Jun 25, 2010 9:10 am ] |
Post subject: | Re: [0.6.5] Useful Code Snippets |
Stickied. |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |