TideScreenshot

Ocean Tide

  • Role: Engineer
  • Team size: 1
  • Engine: Flash
  • Available: Click Here

Description

This piece of 2D motion programming was in response to testing feedback from Tide, where testers said that the tide line lacked a sense of life. The previous wave formation was a simple flat line that TideScreenshotwould extend incrementally up the beach.

In order to make the wave formation look organic i broke down the solid line into many smaller bars. When retracted the wave would randomly pick a bar that would lead the crest of the wave. This bar was then given a velocity, the rest of the bars velocity would be slaved to the lead bar. Their velocity would decay based on their distance from the lead bar.

For every tide event the lead bar would be given a random new y-coordinate which would become its maxim distance. As the lead bar approached the maximum distance it would slow its velocity organically. Once the lead bar reached the maximum distance it would reverse its velocity sending it back to to its original tide line. All “slave” bars would also retreat in this method.

In conclusion the new wave generation looks organic and inspires a better connection with the tide from which the game derives its name and gameplay.

Code

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
public function oceanSetup()
{
for (var i:int = 0; i < 32; i++)
{
var oceanBar:OceanBar = new OceanBar(oceanColor)
addChild(oceanBar)
oceanBar.x = oceanBar.display.width * i;
oceanBar.y = 40;
 
oceanArray.push(oceanBar)
}
 
var delayTimer:Timer = new Timer(lengthOfDelay, 1)
delayTimer.start()
delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE, start)
}
public function start($e:Event)
{
startTideGoingIn()
}
public function startTideGoingIn()
{
var randomInt:int = Math.round(Math.random() * (oceanArray.length - 1))
leadOceanBar = oceanArray[randomInt];
oceanArray.splice(randomInt, 1)
 
addEventListener(Event.ENTER_FRAME, tidesGoesIn)
 
for each( var i:OceanBar in oceanArray)
{
i.display.addEventListener(Event.ENTER_FRAME, tideBarsIn)
}
}
public function tidesGoesIn($e:Event)
{
var currentPos:Number = leadOceanBar.y;
var endPos:Number = sandEdge.y;
 
//As long as the ocean hasnt reached the sand, keep going.
if (currentPos < endPos)
{
var distance:Number = endPos - currentPos;
 
leadOceanBar.y += distance / tideSpeed;
}
//Ocean has reached max height, stop and wash old items away.
if (currentPos + 10 >= endPos)
{
highTide()
}
}
public function tideBarsIn($e:Event)
{
var tempBar:OceanBar = $e.currentTarget.parent
 
var currentPos:Number = tempBar.y;
var endPos:Number = leadOceanBar.y
 
if (currentPos < endPos)
{
var distance:Number = endPos - currentPos;
 
var distanceFromLeader:Number = Math.abs(leadOceanBar.x - tempBar.x);
var rate = distanceFromLeader / oceanBarRate
 
tempBar.y += distance / rate;
}
if(currentPos + 10 >= endPos)
{
//startTideBarOut(tempBar)
}
}
public function startTideBarOut(tempBar:OceanBar)
{
tempBar.display.removeEventListener(Event.ENTER_FRAME, tideBarsIn)
tempBar.display.addEventListener(Event.ENTER_FRAME, tideBarsOut)
}
public function startTideGoingOut($e:Event)
{
var currentPos:Number = leadOceanBar.y;
var endPos:Number = watersEdge.y;
var beginningPos:Number = sandEdge.y;
 
leadBarDistance = beginningPos - currentPos;
 
addEventListener(Event.ENTER_FRAME, tideGoesOut)
 
for each( var i:OceanBar in oceanArray)
{
i.display.removeEventListener(Event.ENTER_FRAME, tideBarsIn)
}
 
for each( var j:OceanBar in oceanArray)
{
j.display.addEventListener(Event.ENTER_FRAME, tideBarsOut)
}
}
public function tideGoesOut($e:Event)
{
//Retreat the tide to a point closer to shore.
var currentPos:Number = leadOceanBar.y;
var endPos:Number = watersEdge.y;
var beginningPos:Number = sandEdge.y;
 
counter += 1
 
if (currentPos > endPos)
{
leadBarDistance = beginningPos - currentPos;
if (leadBarDistance > 60)
{
leadBarDistance = 60;
}
 
leadOceanBar.y -= leadBarDistance / tideSpeed
}
if (currentPos <= endPos)
{
trace("Wait for Tide");
waitBetweenTide()
}
}
public function tideBarsOut($e:Event)
{
var tempBar:OceanBar = $e.currentTarget.parent;
 
if (tempBar.y > waterLine.y)
{
tempBar.y -= leadBarDistance / tideSpeed;
}
else
{
tempBar.display.removeEventListener(Event.ENTER_FRAME, tideBarsOut)
}
}
public function waitBetweenTide()
{
removeEventListener(Event.ENTER_FRAME, tideGoesOut)
//How much time there is between waves.
var randomTideTime:int = minimumTideWaitTime + Math.round(Math.random() * minimumTideWaitTime)
 
oceanTimer = new Timer(randomTideTime, 1)
oceanTimer.start()
oceanTimer.addEventListener(TimerEvent.TIMER_COMPLETE, beginTide)
}
public function beginTide($e:Event)
{
oceanArray.push(leadOceanBar)
startTideGoingIn()
}
public function highTide()
{
removeEventListener(Event.ENTER_FRAME, tidesGoesIn)
highTideLine = leadOceanBar.y;
 
oceanTimer = new Timer(500, 1)
oceanTimer.start()
oceanTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startTideGoingOut)
}
Categories:

Code Examples