2d

Java Smooth 2D Rectangle collision?

寵の児 提交于 2019-12-11 12:03:23
问题 Hey guys i'm making a maze game and I'm trying to figure out how to make a 2D collision smooth. Currently I have some really bad collision code that I thought up since I haven't done this part yet and it is glitchy and sometimes goes inside the wall then you can't get out. My code: public void checkCollision() { Rectangle player_rectangle = new Rectangle(player.getX(),player.getY(),32,32); for(Wall wall : walls) { Rectangle wall_rectangle = new Rectangle(wall.getX(), wall.getY(), 32,32); if

How to draw a butterfly curve as accurate as possible?

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:57:31
问题 I am trying to draw a butterfly curve using Java . Here's the parametric equation for the mentioned curve: From what I remember from the college, the way to draw a parametric equation with Java is the next: public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.translate(300,300); int x1,y1; int x0 = 0; int y0 = (int)(Math.E-2); //for x = 0, we get y = Math.E - 2 int nPoints = 1000; g2.scale(30,-30); for(int i=0;i<nPoints;i++) { double t= 12*i*Math

Direct2D - preserve the existing content and overwrite the new values

核能气质少年 提交于 2019-12-11 10:34:30
问题 I am planning to develop a XY Plotter for my application. To give some basic idea, how it should look like (of course the implementation would be different), please refer here and here. During the simulation (let's assume, it takes 4 hours to complete the simulation), on a fixed X axis, the new Y values should be (over)written. But, the problem with Direct2D is that, every time pRenderTarget->BeginDraw() is called, the existing Drawing(/Plot/BitMap/Image, etc) is deleted and a new image is

Dedicated drawing surface in Java?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 10:19:52
问题 I want to do efficient 2D drawing in Java. I would like to have some kind of surface which I may draw freely without having to let the view hierarchy traverse and update, which may cause stutter. I have used a JPanel at first and called repaint() but I find it not to be optimal (and it is the reason I ask). The closest thing I have worked with is the Android's SurfaceView and it gives me a dedicated drawing surface. To achieve this dedicated drawing surface, do I need to use OpenGL or is

How to sort a 2d array according to the second column using stl sort function?

烈酒焚心 提交于 2019-12-11 09:57:46
问题 How to sort a 2d array according to the second column using stl sort function ? For eg If we have an array a[5][2] and we want to to sort according to the ar[i][1] entry , how do we do it using the stl sort function. I understand we have to use a boolean function to pass as the third parameter but I am not able to design the appropriate boolean function ? 回答1: The stl sort requires the rvalue of the iterator being passed as the arguments. If you wanna use the sort function, you will have to

LIBGDX making 5 different buttons on one screen

三世轮回 提交于 2019-12-11 09:20:03
问题 I have 5 buttons i need to make do different things but they don't and i need to know how to make them do it. Here is my code; public class MainMenu implements Screen { CrazyZombies game; Stage stage; TextureAtlas atlas; Skin skin; SpriteBatch batch; Button play, option, quit, custom, store, menu; public MainMenu(CrazyZombies game) { this.game = game; } public void create () { stage = new Stage(); } @Override public void render(float delta) { Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1); Gdx.gl

Why isn't my homing missile algorithm working?

拟墨画扇 提交于 2019-12-11 08:49:43
问题 I've taken code that's heavily inspired by this answer but my projectile is not homing in the way I expect. The initial projectile direction is often perpendicular to the target. At which point, it does seem to home in on his direction, but if it "passes" him, it seems to get stuck in place like it's frozen at a point but then seems to follow the movements the target makes without moving at its intended speed. I've commented a line of code that I'm concerned about. He's using V3 and V4 in his

GameBoy Advance objects not being displayed in correct place when player is moving

老子叫甜甜 提交于 2019-12-11 08:29:52
问题 This might take a while to explain - go grab a snack while you're reading this. I am developing a 2D puzzle platforming game for the Gameboy Advance in C++ (I'm a fairly new programmer). Up until last night, I have been making a phyics engine (just some axis aligned bounding box stuff) which I was testing using a level which was the size of the GBA's screen. However, the final game will demand having a level which is bigger than the size of the screen, and so I have tried to implement a

Mac dev - Help getting started with 2d games

老子叫甜甜 提交于 2019-12-11 06:15:15
问题 I want to make some simple 2d games/clones (for Mac), but I have a few questions: Should I use Quartz 2d or OpenGL (I don't plan to try 3d anytime soon) There seems to be a lot of typedef'd things like CGFloat/GLfloat, which should I use? Should I use Objective-C for the game too (classes) or just C? (I assume I'll use Objective-C and Cocoa for window and views.) Is it fine to redraw the entire view each time? I don't really understand how the NSView's -drawRect dirtyRect parameter works, how

Finding the neighbors of 2D array

强颜欢笑 提交于 2019-12-11 06:14:10
问题 I've a 2D grid of 75rows by 75 cols, I draw symbols of 2 colors (red and blue) on users clicks, it works fine but I'm stuck on a major problem I want to find the neighbor of those symbols: Example when the user click on a cell, it prints a symbol (oval) now I want that click also checks in its neighbors if the cell are occupied or empty, if occupied, by which symbol. I found the algorithm below which seems to fit the need, but can't figure out how to adapt to my code: private static int[][]