Wilson Cash

Greenhorn
+ Follow
since Sep 24, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Wilson Cash

Oh, I'm not sure if it does what I want or not, I'm just not sure how to do it. The code I posted just shows what I have so far.
10 years ago
Hi.

Is there a way to split a string into words, but only until a certain number of words? So for example, say I have a string "Hello my name is Adam", is it possible to split it into "Hello" "my" "name is Adam"?

My code right now:



Thanks in advance.
10 years ago
Hi,

Thanks for the help guys. I have attached a screen shot of the projectile just as it touches the rocket. The numbers in the top left are the coordinates of the rocket (top) and projectile (bottom). (The rocket is a gray square for now)
I am pretty sure that the arraylists contain something because the projectiles and rockets are all rendered from the arraylist and removed when they are not on screen which indicates that the arraylist does contain some entries.
11 years ago
Hi,

I apologize if this is in the wrong board. The moderators can move it if it is.

I have two abstract classes. Rocket and Projectile, which look like this (I have only left the relevant parts)





Then I have subclasses extending those two classes (I will show NormalRocket and MachineGunProjectile) which call the super of bounds like so:





I have a level class which contains two lists, one for rockets and the other for projectiles, and rockets and projectiles are added to the respective lists:



I am using the following code to check for collision between the projectiles and rockets. The problem is, that "HIT" is not printed and I cannot figure out why:



I do not know why this does not work, I have tried 2 different techniques so far and neither work. Can anyone help me solve this problem? I can post more code if it is necessary.
11 years ago
Thanks. That works perfectly.
11 years ago
Hi!

I'm working on a save system for my game, and everything is fine. However, I need to save some variables to a properties file, which are integers. However setProperty does not allow saving integers. I am asking how to write the int into the file without modifying it too much. Is this possible? I tried casting, but that does not seem to work. I think I need to parse the variables in some way, but I am clueless on how to do that.

Here is my code:



Thanks!
11 years ago
I'm not really sure what you mean by creating it? I have an InputHandler class.
11 years ago
Hi!

I have a game, and I just added a InputHandler class. The problem is that whenever I run my game, I get a java.lang.nullPointerException in my Player class where the if statement for checking if the key is pressed.

Game



InputHandler



Player



I have tried lots of things but I just cannot figure this out. It's probably something that I just overlooked and can't find. Help is appreciated. Thanks!

This is the error message:

11 years ago
Not exactly sure how I would go about checking where it says that.

EDIT: I assume you mean the CPU field. In that case, it is 00 and goes up occasionally but it has not gone higher that 04. The memory usage is just below 46,000K
11 years ago
Hi,

I have a simple game set up, not yet finished, and only using basic rectangles for graphics right now.

The problem is, that when start the game for the first time after starting up eclipse (or my computer) the game runs at over 160 FPS, after a while though, it drops to 100, and if I launch it again, it stays at 100 FPS and occasionally speeding up to 167 FPS and slowing down again. Can anyone explain why this is happening, I can provide my code if necessary, if it is a problem with its efficiency.

Thanks in advance!
11 years ago
Hi!

I was making an app for the android, where if you press a button, a sound plays. The problem is, that after playing one sound, pressing the buttons again does nothing



How can I fix this?

Thanks!
11 years ago
Hi,

I was trying to load an image and print it out on the screen, but for some reason it does not seem to appear. The path is correct (the file is in a res folder), but even with an image that is elsewhere on my computer with the correct file path it still does not work.

Game.java



Screen.java



Background.java



Thanks!

Also, another question I have, is how would I define the drawImage function in the background class, so that in the screen.paintComponent method I just have to call background.paint(g) and it prints it out on the screen?
Something like this:



and then I just have to call player.paint(g) in screen.paintComponent method

but instead with an image like so:



but that does not work because "The method drawImage(Image, int, int, ImageObserver) in the type Graphics is not applicable for the arguments (Image, int, int, Background)"
11 years ago
Yeah, I'll use the the object oriented way more, however I will also use the boolean one for simple tests.
11 years ago
Thanks for the replies guys. Both worked well!
11 years ago