So I am still having issues with getting this code to work with WCK. I am going to go into as much detail with this issue as I can because I desperately need help. So I took parts of the code that I used from above and pasted them into my own .as file called Golf.as.
I basically combined the boxman.as file and the tutorial file above. then removed the Boxman keyboard controls and replaced them with the mouse events from the tutorial.
I did "public class Golf extends Circle{" because I want my hero to function like a ball.
So here is what I do.
I have Golf.as saved in the demo folder.
In the Library I right click my "ball" movie clip go to properties and set the Class to demo.Golf. (For some reason I can't just type Golf in the base class. I need to have it be demo.Golf so it can find it. If you look at Boxman in the demo flash file it just has BoxMan and it finds the .as file in the demo folder. So that might be part of the problem but i can't figure out why.)
Then I go to Component Definitions and set the class to wck.BodyShape.
When I publish it the ball just sits there and doesn't move at all.
Also I get this error
C:\Users\Chad\Documents\Design Documents\Game\jesses-wck-2b31de3\demo\Golf.as, Line 1 5001: The name of package '' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. C:\Users\Chad\Documents\Design Documents\Game\jesses-wck-2b31de3\demo\Golf.as
Here is the code I modified with the tutorial and the boxman.as file. I am totally lost and need some help. please if there is any Box2D guru's out there that could take a look at this I would be forever grateful.
Here is the code I modified with the tutorial and the boxman.as file.
Code:
package {
import Box2D.Dynamics.b2World;
import Box2DAS.*;
import Box2DAS.Collision.*;
import Box2DAS.Collision.Shapes.*;
import Box2DAS.Common.*;
import Box2DAS.Dynamics.*;
import Box2DAS.Dynamics.Contacts.*;
import Box2DAS.Dynamics.Joints.*;
import cmodule.Box2D.*;
import wck.*;
import shapes.*;
import misc.*;
import extras.*;
import flash.utils.*;
import flash.events.*;
import flash.display.*;
import flash.text.*;
import flash.geom.*;
public class Golf extends Circle{
public var m_world:b2World;
public var m_iterations:int=10;
public var m_timeStep:Number=1.0/30.0;
public var the_arrow:Sprite = new Sprite();
public var the_arrow_angle:Number;
public var my_canvas:Sprite = new Sprite();
public var deg_to_rad:Number=0.0174532925;
public var rad_to_deg:Number=57.2957795;
public var charging:Boolean=false;
public var power:int=0;
public var impulse:Boolean=false;
public var contacts:ContactList;
public override function create():void {
reportBeginContact = true;
reportEndContact = true;
fixedRotation = true;
super.create();
listenWhileVisible(world, StepEvent.STEP, parseInput, false, 10);
listenWhileVisible(this, ContactEvent.BEGIN_CONTACT, handleContact);
contacts = new ContactList();
contacts.listenTo(this);
}
public function handleContact(e:ContactEvent):void {
var p:Pellet = e.other.m_userData as Pellet;
if(p) {
Util.addChildAtPosOf(world, new FX1(), p);
p.remove();
}
}
public function Update(e:Event):void {
m_world.Step(m_timeStep, m_iterations);
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) {
if (bb.GetUserData()!=null) {
the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30;
the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30;
var dist_x=the_arrow.x-mouseX;
var dist_y=the_arrow.y-mouseY;
the_arrow_angle=Math.atan2(- dist_y,- dist_x);
the_arrow.rotation=the_arrow_angle*rad_to_deg;
if (charging) {
power++;
if (power>=120) {
power-=120;
}
my_canvas.graphics.clear();
my_canvas.graphics.lineStyle(3,0x000000,0.5);
draw_arc(my_canvas,the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30,the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30,20,270,270+power*3,1);
}
if (impulse) {
bb.ApplyImpulse(new b2Vec2(Math.cos(the_arrow_angle)*power/4, Math.sin(the_arrow_angle)*power/4),bb.GetWorldCenter());
impulse=false;
power=0;
}
}
}
}
public function charge(e:MouseEvent):void {
charging=true;
}
public function shoot(e:MouseEvent):void {
charging=false;
my_canvas.graphics.clear();
impulse=true;
}
public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision):void {
var angle_diff=angle_to-angle_from;
var steps=Math.round(angle_diff*precision);
var angle=angle_from;
var px=center_x+radius*Math.cos(angle*deg_to_rad);
var py=center_y+radius*Math.sin(angle*deg_to_rad);
movieclip.graphics.moveTo(px,py);
for (var i:int=1; i<=steps; i++) {
angle=angle_from+angle_diff/steps*i;
movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
}
}
}
}