bouncing problem

Non-platform specific questions.

bouncing problem

Postby Garfield501 » Tue Sep 22, 2009 5:56 pm

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
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: bouncing problem

Postby zygoth » Tue Sep 22, 2009 6:23 pm

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.
Nova: 100% Vertigo/Mazeman: 100%
Visit my website to download them both! http://www.ketonegames.com
User avatar
zygoth
 
Posts: 140
Joined: Mon Jun 11, 2007 6:37 pm
Score: 5 Give a positive score

Re: bouncing problem

Postby Garfield501 » Tue Sep 22, 2009 6:27 pm

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.
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: bouncing problem

Postby Kalladdolf » Tue Sep 22, 2009 6:39 pm

It should though.
I reconstructed the problem and it works fine.
Try this file:
bounce.zip
No data.
(824 Bytes) Downloaded 93 times


EDIT: Or do you want to stop the enemy completely from trying to move to the left?
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: bouncing problem

Postby Garfield501 » Wed Sep 23, 2009 1:29 pm

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
Last edited by Garfield501 on Wed Sep 23, 2009 3:00 pm, edited 2 times in total.
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: bouncing problem

Postby Kalladdolf » Wed Sep 23, 2009 2:54 pm

No worries.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: bouncing problem

Postby Garfield501 » Wed Sep 23, 2009 3:00 pm

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
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: bouncing problem

Postby skydereign » Wed Sep 23, 2009 7:01 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: bouncing problem

Postby Garfield501 » Wed Sep 23, 2009 7:20 pm

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?
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: bouncing problem

Postby skydereign » Wed Sep 23, 2009 7:30 pm

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: bouncing problem

Postby Garfield501 » Thu Sep 24, 2009 12:21 pm

It works.
Thank you very much.

Actually it is very easy, but you just have to know how to do it. :D
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron