Be a Supporter!
Response to: biggest WTF moment? Posted October 29th, 2012 in General

When I came off the train and saw a guy in front, I couldn't see his face but he had very dark skin so I though nothing of it but then I noticed he had a weird gothic style box and his facial features didn't look right for someone of his colour....then I realised he had white hands and he was a heavy metal minstrel.

Response to: AS3 Click to begin game problem Posted August 22nd, 2012 in Game Development

actually I'm just gonna put up the entire code way easier

Import Code

//IMPORTS
import Brick;
//Current level player is on
var currentLvl:int = 1;
//The array code for lvl 1
//All of the later levels add one more row of bricks
var lvl1Code:Array = new Array(1,1,1,1,1,1,1);
var lvl2Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1);
var lvl3Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
var lvl4Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1);
var lvl5Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1);
//The array that contains all of the level codes
var lvlArray:Array = new Array(lvl1Code, lvl2Code, lvl3Code, lvl4Code, lvl5Code);

Main code

stop();
//VARIABLES
//These variables are needed for moving the ball
var ballXSpeed:Number = 8; //X Speed of the Ball
var ballYSpeed:Number = 8; //Y Speed of the Ball
//How many bricks are left on the stage
var brickAmt:int = 0;
//how many lives you got
var lives:int = 3;
//if the game is over
var gameOver:Boolean = false;
//The score of the game
var score:int = 0;
//First I defined a function where all of
//the code needed to start the game is placed
//This includes listeners, variable definitions, and other stuff
function beginCode(event:MouseEvent):void{
//removes the listener for a click
stage.removeEventListener(MouseEvent.CLICK, beginCode);
//Adds a listener to the paddle which
//runs a function every time a frame passes
mcPaddle.addEventListener(Event.ENTER_FRAME, movePaddle);
//Adds a listener to the ball which
//runs a function every time a frame passes
mcBall.addEventListener(Event.ENTER_FRAME, moveBall);
//adding a listener to check if the level is done
addEventListener(Event.ENTER_FRAME, checkLevel);
//removing the "Click to Start" Text
txtStart.text = '';
}

function movePaddle(event:Event):void{
//The paddle follows the mouse
mcPaddle.x = mouseX - mcPaddle.width / 2;
//Keeping the paddle in the stage

//If the mouse goes off too far to the left
if(mouseX < mcPaddle.width / 2){
//Keep the paddle on stage
mcPaddle.x = 0;
}
//If the mouse goes off too far to the right
if(mouseX > stage.stageWidth - mcPaddle.width / 2){
//Keep the paddle on stage
mcPaddle.x = stage.stageWidth - mcPaddle.width;
}
}

function moveBall(event:Event):void{
//Code for moving ball goes here
mcBall.x += ballXSpeed; //Move the ball horizontally
mcBall.y += ballYSpeed; //Move the ball vertically
//Bouncing the ball off of the walls
if(mcBall.x >= stage.stageWidth-mcBall.width){
//if the ball hits the right side
//of the screen, then bounce off
ballXSpeed *= -1;
}
if(mcBall.x <= 0){
//if the ball hits the left side
//of the screen, then bounce off
ballXSpeed *= -1;
}
if(mcBall.y >= stage.stageHeight-mcBall.height){
//if the ball hits the bottom
//then bounce up and lose a life
ballYSpeed *= -1;
lives --;
//if there aren't any lives left
if(lives <= 0){
//the game is over now
gameOver = true;
//remove those silly listeners
mcPaddle.removeEventListener(Event.ENTER_FRAME, movePaddle);
mcBall.removeEventListener(Event.ENTER_FRAME, moveBall);
removeEventListener(Event.ENTER_FRAME, checkLevel);
removeEventListener(Event.ENTER_FRAME, updateTextFields);
//go to a lose frame
gotoAndStop('lose');
}
}
if(mcBall.y <= 0){
//if the ball hits the top
//then bounce down
ballYSpeed *= -1;
}
//Hitting the paddle
if(mcBall.hitTestObject(mcPaddle)){
calcBallAngle();
}
}

function calcBallAngle():void{
//ballPosition is the position of the ball is on the paddle
var ballPosition:Number = mcBall.x - mcPaddle.x;
//hitPercent converts ballPosition into a percent
//All the way to the left is -.5
//All the way to the right is .5
//The center is 0
var hitPercent:Number = (ballPosition / (mcPaddle.width - mcBall.width)) - .5;
//Gets the hitPercent and makes it a larger number so the
//ball actually bounces
ballXSpeed = hitPercent * 10;
//Making the ball bounce back up
ballYSpeed *= -1;
}

function makeLvl():void{ //Places bricks onto Level
//checking if indeed there are any more levels left
if(currentLvl > lvlArray.length){
//the game is over now
gameOver = true;
//remove those silly listeners
mcPaddle.removeEventListener(Event.ENTER_FRAME, movePaddle);
mcBall.removeEventListener(Event.ENTER_FRAME, moveBall);
removeEventListener(Event.ENTER_FRAME, checkLevel);
removeEventListener(Event.ENTER_FRAME, updateTextFields);
//go to a lose frame
gotoAndStop("win");
}
//finding the array length of the lvl code
//The index has to be currentLvl-1 because:
//array indexes start on 0 and our lvl starts at 1
//our level will always be 1 higher than the actual index of the array
var arrayLength:int = lvlArray[currentLvl-1].length;
//the current row of bricks we are creating
var brickRow:int = 0;
//Now, creating a loop which places the bricks onto the stage
for(var i:int = 0;i<arrayLength;i++){
//checking if it should place a brick there
if(lvlArray[currentLvl-1][i] == 1){
//creating a variable which holds the brick instance
var brick:Brick = new Brick();
//setting the brick's coordinates via the i variable and brickRow
brick.x = 15+(i-brickRow*7)*75;
brick.y = 10+brickRow*20;
//checks if the current brick needs a new row
for(var c:int = 1;c<=10;c++){
if(i == c*7-1){
brickRow ++;
}
}
//finally, add the brick to stage
addChild(brick);
}
}
}

function checkLevel(event:Event):void{
//checking if the bricks are all gone
if(brickAmt == 0){
//reset the level by increasing the level
currentLvl ++;
//and re-running makeLvl
//resetting the text's word
txtStart.text = "Click To Begin";
makeLvl();
//then resetting the ball's and paddle's position
mcBall.x = 150;
mcBall.y = 265;
mcPaddle.x = 230;
//then removing all of the listeners
mcPaddle.removeEventListener(Event.ENTER_FRAME, movePaddle);
mcBall.removeEventListener(Event.ENTER_FRAME, moveBall);
removeEventListener(Event.ENTER_FRAME, checkLevel);
//then listening for a mouse click to start the game again
stage.addEventListener(MouseEvent.CLICK, beginCode);
}
}

function updateTextFields(event:Event):void{
txtStats.text = "Level: "+currentLvl+" Lives: "+lives+" Score: "+score;
}
//if the mouse clicks, then begin the game
stage.addEventListener(MouseEvent.CLICK, beginCode);
//setting the text's word
txtStart.text = "Click To Begin";
//creating a function to update the text fields
addEventListener(Event.ENTER_FRAME, updateTextFields);
//making the level
makeLvl();

lose code

//The lose frame

//resetting the game if the mouse is clicked
stage.addEventListener(MouseEvent.CLICK, resetGame);

function resetGame(event:MouseEvent):void{
//removing this listener
stage.addEventListener(MouseEvent.CLICK, resetGame);
//resetting the game
gotoAndPlay(1);
}

//showing the final score
txtScore.text = "Final Score: "+score;

Win Code

stage.addEventListener(MouseEvent.CLICK, resetGame);

Response to: AS3 Click to begin game problem Posted August 22nd, 2012 in Game Development

At 8/22/12 09:37 AM, 4urentertainment wrote:
At 8/22/12 09:02 AM, kingsage18 wrote: Yeah I suppose your right but I'm on a deadline and like an idiot I chose a tutorial without seeing if everything worked :/
It sounds like you just need a clean restart function that makes sure everything is deleted and/or reset properly. Post the code you think contains the problem or the fla if it's not big.

A good technique is to always plan things ahead. I've always found that ending the game usually becomes messy, but that's always because I never used to plan that far. Before adding something, like a bunch of enemies or backgrounds, think of how and when you'll remove them. That goes for event listeners as well.

code wise I think its this piece

function beginCode(event:MouseEvent):void{
//removes the listener for a click
stage.removeEventListener(MouseEvent.CLICK, beginCode);
//Adds a listener to the paddle which
//runs a function every time a frame passes
mcPaddle.addEventListener(Event.ENTER_FRAME, movePaddle);
//Adds a listener to the ball which
//runs a function every time a frame passes
mcBall.addEventListener(Event.ENTER_FRAME, moveBall);
//adding a listener to check if the level is done
addEventListener(Event.ENTER_FRAME, checkLevel);
//removing the "Click to Start" Text
txtStart.text = '';
}

or this

function checkLevel(event:Event):void{
//checking if the bricks are all gone
if(brickAmt == 0){
//reset the level by increasing the level
currentLvl ++;
//and re-running makeLvl
//resetting the text's word
txtStart.text = "Click To Begin";
makeLvl();
//then resetting the ball's and paddle's position
mcBall.x = 150;
mcBall.y = 265;
mcPaddle.x = 230;
//then removing all of the listeners
mcPaddle.removeEventListener(Event.ENTER_FRAME, movePaddle);
mcBall.removeEventListener(Event.ENTER_FRAME, moveBall);
removeEventListener(Event.ENTER_FRAME, checkLevel);
//then listening for a mouse click to start the game again
stage.addEventListener(MouseEvent.CLICK, beginCode);
}
}

and lastly

function updateTextFields(event:Event):void{
txtStats.text = "Level: "+currentLvl+" Lives: "+lives+" Score: "+score;
}
//if the mouse clicks, then begin the game
stage.addEventListener(MouseEvent.CLICK, beginCode);
//setting the text's word
txtStart.text = "Click To Begin";
//creating a function to update the text fields
addEventListener(Event.ENTER_FRAME, updateTextFields);
//making the level
makeLvl();

but if it's easier just to look at the whole thing the source file is downloadable at the tutorial site

http://www.flashgametuts.com/obj/tuts/brick-breaker-as3/pt6/
brick-breaker-as3-source.zip

Response to: AS3 Click to begin game problem Posted August 22nd, 2012 in Game Development

At 8/22/12 08:54 AM, Sandremss128 wrote: I guess the point of that flawed tutorial is so you can learn how to extend it by yourself. In the end tutorials are for you to learn how to do stuff and if you haven't learned how to set visible = false after it has been clicked; you've been doing it wrong.

Yeah I suppose your right but I'm on a deadline and like an idiot I chose a tutorial without seeing if everything worked :/


Yeah I'm making a simple brickbreaker game I've followed all the tutorials to the letter.
Yet I've noticed an error with my code and the tutorial's that I really want to get rid of.

Every time you either win, or lose a game you click to go back to frame one, where it says "click to begin" but when you click and start the game, the "click to begin" still remains on screen and if you click again it just restarts mid-game and the ball just builds and builds more momentum.
This is really getting on my nerves if anyone can help me I'd appreciate it a lot

here is the tutorial I used

Response to: Help needed on flash game Posted January 3rd, 2010 in Game Development

anyway i got it to work thank you to all that help

Response to: Help needed on flash game Posted January 3rd, 2010 in Game Development

I'm using AS2 and adobe CS4

Response to: Help needed on flash game Posted January 3rd, 2010 in Game Development

At 1/3/10 12:58 PM, cheese123 wrote: And you are at University?

Why couldn't you just google this?

yeah I'm university abertay dundee to exact, but anyway i wouldn't be asking people if i didn't already check on google and so far its like finding a slightly lighter needle inside and pile of normal needles, nothing comes truly comes up that really helps me so yeah I'm sort of on my last resort.

Help needed on flash game Posted January 3rd, 2010 in Game Development

Hi ok i best explain this, I've been given a task by my uni to create a basic flash game with animation. Now I've been trying to finish the walk cycle tutorial but the actionscript is ( unintentionally) wrong and the guy who takes our class doesn't know the first thing about actionscript.

So what I'm asking is if anyone can help me out with assigning walk cycle animation to the arrow keys on my keyboard.

I've created my symbols and SWF files and movie clips etc. The movie clips are simply called WalkLeft and WalkRight.

if anyone can help i would appreciate it.

Response to: God is like John Posted August 4th, 2009 in General

My dad is called John and he looks like solid snake from MGS4

Response to: Will The World Really End? Posted August 4th, 2009 in General

the world will probably end when the sun implodes, unless we can make it de-age to a bright blue by that time.

any way if the world does end in 2012 well it looks like we're never going to see the halo movie.

Response to: a Bully... Posted August 3rd, 2009 in General

tell your parents it might work and if it doesn't fight him and explain the situation then say that he starts it. Seeing how you parents will know, its most likely they'll be proud of you stick up for your self.

the only wrong choice is to not do anything, it's easy to become a bully when your around them trust me

Response to: Vote for a World Ruler Posted August 3rd, 2009 in General

actually i take that back not penguins this guy we

he seems legit'

Vote for a World Ruler

Response to: Vote for a World Ruler Posted August 3rd, 2009 in General

penguins it would be like planet of the apes on absolutely funny http://www.newgrounds.com/bbs/post/reply /1089363#

picture that an army of penguins with giant slave pits now that's would be funny