How can I get this hittest to work -
i'm creating game player holding baseball bat , when click button swing bat. when swing bat hit enemy enemy goes flying off in opposite direction of hit them golf ball. have done moving , attacking function working how can register hittest hits enemy when facing towards , enemy going back. done far:
package { import flash.display.movieclip; import flash.events.event; import flash.events.keyboardevent; import flash.events.mouseevent; import flash.ui.keyboard; public class player extends movieclip { var walkspeed:number = 4; var walkright:boolean = false; var walkleft:boolean = false; var walkup:boolean = false; var walkdown:boolean = false; var attacking:boolean = false; public function player() { stage.addeventlistener(keyboardevent.key_down , walk); addeventlistener(event.enter_frame, update); stage.addeventlistener(keyboardevent.key_up, stopwalk); stage.addeventlistener(mouseevent.click, attack); } function walk(event:keyboardevent) { if (event.keycode == 68) { walkright = true; } if (event.keycode == 87) { walkup = true; } if (event.keycode == 65) { walkleft = true; } if (event.keycode == 83) { walkdown = true; } } function update(event:event) { if (attacking == true) { walkright = false; walkleft = false; walkup = false; walkdown = false; } else if (attacking == false) { var dx = parent.mousex - x; var dy = parent.mousey - y; var angle = math.atan2(dy,dx) / math.pi * 180; rotation = angle; if (walkright == true) { x += walkspeed; gotoandstop('walk'); } if (walkup == true) { y -= walkspeed; gotoandstop('walk'); } if (walkleft == true) { x -= walkspeed; gotoandstop('walk'); } if (walkdown == true) { y += walkspeed; gotoandstop('walk'); } } } function stopwalk(event:keyboardevent) { if (attacking == false) { if (event.keycode == 68) { event.keycode = 0; walkright = false; gotoandstop('stance'); } if (event.keycode == 87) { event.keycode = 0; walkup = false; gotoandstop('stance'); } if (event.keycode == 65) { event.keycode = 0; walkleft = false; gotoandstop('stance'); } if (event.keycode == 83) { event.keycode = 0; walkdown = false; gotoandstop('stance'); } } } function attack(event:mouseevent) { if (attacking == false) { attacking = true; gotoandstop('attack'); } } } }
when character's direction changes, change variable depending on way facing, example; direction = 0 when facing down, 1 when facing right, etc. use , enemy's position work out whether or not enemy has been hit. making enemy fly back, character's direction work out way fly back. give example code explain, i'm on tablet.
Comments
Post a Comment