eclipse - Java Game Development: Weird Movement bug -
i've been following these tutorials on how make top down shooter in java foreign guy mike on youtube, in eclipse.
but ran weird bug player move diagnally when not shooting, when player shoots, can't move north , west at same time, looked little deeper couldn't find anything.
here player movement code:
if(left) { dx = (0 - speed); } if(right) { dx = speed; } if(down) { dy = speed; } if(up) { dy = (0 - speed); } x += dx; y += dy; if(x < r) x = r; if(y < r) y = r; if(x > gamepanel.width - r) x = gamepanel.width - r; if(y > gamepanel.width - r) y = gamepanel.width - r; dx = 0; dy = 0; if(firing) { long elapsed = (system.nanotime() - firingtimer) / 1000000; if(elapsed > firingdelay) { gamepanel.bullets.add(new bullet(270, x, y)); firingtimer = system.nanotime(); } }
and here entire bullet class:
package games.duphus.wave; import java.awt.*; public class bullet { private double x; private double y; private int r; private double dx; private double dy; private double rad; private int speed= 10; private color color1; public bullet(double angle, int x, int y) { this.x = x; this.y = y; r = 2; rad = math.toradians(angle); dx = math.cos(rad) * speed; dy = math.sin(rad) * speed; color1 = color.yellow; } public boolean update() { x += dx; y += dy; if(x < -r || x > gamepanel.width + r || y < -r || y > gamepanel.height + r) { return true; } return false; } public void draw(graphics2d g) { g.setcolor(color1); g.filloval((int) (x - r), (int) (y - r), 2 * r, 2 * r); } }
any , appreciated.
i didn't @ code much, think have keyboard ghosting issue. can't tell how fix except change keys use firing , moving.
Comments
Post a Comment