Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-17-2011, 01:28 PM   #1
Emazizing
Registered User
 
Join Date: Jan 2011
Location: Kirkland Lake, Ontario.
Posts: 3
Exclamation [AS3] Trying to make a color game

Hey guys Im new to this website and Im currently in my programming class trying to work on my final project. The thing is with this class it takes a lot of minds to do one thing because we all have a very loose idea on how to properly use flash ( including the teacher) and I want to start being able to work on flash indapendently and actually start getting good at it!

So I decided to come to the people that would know the most and would be able to help, give me helpful tips, and help me learn Actionscript 3.0!!! =DD

Okay so heres whats going down,

(click here)
Click image for larger version

Name:	Untitled.png
Views:	221
Size:	104.5 KB
ID:	36109

In my game what is suppose to happen is that the Colored Bucket of Paint comes onto the screen and you enter the name of the color and press 'Ok' and whether you enter it WRONG or CORRECT those words in giant text will come onto the screen yelling "WRONG!" or "CORREEECT!". If you get the answer correct the game will move on the next color, if not it will ask you to enter the color name again. This game is aimed at young children according to the teacher his children need to be able to be play it.

I just need to know where to start and how, which I want to eventually get out of the habit of needing. This programming class kinda works with everyone just trying to figure out the same issues and not being able to work indapendently which I want to start doing!

Hopefully someone will help me, and teach me the basics and proper usage of Action Script 3.0 and Action Script in general! =)
Emazizing is offline   Reply With Quote
Old 01-17-2011, 02:15 PM   #2
maskedMan
Obfuscated Coder
 
maskedMan's Avatar
 
Join Date: Apr 2008
Posts: 1,571
Default

If it's aimed at a young enough audience, it might be better to present multiple choice buttons instead of a text field, so that could be the "real" answer to the problem... but it might not solve the overall issue of "where do I get started / how do I even think about the problem?"

As for how you do what you've asked about, it looks like you have 4 or 5 pre-defined colors, so that makes it easier. I'm not going to talk about how to tween the paint buckets, many of the specifics of how to structure anything or how to get the "wrong/correct" text onto the screen, only give a rough overview of what you'd do for the main game logic.

First thing you would do is create an array of color names so that you can select the color you need.
Code:
var colorNames:Array = ["red","blue","green","orange"];
Then you'd make an array containing the paint buckets of the same color that you'd use to select the paint bucket image you need.
Code:
var buckets:Array = [redBucket,blueBucket, ...];
Now in order to make a selection from the Array you need a random number generator. Flash has a way to get a random number. Call Math.random() to recieve a number between 0 and 1. Multiply this by the number of items in your array and round down. You now have a random number pointing to an array location. Store the currently selected color into a variable:
Code:
var randomNumber:int = Math.floor(Math.random() * colorNames.length);
var currentColor:String = colorNames[randomNumber];


Bring the selected paint bucket onscreen.

When the user presses the "ok" button, you'll want to compare the value of the text field against the current word. If you don't care what kind of capitalization the user types, you can use "toLower()" to change the value of the text box. That way a user typing "OrANge" will still be correct if the array value as "orange"

Code:
if(textField.text && textField.text.toLower() == currentColor){
   // You win!
}else{
   // wrong!
}

This is of course an incredibly rough overview. There are a lot of holes you'll have to fill in yourself. Also, this does not go into any of the more advanced topics of Object Oriented Programming.
__________________
http://www.scriptocalypse.com - It's not the end of the world. It's just Actionscript!

man.mask = mask_mc;
maskedMan is offline   Reply With Quote
Old 01-25-2011, 05:42 PM   #3
Emazizing
Registered User
 
Join Date: Jan 2011
Location: Kirkland Lake, Ontario.
Posts: 3
Post

Hey man, thanks for the tips and code it really helped me get along. I handed the project not completed however because I got stuck trying to make a replay button. However I am going to finish this game for my own sake!! so here is the code so far.

Code:
var colorNames:Array = ["red","blue","green","orange","yellow"];
var buckets:Array = [redBucket,blueBucket,greenBucket,orangeBucket,yellowBucket];
var randomNumber:int = Math.floor(Math.random() * colorNames.length);
var currentColor:String = colorNames[randomNumber];
var cnt:int = 0;

okBut.addEventListener(MouseEvent.MOUSE_DOWN,checkTxt);
againBut.addEventListener(MouseEvent.CLICK,rePlay);

//Bucket Colors
//**********

if (randomNumber == 0)
{
	redBucket.x = 250;
	redBucket.y = 150;
}

if (randomNumber == 1)
{
	blueBucket.x = 250;
	blueBucket.y = 150;
}

if (randomNumber == 2)
{
	greenBucket.x = 250;
	greenBucket.y = 150;
}

if (randomNumber == 3)
{
	orangeBucket.x = 250;
	orangeBucket.y = 150;
}

if (randomNumber == 4)
{
	yellowBucket.x = 250;
	yellowBucket.y = 150;
}

//Check Text Function
//****************
function checkTxt(event: MouseEvent):void
{

	if (textField.text && textField.text.toLowerCase() == currentColor)
	{
		correct.x = 275;
		correct.y = 200;
		redBucket.x = -200;
		redBucket.y = -200;
		blueBucket.x = -200;
		blueBucket.y = -200;
		greenBucket.x = -200;
		greenBucket.y = -200;
		orangeBucket.x = -200;
		orangeBucket.y = -200;
		yellowBucket.x = -200;
		yellowBucket.y = -200;
		textField.x = -200;
		textField.y = -200;
		box.x = -200;
		box.y = -200;
		okBut.x = -200;
		okBut.y = -200;
		againBut.x = 275;
		againBut.y = 315;

	}
	else
	{
		wrong.x = 275;
		wrong.y = 200;
		redBucket.x = -200;
		redBucket.y = -200;
		blueBucket.x = -200;
		blueBucket.y = -200;
		greenBucket.x = -200;
		greenBucket.y = -200;
		orangeBucket.x = -200;
		orangeBucket.y = -200;
		yellowBucket.x = -200;
		yellowBucket.y = -200;
		textField.x = -200;
		textField.y = -200;
		box.x = -200;
		box.y = -200;
		okBut.x = -200;
		okBut.y = -200;
		againBut.x = 275;
		againBut.y = 315;
	}
}

//Replay Button
//***********
function rePlay (event: MouseEvent):void
{
	
	this.gotoAndPlay(1);
}
The code itself I know is very tedious and there are probably easier and more efficient ways of coding this but Im not sure how to do those things. Also I have a suspicion that because all the layers have one frame this is why the replay button does not work.
Emazizing is offline   Reply With Quote
Old 01-25-2011, 06:11 PM   #4
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

You could put all the initialization code in an init() function, which you call both in the body of the frame, and in the rePlay() function
rrh is offline   Reply With Quote
Old 01-29-2011, 05:55 PM   #5
Emazizing
Registered User
 
Join Date: Jan 2011
Location: Kirkland Lake, Ontario.
Posts: 3
Default

Hey rrh, Im trying to figure out a way to make a init() function like you said, could you possibly explain in more detail?
Emazizing is offline   Reply With Quote
Old 01-30-2011, 02:52 PM   #6
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

I mean make a function, you can call it anything, "init" is just an example. Put all the code that sets up your game in there, so you can call it again when you reset.

Oh, and stuff like this you might need to split:
Code:
var colorNames:Array = ["red","blue","green","orange","yellow"]; //this

var colorNames:Array;  //leave this outside the function
colorNames = ["red","blue","green","orange","yellow"];  //put this in the function
Because if you put the "var colorNames:Array;" inside the function, then the variable will only be accessible from inside the function.
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:59 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.