Language…
3 users online: ClaireChan, Firstnamebutt, tOaO - Guests: 99 - Bots: 385
Users: 64,795 (2,381 active)
Latest user: mathew

ActionScript 2.0!

Woo hoo! In my offtime *coughschoolcough* I've been programing a simple game in flash!

Heres my code: (I didn't use the code tag becuase it'd butcher it. D:) (Disabled layout too)

------------//Code\\------------

init();

function init(){
//initialize
//all moving objects must have xspeed and yspeed
char.xspeed = 3;
char.yspeed = 3;
enemy.xspeed = 2;
enemy.yspeed = 2;
}//end init

char.onEnterFrame = function(){
checkKeys(this);
checkBounds(this);
}//end enterFrame

enemy.onEnterFrame = function(){
moveOb(this, 0, -1);
checkBounds(this);
}//end enterFrame

function checkKeys(player){
//check for input and call moveOb function
if(Key.isDown(Key.UP)){
moveOb(player, 0, -1);
}//end if
if(Key.isDown(Key.DOWN)){
moveOb(player, 0, 1);
}//end if
if(Key.isDown(Key.RIGHT)){
moveOb(player, 1, 0);
}//end if
if(Key.isDown(Key.LEFT)){
moveOb(player, -1, 0);
}//end if
}//end checkKeys

function checkBounds(object){
//if object is off stage wrap to opposite side
if(object._x < 0 - object._width / 2){
object._x = Stage.width + object._width / 2;
}//end if
if(object._x > Stage.width + object._width / 2){
object._x = 0 - object._width / 2;
}//end if
if(object._y < 0 - object._height / 2){
object._y = Stage.height + object._height / 2;
}//end if
if(object._y > Stage.width + object._height / 2){
object._y = 0 - object._height / 2;
}//end if
}//end checkBounds

function moveOb(object, xdir, ydir){
//xdir: if -1 moves left, if 1 moves right, if 0 dosen't move horizontally
//ydir: if -1 moves up, if 1 moves down, if 0 dosen't move vertically
object._x += object.xspeed * xdir;
object._y += object.yspeed * ydir;
}//end move

--------//End Code\\--------

Theres nothing wrong with it, but does anyone know a good way of cacluating when objects are touching? hitTest() is slow and ineffective. :/

This code is also open source to anyone who wants it. Just stick two Movie Clips on the stage, on with the instance name "char", and another with the instance name "enemy" No quotes.

Please note nothing will happen if you hit the enemy.

Kudos to anyone who understands it, and if you want me to dissect it I will.
Hmm check the x and y pos? Im guessing it would work, but I dont know actionscript. Dont have that Macromedia Flash thingy.
Eh, I'm just gunna go with hitTest(). >_<