Arrays: Simple tools of the trade. (AS2 & AS3 style)

16 Jul
The following code is in ActionScript 2.
_root.myArr = [1,2,3,4,5];
//This should result in "1,2,3,4,5,6"
//This should result in "1,X,Y,4,5,6"

Simply put, in ActionScript 2, an array can be made
as simply as just creating a name (like "myArr") and
making it equal a bracket of preset values.
However, unlike languages like Java
(arrays... not ArrayLists),
arrays in ActionScript2 and ActionScript3 can "pushed".
This means you can place values at the end of the array.
This is incredibly helpful for situations where you
need to group a set of values together.
Especially values that are created mid-game.
(Think particles which is a future topic)

The following code is for ActionScript 3.

package {
	import flash.display.Sprite;
	public class MainDoc extends Sprite {
		private var myArr:Array = new Array(1,2,3,4,5);
		public function MainDoc() {
			trace("After pushing '6': " + myArr);
			trace("After Shift: " + myArr);
			//shift removes the first value
			trace("After Unshift of 1: " + myArr);
			//by UNshifting a value (this time it happened to be the original first value of '1')
			//you put it at the front of the array.
			trace("Popped: " + myArr.pop());
			//Pop is a method that removes the last value of the array ('6') and returns it.

			//You can find more methods/properties of arrays in the link below!

The link for more array fun. But I'm not quite sure
if all these methods/properties would work in AS2.


Slow week

14 Jul

Sorry people… It’s been a while since I posted something here last, but alas, I tell you that I will post a lot more posts to make up for it.

Ternary whoozawhats?

6 Jul

Are you some sort of code-efficiency freak? Yep… I figured you were. If you don’t know about this already, then it will be a shock when I tell you that you could cut parts of your code in half its line size!!!

var bool:Boolean = false;
if(bool == false){
    trace("bool is definitely false");
} else {
    trace("bool is definitely true");

That’s the if/else simply-read way…
While it may be a little bit easier to comprehend, this saves a little more space if placed in the stead of if/else statements.

var bool:Boolean = false;
trace(bool ? "Bool is clearly true":"Bool is definitely false");

Breaking it down…
3 unnecessary lines cut. While ternary operators may be a little bit more difficult to read, it is quite simple once analyzed.
Let’s just look at how the typical ternary operator is.

The following is the basic template…

condition ? ifConditionIsTrue:ifConditionIsFalse

If it is your first time working with these… please take note of your condition, because Example A has a different output than Example B.

Example A

var iAmReading:Boolean = false;
trace(iAmReading ? "I'm reading right now... please keep quiet":"Sorry, too busy putting this online.");

Example B

var iAmReading:Boolean = true;
trace(iAmReading ? "I'm reading right now... please keep quiet":"Sorry, too busy putting this online.");

A basic tutorial for the ages.

5 Jul

Well, I’ve thought about it and figured that i should make a tutorial talking about how to create basic things in THREE, count em , THREE languages…

1. ActionScript 2
2. ActionScript 3
3. Java

I’ve thought about how I should do this (Should i make the lessons how to make the same thing in all three languages? Or should I make em all whatever is basic in those specific languages (diverse subjects)?
As multi-functional and unnecessary as this swiss army knife… can opener… shoe shiner… doohickey… 😀

Let’s finally post some coding. Java coding.

4 Jul

Odd, isn’t it? You would think that since I am seriously focused on ActionScript 2 or ActionScript 3 that I would post code of AS2/AS3. No, this is Java. Slightly different from AS3, but still similar.

Added how to make a slightly better-than-average first applet for java. Sure, it isn’t swing… but it is a first step in making GUIs. Found it in my old abandoned Java tests folder. Enjoy 😀

//To run this, just right-click it, view it on "appletviewer" (applet viewer)

import java.applet.*;//to be able to declare that it extends Applet.

import java.awt.event.*;//for events! in this case, "KeyEvents" or if you know AS3, it's basically "KeyboardEvents"

import java.awt.*;//awt is for drawing objects and such, but we will really be looking at
//this more and more

//import what you need.
public class MovingSquare extends Applet implements KeyListener{
    //set the initial values
    String message = "";
    int speed = 5;
    int x = 225;
    int y = 225;
    public void init(){
        //init = the initial settings of your project. Just going to set the Background and addKeyListeners
        //for those of you who use AS3 (or other languages as well), this.addKeyListener(this) may seem redundant at first, 
        //but it is saying to add a keyListener to the applet... init()
    public void keyPressed(KeyEvent e){
        //switch(case) is a statement that goes to whatever case is inputted. in this case... e.getKeyCode()
            case KeyEvent.VK_LEFT: x -= speed;
            case KeyEvent.VK_RIGHT: x += speed;
            case KeyEvent.VK_UP: y -= speed;
            case KeyEvent.VK_DOWN: y += speed;
        //move at the rate of speed in whichever direction you choose. Also, repaint() is needed for updating graphics.
    public void keyReleased(KeyEvent e){}
    //if you mention keyPressed, you HAVE TO mention keyReleased and keyTyped...
    public void keyTyped(KeyEvent e){
        char c = e.getKeyChar();
        //getKeyChar = "get key that was inputted on the keyboard"
        if (c == '\b') {
            //if the character inputted was a backspace (known as \b)
            if (message.length() > 0) {
                message = message.substring(0, message.length()-1);
                //if it was a backspace, subtract the last message's character.
        } else {
            message += c;
            //otherwise, just add the character to the end of the message.
        //repaint! See above example.
    public void paint(Graphics g){
        g.drawString(message, 225, 35);
        g.drawString("Type Here:", 160, 35);
        g.fillRect(x, y, 50, 50);
        //draw everything here.

GIMP: A pretty kick-ass art software.

4 Jul

Since this is my blog, there is no reason to lie but in all my previous games (published at least), I never really had a set logo for “omazing games”… so before I published my current project, i decided to make one… but what software should I use?

So I decided to look around to the most popular choices of software. I stumbled across a pretty well-known software (pretty much designed for Linux users but it works perfectly fine on Windows!) called GIMP. It’s amazing, it’s free, and it has an incredibly vast amount of features. For those of you who don’t know what to compare it to, how about the better known “PhotoShop” or “Illustrator”. After you experience a 30-day free trial for each of those 2 previously mentioned, you either can just dump it and forget about it, or you can buy it… not for 100, 200, 300, or even 500. But around 600 for the latest version… at best.

If you were desperately wanting to purchase a legal copy of Illustrator or PhotoShop, eBay usually isn’t your guide (just people who got it for free, sometimes illegally, selling it for a giant profit).

Then you could look at GIMP. Unlike PhotoShop, you could make an image rather than have to doctor a previously created one. And guess what (even though I’ve already said this before…) It’s free.

“Yeah, but usually when something costs cheaper, it lacks in quality.” That may be true in other various instances, but not here… How? Because products like these, the ones designed for the Linux community, is by Linux users, for Linux users. Unlike how Windows OS users (and Mac OS X users especially), these products aren’t necessarily made for a profit, but for a community. Even if it doesn’t match your expectations (despite the fact that I honestly doubt that), here is a link that you should DEFINITELY try:

Hell, it’s better than using whatever “paint” program you are using.

Afterword, here is my logo, that I made with GIMP… in 1 minute.

I liek it

Game in 1 hour (#2)

29 Jun

I won (by default i may add with this game in Gi1H #2):