Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2176391
  • 博文数量: 436
  • 博客积分: 9833
  • 博客等级: 中将
  • 技术积分: 5558
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-29 10:27
文章存档

2013年(47)

2012年(79)

2011年(192)

2010年(118)

分类:

2010-11-04 21:55:38

                                       第五次报告

 

游戏初始化

游戏中

game.cs 代码

//---------------------------------------------------------------------------------------------

// Torque Game Builder

// Copyright (C) GarageGames.com, Inc.

//---------------------------------------------------------------------------------------------

 

//---------------------------------------------------------------------------------------------

// startGame

// All game logic should be set up here. This will be called by the level builder when you

// select "Run Game" or by the startup process of your game to load the first level.

//---------------------------------------------------------------------------------------------

function startGame(%level)

{

   //exec'ing is important   执行加载一些必要的.cs游戏脚本

   exec("./piece.cs");

   exec("./board.cs");

   exec("./audioDatablocks.cs");

   exec("./GenericImageButton.cs");

  

  

   Canvas.setContent(mainScreenGui);

   Canvas.setCursor(DefaultCursor);

  

   new ActionMap(moveMap);  

   moveMap.push();

  

   $enableDirectInput = true;

   activateDirectInput();

   enableJoystick();

  

   sceneWindow2D.loadLevel(%level);

  

   setup();    调用setup();函数

  

   //sceneWindow2D.setUseObjectMouseEvents(true);

}

 

 

/// ()

/// makes sure objects will get mouse events

///

function setup()    最初的一些加载

{

   //ready the audio!

   audioSetup();   调用audioDatablocks.cs里的audioSetup()函数,准备好音效

  

   // make sure the scene window is set to send mouse events to objects

   if(!sceneWindow2D.getUseObjectMouseEvents()) {  设置触发鼠标事件

      sceneWindow2D.setUseObjectMouseEvents(true);

   } 

}

 

 

//---------------------------------------------------------------------------------------------

// endGame

// Game cleanup should be done here.

//---------------------------------------------------------------------------------------------

function endGame()

{

   sceneWindow2D.stopCameraShake();

   sceneWindow2D.endLevel();

   moveMap.pop();

   moveMap.delete();

}

 

 

audioDatablocks.cs 代码

对声音调用播放的脚本

//-----------------------------------------------------------------------------

// Torque Game Builder

// Copyright (C) GarageGames.com, Inc.

//-----------------------------------------------------------------------------

 

//the current unused pop sound effect

$popNumber = 0;

 

/// ()

/// prepares the 16 audio descriptions and profiles (one for each channel)

/// All the channels will be used to create the overlapping sound effects

// instead of simply running one on top of another

function audioSetup()

{

   for(%a = 0; %a < 16; %a++){                   新建16对音频模式和音频材料

      new AudioDescription("AudioNonLooping" @ %a)  音频模式 不循环模式

      {

         volume = 0.5;

         isLooping= false;

         is3D = false;

         type = $GuiAudioType;

         channel = %a;

      };

 

      new AudioProfile("popAudio" @ %a)    新建音频材料

      {

         filename = "~/data/audio/BLIP.wav";  文件地址在工程目录下/data/audio/BLIP.wav

         description = "AudioNonLooping" @ %a; 文件模式为不循环模式

         preload = true;

      };     

     

     

   }

}

 

/// ()

/// schedules a sound to be played within the next 200 milliseconds

/// Done this way so that not all the sounds are played at the same time

function playNextPop()               playNextPop()是在游戏得分时调用此函数,播出声音

{

 

   schedule(getRandom(0, 200), 0, "playPop");  schedule函数里的getRandom(0, 200)产生0~200随机数,作为播放声音延迟毫秒数,以至游戏时当连续触发声音时,听上去有紧凑感

}

 

/// ()

/// Plays the sound in the next available channel

///

function playPop()          调用不同的音频材料 播放之前定义好的popAudio声音材料

{

   alxPlay("popAudio" @ $popNumber);

  

   $popNumber++;

   if($popNumber >= 16)

   {

      $popNumber = 0;

   }

}

 

 

//-----------------------------------------------------------------------------

piece.cs

其中的许多函数功能仍在认识中

// Torque Game Builder

// Copyright (C) GarageGames.com, Inc.

//-----------------------------------------------------------------------------

 

/// @class Piece

/// @brief The class for one reactor piece

///

/// The Piece class manages one piece, meaning basically the turning functions

///

/// @field int turnSpeed The speed that the piece will turn

 

 

/// (SimID this)

/// This callback function is called by the engine when %this is clicked.

/// When a piece is clicked and there are no reactions currently going on,

/// we reset the score and then prepare and start the clicked piece moving.

///

/// @param this The Piece object

function Piece::onMouseUp(%this,%modifier,%worldPos, %mouseClicks)  鼠标按下触发

{ 

   //sanity is fun!

   if( !isObject(%this.board) )

      error("The clicked piece doesn't belong to a board.");

  

   //first, check if turning is already happening

   //since only one reaction can go on at a time

   if(%this.board.isStable())

   {

      //reset the score, but not the board

      %this.board.newReaction(true, false);

     

      //now, start this Piece turning

      %this.prepareTurn();

      %this.startTurn();

     

   }

  

}

 

/// (SimID this)

/// This function sets a rotationTarget for the object and increases the score.

/// It is very important to activate a turn in two steps so that the logic

/// that starts a turn doesn't conflict with itself as it runs through the array

///

/// @param this The Piece object

function Piece::prepareTurn(%this)    准备旋转

{

  

   //use the next orientation, but don't change it here

   %this.setRotationTarget((%this.orientation+1) * 90.0, true, true, true, 0.1);

   %this.hasTarget = true;  

  

   //add 1 to the board's score

   %this.board.incScore(1);

}

 

/// (SimID this)

/// This function should be called after prepareTurn has been called. It will

/// start the piece rotating towards the rotationTarget from prepareTurn.

///

/// @param this The Piece object

function Piece::startTurn(%this)  开始旋转

{

   //Change the piece's orientation to reflect where it's turning

   %this.orientation++;

   %this.orientation = %this.orientation % 4;

  

   //start turning - it will stop when it hits the rotationtarget

   //turnSpeed is declared as a dynamic field in the level builder

   %this.setAngularVelocity(%this.board.turnSpeed);

  

   //add one to the number of pieces that are turning currently

   %this.board.movingPieces++;

  

   //start a particle effect

   if( %this.board.useParticles )

      %this.particle.playEffect();

  

   //Switch the piece to its rotating animation

   %this.playAnimation(pieceCellsRotating, true, 0, false);

  

   //play a sound

   playNextPop();

  

}

 

/// (SimID this)

/// This callback function is called by the engine when the rotation target is

/// hit. When that is done, we can check if all the pieces are done rotating,

/// in which case we are ready for the board to start the next round of turns.

///

/// @param this The Piece object

function Piece::onRotationTarget(%this) 

{

   //Return the piece to its non-rotating animation

   %this.playAnimation(pieceCellsAnimation, true, 0, true);

  

   %this.hasTarget =false;

  

   //this is important because only pieces that moved last state

   //can activate ones when calculating the next

   %this.movedLastEval = true;

  

   //one fewer piece is moving

   %this.board.movingPieces--;

  

   //if there are no Pieces being turned

   //  then we can evaluate any new moves

   if(%this.board.isStable())

      %this.board.evalBoard();

  

  

}

 

/// (SimID this)

/// generates a random rotation and then rotates the piece to that

///

/// @param this The Piece object

///

function Piece::randomizeOrientation(%this)   算出旋转的角度

{

   //randomize the pieces orientation. It can be one of 4 states

   // up, right, down, left

   %this.orientation = getRandom(0,3);

   //then we rotate the piece to that orientation

   %this.setRotation(%this.orientation * 90.0);

}

 

 

/// (SimID this)

/// Returns whether one of the piece's activation nodes is pointing up

///

/// @param this The Piece object

/// @return bool indicating whether or not there is a node pointing up

function Piece::up(%this)          

{

   return ((%this.orientation == 0) || (%this.orientation == 1));

}

 

/// (SimID this)

/// Returns whether one of the piece's activation nodes is pointing down

///

/// @param this The Piece object

/// @return bool indicating whether or not there is a node pointing down

function Piece::down(%this)        

{

   return ((%this.orientation == 2) || (%this.orientation == 3));

}

 

/// (SimID this)

/// Returns whether one of the piece's activation nodes is pointing left

///

/// @param this The Piece object

/// @return bool indicating whether or not there is a node pointing left

function Piece::left(%this)            

{

   return ((%this.orientation == 0) || (%this.orientation == 3));

}

 

/// (SimID this)

/// Returns whether one of the piece's activation nodes is pointing right

///

/// @param this The Piece object

/// @return bool indicating whether or not there is a node pointing right

function Piece::right(%this)         

{

   return ((%this.orientation == 1) || (%this.orientation == 2));

}

 

这星期在代码方面只实现了游戏的一部分功能,后面的工作依然艰难。不过在一些功能的添加方面有了一定的突破,如添加一些实物,树、山、烟雾等。下周依然把重点放在编写代码上面,然后继续深入其他功能的实现。

 

                           个人总结

李萌 1081000068

 在这一周里,我学习了如何简单的制作小动画。在实践的同时,我感觉到了游戏开发中的乐趣。一个游戏的开发不仅应该是需要非常复杂的代码,同时也需要精心的界面设计和合理充分的应用到尽可能多的开发工具。如果把每个组员所学习到的知识都应用进来,游戏的界面与内容会更加的精彩。

--------------------------------------------------------------------------------------------------------------

任秋双 1081000076

在这新的一周的学习中我开始进行学习了TGB-Scroller Tutorial即关于滚动的教程,其中包括向屏幕中添加滚动的云、树、山等。我已经学会如何添加图片到场景中,并且对场景中的各种景物滚动速度以及方向的设置已经比较熟悉了。其中,更重要的一点是我学会了使用图层,即将各种对象设置到不同的层面,也就是将这些景物进行按层放置,设置有远近的区别。使用图层之后使景物之间的远近、高低的区别更加鲜明了。在按照教程中所教授的内容进行实践之后,我还尝试使用了一些其它的功能,使用了不同的数据对其进行了检测,这些可以为我们的2D游戏添加一些新的色彩。

-----------------------------------------------------------------------------------------------------------------

 

马丹惠 1081000073

这周我对帮助文档的Particles部分的前五点进行了翻译。通过翻译帮助文档,我对颗粒的概念以及颗粒的一些简单设置有了进一步的了解。首先是添加附加的素材,通过在菜单选择Open Project,然后选择games/TutorialBase/project.t2dProj.最后,创建一个新场景,将这个新场景保存为"ParticleTutorial".

然后是颗粒的一些设置,通过跟着文档的说明进行操作,我制作出了文档所提到的下雨的烟云。并且又对其他一些素材进行了编辑。设计总的来说,这周的收获还是比较大的,可以对库中的素材进行简单的编辑,然后组合成一个小的场景。

----------------------------------------------------------------------------------------------- 

石佳 1081000077

本周通过对帮助文档的阅读以及翻译,我学会了如何快速的创建大量相同的对象,这在以后的游戏设计中,可以帮助我们节约很多时间。因为我们组做的游戏是模拟大富翁游戏,在这个游戏的场景中,会设计到许多那个的对象,比如说土地,道路等。同时通过实际操作,我也更加了解了各个应用模式的不同,在游戏的地图创建时,会很有帮助。因为时间只剩下两周了,所以我们也开始着手对游戏进行设计,而不是单独的对文档进行阅读,也对代码进行了分析和阅读。在下周的工作中,将尽快搭建好游戏所需要的地图,为下一步工作准备。

-----------------------------------------------------------------------------------------------

 田冲 1081000081
这星期通过我仔细的阅读教程和对TGB其中一些功能的实践,我已经逐渐从开始对TGB的毫无了解到现在基本可以熟练掌握TGB中的一些功能。对于游戏的开发,打好游戏的“地基”--基本操作,包括创建项目、引用资源、修改模式等都是最基本同时也最是一定会用到的。通过这次对TGB——FishGame的学习也为以后游戏开发做了充分的准备!

-----------------------------------------------------------------------------------------------

于春雪 1081000094

这一周里,我学习了如何在场景里把图片设置成不同的模式,熟悉了图片“FULL”“KEY”“CELL”这三种模式带来的不同效果。“FULL”就是将整张图片添加到场景中;“KEY”可以将一张大的图片切割。总之这周对此2D游戏引擎熟悉了更多功能。

-----------------------------------------------------------------------------------------------

王梦婕 1081000086
在这周,通过阅读TGB——FishGame教程,我学会了如何引用自己想要的图像,基本掌握了在场景里变换图片模式的操作,通过实践真正的掌握了TGB的基本操作。这款软件易于初学者操作,挺好上手,在一次次的实践中我对这款2d游戏引擎有了更多的了解!
-----------------------------------------------------------------------------------------------

宋欢 10181000078

这一周,我对英文的帮助文档进行了部分的翻译,主要内容有对象的各种效果的加载和调试。通过翻译和对软件的使用,也了解了各种效果的使用方法和差异。比如通过改变ROTATION的值来改变旋转的不同方式和效果等。

收获:首先,英文阅读能力有了一部分的提高,同事翻译软件的使用能力也提高了不少。其次,也认识到了帮助文档的重要性,不只是重点部分需要去看帮助文档,还有一些小的细节也需要去注意,细节决定成败。

-----------------------------------------------------------------------------------------------

王竞雄 1081000083

这周我的主要工作是对帮助文档进行学习,我负责翻译的是工作区与相机视角的部分。并且进行了TGB2D的一些基本功能的操作,对TGB2D有了一定的了解。

-----------------------------------------------------------------------------------------------
牛绍勇 1081000075
 
这周我主要学会了加载音乐 文件的输入输出 阅读了游戏源代码Reactor,在Torsion中阅读代码还是比较方便的,有些标准库里写好的函数功能还不是特了解,只能慢慢尝试,下周我主要想了解一些键盘鼠标的监听,触发事件机制,加快游戏的开发进度。
阅读(1105) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-04 22:52:48

你好!我最近也在学习Torque2D引擎,有个问题想和你们探讨一下:TorqueScript是一个面向对象的脚本语言,但是要如何实现自己的类层次呢?如何自己定义类?如何继承自己定义的类?