I have swish max , I make 1 circle that move with keypress , but I want to keep circle and player in one place , so I need wall to block moving out of there. how can I program a wall?
i would make a wall class. the job of this class is to simply exist. onEnterFrame, the circle should run a collision test with a list of walls. if it hits, have the circle bounce back a few pixels.
AS2 (idk AS3)
class wall extends MovieClip { function onLoad() { _root.circle.walls.conact(this) } }
class circleThing extends MovieClip var walls //list of walls var xvel //x axis velocity var yvel //y axis velocity function onLoad() { walls=[] xvel=0 yvel=0 } function onEnterFrame() { if(key.isDown(key.UP)) { this.yvel=15 } if(key.isDown(key.down)) { this.yvel=-15 } if(key.isDown(key.LEFT)) { this.xvel=-15 } if(key.isDown(key.RIGHT)) { this.xvel=15 } for(var i in walls) { if(this.hitTest(walls)) { //some commands that bounce you back. to lazy to do it [i]all for you } } this._x=+xvel this._y=+yvel }