[摘要]
krpano可以做全景漫游,也可以用于开发小游戏,这个相信很多人都知道,下面介绍一个简单的krpano制作的layer碰撞球游戏,要做游戏的朋友可以下载代码学习参考。
主要代码
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
<!-- 背景画像 --> <layer name="background" url="spacy.jpg" width="100%" height="prop" align="center" enabled="false" visible="true" zorder="10" /> <!-- スタートボタン --> <layer name="startbutton" url="startButton.png" width="80%" height="prop" align="center" edge="center" zorder="80" enabled="true" visible="true" onclick="onClickStart();" /> <!-- リプレイボタン --> <layer name="replaybutton" url="replayButton.png" width="80%" height="prop" align="center" edge="center" zorder="80" enabled="false" visible="false" onclick="onClickReplay();" /> <!-- 得点表示 --> <layer name="scoreboard" url="textfield.swf" align="topright" visible="true" enabled="false" css="font-family:Arial; font-size:20px; color:#00ff00;" autoheight="true" background="false" border="false" textshadow="0.7" textshadowrange="4.0" textshadowangle="45" textshadowcolor="0xffffff" textshadowalpha="1.0" html="SCORE: 000000" zorder="30" width="200" /> <!-- パドル --> <layer name="paddle" url="paddle.png" width="80" height="15" align="topleft" edge="topleft" zorder="50" enabled="false" visible="true" movement="0" /> <!-- ボール --> <layer name="ball" url="ball.png" width="30" height="30" align="topleft" edge="topleft" zorder="55" enabled="false" visible="true" vector_x="1" vector_y="1" speed="1.0" x="0" y="0" /> <!-- 初期化処理 --> <action name="startup"> <!-- パドルの縦位置をセット --> sub( paddleY, stageheight, 50 ); copy( layer[paddle].y, paddleY ); set( gamestatus, false ); </action> <!-- スタートボタンクリック --> <action name="onClickStart"> <!-- スタートボタンを消去 --> set( layer[startbutton].visible, false ); set( layer[startbutton].enabled, false ); <!-- ゲーム開始 --> startGame(); </action> <!-- リプレイボタンクリック --> <action name="onClickReplay"> <!-- スタートボタンを消去 --> set( layer[replaybutton].visible, false ); set( layer[replaybutton].enabled, false ); <!-- ゲーム開始 --> startGame(); </action> <!-- ゲームオーバー --> <action name="onGameEnd"> <!-- ゲーム開始ステータス:停止 --> set( gamestatus, false ); <!-- リプレイボタンを表示 --> set( layer[replaybutton].visible, true ); set( layer[replaybutton].enabled, true ); </action> <!-- ゲーム開始 --> <action name="startGame"> <!-- スコアリセット --> set( gamescore, 0 ); txtadd( scoretext, "SCORE: ", get(gamescore) ); copy( layer[scoreboard].html, scoretext ); <!-- ボールの初期位置セット --> set( layer[ball].x, 0 ); set( layer[ball].y, 0 ); set( layer[ball].vector_x, 1 ); set( layer[ball].vector_y, 1 ); set( layer[ball].speed, 1.0 ); <!-- パドルの縦位置をセット --> sub( paddleY, stageheight, 50 ); copy( layer[paddle].y, paddleY ); <!-- ゲーム開始ステータス:開始 --> set( gamestatus, true ); <!-- メインループ呼び出し --> asyncloop( gamestatus, mainLoop() ); </action> <!-- メインループ --> <action name="mainLoop"> <!-- パドル移動 --> relocatePaddle(); relocateBall(); </action> <!-- パドル移動 --> <action name="relocatePaddle"> sub( paddleX, mouse.stagex, 40 ); sub( layer[paddle].movement, paddleX, layer[paddle].x ); copy( layer[paddle].x, paddleX ); </action> <!-- ボール移動 --> <action name="relocateBall"> <!-- 移動量を計算 --> mul( ball_move_x, layer[ball].vector_x, layer[ball].speed ); mul( ball_move_y, layer[ball].vector_y, layer[ball].speed ); <!-- ボールを移動 --> add( layer[ball].x, ball_move_x ); add( layer[ball].y, ball_move_y ); <!-- 壁との当たり判定 --> if( layer[ball].x LE 0, mul( layer[ball].vector_x, -1 ); accelerateBall(); addScore(); ); sub( xmax, stagewidth, 30 ); if( layer[ball].x GE xmax, mul( layer[ball].vector_x, -1 ); accelerateBall(); addScore(); ); if( layer[ball].y LE 0, mul( layer[ball].vector_y, -1 ); accelerateBall(); addScore(); ); <!-- パドルとの当たり判定 --> add( paddle_width_max, layer[paddle].x, 80 ); add( paddle_height_max, layer[paddle].y, 15 ); add( ball_width_max, layer[ball].x, 30 ); add( ball_height_max, layer[ball].y, 30 ); add( ball_width_center, layer[ball].x, 15 ); add( paddle_width_center, layer[paddle].x, 40 ); <!-- ボールの下端がパドルの上端より下にある --> if( ball_height_max GE layer[paddle].y, if( layer[ball].y LE paddle_height_max, if( ball_width_max GE layer[paddle].x, if( layer[ball].x LE paddle_width_max, <!-- 情况判断 --> mul( layer[ball].vector_y, -1 ); accelerateBall(); addScore(); <!-- 向右方向移动 --> if( layer[paddle].movement GT 0, if( layer[ball].vector_x GT 0, <!-- 如果球向右方向移动的话,向右方向加速 --> div( movement_rate, layer[paddle].movement, 40 ); if( movement_rate GT 1.0, set( movement_rate, 1.0 ) ); add( layer[ball].vector_x,movement_rate, 1.0 ); , <!-- 如果球向左方向移动的话,向右方向减速 --> div( movement_rate, layer[paddle].movement, 40 ); if( movement_rate GT 1.0, set( movement_rate, 1.0 ) ); sub( layer[ball].vector_x, 1.0, movement_rate ); decelerateBall(); ); ); <!-- 向左移动 --> if( layer[paddle].movement LT 0 if( layer[ball].vector_x LT 0, <!-- 如果球向左方向移动的话,向左方向加速 --> div( movement_rate, layer[paddle].movement, 40 ); if( movement_rate LT -1.0, set( movement_rate, -1.0 ) ); add( layer[ball].vector_x,movement_rate, -1.0 ); , <!-- 如果球向右方向移动的话,向右方向减速 --> div( movement_rate, layer[paddle].movement, 40 ); if( movement_rate LT -1.0, set( movement_rate, -1.0 ) ); sub( layer[ball].vector_x, -1.0, movement_rate ); decelerateBall(); ); ); ); ); ); ); <!-- 游戏结束判定 --> if( layer[ball].y GT stageheight,onGameEnd(); ); </action> <!-- 分数计算 --> <action name="addScore"> add( gamescore, 100 ); txtadd( scoretext, "SCORE: ", get(gamescore) ); copy( layer[scoreboard].html, scoretext ); </action> <!-- 加速动作 --> <action name="accelerateBall"> if( layer[ball].speed LT 7.0, mul( layer[ball].speed, 1.2 ); ); </action> <!-- 减少动作 --> <action name="decelerateBall"> if( layer[ball].speed GT 1.0, mul( layer[ball].speed, 0.8 ); ); </action> |
下载地址
[需开通会员权限]