• What Do You Need Help With? V6
    7,544 replies, posted
Sort of off-topic, but when I have a kid, and I give them a computer, Should I just give them a laptop with Ubuntu on it? Or will I be crippling their ability to hang out with their windows/mac-using peers forever?
Use [url=http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#scheduleAtFixedRate(java.util.TimerTask,%20long,%20long)]timers[/url]? (I googled java every x seconds)
[QUOTE=proboardslol;46401163]Sort of off-topic, but when I have a kid, and I give them a computer, Should I just give them a laptop with Ubuntu on it? Or will I be crippling their ability to hang out with their windows/mac-using peers forever?[/QUOTE] I mean kids these days generally just play Facebook games and smartphone games, so I don't see why Ubuntu would hamper that. That said, they might be a little lost when they start using Windows 7 when they get to school.
[QUOTE=NixNax123;46400012]Also, how could I get that to perform with the show() method, which performs every frame? [editline]3rd November 2014[/editline] I guess I'll have to make a wave class! Time to do that.[/QUOTE] Compare a variable with the current time, if it's less than it minus three seconds execute whatever you want and set the variable to the current time. This isn't going to execute exactly every three seconds though, depending on how often your update executes.
[QUOTE=proboardslol;46401163]Sort of off-topic, but when I have a kid, and I give them a computer, Should I just give them a laptop with Ubuntu on it? Or will I be crippling their ability to hang out with their windows/mac-using peers forever?[/QUOTE] I don't even see schools as an issue for learning to use certain Operating Systems. I have friends who grew up on Macs, and they had no trouble learning Windows on their own.
[QUOTE=proboardslol;46401163]Sort of off-topic, but when I have a kid, and I give them a computer, Should I just give them a laptop with Ubuntu on it? Or will I be crippling their ability to hang out with their windows/mac-using peers forever?[/QUOTE] i think a mac would probably be better for someone who has not used computers before, it's fairly similar to ubuntu anyway and windows is easy to learn to use later
How would I get a sprite to move toward another sprite's position? [code] public void update(float dt) { // updates enemy position/speed based on time vx = ???; vy = ???;[/code]
[QUOTE=NixNax123;46401853]How would I get a sprite to move toward another sprite's position? [code] public void update(float dt) { // updates enemy position/speed based on time vx = ???; vy = ???;[/code][/QUOTE] [code] vector2 direction = normalize(other.position - position); position += direction * movementspeed; [/code]
[QUOTE=NixNax123;46401853]How would I get a sprite to move toward another sprite's position? [code] public void update(float dt) { // updates enemy position/speed based on time vx = ???; vy = ???;[/code][/QUOTE] Get the normal to the target vector (target position minus current position divided by its length) Speed = normal vector * desired velocity [url]http://tutorial.math.lamar.edu/Classes/CalcII/Vectors_Basics.aspx[/url] You can keep treating X and Y separately or use a 2D Vector library to make it a little easier
I'm taking calc 3 right now and for some reason I just completely forgot about that. I feel so dumb :v: thank you! [editline]3rd November 2014[/editline] Solved: [code] Vector2f top = new Vector2f(GameScreen.getCurrentPlayer().getPos().x - x, GameScreen.getCurrentPlayer().getPos().y - y); double length = Math.sqrt(top.x*top.x + top.y*top.y); double normX = top.x/length; double normY = top.y/length; x += normX * 120 * dt; y += normY * 120 * dt;[/code] [editline]3rd November 2014[/editline] Now I'm having a problem where I need to spawn enemies at a set interval. This is what I have so far: [code] public EnemyWave(int spawnRate, int maxEnemies) { this.spawnRate = spawnRate; this.maxEnemies = maxEnemies; numEnemies = 0; } public void start() { while (numEnemies != maxEnemies) { new SpawnEnemyAction().execute(); numEnemies++; } }[/code] And I invoke start() in this method, which is called every frame: [code] public void show() { // entity handling etc currentWave.start();[/code] How would I get an enemy to appear every X seconds without stopping the game while the start() method sleeps?
[QUOTE=Kondor;46401795]i think a mac would probably be better for someone who has not used computers before, it's fairly similar to ubuntu anyway and windows is easy to learn to use later[/QUOTE] Why learn how to use Macs first if you're not going to use Macs predominantly? [editline].[/editline] wait this discussion is a bad idea
[QUOTE=Kondor;46401795]i think a mac would probably be better for someone who has not used computers before, it's fairly similar to ubuntu anyway and windows is easy to learn to use later[/QUOTE] I grew up on windows, I think it really just depends on what you started on.
[QUOTE=NixNax123;46402007] Now I'm having a problem where I need to spawn enemies at a set interval. This is what I have so far: [code] public EnemyWave(int spawnRate, int maxEnemies) { this.spawnRate = spawnRate; this.maxEnemies = maxEnemies; numEnemies = 0; } public void start() { while (numEnemies != maxEnemies) { new SpawnEnemyAction().execute(); numEnemies++; } }[/code] And I invoke start() in this method, which is called every frame: [code] public void show() { // entity handling etc currentWave.start();[/code] How would I get an enemy to appear every X seconds without stopping the game while the start() method sleeps?[/QUOTE] Anyone?
you can just have a timer in the update function which checks to see if X seconds have passed and if they have then spawn another enemy and reset the timer
[QUOTE=Kondor;46403437]you can just have a timer in the update function which checks to see if X seconds have passed and if they have then spawn another enemy and reset the timer[/QUOTE] How would I do that?
[QUOTE=NixNax123;46403467]How would I do that?[/QUOTE] Record when the last enemy spawned, then in the update method compare it to the current time. If the result is greater than or equal to the delay, then spawn another enemy. [editline]3rd November 2014[/editline] e.g. [code]private long enemySpawnTime; private long delay = 1000; public void spawnEnemy() { //whatever enemySpawnTime = methodToGetTime(); } public void update() { //whatever if (methodToGetTime() - enemySpawnTime >= delay) { spawnEnemy(); } }[/code] Replace methodToGetTime with whatever is the most ideal way to get the current time, and replace 1000 with whatever you want the delay to be in the same measurement of time and etc.
-snip found solution -
I want to study more theoretical aspects of computer science, but I'm a freshman. What are some good resources on theory for a beginner?
like what kind of stuff are you interested in
[QUOTE=Kondor;46411270]like what kind of stuff are you interested in[/QUOTE] Mathematics.
[QUOTE=proboardslol;46411606]Mathematics.[/QUOTE] [url]http://www.amazon.com/gp/aw/d/1435458869/ref=pd_aw_sims_2?pi=SL500_SY115&simLd=1[/url] [url]http://www.amazon.com/gp/aw/d/1568817231/ref=pd_aw_sims_9?pi=SL500_SY115&simLd=1[/url] [url]http://www.amazon.com/gp/aw/review/1584503300/RNSA11AKLL1Q5/ref=mw_dp_cr?cursor=2&sort=rd[/url] etc
Could someone help me understand the parts I commented out? I am slightly confused. [CODE] int main() { int choice; bool fQuit = false; Shape * sp = nullptr; while (fQuit == false) { cout << "(1) Circle - (2) Rectangle - (3) Square - (0) Quit: "; cin >> choice; switch (choice) { case 1: sp = new Circle(5); break; case 2: sp = new Rectangle(4,6); break; case 3: sp = new Square(5); break; default: fQuit = true; break; } if (fQuit == false) { sp->Draw(); // I am deleting the pointer from the heap, maybe there's no need to set it to NULL because it goes out of scope? delete sp; // sp = NULL; Is this not necessary anymore? cout << endl; } } return 0; }[/CODE]
In C++, "new" usually allocates memory and then constructs an object. "delete" calls the destructor of the class and then frees the memory. When you've created an object with new, delete is the operator that does all the necessary cleanup. Assigning a pointer to null doesn't do anything except change the pointer value. It doesn't destroy the object nor does it free the memory. Smart pointers do things slightly differently.
Can anyone recommend any good sources/books on 2D lighting? I'm going to try to implement it into my game (in JSFML), if this is impossible with that library, tell me now.
[code]package net.robharding.base; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.VPos; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; public class Login extends Application { @Override public void start(Stage stage) throws Exception { VBox pane = new VBox(); Text usernameT = new Text("Username"); usernameT.setFont(Font.font("Sans serif", FontWeight.NORMAL, FontPosture.REGULAR, 16)); usernameT.setLayoutX(10); usernameT.setLayoutY(10); pane.getChildren().add(usernameT); stage.setScene(new Scene(pane, 300, 450)); stage.setTitle("|JavaChat| - Login"); stage.setResizable(false); stage.show(); } // Main method public static void main(String[] args) { launch(args); } }[/code] Why isn't the text positioning? It's just in the top right corner
[QUOTE=ThePuska;46418069]In C++, "new" usually allocates memory and then constructs an object. "delete" calls the destructor of the class and then frees the memory. When you've created an object with new, delete is the operator that does all the necessary cleanup. Assigning a pointer to null doesn't do anything except change the pointer value. It doesn't destroy the object nor does it free the memory. Smart pointers do things slightly differently.[/QUOTE] The operating system [B]should[/B] free the no-longer-referenced data when the application has stopped.
[QUOTE=BOT Ferris;46421209][code]package net.robharding.base; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.VPos; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; public class Login extends Application { @Override public void start(Stage stage) throws Exception { VBox pane = new VBox(); Text usernameT = new Text("Username"); usernameT.setFont(Font.font("Sans serif", FontWeight.NORMAL, FontPosture.REGULAR, 16)); usernameT.setLayoutX(10); usernameT.setLayoutY(10); pane.getChildren().add(usernameT); stage.setScene(new Scene(pane, 300, 450)); stage.setTitle("|JavaChat| - Login"); stage.setResizable(false); stage.show(); } // Main method public static void main(String[] args) { launch(args); } }[/code] Why isn't the text positioning? It's just in the top right corner[/QUOTE] When I run your code, the text is positioned in the top left for me. Nevertheless, here's just a few pointers before I explain how to align it properly. - Don't use Text, use [url=http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Label.html]Label[/url] instead for displaying text on a control or stage - You shouldn't be setting any X or Y positions on the layout - the whole purpose of a layout manager is to let it do this for you In order to get your label to align properly, you'll need to change the alignment of its parent (in this case, the VBox) with the [url=http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Labeled.html#setAlignment-javafx.geometry.Pos-]setAlignment[/url] method. You can, of course, use this method on the label itself - but you'll need to use the [url=http://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/Region.html#setMaxWidth-double-]setMaxWidth[/url] method in order to tell the label to use up as much space as it can. Here's what I've managed to come up with: [img]http://i.imgur.com/MZ71wUn.png[/img] Here's the appropriate code for the application's start method: [code] @Override public void start(Stage stage) throws Exception { //setup stage stage.setTitle("My Super Cool Window"); stage.setResizable(false); //vbox VBox vbox = new VBox(); vbox.setAlignment(Pos.BASELINE_CENTER); //username label Label usernameLabel = new Label("Username"); usernameLabel.setFont(Font.font(32)); vbox.getChildren().add(usernameLabel); //show stage.setScene(new Scene(vbox, 300, 450)); stage.centerOnScreen(); stage.show(); } [/code]
Is there a function in C (or a library) which counts the number of digits there are in an integer? Say, I input the number 12345, then the program would return 5 since there are 5 digits in 12345.
The logarithm of the number in base 10 gives you that number. i.e. number_of_digits = floor(log10(x)) Logarithms can be converted from one base to another log10(x) = log(x) / log(10) math.h defines a log function.
I see, thanks!
Sorry, you need to Log In to post a reply to this thread.