Skip to content
Alex Huynh edited this page Sep 1, 2015 · 11 revisions

Programming

Contents


How do I ____?

...output to the console?

  • Use trace("Game over! You died " + deaths + " time(s)! What a loser!");

...move something or change the graphics?

  • Every class that extends ABST_Prop will have a public MovieClip object called mc_object.
  • To translate, change mc_object.x and mc_object.y. (0,0) is the middle of the screen. -x is left, -y is up. The game is 800x600 pixels in size.
  • To affect velocity, change dx and dy (don't use mc_object).
  • To rotate, change mc_object.rotation to a value in degrees from 0 (right) to 360.
  • To scale, change mc_object.scaleX and mc_object.scaleY. A value of -1 reflects the image.
  • To affect transparency, change mc_object.alpha to a value in [0, 1].
  • To hide without destroying, set mc_object.visible to false.

...do stuff with the Player?

  • When in a ABST_Obstacle, use cg.player.
  • When in ContainerGame, just use player.
  • To get the Player position, use new Point(player.mc_object.x, player.mc_object.y). If trying to do a collision check, add 400 to player.mc_object.x and 300 to player.mc_object.y.
  • To check if alive, use player.alive, a public Boolean.
  • To kill, call player.kill().

...detect collisions?

  • Remember that you must use mc_object to get the MovieClip associated with a class. Don't use just the class itself; it won't work!
  • For a 'simple and fast' bounding box check between 2 MovieClip, use movieClipA.hitTestObject(movieClipB).
  • For a 'precise but slow' pixel-perfect check between a MovieClip and a Point, use movieClipA.hitTestPoint(pointB.x, pointB.y, true).
  • To make a Point with the location of a MovieClip such as mc_object, use new Point(mc_object.x, mc_object.y).

...do stuff with slowing down time?

  • To access the current time scale, use TimeScale.s_scale, a public static Number that is normally 1. Multiply it with stuff, such as dX.

FAQ's

What is a MovieClip?

  • A MovieClip is essentially the graphic that's being displayed. It has built-in features such as x, y, and rotation.

How do I fix "Type was not found or was not a compile-time constant"?

  • Try importing the thing it can't find. Go to the top immediately after the first { and type import and then the name of the thing you're trying to use. FlashDevelop should auto-complete it.

Why is x, y, rotation, etc. not defined?

  • You need to use mc_object to get these variables. Many are listed below.
  • x, y, rotation, scaleX, scaleY, alpha

Class Summaries

ABST_Prop

An abstract class containing useful functions for all game objects.

It is updated every frame (30/sec) by calling step(), and the object is removed if completed is set to true. The actual MovieClip graphic object associated with this ABST_Prop is mc_object.

Player extends ABST_Prop

The class that handles the player, including listening for W A S D Shift keyboard presses.

ABST_Obstacle extends ABST_Prop

An abstract class implementing the core functionalities for an obstacle.

It is given a JSON object in its constructor (_params) that it will use with setParam() to set itself up. It is managed by ObstacleManager and queued up to be spawned in ObstacleTimeline.

ObstacleManager

Updates all of the game's ABST_Obstacle objects. Uses ObstacleTimeline to figure out what obstacles to spawn, and when to spawn them.

For some reason, also checks if the Player has collided with a deadly obstacle. Why is that? We should move that to ABST_Obstacle...

ObstacleTimeline

Keeps track of the obstacles to be spawned in a level.

Engine

Keeps track of high-level game state (such as menu or game), and provides the primary step firer based on Event.ENTER_FRAME.

ContainerGame

Manages the higher-level game elements, such as Player and ObstacleManager.