File: Easteregg.c

package info (click to toggle)
openclonk 8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 169,656 kB
  • sloc: cpp: 180,484; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 148; sh: 101; javascript: 34
file content (132 lines) | stat: -rw-r--r-- 3,945 bytes parent folder | download | duplicates (5)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Triggers colored wipf rainbow on a succesful jump roll and wall jump performed by the player.

#appendto Clonk

public func DoRoll()
{
	// Only perform events on first roll.
	if (GetEffect("IntDoneRoll", this))
		return _inherited(...);
	else
		AddEffect("IntDoneRoll", this, 100);
		
	// Add some stars effect to the clonk indicating the easteregg.
	CreateParticle("StarSpark", PV_Random(-3, 3), PV_Random(-14, -10), PV_Random(-5, 5), PV_Random(-8, 0), 25, Particles_Magic(), 20);
	
	if (GetEffect("IntDoneWallJump", this))
		DoEasterEgg();

	return _inherited(...);
}

protected func FxIntDoneRollStart(object target, proplist effect, int temporary)
{
	// Just a an effect which should always stay and hence accept always.
	return FX_OK;
}

public func StartJump()
{
	// Only do something if it is a wal jump, not an ordinary one.
	if (!GetEffect("WallKick",this))
		return _inherited(...);
		
	// Only perform events on first wall jump.
	if (GetEffect("IntDoneWallJump", this))
		return _inherited(...);
	else
		AddEffect("IntDoneWallJump", this, 100);

	// Add some stars effect to the clonk indicating the easteregg.
	CreateParticle("StarSpark", PV_Random(-3, 3), PV_Random(-14, -10), PV_Random(-5, 5), PV_Random(-8, 0), 25, Particles_Magic(), 20);
	
	if (GetEffect("IntDoneRoll", this))
		DoEasterEgg();

	return _inherited(...);
}

protected func FxIntDoneWallJumpStart(object target, proplist effect, int temporary)
{
	// Just a an effect which should always stay and hence accept always.
	return FX_OK;
}

// Award achievement if a gold bar has been collected.
public func Collection(object collected)
{
	if (collected->GetID() == GoldBar)
	{
		// Only perform events on first wall jump.
		if (GetEffect("IntAwardedAchievement", this))
			return _inherited(collected, ...);
		AddEffect("IntAwardedAchievement", this, 100);
		// Add some stars effect to the clonk indicating the easteregg.
		CreateParticle("StarSpark", PV_Random(-3, 3), PV_Random(-14, -10), PV_Random(-5, 5), PV_Random(-8, 0), 25, Particles_Magic(), 20);		
		// Achievement: easter egg found.
		GainScenarioAchievement("TutorialEasterEgg");
	}
	return _inherited(collected, ...);
}

protected func FxIntAwardedAchievementStart(object target, proplist effect, int temporary)
{
	// Just a an effect which should always stay and hence accept always.
	return FX_OK;
}


// Creates the easteregg.
public func DoEasterEgg()
{
	// Create the wipf rainbow at the cave exit.
	CreateRainbow();
	
	// Create a chest with gold at the other end of the rainbow.
	var chest = CreateObjectAbove(Chest, AbsX(576), AbsY(260));
	chest->CreateContents(GoldBar, 10);
	return;
}

// Creates a rainbow consisting of small colored wipfs.
public func CreateRainbow()
{
	// Rainbow properties
	var cx = 772, cy = 400; // rainbow center
	var r = 244; // rainbow radius
	var colors = [[255, 0, 0], [255, 127, 0], [255, 255, 0], [0, 255, 0], [0, 0, 255], [75, 0, 130], [143, 0, 255]];

	// Loop over the number for particles in the rainbow and create it. 
	var arc_start = 120;
	var arc_length = 1360;
	var nparticle = 150;
	
	// Dummy object for attaching the particles and make them background.
	var dummy = CreateObject(Dummy);
	dummy.Visibility = VIS_Owner;
	dummy.Plane = -600;
	dummy->SetCategory(C4D_StaticBack | C4D_Background | C4D_Parallax);
	dummy.Parallaxity = [20, 20];
		
	// Loop over the arc and the colors and create the particles.	
	for (var angle = arc_start; angle < arc_start + arc_length; angle += (arc_length / nparticle))
	{
		for (var i = 0; i < GetLength(colors); i++)
		{
			var x = dummy->AbsX(cx + Cos(angle, r - 2 * i, 10));
			var y = dummy->AbsY(cy - Sin(angle, r - 2 * i, 10));
			var wipf =
			{
				Size = 7,
				Rotation = 90 - angle / 10,
				R = colors[i][0],
				G = colors[i][1],
				B = colors[i][2],
				Alpha = 128, //PV_Step(1, 0, 1, 255),	
				Attach = ATTACH_Back,
			};
			dummy->CreateParticle("Sphere", x, y, 0, 0, 0, wipf, 1);
		}
	}
	return;
}