开发者

Text based health If object hit then -20 Actions Script 3.0

开发者 https://www.devze.com 2023-04-06 18:17 出处:网络
I am create a little game just to get more experience in Action Script 3.0. What I want is: If you shoot. And the bullet hits. Than the text above should -20..

I am create a little game just to get more experience in Action Script 3.0. What I want is:

If you shoot. And the bullet hits. Than the text above should -20.. Say It has 100(health). And we hit. It will display 80. Second hit 60 etc.

This is what I am having but it does not seem to work out.

 var a;
 var b;

 a = 100;
 b = 20;

Health.text = a

//-------- This above part works.

//After adding the part under here. The whole 'Game开发者_Python百科' doesnt work.

if (kogel.hitTestObject(baws)) //Kogel=bullet. Baws=target

        {
            Health.text = -b
        }

This is the whole code; $

var geweer;  //poppetje in de instance name voor je object die je wilt bewegen.
var ster:Star;
var omhoog;
var omlaag;
var a;
var b;

a = 100;
b = 20;

Health.text = a

stage.addEventListener(KeyboardEvent.KEY_DOWN,beweeg);
function beweeg(event:KeyboardEvent)


    { 
        switch(event.keyCode)
        {
            case 38:
            geweer.y = geweer.y -10;
            //kogel.y = kogel.y -10;
            break;

            case 40:
            geweer.y = geweer.y +10;
            //kogel.y = kogel.y +10;
            break;

            case 32:
            kogel = new Star();
            addChild(kogel);
            kogel.y = geweer.y
            kogel.x = geweer.x

        }

            }

stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event)

{

kogel.x = kogel.x + 5

    }


if (kogel.hitTestObject(baws))
        {
            Health.text = -b
        }

Thanks,

Levi


Disclaimer: I am no AS 3.0 coder but many imperative languages use similar assignment principles.

It looks like you're just assigning to the text to -20. What you should do is

Health.text = Health.text - b

or

Health.text -= b


Perhaps this will work better

if (kogel.hitTestObject(baws)) //Kogel=bullet. Baws=target

  {
    a -= b;
    Health.text = a;
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消