sct
YaBB Newbies
Offline
Posts: 2
Collisions?
May 29th , 2005, 12:08pm
I am writing a simple game in Processing in order to try to learn a bit more about it. I have an enemy class and a polygon which is drawn at the mouse coordinates to represent the player, but I was wondering how I would work out collisions, or if there are any commands in processing to deal with this sort of thing. Can anyone help? Here's the code: //Simple game test //Last updated 28.05.05 int amtFoes = 10; Enemy[] foes; int maintimer; void setup() { noCursor(); smooth(); size(300,200); background(20,20,45); framerate(60); foes = new Enemy[amtFoes]; for(int i=0; i<amtFoes; i++) { int index = i; foes[index] = new Enemy((i*25)+35, 10, 0, false); } } void draw() { background(20,20,45); for(int i=0; i<amtFoes; i++) { foes[i].update(); foes[i].drawtoscreen(); } fill(140,150,210,180); beginShape(POLYGON); vertex(mouseX,mouseY); vertex(mouseX+10,mouseY+15); vertex(mouseX,mouseY+10); vertex(mouseX-10,mouseY+15); endShape(); if(maintimer<millis()) { for(int i=0; i<amtFoes; i++) { int index = i; foes[index] = new Enemy((i*25)+35, random(-10,-50), random(9.25,9.55), false); } maintimer = maintimer + 5000; } } class Enemy { float x,y; float dir; boolean dead; int shottmr; Enemy(float cx, float cy, float cdir, boolean cdead) { x = cx; y = cy; dir = cdir; dead = cdead; } void update() { x = x + sin(dir)*1.8; y = y - cos(dir)*1.8; } void drawtoscreen() { fill(200,180,120,150); stroke(255,255,255); ellipse(x,y,20,20); } } class EnemyBullet { float x,y; int speed; EnemyBullet(float bx, float by, int bspeed) { x = bx; y = by; speed = bspeed; } } Ps. Have I posted this in the right section?