Archive for March, 2009

Code!

Saturday, March 7th, 2009

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

So, I’ve completed about half a scene of the game so far and I thought it’d be interesting to show just how much coding that takes:


Mouse.hide();
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = “noScale”;

import flash.ui.Mouse;
import fl.transitions.*;
import fl.transitions.easing.*;

var fade_in:Object = new Object();
fade_in.type = Fade;
fade_in.direction = Transition.IN;
fade_in.duration = .5;
var fade_out:Object = new Object();
fade_out.type = Fade;
fade_out.direction = Transition.OUT;
fade_out.duration = .5;
var forest_background:background_forest = new background_forest();

var default_cursor:cursor_default = new cursor_default();
default_cursor.visible = false;
var over_cursor:cursor_over = new cursor_over();
over_cursor.visible = false;
var owl_shadow:scene_object_owl = new scene_object_owl();
var owl:character_owl = new character_owl();


addChild(owl_shadow);
owl_shadow.name = “owl_shadow”;
owl_shadow.x = 115;
owl_shadow.y = 233;
owl_shadow.addEventListener(MouseEvent.CLICK, owl_shadow_clicked);

function cursor()
{
addChild(default_cursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, cursor_move_handler);
stage.addEventListener(Event.MOUSE_LEAVE, cursor_leave_handler);
}

function cursor_move_handler(evt:MouseEvent):void
{
default_cursor.x = evt.stageX + 1;
default_cursor.y = evt.stageY + 1;
default_cursor.visible = true;
}

function cursor_leave_handler(evt:Event):void
{
default_cursor.visible = false;
}

cursor();

function cursorOver()
{
addChild(over_cursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, over_move_handler);
stage.addEventListener(Event.MOUSE_LEAVE, over_leave_handler);
}

function over_move_handler(evt:MouseEvent):void
{
over_cursor.x = evt.stageX + 1;
over_cursor.y = evt.stageY + 1;
over_cursor.visible = true;
}


function over_leave_handler(evt:Event):void
{
over_cursor.visible = false;
}

owl_shadow.addEventListener(MouseEvent.MOUSE_OVER, over_over_handler);

function over_over_handler (evt:Event):void
{
cursorOver();
removeChild(default_cursor);
}


owl_shadow.addEventListener(MouseEvent.MOUSE_OUT, over_out_handler);

function over_out_handler (evt:Event):void
{
cursor();
removeChild(over_cursor);
}


function owl_shadow_clicked(e:MouseEvent):void
{
TransitionManager.start(owl_shadow, fade_out);
addChildAt(owl, 1);
owl.x = 500;
owl.y = 450;
TransitionManager.start(owl, fade_in);
}


stop();

Now I’m by no means a programmer - I understand what each line of code does here and it’s all working nicely, but I lack the fundamental programming knowledge to talk about it, so I’ll just list what that big chunk of code does:

  • Removes the default cursor and replaces it with my own, as well as changes it when the player mouses over a “hotspot”.
  • Makes the game full-screen on your monitor.
  • Makes the first scene appear at the start of the game.
  • Adds a clickable object to the scene and determines where it is.
  • When object is clicked, a character fades into the middle of the screen.

If you’re good at programming, feel free to point out my n00bish methods :P