andythepandy
12-12-2007, 06:54 PM
hi there,
i need help with this very basic game i'm making.
i have code to determine which way to fire a bullet considering which side of the player the mouse is. But when i fire a bullet it goes in the correct direction but when i move the mouse over to the other side of the player, the bullet changes direction in the air!
this is my code:
level = new Array()
yspeed = 0
xspeed = 0
max_speed = 16
walk_speed = 4
gravity = 1
ball_speed = 7
can_jump = false
jumping = false
jump_power = 10
ball_released = false
_root.createEmptyMovieClip("lev",_root.getNextHighestDepth())
level[0] = new Array(1,1,1,1,1,1,1,1)
level[1] = new Array(1,0,0,0,0,0,1,1)
level[2] = new Array(1,0,1,1,1,0,0,1)
level[3] = new Array(1,0,0,0,0,0,0,1)
level[4] = new Array(1,0,0,0,0,1,0,1)
level[5] = new Array(1,0,1,1,1,0,0,1)
level[6] = new Array(1,0,0,0,0,0,1,1)
level[7] = new Array(1,1,1,1,0,0,0,1)
level[8] = new Array(1,0,0,0,0,1,1,1)
level[9] = new Array(1,0,1,0,0,0,0,1)
level[10] = new Array(1,1,1,1,0,0,0,1)
level[11] = new Array(1,0,0,0,0,0,0,1)
level[12] = new Array(1,1,1,1,1,1,1,1)
for(y = 0;y<=12;y++){
for(x = 0;x<=7;x++){
if(level[y][x] !=0){
place_brick = lev.attachMovie("block","block_"+lev.getNextHighestDepth(),lev.getNextHighestDepth (),{_x:x*20+10,_y:y*20+10})
place_brick.gotoAndStop(level[y][x])
}
}
}
_root.attachMovie("player","player",_root.getNextHighestDepth(),{_x:30,_y:40})
player.onEnterFrame = function(){
yspeed+=gravity
if(yspeed>max_speed){
yspeed = 16
}
if(Key.isDown(Key.LEFT)){
xspeed = -walk_speed
}
if(Key.isDown(Key.RIGHT)){
xspeed = walk_speed
}
if(Key.isDown(Key.UP)and can_jump){
yspeed-=jump_power
can_jump = false
}
while(_root.lev.hitTest(this._x,this._y+this._heig ht/2-0.1+yspeed,true)){
yspeed--
can_jump = true
}
while(_root.lev.hitTest(this._x-this._width/2+3+xspeed,this._y,true)){
xspeed++
}
while (_root.lev.hitTest(this._x+this._width/2+3+xspeed, this._y, true)) {
xspeed--;
}
while(_root.lev.hitTest(this._x,this._y-this._height/2+2+yspeed,true)){
yspeed++
}
this._y+=yspeed
this._x+=xspeed
xspeed = 0
}
function onMouseDown(){
xpos = player._x
ypos = player._y
cannonball_fired = attachMovie("cannonball","cannonball_"+_root.getNextHighestDepth(),_root.getNextHighestD epth(),{_x:xpos,_y:ypos})
cannonball_fired.onEnterFrame = function(){
if(_xmouse>player._x){
this._x+=ball_speed
ball_released = true
}
if(_xmouse<player._x){
this._x-=ball_speed
ball_released = true
}
if(_root.lev.hitTest(this._x,this._y,true)){
this.removeMovieClip()
ball_released = false
}
if(ball_released == true){
this._x+=10
}
}
}
i need some code to determine wether the bullet had been released and if it is true, make moving the mouse have no effect on it.
thanks for any help,
Andy
i need help with this very basic game i'm making.
i have code to determine which way to fire a bullet considering which side of the player the mouse is. But when i fire a bullet it goes in the correct direction but when i move the mouse over to the other side of the player, the bullet changes direction in the air!
this is my code:
level = new Array()
yspeed = 0
xspeed = 0
max_speed = 16
walk_speed = 4
gravity = 1
ball_speed = 7
can_jump = false
jumping = false
jump_power = 10
ball_released = false
_root.createEmptyMovieClip("lev",_root.getNextHighestDepth())
level[0] = new Array(1,1,1,1,1,1,1,1)
level[1] = new Array(1,0,0,0,0,0,1,1)
level[2] = new Array(1,0,1,1,1,0,0,1)
level[3] = new Array(1,0,0,0,0,0,0,1)
level[4] = new Array(1,0,0,0,0,1,0,1)
level[5] = new Array(1,0,1,1,1,0,0,1)
level[6] = new Array(1,0,0,0,0,0,1,1)
level[7] = new Array(1,1,1,1,0,0,0,1)
level[8] = new Array(1,0,0,0,0,1,1,1)
level[9] = new Array(1,0,1,0,0,0,0,1)
level[10] = new Array(1,1,1,1,0,0,0,1)
level[11] = new Array(1,0,0,0,0,0,0,1)
level[12] = new Array(1,1,1,1,1,1,1,1)
for(y = 0;y<=12;y++){
for(x = 0;x<=7;x++){
if(level[y][x] !=0){
place_brick = lev.attachMovie("block","block_"+lev.getNextHighestDepth(),lev.getNextHighestDepth (),{_x:x*20+10,_y:y*20+10})
place_brick.gotoAndStop(level[y][x])
}
}
}
_root.attachMovie("player","player",_root.getNextHighestDepth(),{_x:30,_y:40})
player.onEnterFrame = function(){
yspeed+=gravity
if(yspeed>max_speed){
yspeed = 16
}
if(Key.isDown(Key.LEFT)){
xspeed = -walk_speed
}
if(Key.isDown(Key.RIGHT)){
xspeed = walk_speed
}
if(Key.isDown(Key.UP)and can_jump){
yspeed-=jump_power
can_jump = false
}
while(_root.lev.hitTest(this._x,this._y+this._heig ht/2-0.1+yspeed,true)){
yspeed--
can_jump = true
}
while(_root.lev.hitTest(this._x-this._width/2+3+xspeed,this._y,true)){
xspeed++
}
while (_root.lev.hitTest(this._x+this._width/2+3+xspeed, this._y, true)) {
xspeed--;
}
while(_root.lev.hitTest(this._x,this._y-this._height/2+2+yspeed,true)){
yspeed++
}
this._y+=yspeed
this._x+=xspeed
xspeed = 0
}
function onMouseDown(){
xpos = player._x
ypos = player._y
cannonball_fired = attachMovie("cannonball","cannonball_"+_root.getNextHighestDepth(),_root.getNextHighestD epth(),{_x:xpos,_y:ypos})
cannonball_fired.onEnterFrame = function(){
if(_xmouse>player._x){
this._x+=ball_speed
ball_released = true
}
if(_xmouse<player._x){
this._x-=ball_speed
ball_released = true
}
if(_root.lev.hitTest(this._x,this._y,true)){
this.removeMovieClip()
ball_released = false
}
if(ball_released == true){
this._x+=10
}
}
}
i need some code to determine wether the bullet had been released and if it is true, make moving the mouse have no effect on it.
thanks for any help,
Andy