Vous êtes sur la page 1sur 6

An Educational iPhone Game:Fishing Adventure using iPhone SDK and Cocos2D Library

Thongchai Kolyutsakul, Nattapong Kurupraditwong, Natasha Dejdumrong Department of Computer Engineering King Mongkuts University of Technology Thonburi 126 Pracha Uthit Rd., Thung Khru, Bangkok, 10140, Thailand Email: alistair2305@hotmail.com, jame james@hotmail.com, natasha@cpe.kmutt.ac.th

Abstract
This paper provides information on creating an iPhone educational-casual-sport game, called Fishing Adventure. This game is developed on Objective-C language using Xcode and iPhone SDK. Cocos2D library is used to manage the game visual elements, including some useful classes such as ParticleSystems. The player will be able to play through a storyline, achieve quests, buy equipments, and learn about different kinds of sh. New contributions are benets of implementing knowledge-based games, shstrength simulation using Perlin Noise, natural visual effects of water and waterfall .

iPhone Application developers have been working to create programs that provide convenience to users, which causing a rapid growth for several kinds of iPhone applications such as personal organizers, media players, e-book readers, etc. Particularly, one of the top downloaded application categories is games. This is not surprising because games are unlike other applications; they have the capability to make us fun, excited, relaxed, and other emotions that no other applications can do. Our iPhone game project is called Fishing Adventure. It is an educational-casual-sport game that utilizes G-sensor and also provides a storyline to make the game more intense and attractive. In other words, we focus on entertaining the users as well as providing knowledge of well-known shes. Our goal is to create a fun game on iPhone. We chose iPhone because we want to work with its new features which are accelerometer (gravity sensor or G-sensor) and touch screen. A shing game is a good choice because we can relate the shing rod movement to the accelerometer and use the touch screen as the shing rod spinning wheel. Moreover, there are libraries that help building game scenes, graphical elements and stunning particle effects. Beside the educational game idea and interesting features of iPhone, good programming skills, beautiful artwork, and stunning effects are required to make games worth playing and more popular. This paper will mainly provide theories about how to make the game more interesting and avoid the player from getting bored in the middle of the game. Moreover, we will talk about useful classes and methods of Cocos2D library to implement with game visual effects such as Waves3D and Particle System. The Storyline The player will play as the main character that has to win the shing competition and get the prize to heal his sick father. He has to clear several quests in six shing locations. The player will get a brooch after completing the rst ve

Introduction

Games are known to most people as a type of entertainment for many years. Just like movies and music, games have become a part of peoples interests all around the world due to its versatile game genres that provide different gaming experience for individuals such as action, role-playing, sports adventure, life-simulation, vehicle-simulation, strategy, and puzzle. Moreover, there have been efforts to integrate games for educational purposes to create more motivation and classroom dynamics especially for small children who hardly pay attention to their lessons, give rise to educational game genre [6]. There is evidence that teaching methods based on educational games are not only attractive to small children, but also university students [8]. Games can help teachers to organize more active classes and help ordinary people to passively learn many things through the aid of educational games. An effective way that can help delivering games to people in wider region is possible through mobile devices. One of recently introduced devices that is powerful and well known in global level is iPhone technology.

locations. The nal location will be accessible after all ve brooches are collected. The player has to catch the nal sh in order to win the competition.

2
2.1

LITERATURE REVIEW
Game Theories

Game theories are needed in the design process to keep the game interesting as the player progress and determine the scale of the game affecting the playtime and game ow control. These theories focus on a small-sized game with a story to follow. 1. Game Representation - the player is allowed to access shing locations where he/she has already completed, having more choices as the game advances. This representation is called Extensive Form Representation [1]. 2. Game Structure - only one start and one end, unlike MMORPG games which we can choose different jobs at the start. This form of game is called Classic. The other structure is Fractual. It is has multiple start and/or multiple end points. Small puzzle games, having single of few problems to be solved, take less than one hour to complete while complex games take more than ten hours because they have a lot more problems. 3. The Flow Channel - Wavy line: all games ow should be like an ideal ow channel, like a wavy line (Fig. 1). This is done by introducing new features periodically so the player will not be bored before the game ends. This game consists of many systems that interact with each other. Thus we have to plan the system carefully.

in the nature. A better technique that is commonly used in simulating noise in nature such as cloud, water ripples, and tree leaves is called Perlin noise. An obvious example is the outline of a mountain range. Its height consists of many levels of variations such as large variations in (the mountains), medium variations (hills), small variations (boulders), tiny variations (stones), and so on. In addition, many other distributions of things in the nature, grass on a eld, waves in the sea, the movements of ants, the growth of branches of a tree, patterns in marble, winds, etc. All of these examples demonstrate the same patterns of large and small variations. Perlin Noise function simulates this phenomenon by simply adding up noisy functions at a range of different scales.

Figure 1: Ideal Flow Channel

2.2

Dataset

Data are stored in text les. Since we only have a small amount of data, there is no need of using a database or XML which are complicated to write and retrieve the values. The rst line of the example below indicates the row and column of the le. The next line is rod ID, rod name, rod efciency, two rod parameters, and the rod price. The price of negative one means that rod cannot be sold. (Fig. 2 is a data example.)

5 0 1 2 3 4

6 NoviceRod ApprenticeRod RegularRod ExpertRod UltimaRod

1.0 2.0 5.0 8.0 10.0

160 180 200 220 260

30 40 50 50 60

-1 1000 7000 20000 1000000

Figure 2: An example of RodData text le

2.3

Perlin Noise for Fish Strength Simulation

However, this method requires large amount of calculation and it is not suitable for water ripple simulation in such a resource limited platform such as iPhone. Therefore, Perlin noise is used in our game to simulate the pulling force performed by a perticlaer catching sh. This calculation is not very expensive since only one number has to be generated at a time, not ten thousands of pixels for an image.

Random noise can be used to simulate sh pulling forces but it will produce unstable and unnatural like the real noise. Therefore, using a random noise is not desirable for noise

1. Generating Perlin Noise Perlin noise consists of two main functions, a Noise Function, and an Interpolation Function (connections between points within the noise). It works by using various frequencies and amplitudes and accumulate them together to create a nice noisy function. Persistence is a term to dene how much amplitude is retain for each higher frequency. It is very common to use twice the frequency for each successive noise calculation. However, other frequencies and amplitudes can be used to create Perlin Noise functions. In the following equation, f is frequency, A is amplitude, P is persistence, and i is the ith noise function being added. f = 2i . P .
i

will talk about two interpolation methods, Linear and Cosine interpolation.

(1) (2)

A =

Figure 3: Composition of a Perlin Noise with different persistences

Each successive noise function added is known as an octave. The reason is that each noise function is twice the frequency of the previous one. In music, octaves also have this property. The noise is generated by the sum of noises in different frequencies and amplitudes, as shown in Fig. 3. 2. Creating Noise Function Similar to other computer program random functions, they return pseudo-random numbers, which return the same set of pseudo random numbers every time the same number is passed into function. Actually there is no xed pattern for this type of function as long as it works and returns good random numbers. Here is an example of a random number generator. It returns oating point numbers between -1.0 and 1.0. The code in Fig. 4 is an Objective-C language method. Each of those frightening large numbers inside this function is a prime. Generally, it is considered better to use primes for better random outputs. 3. Interpolation Interpolation function for Perlin Noise is a function that calculates a set of values between two points, in order to smoothly connect them together. There are many kinds of interpolation. The smoother the interpolation, the more calculations are needed. A standard interpolation function takes three inputs, a and b, the values to be interpolated between, and x which takes a value between 0 and 1. The Interpolation function returns a value between a and b based on the value x. When x equals 0, it returns a, and when x is 1, it returns b. When x is between 0 and 1, it returns some value between a and b. This article

(a) Linear Interpolation: this type of interpolation simply draws a straight line to connect the points. It looks awful, but may be used if we need to create Perlin Noise in real time due to its cheap calculation. (b) Cosine Interpolation: this method gives much smoother curve than Linear Interpolation. It is obviously better and worth the effort if you can afford very slight loss in speed. IT is an optimal solution for the implementation on iPhone.

2.4

Singleton Classes - Game Managers

Singleton class is a class that only has one instance and that instance is globally visible. Normally, classes in Objective-C have to declare its instance before using and that instance is only visible in the class that is implementing it. Singleton class acts like a global variable that every class can read and modify. It helps reducing unnecessary function argument passing. We named singleton classes as Managers. We created three main managers, which are Dialogue Manager, Fishing Manager and Player Manager. -(double)Noise:(int)nx { int n = nx * 57; n = (n 13) n; return (1.0 - ( (n * (n * n * r1 + r2) + r3) & 0x7fffffff) / 1073741824.0); } Figure 4: A Pseudo-random integer method

-(double)Interpolate:(double)a x:(double)ix y:(double)iy { return ix*(1-a) + iy*a } Figure 5: A Linear Interpolation Method

2.6

Particle System

-(double)Interpolate:(double)a x:(double)ix y:(double)iy { double val = (1 - cos(a * M PI)) * 0.5; return ix * (1 - val) + iy * val; } Figure 6: A Cosine Interpolation Method

Particle system is a part of Cocos2D library which can generate particle movements in a controlled environment such as the initial position, initial speed, angle, gravity, particle lifetime, tangential and radial acceleration. Texture, opacity and colors of the particles can be changed by setting the parameters inside the class instance. Moreover, you can specify the variance for most of the parameters (except the gravity) so that the particles are randomly generated and look more natural. It is a very useful feature for creating fabulous effects without much resource expense.

1. Fishing Manager: manages the appearance of the shing scene such as the length of the distance gauge; storing variables associated each sh location such as the location ID and sh encounter index. 2. Dialogue Manager: stores all the dialogue, event numbers and methods used to display the text dialogue box and the text inside. 3. Player Manager: stores all data read from the text les (sh data, rod data, bait data, location data, etc.) and the equipment that the player is currently using. Data from each le will be stored in separated array which can be accessed by specifying the index number. In addition, player predened variables are specied here such as the maximum amount of sh that can be stored in the players sh bucket. A singleton class works by using a shared instance variable together with a set of singleton class methods in the implementation le. All other classes that implemented a singleton class access the same shared variable. Figure 7: Example of a Singleton class usage

IMPLEMENTATIONS AND VISUAL EFFECTS


Perlin Noise for Fish Strength Simulation

3.1

2.5

Schedulers

Schedulers are methods used to perform functions that require frequent variable checking or frequent function calls. For example, in the dialogue layer where we display the dialogue we made each character of the dialogue to appear consecutively after one another with a 0.05 second delay. That means 20 characters will take 1 second to appear. This frequent function call can be achieved by using Objective-C scheduler function. A schedule has to be unscheduled after use, otherwise it will keep running.

The sh strength is represented by a gauge labeled Escape Break on top of the screen. Strong sh will decrease the gauge to the escape zone and the player will spin the shing rod wheel below to increase the gauge so the sh wont escape. Also, the gauge must not stay in the break zone for too long or the rope will break and the sh will get away. First we experimented with a typical random function for the sh strength gauge calculation. The gauge movement is not very smooth and sometimes decreases very fast and then stops in a sudden, which is not similar to natural sh movement. Then we implemented the Perlin noise and started to see smoother gauge movements. It slowly decreases and no sudden movement occurs, making it easier to move the wheel correspond to the sh gauge on top.

3.2

Water Eect

A simple Cocos2D Waves3D method is used to create water ripple effect. The smaller the grid parameter (grid : ccg(5, 5) in the last line of Fig. 9), the better frame rate. By using this method, there will be black wave spaces on every sides of the wave picture no matter how large the image is or where it is placed. This has to be xed desperately by hiding those black areas with another image. Another simple technique for water simulation is to have the same water picture on top of another one, but its opacity will be reduced and move up and down slowly. In other words, it is to add about two fading water layers on top of a still water picture to generate the water ripple effect. However, this cannot technique be used with Waves3D method at the same time because it does not support opacity and position changing.

Figure 10: Water effect using two images and slide the top less opacity up and down to create water ripples.

Figure 11: ParticleSun instance, one of Particle System instances.

3.3

Waterfall Eect

Figure 8: The Fishing Scene Interface

It is actually a modied particle system class is used to generate waterfall effect. As mentioned, particle class is used to set up particles to move in a controlled environment. For waterfall, particles are simply tiny-white-square images (sized about 44 pixels with 1 pixel variance). The opacity is set to 0.1 of the white image. Those particles are deployed upward by 45 degrees from the top of the waterfall, set a small radial acceleration as the water tend to spread out as it goes down Moreover, another particle instance will be added for the water splash when the waterfall reaches the water below. The blendAdditive option is set to YES for both particle instances so that the overlapping particles will be brighter in white color at the top of the waterfall, as shown in Fig. 11.

Sprite *water = [SpritespriteWithFile:@sea water.jpg]; [water setPosition:ccp(160,140)]; [self addChild: water z:0]; [water runAction: [RepeatForever actionWithAction: [Waves3D actionWithWaves:50 amplitude:30 grid:ccg(5,5) duration:300]]]; Figure 9: Cocos2D Waves3D method example Figure 12: Four dense and one subtle waterfall particle instances running on iPhone simulation

Figure 15: Equipment change scene

Figure 13: Waterfall particle instances together with a waterfall cliff and waterfall background Figure 16: Dialogue example in the Fish Equipment Shop

CONCLUSION

References
[1] A. I. Wang, T. Ofsdahl, and O. K. Morch-Storstein. An evaluation of a mobile game concept for lectures. In Proceedings of the 21st Conference on Software Engineering Education and Training (CSEET 08), pages 197204, Charleston, SC, USA, April 2008. [2] A.Baker,E.O.Navarro,andA.vanderHoek. Problems and programmers: an educational software engineering card game. In Proceedings of the 25th International Conference on Software Engineering (ICSE 03), pages 614619, Portland, Ore, USA, May 2003. [3] E. O. Navarro and A. van der Hoek. Simse: an educational simulation game for teaching the software engineering process. In Proceedings of the 9th Annual SIGCSE Conference on Innovation and Technology in Computer Science Education (ITiCSE 04), page 233, Leeds, UK, June 2004. [4] L. Natvig, S. Line, and A. Djupdal. age of computers; an innovative combination of history and computer game elements for teaching computer fundamentals. In Proceedings of the 34th Annual Frontiers in Education (FIE 04), volume 3, pages 16, Savannah, Ga, USA, October 2004. [5] M. S. El-Nasr and B. K. Smith. Learning through game modding. Computers in Entertainment, 4(1):45 64, 2006. [6] R. Rosas, M. Nussbaum, P. Cumsille, et al. Beyond nintendo: design and assessment of educational video games for rst and second grade students. Computers & Education, 40(1):7194, 2003. [7] R. Rosas,M. Nussbaum, P. Cumsille, et al. Beyond nintendo: design and assessment of educational video games for rst and second grade students. Computers & Education, 40(1):7194, 2003. [8] M. Sharples. The design of personal mobile technologies for lifelong learning. Computers & Education, 34(3-4):177193, 2000.

The iPhone game Fishing Adventure is a casual-sport game using Cocos2D as the main library. The game ow is based on the wavy curve ow channel to try to keep the player anxious and fun along the game. We used Perlin noise for sh strength simulation because it is more natural than random noise. We used singleton class to manage variables needed in different scenes and classes. Simple image scrolling and Waves3D method is used in water effect. Particle system is used for waterfall and menu visual effects. Schedulers are used to repeatedly do some particular instructions such as tracking the states in the shing scene and displaying each letter in serial manger in the dialogue scene. We used text les to store data in the game such as sh data, player data, and location data. Studies we have contributed are benets of implementing knowledgebased games, details of sh-strength simulation using Perlin Noise, and natural visual effects of water and waterfall using Cocos2D library.

Figure 14: Fish Equipment Shop

Vous aimerez peut-être aussi