作者:forsoz_627 | 来源:互联网 | 2023-06-30 14:44
在他捡垃圾之后如何创建增加的分数?我在这件事上很新,需要编码方面的帮助。
我下面的代码在单独的.as文件(电影剪辑)上。
如您所见,有一些代码说明玩家何时击中目标,“垃圾”会消失,但是如何为该特定功能应用新的得分代码呢?因此,每次他捡垃圾时分数都会增加。
![如何在收集事物时增加分数(ActionScript 3 Adobe Animate)? 如何在收集事物时增加分数(ActionScript 3 Adobe Animate)?](https://img.php1.cn/3cd4a/1eebe/cd5/0ef126b5295c089b.webp)
package {
import flash.display.Movieclip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class mazeclass extends Movieclip {
var mouseUp:Boolean = false;
var mouseDown:Boolean = false;
var mouseLeft:Boolean = false;
var mouseRight:Boolean = false;
var speed:Number = 5;
public function mazeclass() {
// constructor codea
stage.addEventListener(KeyboardEvent.KEY_DOWN,CheckDownKeys);
stage.addEventListener(KeyboardEvent.KEY_UP,CheckUpKeys);
stage.addEventListener(Event.ENTER_FRAME,updatePos);
}
private function CheckDownKeys(e:KeyboardEvent){
if(e.keyCode == Keyboard.UP){
mouseUp =true;
}
if(e.keyCode == Keyboard.DOWN){
mouseDown =true;
}
if(e.keyCode == Keyboard.LEFT){
mouseLeft =true;
}
if(e.keyCode == Keyboard.RIGHT){
mouseRight =true;
}
}
private function CheckUpKeys(e:KeyboardEvent){
if(e.keyCode == Keyboard.UP){
mouseUp =false;
}
if(e.keyCode == Keyboard.DOWN){
mouseDown =false;
}
if(e.keyCode == Keyboard.LEFT){
mouseLeft =false;
}
if(e.keyCode == Keyboard.RIGHT){
mouseRight =false;
}
}
private function updatePos(e:Event){
if(mouseUp == true){
if(!wall.hitTestPoint(jacob.x,jacob.y-22,true)){
jacob.y -= speed;
}
}
if(mouseDown == true){
if(!wall.hitTestPoint(jacob.x,jacob.y+22,true)){
jacob.y += speed;
}
}
if(mouseLeft == true){
if(!wall.hitTestPoint(jacob.x-22,jacob.y,true)){
jacob.x -= speed;
}
}
if(mouseRight == true){
if(!wall.hitTestPoint(jacob.x+22,true)){
jacob.x += speed;
}
}
if(jacob.hitTestObject(a1)){
a1.x = a1.y = -1000;
_root.score = 0;
_root.score++;
score.text = _root.score;
}
if(jacob.hitTestObject(a2)){
a2.x = a2.y = -1000;
}
if(jacob.hitTestObject(a3)){
a3.x = a3.y = -1000;
}
if(jacob.hitTestObject(a4)){
a4.x = a4.y = -1000;
}
}
}
}