We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Task 1. Jumping things. This sketch is supposed to work so that draw a thing (rectangle) somewhere in the window, and every time you click the mouse will skip this rectangle to a new location. The size of the rectangle is determined by the parameter to the constructor.
cus i cant get my code to run, do you know how to fix that? does my code and task 1 match?
this is the main file!
Hoppeting ht;
void setup() {
size(600, 400);
ht = new Hoppeting(30);
}
void draw() {
background(0);
ht.display();
}
void mouseClicked() {
ht.hopp();
}
this is the class file:
class Hoppeting {
// Variabler
float x;
float y;
float bredde;
float hoyde;
//Constructor
Hoppeting() {
x = random(height);
y = random(width);
hoyde = 50;
bredde = 100;
}
//Function
void display() {
background(255, 0, 0);
rect(x, y, bredde, hoyde);
}
void hopp() {
x = random(width);
y = random(height);
}
}
.. in the main file at the line:
ht = new Hoppeting(30);
what does the (30) mean?
task 2.
To create a Jumping Circle, a subclass of jumping thing that draws a circle instead of a square. write complete and comment code.
here is my class & subclass, can someone tell me if i do it right? cus i dont get it to work...
class Hoppeting {
// Variabler
float x;
float y;
float bredde;
float hoyde;
//Constructor
Hoppeting(int hoppetingLgth) {
x = random(height);
y = random(width);
hoyde = 50;
bredde = 100;
}
//Function
void display() {
background(255, 0, 0);
rect(x, y, bredde, hoyde);
}
void hopp() {
x = random(width);
y = random(height);
}
}
class Hoppesirkel extends Hoppeting {
// Variabler
float x;
float y;
float bredde;
float hoyde;
//Constructor
Hoppeting(int hoppeting) {
x = random(height);
y = random(width);
hoyde = 50;
bredde = 100;
}
//Function
void display() {
background(255, 0, 0);
ellipse(x, y, bredde, hoyde);
}
void hopp() {
x = random(width);
y = random(height);
}
}
task3.
Describe in your own words what you need to change the example above to use the class jump circle instead of jumping stuff class
task 4.
using an array list should make it possible to have multiple instances of both jumping thing and jump circle in the sketch. write complete and comment code for the changes you choose to do.
thanks!
Answers
i would be really gratefull if someone could help me! cus i got exam in this, and i cant find any good tutorial :(
It's a parameter value to be sent to the class' constructor.
However, your present constructor @ task 1 doesn't accept any parameters!
@gotoloop how can i fix and make it right? i dont really understand the parameter value... and what it do.. can you explain me?
It's hard to spot what're exactly your questions. You should be more specific! #-o
@gotoloop
sorry my english is bad....
The thing is that i dont understand how to fix my constructor so it accept parameters..
any what parameters do..
Maybe a simpler example can enlighten you up a bit?: :-?
@gotoloop still dont understand...
can you do a example with my code? How should my code be, so it can be right?
bump
Here you go son, i think i fixed it for you now.
Main
** Superclass**
sub-class