We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm a noob. How do you know this stuff?
If my code is messy, I had to indent it here in the forum to get it onto the forum.
How do I get the Invaders to move down the y-axis?
Now, I'm a noob, so if you say something like: "just inherit a class" or something... that won't help me. Like, I won't know what you mean. Since I'm a noob.
Also when I run my python server, I can't get my blue files to show up in the browser... so when in your browser you have: localhost:8000 and under that you have blue files like:
sketch.js
index.html
main.js
et cetera
I don't have those 4 files. Which ones do I have? None. I have none. It worked before. I'm probably missing a dot or it is some path thing.
Like when you run your python server, have you ever not had the blue files in the browser? If so, what did you do? Perhaps something like localhost:8000 (right, we got that and then perhaps) //some code here(?)
Here is the code below where I don't know how to make the invaders go down the y-axis when it hits the sides.
Also, does anyone know why I can only use one javascript file in my P5 index.html code? If I use two javascript files, only one will work. I use vim and I tried it in text wrangler. Of course neither worked. Has anyone had this problem?
var invaders = [];
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
for (var i = 0; i < 10; i++) {
invaders[i] = new Invader(i * 60, 50);
}
}
function draw() {
background(60, 100, 100);
var edge = false;
for (var i = 0; i < invaders.length; i++) {
invaders[i].display();
invaders[i].move();
if (invaders[i].x > width || invaders[i].x < 0) {
edge = true;
}
}
if (edge) {
for (var i = 0; i < invaders.length; i++) {
invaders[i].shiftDown();
}
}
}
function Invader(x, y) {
this.x = x;
this.y = y;
this.xdir = 3;
this.diameter = 50;
this.display = function() {
strokeWeight(2);
stroke(0, 100, 100);
noFill();
ellipse(this.x, this.y, this.diameter, this.diameter);
ellipse(this.x, this.y * 2.2, this.diameter, this.diameter);
ellipse(this.x, this.y * 3.4, this.diameter, this.diameter);
ellipse(this.x, this.y * 4.6, this.diameter, this.diameter);
ellipse(this.x, this.y * 5.8, this.diameter, this.diameter);
}
this.shiftDown = function() {
this.xdir *= -1;
this.y += this.diameter;
}
this.move = function() {
this.x = (this.x + this.xdir);
}
}
Answers
Why have you created another thread for the very same issue, ignoring my replies from your original thread: [-( https://forum.Processing.org/two/discussion/20890/space-invader-movement-question
Well you told me to make a class and I didn't and don't know what you are talking about... Is that a constructor?
Do you know how I can make the invaders go down the y-axis? Also do you know why I can only use one javascript file with my index.html?
I found out how to get the blue files. You need to run the python server which btw is== python -m http.server ---- for some reason they changed that part (it use to be something else). Anyways, you need to run it in your home directory and then you will get the blue files. I was in my P5 directory.
I've told you to re-write your class Invader in a way it represents 1 alien only.
Yup, it is indeed your Invader's
function
constructor.As you know, class' names follow the UpperCaseCamel convention for both Java & JS! ~O)
BtW, you should abandon this deprecated way of implementing classes in JS.
It's already past time to adopt ES6's
class
keyword: $-)https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class
What I did was I used only one row of invaders... and what I found out was in my shiftDown function, I forgot to put +=. I only had =... but
now if I use all my invaders, then the rows all spread out inappropriately and not how I want. Like they don't stay together as they should.
BTW, I have no idea what ES6's means. Are you just joking with me? You do realize I know nothing right?
Well, w/o seeing your attempting "index.html" file, I can't indeed. 8-X
ES6 means ECMA Script version 6. And btW, ECMAScript is the real name of JavaScript language! ;;)
"Well, w/o seeing your attempting "index.html" file, I can't indeed."
I don't know what that means? My "index.html" file is just a standard boring html file we use for P5.
are you saying I should be using the word class instead of constructor?
I think you are just screwing with me? I just want the rows to go down. If you ran my code, making sure you add: this.y += this.diameter; where it says //something here, you will see my problem. and then perhaps you can tell me what to do?
Can I make my Invader thing be a variable? I think I have an array in my Invader thing. If I do, then can I make a variable of that invader thing? If I could do that, I should be able to move it. For some reason I can't move it correctly.
Does anybody know what I am talking about? Basically I want the rows to go down correctly?
If that's your actual stand, It's a useless endeavor to waste my time any further. :-@
If you take a bit of a look there, you'll realize the ".html" file is responsible to kickstart all
<script>
.If like you say, you wanna load more than 1 ".js", you're gonna need to edit that file. =P~
Repeating it for the 3rd time: You need to change your class so it represents 1 Invader unit only!
By doing so, each Invader can have its own x & y coordinate pair, and many other individual attributes. :)>-
Okay I'm obviously doing something wrong in this conversation. Having a single invader makes absolutely no sense to me at all. In fact, not only do I not know how to do that, I can't imagine how I would move the invaders down if I did do it.
I guess I would have to make a ton of single classes and then figure out how to move a ton of single classes across and down.
I don't even know what you mean. If I had a single invader, in my mind, I'd be hooped. I don't think I can help you to realize how I don't understand what you are talking about.
I think you should stop answering this question because I'm totally lost. I'm going to have to leave my question(s) again on the forum but don't answer it please as I have no idea whatsoever in which you are talking about.
If I did something to my code to make a single class and that made my invaders move down the y-axis, that would be fine but my guess is I'd be totally lost and screwed.
Can you drive a standard vehicle? Let's pretend no. Well just go drive it but don't start in 5th. Why aren't you starting the car up and driving it? I don't understand... Just don't start it in 5th. What's the problem?
Can you ski? Just go down that cliff there but make sure you parallel turn on the 9s. Of course not on the 4s.
What are you waiting for?
How come you don't realize that I have no idea what you are talking about?