Recent posts by Chrispy645 on Kongregate

Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Yeah it decrements, and then it resets back to 450, and then decrements, resets back to 450, etc…

Here’s what I have at the moment, and for the zillionth time, it refuses to work. :(

class Ship extends MovieClip
{
var shootFreq;
var BerserkMode;
var BerserkTimer;
...
...

Then:

function onLoad()
{
		
shootFreq=8;
BerserkMode=false;
BerserkTimer=0;
...
...

Then in the onEnterFrame block:

function onEnterFrame()
{


if(BerserkMode == true)
{

BerserkTimer—; // keep reducing timer

if(BerserkTimer<=0)

{
shootFreq=8;
BerserkMode=false;
}

}

In PowerUp.as:

			if(type == 4)
			{
			powerupName = "berserk";
			
			 _root.ship.shootFreq=3;
			 // change speed
      		         _root.ship.BerserkTimer=30; // very low number but for testing purposes
			// timer intialization
			
			_root.ship.BerserkMode == true;

		}

Still not working?

EDIT

I have it working now! I just looked at the code which makes the ship shake, which makes use of something similar. But I have a feeling the code could be way more smaller than it is? Ah well, I got it working at least. :)

			if(type == 4)
			{
			powerupName = "berserk";
			
			 _root.ship.shootFreq = 3;
			 // change fire rate
			
			_root.ship.initBerserkMode();
			// go to Ship.as and execute function initBerserkMode()
			

		}

In Ship.as:

		function initBerserkMode() {
		// this is the first function that executes
						
		BerserkEnable = true;
		// make BerserkEnable true (this is a SWITCH)
		
		BerserkTimer = 30*10;
		// make berserk last 10 seconds (1 second = 30 frames)
		
		}

That piece of code leads to this in onEnterFrame:

			if(BerserkEnable == true){
				BerserkModeGo();
				// ok, if the SWITCH is ON, go to that last function
				// (see end of .AS file)
			}

That last function at the end of the .AS file is this:

		function BerserkModeGo() {
		// ok, this is the timer!
	
		BerserkTimer -= 1; // keep reducing timer

                if(BerserkTimer<=0)
		// when timer hits zero, do all of this stuff
		{
                shootFreq=8;
                BerserkMode=false;
                }
			
		}

Excuse my not so neat code pre’ing… I couldn’t be bothered with the indents. :)

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Originally posted by Draco18s:

You didn’t state what the problem is, but I suspect….

if(berserkTimer == 5) {

That this is causing the effect to end after 5 frames (just over 2 shots) not 5 seconds.

Sorry I wasn’t clear – just to recap, berserk works fine, but I cannot get a timer working to make it last for a predetermined amount of time. The “berserkTimer == 5” is actually very short yes, and it is around 5 frames, but it was just for testing purposes. :)

@ imacer, I tried what you did as well as copying the code you’ve used but it didn’t fix it, unfortunately. The problem is, is that the code in Ship.as does not want to execute for some odd reason – perhaps I need to put the code somewhere else in Ship.as? In PowerUp.as, I simplified the code even further:

			if(type == 4)
			{
			powerupName = "berserk";
			
			_root.ship.berserkMode == true;

		}

In Ship.as, when berserkMode is true, the fire rate increases. But the fire rate doesn’t increase… which really leads me to believe all the code I’ve put into Ship.as isn’t working out right. Would you be able to directly quote what your Shootorial has, imacer? (Assuming you’ve got it all working. :))

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

I’m hearin’ ya. I’ve shifted most the code to Ship.as now, and the powerup code is basically this:

			if(type == 4)
			{
			powerupName = "berserk";
			
			_root.ship.berserkMode == true;
			
			_root.ship.shootFrequency=2;

		}

Then I have all my code in Ship.as, which is meant to run when _root.ship.berserkMode is true.

Ship.as:

				if(berserkMode == true) {
			
				berserkTimer++;
			
			}
			
					if(berserkTimer == 5) {
			
					berserkMode == false;
					shootFrequency=8;
		
					berserkTimer = 0;
		
					}

//code is all rough atm for the sake of testing

Sorry if I’ve missed something you’re trying to tell me… I’m’a look at this again tomorrow morning.

If anyone wants to take a look, go for it – PowerUp.as, lines 98-106, and Ship.as, lines 256-269. They should work with the default Shootorial AS2 template (I just tested).

http://www.mediafire.com/download.php?yziwldfzi1z

Cheers.

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

I’m hearin’ ya. I’ve shifted most the code to Ship.as now, and the powerup code is basically this:

			if(type == 4)
			{
			powerupName = "berserk";
			
			_root.ship.berserkMode == true;
			
			_root.ship.shootFrequency=2;

		}

Then I have all my code in Ship.as, which is meant to run when _root.ship.berserkMode is true.

Ship.as:

				if(berserkMode == true) {
			
				berserkTimer++;
			
			}
			
					if(berserkTimer == 5) {
			
					berserkMode == false;
					shootFrequency=8;
		
					berserkTimer = 0;
		
					}

//code is all rough atm for the sake of testing

Sorry if I’ve missed something you’re trying to tell me… I’m’a look at this again tomorrow morning.

If anyone wants to take a look, go for it – PowerUp.as, lines 98-106, and Ship.as, lines 256-269. They should work with the default Shootorial AS2 template (I just tested).

http://www.mediafire.com/download.php?yziwldfzi1z

Cheers.

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Bump

Just to confirm, I’ve tried to do another way of incrementing berserkTimer – I used “berserkTimer+=1”, and “berserkTimer = berserkTimer + 1”, so it definitely isn’t that. :(

 
Flag Post

Topic: Game Programming / Ultimate game making code!!! just copy and paste!!!11

I was just curious to see what was in the thread. :P

But I couldn’t agree more with the OP. :)

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Cheers Dynamite. :)

The last thing I just need to do is add a timer to the powerup, but that’s peeing me off as well. As always I’ve done a load of experiments and none of them seem to work. To recap, here’s my powerup code:

if(type == 4)
{
powerupName = "berserk";
			
berserkMode == true;
			
_root.ship.shootFrequency=2;

}

Somewhere else in PowerUp.as, I have a block of code which is my timer. I’ve made sure to put this code in " function onEnterFrame()" so when every new frame comes, the timer increases by one (since I want the timer to measure in frames, but I won’t mind if it has to be in seconds, either).

My variables declared at the start of PowerUp.as:

	var berserkTimer:Number = 1;
        var berserkMode:Boolean = false;

Now, the rest of the code:

	function onEnterFrame()
	{

         if(berserkMode == true) {
         // if berserk is on, increase timer
         // when timer has hit 10 frames, stop berserk and make shoot frequency 8 again
			
	 berserkTimer++; // increment our timer (it increments every frame being rendered)
		
		if(berserkTimer == 10) {
			
		berserkMode == false; // berserk powerup has finished
		_root.ship.shootFrequency=8;
		
		berserkTimer = 0;
		// reset timer for next time the player gets berserk again
		
		}
			
	}

However, I’m not getting anything happen in the game. So I tried putting the timer code inside the block of code which turns on berserkMode when you grab the powerup.

	if(type == 4)
	{
	powerupName = "berserk";
			
	berserkMode == true;
			
	_root.ship.shootFrequency=2;
			
		if(berserkMode == true) {
                // if berserk is on, increase timer
                // when timer has hit 10 frames, stop berserk and make shoot frequency 8 again
			
		berserkTimer++; // increment our timer (it increments every frame being rendered)
		
			if(berserkTimer == 10) {
			
			berserkMode == false; // berserk powerup has finished
			_root.ship.shootFrequency=8;
		
			berserkTimer = 0;
			// reset timer for next time the player gets berserk again
		
			}
			
		}

	}

That didn’t seem to work either. Anything interesting you see? :P

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Hey – that fixed it! Sweet! Thanks both you guys!

Now all I need to do is add those if/else statements. :)

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Hey, thanks for the replies. :)

I totally get what you guys are talking about now, but I still can’t seem to get the code to work. I’m working in both Ship.as and PowerUp.as, and I have a feeling that my code in either file isn’t recognizing the code from the other.

Anyways I tried out Dynamite’s code (and it sounds totally correct too), but it didn’t seem to work for me so I tried a load of other ways, including simplifying the code just for testing purposes (simplifying as in removing the if/else statement).

Here’s my code in Ship.as (apologies for no code tags yet):

At the start of Ship.as, I have declared the variable:

var shootFrequency:Number = 8;

Later on down the file:

if( Key.isDown(Key.SPACE) && shootLimiter > shootFrequency) // default 8
{

var missile = _root.attachMovie(“Missile”,“Missile” + _root.getNextHighestDepth(), _root.getNextHighestDepth());

missile._x = x + 50;
missile.
y = _y + 2;

shootLimiter = 0;

}

Okay, that works great. If I change the variable “var shootFrequency:Number” at the start, the shoot frequency changes – great!

Now, I go into PowerUp.as, I declare shootFrequency (“var shootFrequency:Number;”) and here’s my code for powerup TYPE 4:

if(type == 4)
{
powerupName = “berserk”;

shootFrequency = 2;

}

Nothing happens. Is there some sort of conflict between PowerUp.as and Ship.as, or maybe the two .as files don’t want to read off each other for some odd reason?

If anyone wants to have a go doing this, go for it. If you get it working, let me know how… it’d be greatly appreciated. Sorry if I’ve caused any inconvenience. :)

Thanks!

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

@ Dynamite, not quite sure mate.

@ watkins, yep I’ve tried that, but I still don’t seem to notice anything. Here was my code:

if(type == 4)
{

powerupName = “berserk”;

_root.ship.shootLimiter = 6; (I’ve tried all sorts of values for this including 2)

_root.soundFX.attachSound(“energy.mp3”);
_root.soundFX.start();

}

I’m thinking maybe the code is taking effect, but maybe it’s happening so fast in a split second I don’t notice a thing?

So anyways, I tried to construct a loop like this which purpose is to be a timer:

if(type == 4)
{
var limittimer:Number;

for(limittimer = 1; limittimer < 15000; limittimer++) {

powerupName = “berserk”;

_root.ship.shootLimiter = 10;

//Add an explosion sound fx. we create the _root.soundFX sound object in the Ship class
_root.soundFX.attachSound(“energy.mp3”);
_root.soundFX.start();

}

}

A weird sound plays when I get the berserk powerup, which is maybe a sign that the loop’s doing something… But damn, it feels so close!

 
Flag Post

Topic: Game Programming / Shootorial AS2 - adding new powerup (increase fire rate)

Hey guys, recently I’ve begun to learn Flash and ActionScript for an assignment at school, and I’m using the Shootorial #8 tutorial as a base to work on and learn off:

http://www.kongregate.com/games/Kongregate/shootorial-8

Anyways, me and a mate have been trying to add a new powerup to the game (in PowerUp.as) and it’s called “berserk”. Basically, it increases the shooting fire rate of the hero/player ship for a certain period of time when the player grabs the powerup.

In PowerUp.as, I’ve changed “Math.floor(Math.random()*3+1);” to “Math.floor(Math.random()*4+1);”, because I’m adding a new powerup for the randomizer to choose from. And then further down the file, I’ve added this code:

if(type == 4)
{
[insert test code here]
}

The powerup shows up in-game but after many attempts at trying to increase the fire rate, nothing seems to work. I’ve tried making for loops, changing the value of “shootLimiter” and I get nothing. A real simple example was:

if(type == 4)
{
shootLimiter = 2;
}

Of course that most likely is way off what I need to do.

If it helps, lines 152-168 in Ship.as contains code related to shooting.

Thanks in advance. :)