tests/lua/hellfire_burns.lua
changeset 10380 07ae8fd1d7d4
child 10381 d263e0abcd7c
equal deleted inserted replaced
10379:caa5b40e405b 10380:07ae8fd1d7d4
       
     1 
       
     2  -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing
       
     3  PointsBuffer = ''  -- A string to accumulate points in
       
     4  function AddPoint(x, y, width, erase)
       
     5      PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
       
     6      if width then
       
     7          width = bor(width,0x80)
       
     8          if erase then
       
     9              width = bor(width,0x40)
       
    10          end
       
    11          PointsBuffer = PointsBuffer .. string.char(width)
       
    12      else
       
    13          PointsBuffer = PointsBuffer .. string.char(0)
       
    14      end
       
    15      if #PointsBuffer > 245 then
       
    16          ParseCommand('draw '..PointsBuffer)
       
    17          PointsBuffer = ''
       
    18      end
       
    19  end
       
    20  function FlushPoints()
       
    21      if #PointsBuffer > 0 then
       
    22          ParseCommand('draw '..PointsBuffer)
       
    23          PointsBuffer = ''
       
    24      end
       
    25  end
       
    26 
       
    27 
       
    28 local ta_pointsize = 63
       
    29 local ta_radius = (ta_pointsize * 10 + 6) / 2
       
    30 
       
    31 local sqrttwo = math.sqrt(2)
       
    32 
       
    33 -- creates round test area
       
    34 function AddTestArea(testarea)
       
    35 	step = 100
       
    36 	xstep = step * testarea["xdir"]
       
    37 	ystep = step * testarea["ydir"]
       
    38 	x = testarea["x"]
       
    39 	y = testarea["y"]
       
    40 	if xstep * ystep ~= 0 then
       
    41 		xstep = math.floor(xstep / sqrttwo)
       
    42 		ystep = math.floor(ystep / sqrttwo)
       
    43 	end
       
    44 	AddPoint(x, y, ta_pointsize);
       
    45 	AddPoint(x + xstep, y + ystep, ta_pointsize, true);
       
    46 end
       
    47 
       
    48 -- vertical test area
       
    49 local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1}
       
    50 
       
    51 -- fail counter
       
    52 local nfailed = 0
       
    53 local nspawned = 0
       
    54 local ndied = 0
       
    55 
       
    56 function onGameInit()
       
    57 	-- At first we have to overwrite/set some global variables
       
    58 	-- that define the map, the game has to load, as well as
       
    59 	-- other things such as the game rules to use, etc.
       
    60 	-- Things we don't modify here will use their default values.
       
    61 
       
    62 	-- The base number for the random number generator
       
    63 	Seed = 1
       
    64 	-- The map to be played
       
    65 	MapGen = 2
       
    66 	-- The theme to be used
       
    67 	Theme = "Bamboo"
       
    68 	-- Game settings and rules
       
    69 	EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders)
       
    70 	CaseFreq = 0
       
    71 	MinesNum = 0
       
    72 	Explosives = 0
       
    73 
       
    74 	-- No damage please
       
    75 	DamagePercent = 1
       
    76 
       
    77 	-- Draw Map
       
    78 	AddPoint(10,30,0) -- hog spawn platform
       
    79 	-- test areas
       
    80 	AddTestArea(taa_v2)
       
    81 
       
    82 	FlushPoints()
       
    83 
       
    84 	-- Create the player team
       
    85 	AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
       
    86 	-- And add a hog to it
       
    87 	player = AddHog("Hunter", 0, 1, "NoHat")
       
    88 	-- place it on how spawn platform
       
    89 	SetGearPosition(player, 10, 10)
       
    90 end
       
    91 
       
    92 
       
    93 function onGameTick20(gear)
       
    94 	if not TestRectForObstacle(300, 1500, 400, 1900, true) then
       
    95 		WriteLnToConsole('HOLE DETECTED')
       
    96 		EndLuaTest(TEST_SUCCESSFUL)
       
    97 	end
       
    98 end
       
    99 
       
   100 function onNewTurn()
       
   101 	WriteLnToConsole('FIRE DID NOT BURN HOLE!')
       
   102 	EndLuaTest(TEST_FAILED)
       
   103 end
       
   104 
       
   105 
       
   106 function onGameStart()
       
   107 	AddGear(350, 1500, gtHellishBomb, 0, 0, 0, 0)
       
   108 end
       
   109