adzer2
YaBB Newbies
Offline
Posts: 15
Ireland
game problem
Feb 13th , 2006, 12:47pm
Hi I am currently writing a pool game, the following code needs some images but if you comment those lines of code out it will work. Anyway, my problem is that I cant get the cue to stay pointed around the white ball but follow the mouse so that the cue points in the direction of where the cursor is, any help would be appereciated Ball r1, r2, r3, r4, r5, r6, r7, y1, y2, y3, y4, y5, y6, y7, b1, w1; int w1XPos = 175; int w1YPos = 0; PImage cue; PImage carpet; void setup() { strokeWeight(2); size(800, 600); cue = loadImage("Cue.jpg"); carpet = loadImage("floor.jpg"); } void draw() { smooth(); stroke (0); background (carpet); translate(width /2, height /2); fill(50, 50, 50); rect (-320, -250, 350, 40);//rack fill (102, 51, 0); point (0, 0); rect (-320, -150, 640, 340);//surround PImage cloth = loadImage("Cloth.jpg"); image(cloth, -300, -130); rect(600, 300, cloth.width, cloth.height);//cloth //rect (-300, -130, 600, 300);//cloth fill(0, 0, 0); ellipse (300, 170, 35, 35);//bottom right pocket ellipse (-300, 170, 35, 35);//bottom left pocket ellipse (0, 165, 35, 35);//bottom middle pocket ellipse (290, -122, 35, 35);//top right pocket ellipse (-290, -122, 35, 35);//top left pocket ellipse (0, -125, 35, 35);//top middle pocket //28 difference on the y axis, 25 on x axis r1 = new Ball(-118, 20, 0, 25); r2 = new Ball(-168, -8, 0, 25); r3 = new Ball(-168, 48, 0, 25); r4 = new Ball(-193, 33, 0, 25); r5 = new Ball(-218, 74, 0, 25); r6 = new Ball(-218, 46, 0, 25); r7 = new Ball(-218, -10, 0, 25); y1 = new Ball(-143, 5, 1, 25); y2 = new Ball(-143, 35, 1, 25); y3 = new Ball(-193, 61, 1, 25); y4 = new Ball(-193, 5, 1, 25); y5 = new Ball(-193, -23, 1, 25); y6 = new Ball(-218, 18, 1, 25); y7 = new Ball(-218, -38, 1, 25); b1 = new Ball(-168, 20, 3, 25); w1 = new Ball(w1XPos, w1YPos, 2, 25); r1.draw(); y1.draw(); y2.draw(); b1.draw(); r2.draw(); r3.draw(); y3.draw(); r4.draw(); y4.draw(); y5.draw(); r5.draw(); r6.draw(); y6.draw(); r7.draw(); y7.draw(); w1.draw(); image (cue, + mouseX , + mouseY); } class Ball { int bSize; int xCoord; int yCoord; int ballColour; float speed; boolean potted = false; Ball(int xPos, int yPos, int colour, int ballSize) { bSize = ballSize; ballColour = colour; xCoord = xPos; yCoord = yPos; } void draw() { pushMatrix(); int cRed = color (255, 0, 0); int cBlack = color (0, 0, 0); int cYellow = color (255, 255, 25); int cWhite = color (255, 255, 255); stroke(0); noStroke(); if (ballColour == 0) //red { fill(cRed); } else if (ballColour == 1) //yellow { fill(cYellow); } else if (ballColour == 2) //White { fill(cWhite); } else if (ballColour == 3) //Black { fill(cBlack); } ellipse (xCoord, yCoord, bSize, bSize); popMatrix(); } }