Quantcast
Destructoid - angusm's Community Blog




About Me
Bullet Points 'Bout Me:
-Computer Science student
-Love games
-Play them
-Wanna make them
-Own Wii
-Own PC
-Own DS
-Mostly play PC
-Am a Nerd
-Am a Jock
-Like Cross Country
-Like Rugby
-Like Wrestling
-Canadian
-Likes brevity
-Likes bullet points


If'n you wanna talk, angusamacdonald@hotmail.com, let's talk
Gamer Profile
3DS friend code:
Steam:
Battle:
PSN:
Mii:
Gamertag:
Following (7)
Atlas
BoXDoS
CaffeinePowered
Coonskin05
DtoidLosAngeles
FAILCAST
Neonie
Dtoid Game: First Coded Class
angusm | 3:47 PM on 02.28.2008 22 comments


For you coders out there, actionscript class of the triangles that the player will be able to build on.

If you DON'T GIVE A FUCK, check out the Concept Sketches and Ideas instead.


package{
class GridTriangle{

var accelX:int; //How much creeps are accelerated along the x axis when they stand on the triangle.
var accelY:int; //Same as above but for y axis.
var buildCost:Number //How much the cost of a tower is multiplied by when it is built on this triangle.
var threePoints:Array; //Keeps track of the location of each point of the triangle.
var color:Color; //Keeps track of the color that the triangle will be drawn.
var buildable:Boolean; //Keeps track of whether or not you can build on this triangle.
var tower:Tower; //Keeps track of the tower built on this triangle.

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int){

threePoints[1] = new Point(x1,y1); //Creates the three points with info from the constructor
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = 0; //Accelerations are 0 by default
accelY = 0;
buildCost = 1; //Buildcost is 1 by default, implying 0 percent change in the cost to build on the triangle
color = new Color(0,0,0,1,0,0,0,0); //Color should be black by default4
buildable = true; //Can build on the triangle by default


}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, aX:int, aY:int){

threePoints[1] = new Point(x1,y1); //Creates a triangle with acceleration from the constructor
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = aX;
accelY = aY;
buildCost = 1;
color = new Color(0,0,0,1,0,0,0,0);
buildable = true;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, aX:int, aY:int, bCost:Number){

threePoints[1] = new Point(x1,y1); //Creates a triangle with acceleration and build cost from the constructor
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = aX;
accelY = aY;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(bCost != 1){ //Changes the color of the lines to reflect the build cost.
if(bCost > 1){ //If the build cost will increase the lines get a red tint.
if(bCost <= 3){ //Build cost should never be more than 3 times the original
color.redOffset = bCost * 85; //The red value = the build cost modifier multiplied by 85.
}else{ //In the rare event that the build cost modifier is greater
color.redOffset = 255; //than three, the red value is set to 255.
}
}else{ //If the cost is going to be cheaper than normal the color
if(bCost >= 0){ //gains a green tint.
color.greenOffset = (1 - bCost) * 255; //The cost should never be less than 0, implying 0% of the
}else{ //original cost. Color changing technique is similar to red
color.greenOffset = 255; //and should be self explanitory.
}
}
}
buildable = true;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, aX:int, aY:int, bCost:Number, canBuild:Boolean ){

threePoints[1] = new Point(x1,y1);
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = aX;
accelY = aY;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(canBuild){ //Same as above, but buildability is taken from
if(bCost != 1){ //the constructor. The line color will be set to
if(bCost > 1){ //gray if the player will be unable to build on the
if(bCost <= 3){ //tile.
color.redOffset = bCost * 85;
}else{
color.redOffset = 255;
}
}else{
if(bCost >= 0){
color.greenOffset = (1 - bCost) * 255;
}else{
color.greenOffset = 255;
}
}
}
}else{
color.greenOffset = 140;
color.redOffset = 140;
color.blueOffset = 140;
}
buildable = canBuild;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, aX:int, aY:int, canBuild:Boolean ){

threePoints[1] = new Point(x1,y1); //Creates triangle with acceleration and buildability from constructor.
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = aX;
accelY = aY;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(bCost != 1){
if(bCost > 1){
if(bCost <= 3){
color.redOffset = bCost * 85;
}else{
color.redOffset = 255;
}
}else{
if(bCost >= 0){
color.greenOffset = (1 - bCost) * 255;
}else{
color.greenOffset = 255;
}
}
}
buildable = canBuild;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, canBuild:Boolean ){

threePoints[1] = new Point(x1,y1); //Creates a constructor with buildability from the constructor.
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = 0;
accelY = 0;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(bCost != 1){
if(bCost > 1){
if(bCost <= 3){
color.redOffset = bCost * 85;
}else{
color.redOffset = 255;
}
}else{
if(bCost >= 0){
color.greenOffset = (1 - bCost) * 255;
}else{
color.greenOffset = 255;
}
}
}
buildable = canBuild;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, bCost:Number){

threePoints[1] = new Point(x1,y1); //Creates a triangle with cost modifier from the constructor.
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = 0;
accelY = 0;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(canBuild){
if(bCost != 1){
if(bCost > 1){
if(bCost <= 3){
color.redOffset = bCost * 85;
}else{
color.redOffset = 255;
}
}else{
if(bCost >= 0){
color.greenOffset = (1 - bCost) * 255;
}else{
color.greenOffset = 255;
}
}
}
}else{
color.greenOffset = 140;
color.redOffset = 140;
color.blueOffset = 140;
}
buildable = true;

}

function gridTriangle(x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, bCost:Number, canBuild:Boolean ){

threePoints[1] = new Point(x1,y1); //Creates a triangle with cost modifier and buildability from the constructor.
threePoints[2] = new Point(x2,y2);
threePoints[3] = new Point(x3,y3);
accelX = 0;
accelY = 0;
buildCost = bCost;
color = new Color(0,0,0,1,0,0,0,0);
if(canBuild){
if(bCost != 1){
if(bCost > 1){
if(bCost <= 3){
color.redOffset = bCost * 85;
}else{
color.redOffset = 255;
}
}else{
if(bCost >= 0){
color.greenOffset = (1 - bCost) * 255;
}else{
color.greenOffset = 255;
}
}
}
}else{
color.greenOffset = 140;
color.redOffset = 140;
color.blueOffset = 140;
}
buildable = canBuild;

}

}
}



Is this post awesome? Vote it up!

0



Post a comment! You can also post a photo below:

Comment with Facebook





Click connect and comment instantly!

Comment with Dtoid





New? SIGN UP - it takes 5 seconds

21 comments | showing # 1 to 21
prev next

liam2015's Avatar - Comment posted on 02/28/2008 15:57
liam2015
I like what I see...
wardrox's Avatar - Comment posted on 02/28/2008 16:00
wardrox
I tab for fun :-P

Got a wiki?
Neonie's Avatar - Comment posted on 02/28/2008 16:04
Neonie
I'll be hounest: I don't understand any of that. But it's always good to see progress.
007's Avatar - Comment posted on 02/28/2008 16:06
007
All hail angusm, writer of codes. Coder of classes.
king3vbo's Avatar - Comment posted on 02/28/2008 16:07
king3vbo
It frightens me that I can read this
mix's Avatar - Comment posted on 02/28/2008 16:11
mix
I'm with Neonie on this "topic"
angusm's Avatar - Comment posted on 02/28/2008 16:14
angusm
@Wardrox

I swear it's all tabbed with nice whitespacing in the actual file, but, when I pasted it into a blog post it got all fucked up :S.
Anthony Burch's Avatar - Comment posted on 02/28/2008 16:15
Anthony Burch
So, what, uh, language is this in? I'm trying to maybe possibly look into learning C# or something. Is that, uh, what this is?
Rockvillian's Avatar - Comment posted on 02/28/2008 16:17
Rockvillian
Nice. So I doubt you'll be using private vars? lol
angusm's Avatar - Comment posted on 02/28/2008 16:26
angusm
@RockVillian
Thanks for pointing out my horrible habits of forgetting that shit. Will fix.

@Reverend Anthony
It's ActionScript, Flash's programming language. It's very similar to Java, which I hear, is uh, similar to C...
Tino's Avatar - Comment posted on 02/28/2008 16:30
Tino
Needs more GOTO
Eschatos's Avatar - Comment posted on 02/28/2008 16:34
Eschatos
We need moar code! And it makes me sad that I only know Java and HTML.
blehman's Avatar - Comment posted on 02/28/2008 16:36
blehman
Is it "bewbs"?
NsOmNiA91130's Avatar - Comment posted on 02/28/2008 16:57
NsOmNiA91130
@angsum

AHAAHHAHAHHAHAHAH.

No.
The GHost's Avatar - Comment posted on 02/28/2008 17:40
The GHost
Very cool, keep up the good work man.

@Blehman
It basically says bewbtastic, or possibly bewbtacular.
Tragic Hero's Avatar - Comment posted on 02/28/2008 18:13
Tragic Hero
I love code, although I am not very fluent in ActionScript I can make out some of it and I like it.

Keep up the good work.
PraiseChaos's Avatar - Comment posted on 02/28/2008 19:04
PraiseChaos
Are you posting the code in hopes other coders will want to contribute code, or just posting code to be posting code?
ShawnKelfonne's Avatar - Comment posted on 02/28/2008 21:44
ShawnKelfonne
Well, I understand the reason for overloading a function, but it just seems to me like a lot of duplicate code there.

Still, good to see that you've actually started work on it.
insomnia's Avatar - Comment posted on 02/29/2008 05:36
insomnia
Needs more indentation... For the rest, good idea...
boatorious's Avatar - Comment posted on 02/29/2008 05:51
boatorious
More code than I've ever written for a game :) I've never seen actionscript before either.

Some quick comments that you may take or leave :
1. The important thing is to be writing code (so don't worry too much about what I'm going to tell you)

2. I'm not sure if you can overload constructors in actionscript, but if so you should make one giant constructor that all your other constructors feed into. This is more of a maintenance issue (if you add or remove a single attribute you'll end up changing a ton of code)

3. variable names : you have a variable called "buildcostnumber" but the description is of a multiplier for build cost. I'd suggest renaming it to avoid confusion.
bcost loop seems weird.

4. You don't set any color if the bcost value is 1. Then you set different color schemes for 1. Bcost 2 or 3, 2. Bcost >= 3, 3. bcost 0, 4. bcost < 0. Did you mean to miss bcost 1? And the code is a little weird too, it took me a few minutes to figure out what was going on (again, a maintenance issue for you if you come back to the code and need to figure out what it was doing).

5. again, don't get too hung up on what I'm telling you -- the most important thing is to keep writing
braulio09's Avatar - Comment posted on 03/02/2008 22:41
braulio09
wow...this code is similar to the Karel the Robot crap I've been seing for the last couple of months. basic programming will still be useful....who would've thought

i sure hope you can finish this one and have it be good before the deadline. good luck!
prev next

Comment with Facebook





Click connect and comment instantly!

Comment with Dtoid





New? SIGN UP - it takes 5 seconds

Comments policy

Destructoid is an open discussion community. You don't need to "audition" to post a comment - just speak your mind. We respect differing opinions on the site, so have at it. Be smart, funny, insightful, clueless, or cute -- but back it up with substance. Keep your cool, keep it fun. We only ask that you act respectfully and above all: don't be a troll and ruin it for everyone else. Don't bring down gamers or we'll, you know, gently shoot you in the face and stuff you into a flaming mailbox. Each comment is your opportuntity to make this community awesomer. Is that even a word?

Avoiding the banhammer only requires common sense: spamming, trolling, racism, NSFW stuff, and other forms of sucking will not be tolerated. If anyone is griefing please report abuse. Be good. Don't suck!