2d

Simple physics-based movement

十年热恋 提交于 2019-11-28 15:32:26
I'm working on a 2D game where I'm trying to accelerate an object to a top speed using some basic physics code. Here's the pseudocode for it: const float acceleration = 0.02f; const float friction = 0.8f; // value is always 0.0..1.0 float velocity = 0; float position = 0; move() { velocity += acceleration; velocity *= friction; position += velocity; } This is a very simplified approach that doesn't rely on mass or actual friction (the in-code friction is just a generic force acting against movement). It works well as the "velocity *= friction;" part keeps the velocity from going past a certain

How to extract part of this image in Java? [closed]

这一生的挚爱 提交于 2019-11-28 15:32:14
I have this sprite sheet: How can I read this image file to extract part of it to be used as a sprite ? If the sprites area read into a BufferedImage , the getSubimage method can be used to get a subimage of the sprite sheet. The getSubimage method will take the x , y , and the width and height of the desired subimage, so the desired sprite can be obtained. Since most of the sprites seem to be the same size, I would think most of them can be retrieved by a nested for loop to iterate through the large image. For example, if the sprite image is loaded using the ImageIO class (such as the read

2D Cross-Platform Game Development Engines [closed]

落花浮王杯 提交于 2019-11-28 14:57:25
I've worked for some time with Corona SDK and love how fast and easy I can create powerful apps using Lua. But it can only compile for iOS and Android, which feels like too little now. My main interest is for it to be able to compile to Desktop AND Mobile. At least for the following: Windows + Mac for desktop, as standalone applications. iOS + Android for mobile. I'd prefer it to lean more towards Lua type scripting instead of ActionScript, but please feel free to post anything that you have worked with and love. I've found the following engines so far: Marmalade Quick - After further looking

Java basic 2d game animation stutter

你说的曾经没有我的故事 提交于 2019-11-28 14:22:14
So, I have been working on a 2d rpg for some time now and I can't seem to fix this one problem. The graphics seem to "jump" or stutter every few seconds for an unknown reason. This is getting quite annoying because I don't know what is causing it. Here is a very basic program I wrote that just has a red square that moves from one side of the screen to the other side. Even in this very basic program the square still stutters every few updates and I really can't figure it out for the life of me. public class Main extends JPanel { int x=0, y=0; public JFrame window = new JFrame("Window"); public

How to read a .pgm image file in a 2D double array in C

。_饼干妹妹 提交于 2019-11-28 13:07:31
The question is quite simple: How to read a .pgm image file into a 2D double array in C. I do not have a .pgm buffer in memory. I would like to read it from the disk into memory. Would really appreciate if I could get a code snippet. Thank You. You probably won't get someone writing you all the code, but here are some useful links that might point you in the right direction: pgm.c pgm.h PGM Format Specification http://www.cplusplus.com/forum/general/2393/ If its saved as ASCII you could just read it with the "normal" file reading methods of C. You can of course use the netpbm library (linux

Three.js - 2D object in 3D space (by Vertices)

旧时模样 提交于 2019-11-28 12:52:07
问题 I have a problem: I have an array of 3D Points. How to draw 2D, flat object given by Vertices in 3D Space? I want to draw line from Points[0] to Points[1], from Points[1] to Points[2] etc… Now I have a following solution: var geometry = new THREE.BufferGeometry(); var vertices = faceToTriangles( VerticesArray ); // my function var uvs = new Float32Array([ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0 ]); geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 )

Function for rotating 2d objects?

心已入冬 提交于 2019-11-28 12:15:01
Is it possible to write a function in python that could rotate any 2d structure with the arguments being only the coordinates (x,y) of the points in the structure? Additional arguments would be included for axis, speed and direction. To my understanding it would only be possible by calculating point distance from symmetrical points and the axis and therefore it would always vary and is thus impossible except for 2d structures made up of standard shapes (triangles, rectangles, squares etc) Good examples would be appreciated. First, we need a function to rotate a point around origin. When we

Pascal's triangle 2d array - formatting printed output

时间秒杀一切 提交于 2019-11-28 11:43:19
I have a small assignment where I have to use a 2d array to produce Pascal's triangle. Here is my code, and it works. there is an extra credit opportunity if I display the triangle like so: however, my spacing is not formatted like that. it simply displays the numbers all lined up on the left. its hard to describe but if you run it you will see what I mean. here is my code: import java.util.*; public class Pascal { public static final int ROW = 16; public static void main(String[] args) { int[][] pascal = new int[ROW +1][]; pascal[1] = new int[1 + 2]; pascal[1][1] = 1; for (int i = 2; i <= ROW

Approximation of n points to the curve with the best fit

我与影子孤独终老i 提交于 2019-11-28 11:34:45
问题 I have a list of n points(2D): P1(x0,y0), P2(x1,y1), P3(x2,y2) … Points satisfy the condition that each point has unique coordinates and also the coordinates of each point xi, yi> 0 and xi,yi are integers. The task is to write an algorithm which make approximation of these points to the curve y = | Acos (Bx) | with the best fit (close or equal to 100%) and so that the coefficients A and B were as simple as possible. I would like to write a program in C # but the biggest problem for me is to

How to convert a Numpy 2D array with object dtype to a regular 2D array of floats

谁都会走 提交于 2019-11-28 09:09:32
As part of broader program I am working on, I ended up with object arrays with strings, 3D coordinates and etc all mixed. I know object arrays might not be very favorite in comparison to structured arrays but I am hoping to get around this without changing a lot of codes. Lets assume every row of my array obj_array (with N rows) has format of Single entry/object of obj_array: ['NAME',[10.0,20.0,30.0],....] Now, I am trying to load this object array and slice the 3D coordinate chunk. Up to here, everything works fine with simply asking lets say for . obj_array[:,[1,2,3]] However the result is