Page 1 of 1

bouncing problem

PostPosted: Tue Sep 22, 2009 5:56 pm
by Garfield501
Hello,
I just started with "GE".
I am trying to make a simple Space invaders game.
The first problem I encountered is the following:



I have an enemy named: enemy_001
Now i made a wall outside the screen on the left side.
When enemy_001 starts the move to the left (i used enemy_001.xvelocity = -1; in Draw actor --> script editor of enemy_001), and it hits the wall outside the screen, it it supposed to "bounce off" to the right. (It moves on the x-coördinate).

So when it hits the wall I used enemy_001.xvelocity = xvelocity +1; in collision --> script editor in enemy_001.
What happens now when it hits the wall, it still moves to the left.


I know I am doing something wrong, but I don't know what.
What do I need to do, so that when it hits the wall, it bounces of to the right.

Thanks in advance,
Mark

PS. sorry for my broken english, but i am dutch :D

Re: bouncing problem

PostPosted: Tue Sep 22, 2009 6:23 pm
by zygoth
You might try

xvelocity = xvelocity * -1;

Also, when referencing a actor variable in an actor you do not need to type actor.variable , just the variable.

Re: bouncing problem

PostPosted: Tue Sep 22, 2009 6:27 pm
by Garfield501
tried it.
It still keeps moving to the left.

EDIT:
i am tried this: xvelocity = xvelocity*-1;
But now it stops when it hits the wall, but it still tries to move to the left.

Re: bouncing problem

PostPosted: Tue Sep 22, 2009 6:39 pm
by Kalladdolf
It should though.
I reconstructed the problem and it works fine.
Try this file:
bounce.zip
No data.
(824 Bytes) Downloaded 92 times


EDIT: Or do you want to stop the enemy completely from trying to move to the left?

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 1:29 pm
by Garfield501
Thank you very much.
After i looked into your program, i think i know what went wrong.

When enemy_001 is drawed, then the code was repeating it self.
My code was working, but I put the code in the wrong place.

I had to place it in Create actor and not in Draw actor.
Now it is working thanks to your program.

Thank you very much. :D

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 2:54 pm
by Kalladdolf
No worries.

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 3:00 pm
by Garfield501
I have a new question (not really a problem this time :lol: )

I have a ship named Player.
I want that when i press my left mouse button, it shoots a bullet named Shipbullet.

What i have at the moment is that i have to click in the Player actor to make it shoot.
Want i want, is then i can click anywhere in the game and that it shoots then.

How do i do this?

Thanks in advance,
Mark

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 7:01 pm
by skydereign
If you are only going to use that mouse button down, then I would create a filled region actor, it is blue, and make it bigger than the view. It should automatically set to have the proper zdepth, in front of other actors, and so just put a mouse button down event, and put the create actor there. You would have to use script editor, if you weren't already, as you need to give the x and y coordinates of player.

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 7:20 pm
by Garfield501
Sorry, but I don't understand you.
I don't really know what you are talking about.

I am using the script editor already, but I am just a newbie with this.

Could you give me a bigger explanation or maybe some kind of a demo?

Re: bouncing problem

PostPosted: Wed Sep 23, 2009 7:30 pm
by skydereign
Okay, first add an filled region actor. When creating your actor, name it click or something similar, set its actor type to filled region. By default the actor type is set to Normal, so you will need to change it. This gives you a blue region that can be increased or decreased in size by dragging its corners. Drag the actor over the view, and make sure it covers the view completely. The filled region actor is primarily used to catch mouse clicks, so its zdepth is already set to 1.

Now that you have this actor, add a mouse button down event for it. In the script, you would use this code, but you might have to change it to fit your actor animations. This creates the actor at the Ship's xy coordinates.
Code: Select all
CreateActor("Shipbullet", "Shipbullet", "(none)", "(none)", Ship.x, Ship.y, true);

Re: bouncing problem

PostPosted: Thu Sep 24, 2009 12:21 pm
by Garfield501
It works.
Thank you very much.

Actually it is very easy, but you just have to know how to do it. :D