File: tennis.lua

package info (click to toggle)
blobby 1.1.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,944 kB
  • sloc: cpp: 22,442; xml: 779; python: 56; makefile: 3
file content (56 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
__AUTHOR__ = "chameleon"
__TITLE__  = "Crazy Volley - Tennis"

-- left/right ground hits
lgh = 0
rgh = 0

function OnMistake(player)
	lgh = 0
	rgh = 0
	score(opponent(player), true, 1)
end

function OnBallHitsPlayer(player)
	local opp = opponent(player)
	if player == LEFT_PLAYER then
		mh = lgh
		oh = rgh
	else
		mh = rgh
		oh = lgh
	end
	lgh = 0
	rgh = 0
	if touches(player) > 1 then
		mistake(player, opp, 1)
	end
	if oh > 0 and touches(opp) == 0 then
		mistake(opp, player, 1)
	end
end

function OnBallHitsGround(player)
	local opp = opponent(player)
	if player == LEFT_PLAYER then
		lgh = lgh + 1
		mh = lgh
		oh = rgh
		rgh = 0
	else
		rgh = rgh + 1
		mh = rgh
		oh = lgh
		lgh = 0
	end
	if mh > 1 or touches(player) > 0 then
		lgh = 0
		rgh = 0
		mistake(player, opp, 1)
	end
	if oh > 0 and touches(opp) == 0 then
		lgh = 0
		rgh = 0
		mistake(opp, player, 1)
	end
end