I was just messing around / experimenting with classes and I wanted to make a cat object with a class, and a dog object which will basically chase the cat around.
I have a seek() method for the dog (like in Nature of Code chapter 6)
but I can't figure out how to make the force that moves the dog
Does anyone Know how to make a basic "force", (kinda like in Nature of Code chapter 2)?
there's probably no reason to put all the code but here it is, sorry for the sloppyness
class Dog { PVector location; PVector velocity; PVector acceleration; float maxspeed; float maxforce; float r; // the size
Dog(float x, float y) { acceleration = new PVector(0,0); velocity = new PVector(0,0); location = new PVector(x,y); r = 8.0; maxspeed = 4; maxforce = 0.1; } void update() { velocity.add(acceleration); velocity.limit(maxspeed); acceleration.mult(0); }
goal = new PVector(myCat1.xpos, myCat1.ypos); // IS THAT THE RIGHT WAY TO USE VARIABLES FROM THE OTHER CLASS? myDog.applyForce(); myDog.seek(goal); myDog.display();
println(myCat1.xpos); }
Cat class
class Cat { color c; float xpos; float ypos; float xspeed; float xdir; float ydir; int rad = 10;
//
// the constructer is defined with arguments // Cat(color tempC, float tempXpos, float tempYpos, float tempXspeed, float tempXdir, float tempYdir) { c = tempC; xpos = tempXpos; ypos = tempYpos; xspeed = tempXspeed; ydir = tempYdir; xdir = tempXdir; //targeter = new PVector(xpos,ypos); }
This is just the example sketch from the GML4u library
When I run it gives me an error (in a pop up window) that 2 libraries are competing for the same sketch,
Does anyone know how to fix this?
Thanks
** oh update, I just got the same error in another sketch that isn't using gml4u, just toxic libs.
its says duplicate libraries must be deleted before running the sketch. ???
/** * GML4U library * Author Jerome Saint-Clair * http://saint-clair.net * * This example shows how to iterate through GML strokes * and points to draw GML with your own custom style * */
// has user text been entered and sent? if (!saved.equals("")) { // answer has been given now evaluateAnswer(); } else { // wait till answer is complete text(typing, 50, 100); //text(saved, 50, 150); } }
void evaluateAnswer() { text(saved, 50, 100); if (saved.equals(answer1)) {
Hello, I'm working on a basic game concept, but I'm having trouble with taking user input (text.)
I want the game to ask a question, then the user answers, if the answer is correct display one image or animation and if its wrong display a different one.
So I have all these png images that are parts of animations and i want to display one according to the text input, later i want to make an animation class and display that.
heres the code now, it takes user input and saves it ( I copied it from the Daniel Shiffman book)
should i edit the draw loop or the key pressed loop?? Any help would be really appreciated thanks!
how would i make it "read" the user text and then do something based on that??
I can put all the code here, but i figured the rest isn't really important it just loads a bunch of images and strings, next I want to display different images and strings based on the text