Firing left and right

For questions about using Classic.

Post » Mon Jan 14, 2008 7:42 pm

Hi, I'm wondering how you can make the player with platform controls fire left and right and maybe up.
B
4
S
2
G
4
Posts: 164
Reputation: 2,178

Post » Mon Jan 14, 2008 8:53 pm

One thing you could try is setting a private variable on the player, like a string called 'direction', and have it set to 'left', 'right', and 'up' when the player is pressing those controls - up, probably only when held. Then, when the fire button is pressed, determine angle from the player based upon 'direction'. This is a non-programmer's version, though.
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Tue Jan 15, 2008 8:42 pm

Could you explain that a bit more I don't really understand
B
4
S
2
G
4
Posts: 164
Reputation: 2,178

Post » Tue Jan 15, 2008 9:24 pm

Here, look at this:

http://www.mediafire.com/?e9raxnx8yx1

Look at it. LOOK AT IT AND LOVE IT AAAAHHHRRGGGG!!!

Anyway, there are three objects here... a player, a bullet, and the barrier to keep the player from going offscreen.

We can ignore the barrier.

Look at the bullet. Check out it's properties. It's set to Bullet Movement. Easy enough, eh?

Now look at the player. Double-click it. Select Image Points in the Picture Editor. Notice where the "fire" image point is set. Now go back to the layout.

Select the player again, and look at the Animator Bar tab. Notice that there are two angles for the player, 0 degrees and 180 degrees (right and left). If you select the 180 degrees animation and double-click the frame in the Animator Bar, you will notice that the "fire" Image Point is set up here as well... but it's on the opposite side. This is because we have to compensate for the gravitational field of Jupiter during winter. Or maybe because the player is just facing the other way.

Now look at the Event Sheet Editor. We have three simple events:



The first two orient the player when we press a directional key. This is based off the angles set up in the animator bar.

The third fires a bullet. The bullet spawns at the player's image point "fire." It automatically orients itself based on the player's angle. There is no need to specifically tell it which way to go, it already knows. It's got a doctorate in physics.

If you study this example, I'll bet you can figure out how to make your player shoot up, as well. I mean shoot in an upward direction, not take heroin. Winners never use drugs.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Jan 16, 2008 12:14 am

Hehe, thanks deadeye, good demo :) If I had a gold star, I'd give you one.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Wed Jan 16, 2008 4:03 pm

Thanks that worked wonders.
B
4
S
2
G
4
Posts: 164
Reputation: 2,178


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests