I've been making some games using 2d OpenGL Processing, but now I'd like to give 3d programming a try. Is processing 3d suitable for this? I've programed in Lua, Python and Java before, and I'm trying to find a suitable game engine to experiment with. I've tried the Blender Game Engine, but It's pretty hard, and on my Windows partition I'm trying out Unity because I heard they're getting Linux support.
So I'm making a game. I have a class called Oid, which in the game is a perfect circle with center, radius, speed, color etc. attributes. The following code, a method of Oid, is supposed to detect when the oid has touched another indicated oid. But it doesn't work, it detects the collision when the other oid is still some distance away!
What is the preferred solution for resolution-independent coding? Using the size() method I can target only one resolution, or I can put size(screenWidth, screenHeight), but like that my code will not look the same accross multiple resolutions. Is there any way to write code for one resolution (say, 640x480) and scale it up to any resolution? Obviously, it will be pixelated, but I want my game to be playable fullscreen in Present Mode on any resolution. Currently, a 640x480 sketch in Present mode on a 1080p monitor is the size of a postage stamp.
From my game header:
/*DESCRIPTION ------
floVV is a 2d arena game based on realistic physics!
projectile inheritance and physically realistic recoil (on the shooter and the target) are implemented.
bullet damage in floVV is calculated not based on weapon types or on arbitrary damage calculations, but on the actual kinetic force imparted by the bullet.
your only means of movement in floVV is weapon recoil, with some "thruster" weapons intended entirely for this purpose.
use the mouse to aim your character, then right click on the game screen to use your jets and left click to fire your weapons. number keys 1 thru 4 switch weapons.
----------END DESCRIPTION*/
I've been working on this awhile, and I want to know what you like and what you don't!
so
this link lets you download my sketchbook. The sketch Tilde is what I'm talking about here.
When you click the mouse, it's supposed to add a new bullet to the game, which is supposed to shoot off towards the bottom of the screen. The problem is, the bullet is somehow dragging the player character along with it! I traced the problem to method update() of MotileRect, which does
pos.add(speed); //this is supposed to add this MotileRect's speed vector to this MotileRect's position vector,
thus moving it. But somehow it adds the MotileRect speed vector to the Player's position vector! how?!!?!
What is the preferred way to make some polygons in processing? I want to create some polygons, move and rotate them around in the sketch, and, most importantly, detect when one of these polygons collides with another one.
So I've got classes Rect, MotileRect, and GravRect. Rect is an on-screen rectangle, MotileRect can move, and GravRect is *supposed* to pull MotileRects in toward it. Here they are:
class Rectangle { PVector pos;
int h; int w;
int r; int g; int b;
Rectangle (PVector inpos, int inw, int inh, int inr, int ing, int inb) { //define with a vector pos = inpos; h = inh; w = inw; r = inr; g = ing; b = inb; }
The problem is that my current implementation of gravity... doesn't work. It flings the rect it's supposed to be sucking in ALL OVER THE PLACE, in a way that's not consistent with anyone's laws of gravity, except maybe the LHC people. Anyway, what code should I use to make the gravity work?
So I'm trying to make a game in Processing, and i've got this source here:
PlayerRect mov = new PlayerRect(new PVector(40, 94), 5, 5, 0, 0, 255); final int windowX = 800; final int windowY = 600; void setup() { size(windowX,windowY); } void draw() { background(150); mov.update(); mov.render(); mov.moveself(); }
class Rectangle { PVector pos;
int h; int w;
int r; int g; int b;
Rectangle (PVector inpos, int inw, int inh, int inr, int ing, int inb) { //define with a vector pos = inpos; h = inh; w = inw; r = inr; g = ing; b = inb; }
So I'm programming a simple "dodging bullets" game in the vein of Kenta Cho's rRootage. I have class Source, which is the source that bullets emanate from: (You can check out the whole program at my github sketchbook page (
https://github.com/yanom/yanomsketchbook) under the working title "fightergame"
class Source { int x; int y; float speed; int r; int g; int b;
Source () { x = 250; y = 250; speed = 5.0; r=255; g=0; b=0; }
Source (int inx, int iny) { x = inx; y = iny; speed = 5.0; r=255; g=0; b=0; }
Source (int inx, int iny, float inspeed) { x = inx; y = iny; speed = inspeed; r=255; g=0; b=0; }
Source (int inx, int iny, float inspeed, int ir, int ig, int ib) { x = inx; y = iny; speed = inspeed; r=ir; g=ig; b=ib; }
void handle(ArrayList holdbullet, int numbullets, int windowSize) { /* if (goingRight) { x += 6; } else { x -= 6; } if (x<8) { goingRight = true; } if (x>(windowSize-8)) { goingRight = false; } */
for (int iii=1; iii<=numbullets; iii++) { float randX = random(-1*speed, speed); float randY = random(-1*speed, speed);
And currently, it receives int numbullets in it's handle() function, which is called every frame the program runs, and it releases that many bullets every frame. The thing is, what's the best way to release
less than one bullet per frame?
Like, release 30 bullets every 60 frames or something. But also still be able to release multiple bullets per frame.
Also probably of interest is class Layer. Layer has-a Source. Layer updates every frame and currently, each Layer tells it's Source how many to shoot that frame. The Layer knows how many to shoot because of global variable difficulty (currently set to 1).
That's kinda a crappy setup there so I need a better solution for releasing bullets :D
So sometimes you can't run Processing for Linux because it has java for 32 bit Linux, and your system is 64 bit Linux. So I patched up 1.5.1, removing the 32 bit java and putting in 64 bit Java. You can download it here:
I recently installed the Linux Mint (64 bit) Linux distribution, and downloaded Processing for Linux, but when I try to start the Processing Development Environment, by using ./processing in the directory, I get treated to this error:
yanom@linuxmint ~/processing-1.5.1 $ Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/yanom/processing-1.5.1/java/lib/i386/xawt/libmawt.so: libXext.so.6: cannot open shared object file: No such file or directory at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699) at java.lang.Runtime.load0(Runtime.java:770) at java.lang.System.load(System.java:1003) at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1720) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028) at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.loadLibraries(Toolkit.java:1605) at java.awt.Toolkit.<clinit>(Toolkit.java:1627) at processing.app.Base.<clinit>(Base.java:445) Could not find the main class: processing.app.Base. Program will exit.
This seems like a simple thing, but it's been eluding me all day. How do I choose a random entry in an array or ArrayList? All of my solutions either end up producing values out of range or some elements in the ArrayList don't ever get picked (the first or last ones, sometimes). Does anyone know how?
So I got this weird idea that I would write a Processing sketch that simulates a closed 2d system (perhaps a sheet of metal totally insulated from the outside world) where some regions start out hotter than others and by heat being conducted the whole system comes to equilibrium. So I wrote this code (every frame the code determines the average temperature of the system and prints it out).
final int windowSize = 500; int[][] heatarray = new int[windowSize][windowSize]; int totalheat = 0;
void setup() { size(windowSize, windowSize); frameRate(30); for (int iii=0; iii<=(windowSize-1); iii++) { //windowSize-2 makes it go 0-499 for (int jjj=0; jjj<=(windowSize-1); jjj++) { heatarray[iii][jjj] = round((noise(iii/200,jjj/200)*200)); } } }
void haverage(int x1,int y1,int x2, int y2) { int average = (heatarray[x1][y1]+heatarray[x2][y2])/2; heatarray[x1][y1] = average; heatarray[x2][y2] = average; }
Soooo try running the program. You'll see that *gasp* the average temperature of the system decreases every frame! This shouldn't happen, because this is supposed to be a closed system so there's nowhere for the heat to go! But yet it decreases. Can anyone find the bug? Help!
So I need a way to detect what keys are currently pressed down. In my game program I need to move an object in 8 directions:
Up if W key is pressed
Down if S key is pressed
Left if A key is pressed
Right if D key is pressed
But, if two keys are pressed, I need it to move diagonally. keyPressed and KeyReleased stuff isn't doing it for me, because it can really only handle one key at a time, and it's just not suitable for game controls.
Is it possible to create an array of infinite size, put a lot of stuff (objects) in there and then loop over the array, accessing however many objects there may be?
I've been working on this all night. I have an array of 10 Rectangle objects. A rectangle has data values x,y,w,h which represent the X,Y location of the rectangle and it's height and width. no rectMode(); calls are used. I'm using this algorithm I found to try to detect collision between any of the 10 rects colliding as they move about:
boolean collDetect(Rectangle rect1, Rectangle rect2) { // this will be collison detection
if (rect1.x+rect1.w < rect2.x) { return false; } if (rect1.x > rect2.x+rect2.w) { return false; } if (rect1.y+rect1.h < rect2.y) { return false; } if (rect1.y > rect2.y+rect2.h) { return false; }
return true;
}
I loop through the objects like this in the draw() function:
for (int iii=0; iii <= 9; iii++) { for (int jjj=0; jjj<= 9; jjj++) { if (iii != jjj) { //not the same rect boolean coll = collDetect(myRects[iii],myRects[jjj]); if (coll == true) { myRects[iii].rectColor = color(255,0,0); myRects[jjj].rectColor = color(255,0,0); } else { myRects[iii].rectColor = color(0); myRects[jjj].rectColor = color(0); } } } }
To try to flag any collisions and turn the colliding rects red. But it only flags like 1/5 of all the collisons! Full source is below, see for yourself.
//TODO: Fix it so that they don't all fall into a state of just going one direc //TODO: do this by checking if movement is 0 on every boundry hit and reassign //TODO: if it is.
final int windowSize = 500;
Rectangle[] myRects; int locationX, locationY;
void setup () { myRects = new Rectangle[10]; for (int iii=0; iii <= 9; iii++) { locationX = int(random(windowSize)); locationY = int(random(windowSize)); myRects[iii] = new Rectangle(locationX, locationY); } size(windowSize,windowSize); noStroke(); }
void draw () { background(0,100,100); for (int iii=0; iii <= 9; iii++) { myRects[iii].update(); for (int jjj=0; jjj<= 9; jjj++) { if (iii != jjj) { //not the same rect boolean coll = collDetect(myRects[iii],myRects[jjj]); if (coll == true) { myRects[iii].rectColor = color(255,0,0); myRects[jjj].rectColor = color(255,0,0); } else { myRects[iii].rectColor = color(0); myRects[jjj].rectColor = color(0); } } } } }
boolean collDetect(Rectangle rect1, Rectangle rect2) { // this will be collison detection
if (rect1.x+rect1.w < rect2.x) { return false; } if (rect1.x > rect2.x+rect2.w) { return false; } if (rect1.y+rect1.h < rect2.y) { return false; } if (rect1.y > rect2.y+rect2.h) { return false; }
return true; }
class Rectangle { int x; //position int y;
int h; int w;
int mvmntx; int mvmnty;
color rectColor = color(0,0,0);
Rectangle (int c1x, int c1y) { x = c1x; y = c1y; h = 20; w = 20; mvmntx = round(random(-2,3)); //movement mvmnty = round(random(-2,3));
void boundryCheck() { if (x < 0) { mvmntx = round(random(1,3)); } if (y < 0) { mvmnty = round(random(1,3)); } if (x+w > windowSize) { mvmntx = round(random(-2,0)); } if (y+h > windowSize) { mvmnty = round(random(-2,0)); } }