Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Newbie & Debugging Questions / How would I make one of the tiles disappear from this array? on: 2014-11-20 16:58:38
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public TileGrid() {
      map = new Tile[20][15];
      for(int i = 0; i < map.length; i++) {
         for (int j = 0; j < map[i].length; j++) {
            map[i][j] = new Tile (i * 64, j * 64, 64, 64, TileType.futurefloor);
         }
      }
   }
   
   public void Draw() {
      for (int i = 0; i < map.length; i++) {
         for (int j = 0; j < map[i].length; j++) {
            Tile t = map[i][j];
            DrawQuadTex(t.getTexture(), t.getX(), t.getY(), t.getWidth(), t.getHeight());
         }
      }
   }


I've moved from Java software rendering to LWJGL which someone suggested on one of my newb posts, I'm finding it more fun and effective. I've got a question here about a tilemap array I've managed to draw to the screen.

 How would I go about removing tiles, lets say upon a mouse click?

Thanks
2  Game Development / Newbie & Debugging Questions / Re: 2D Destructable Terrain / Lemmings / Worms... The easiest way? on: 2014-11-19 12:32:18
manipulate pixels for terrain and set pixel rgb to what ever when blowtorch is near pixels

And I'm guessing this would be using pixel data for collision? So when the player hits the terrain in some form, you'd use a method like 'getPixelData()' which would return the current pixels, then use something like 'deletePixels()' ?
3  Game Development / Newbie & Debugging Questions / 2D Destructable Terrain / Lemmings / Worms... The easiest way? on: 2014-11-19 11:45:13
I have done some research but I'm having a difficult time understanding

What would be the simplest way to make a sprite/object 'rub out' the terrain. I'm guessing from research you would use alpha channels?

For example,

One sprite player controlled with WSAD
Simple bitmap as the terrain that the player walks along with collision
Background with stars/sun/moon or whatever

The player walks/runs along the terrain and decides to dig like lemmings by pressing the mouse on them, or the worm walks along and you press it for the blowtorch

How would you put this into code?
4  Discussions / Miscellaneous Topics / Re: The C family, should I dig deeper? on: 2014-11-13 23:29:58
C is great for microcontrollers which is my 2nd best thing from Java, MikroC for PIC is my IDE of choice which is ace (Although the latest versions have gone a bit over the top of my head). I'd suggest if you have the money to proberbly invest in a second hand kit, its not really that expensive considering. You'll probably find a development board around the same price as as a full on Arduino kit.

I'm mentioning this due to the fact I've learned a hell of a lot with C and some basic ARM/PIC assembly, not an expert but it helps understand the 'computer' in 'science'. basic I/O, interfacing.

This is proberly why they use C for GL shaders, because its the lowest language to the machine which where OpenGL is interfacing with the 'hardware' - again, I'm pretty new to Java2D not to mention OpenGL

I've seen your replys to my posts regarding Java 2D lately since I've joined and you seem to know the score when it comes to the subject so I would certainly recommened using something like C with microcontrollers rather than the Arduino with its own C++ librarys because trust me, you wouldn't learn as good from this, its hard to explain but its like in comparison 'Processing' vs 'Java2D in Eclipse' with... 'Arduinos C++ vs MikroC / ASM with PIC/AMTEL' --- Mentioning this just incase you did want to delve into it.

I hope this helps, I feel I need to share 'what I know' to contribute to your efforts with my problems Smiley

EDIT: Also, my favourite book out of my C collection to understand it in lamers terms, or if things get a bit rusty - "Head First C", explains things clearly in diagrams, pictures. Some book people would shrug themselfs upon but if your open minded it does the job.
5  Game Development / Game Play & Game Design / Re: Any decent links to Java2D / BufferedImage / Math type FX tutorials? on: 2014-11-13 19:44:38
Thanks for the excellent response and agreed on the presentation/intro, also, when starting his videos he goes on to much about his life mostly, then your itching to get on with it - I like to download the YT videos so I have more control on the pausing, double screen issues etc. So when your watching one after another, he should of thought about this in the first place for people downloading them for future reference, they'd be worthless putting onto your project drive for that purpose because you'd be hearing 'his missis has just had a fight with his mum over the cat she ran over on a night out when he was hungover in town the other day'

On your reponse regrading the timers, you might be able to help me out here. You don't sound so bad now you've shed a bit more detail, I'm new to this so can be awkward.... On the timers when you mentioned animation how the hell does a BufferedImage created a whirl of pixels when chernos not created a paint method? All he did was create a bufferedimage in memory by the look of it... Best example would be looking at that video I posted above, once I've cracked how to view pixels from the BufferedImage then I can use these timers we mentioned to create cool stuff, I made a post the other day richy and gibbo helped us with but that was packing pixels into an interger... But cherno seems to have created pixels straight from the bufferedImage and put it into an array then timed/looped it to create what he did in the video.

If you could shed some light on this that'd be great and that'd be the topic solved, as from then all I'd need to do is look up formulas and port the code if this makes sense... from things like bufferedimage rather than paint.drawLine etc

Hope this makes sense

EDIT: I forgot to add, how hes displaying coloured pixels from bufferedimage that is, any small example code would be greatful, just in one method so I could understand it...
6  Game Development / Game Play & Game Design / Re: Any decent links to Java2D / BufferedImage / Math type FX tutorials? on: 2014-11-13 17:31:49
Already know about that, I'm always studying Java. I've also played all of his others, that fedora cap game, minicraft, miners4k etc. Hes got cool ideas but didn't cherno clearly states that hes inspired from notchs idea and that there friends? Notch also used ideas for minecraft from that space block game, Bill Gates used ideas from altair, Steve Jobs used ideas with the mouse thing, everyone 'steals' ideas, its all to do with putting the work down and making it evolve n if it turns out more user friendly and people seem to get on with it more and find it more fun (flappy bird for example) your onto a winner. I mean, someone invented electricity but someone would of found out about it eventually but the bloke whos not on alive anymore still recieves all the credit for it, now its evolved.

Nearly all simular tutorials by different people use the tick method on top of the fps algorithm, from a beginners point of view, I'd say thats how Java game programming evolves in general, just like an electro house or dubstep producer using sample packs from third party sources.

I don't want to start a debate, I've not used this forum very long. It's all been so welcoming and very helpful so far, its helped me improve but I don't want you to take this the wrong way but your responses seem a little grumpy from what I've seen around the forum.
7  Game Development / Game Play & Game Design / Re: Any decent links to Java2D / BufferedImage / Math type FX tutorials? on: 2014-11-12 20:09:26
[snip]

TheCherno is a terrible tutor and is highly inexperienced. Don't watch his tutorials unless you want to destroy a few IQ points.

- Jev

I found he explains things a lot more than just coding than many I've seen on youtube, yeah he can hault and stall a lot "ok, ok, sooo ok, right, right" but tbh he does go into detail and has helped me.

Then you have the show offs just using notepad who just storm through it with no explaination and call it a tutorial.

Each to there own taste, if you have anything to share topic related please let me know...

- C
8  Game Development / Game Play & Game Design / Re: Any decent links to Java2D / BufferedImage / Math type FX tutorials? on: 2014-11-12 10:47:13
Thanks for the advice, I'll give it a whirl when I boot up GameMaker  Roll Eyes

Heres a good one I found yesterday which is interesting, start of a pure Java 3d game tutorial testing out the start of the engine:

<a href="http://www.youtube.com/v/dwn_UrItwfw?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/dwn_UrItwfw?version=3&amp;hl=en_US&amp;start=</a>
9  Game Development / Game Play & Game Design / Any decent links to Java2D / BufferedImage / Math type FX tutorials? on: 2014-11-12 10:18:04
As the subject asks,

I'm obsessed with creating display/images with Java alone, like random pixels in an array that displays on JFrame, a bit like what 'processing' does but I'm looking for decent links that deal with just Pure Java in like eclipse/netbeans if anyone could help us out? At the moment I'm only able to created random images, but there must be something around that deals with maths to create 'more less-random' images - maybe using the math class etc? For example, mandelbrots etc

Cheers
10  Game Development / Newbie & Debugging Questions / Re: 2D Array with ArrayList for map on: 2014-11-12 09:25:04
Seems like a cool ''newbie'' (Should I say) project your working on, its a simular sort of question I've been meaning to ask. Please post the game when its finished! Especially with you working on tilemap arrays rather than using tiled etc. I love the whole idea of doing everything in Java.

And I know what you mean about taking steps back etc, I get the same feeling, but just enjoy learning thats what I always say. it'll prob just get boring if you knew over 90%
11  Game Development / Newbie & Debugging Questions / Re: How many different ways of creating Pong in Java on: 2014-11-11 20:07:29
From what I know so far, you can achieve making collision detection using the Rectangle class, and making a getBounds method with some if statements.

I've been learning ArrayLists for storing objects, so from my knowledge so far... I could create about 3 various versions of a simple pong from my 'Based on' list..

I was just looking for inspiration really, I hardly no anyone in real life who does this so it can be quiet tempting to ask these sort of questions n can get lonely (bless me!)

So to people where this topic doesnt make sense, what other ways could you program pong with various Java classes that could be used?? I've mentioned what I know above, I'm yet to study hashmaps as I see them a lot in games. <--- I think this question is more approprate btw

I think using pong as an example is more better than lets say, chess... topic friendly straight to the point kinda thing...
12  Game Development / Newbie & Debugging Questions / How many different ways of creating Pong in Java on: 2014-11-11 15:53:42
This is a very curious question, which would inspire me based on the possible replys I might get. More influence I'd say though.

I've not been programming in Java for that long, I've found it harder to learn than most people but still I have faith. I know this may be a stupid question but on estimate, it doesnt have to be correct but explainations would be a bonus, how many ways could you program a basic game like pong?

Based on:
1. Any size
2. Has Score
3. AI or 2 player (2 sets of keys) (I know this ones gunna add to it!)
4. No title screen
5. No third party library

Kinda make sense now?

My main interest is how someone would be ArrayList for objects and others using other methods, if you get me... I've asked this question before, on another forum though but it wasnt gaming based.

Like I say, answers to this question is going to help personally when the confidence level drops, we must all have that time some days where you feel you arnt learning as much!
13  Game Development / Newbie & Debugging Questions / Re: Image Effects on: 2014-11-11 11:41:52
Sorry if this has been posted twice, its a big topic but I've just came across this which is useful using LWJGL & Java

https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6
14  Discussions / General Discussions / Re: Worried, Scared. Life wasted? [ANSWERED] on: 2014-11-11 10:27:52
I don't want you to take this the wrong way but I'd suggest not to look at the fame and money side of it and just do it to enjoy it while applying for development/web jobs while working on your hobbie in your spare time and get into that moment where you loved to learn, they say that if you program your whole life you'll never know everything so if you've near enough mastered Java, or you think you have. Learn something like C / C++ / ASM and enjoy it like you enjoyed learning Java.

Just be happy with who you are, be happy with learning, you've got lots of time ahead of you to not worry about being 'at the bottom' - No ones at the bottom, some people get lucky with there craft and trust me, being really 'big' at something can be more hassle than its worth. Jealousy, hate mails, going bankrupt, market going downhill, which could lead to actually hating what you've achieved and wished you just stayed with who you really was as a laid back enjoyable hobbiest. Don't get me wrong, there is the positives in having a big rep but you'll realise when its time to settle down and start a family (which we all do!) you'll then realise what all the fuss was about.

Carry on enjoying it and you never know, you might have that top 'notch' idea! But don't fight with your own mind it'll happen, just stay focused.
15  Game Development / Newbie & Debugging Questions / Re: Bitshift Operators in RGB values? on: 2014-11-11 10:18:08
@CodeHead Math.random() returns a value less than 1, so it does need to be multiplied by 256 to produce values in the range 0...255.99999, which then give equal probability of 0...255 when cast (truncated) to int.

Quite correct. I blame it on not having my morning caffeine fix when I typed that. I was forgetting a type cast to an int functioned more like a floor than a round. My apologies. Smiley

I seem to drink a lot more coffee and energy drinks since I got bang into programming, they go well together.

@quew8 -- Thanks very much for that link you posted, I've bookmarked it. And I'd suggest anyone reading this for future reference to read SHC post:

To store a value of 255, you need 8 bits size. The purpose of this, is to simply package them into a single 32 bit package. (java int is 4bytes, giving you 4*8=32 bits). The idea is to represent every 8-bit value in 32-bits and simply, or them.

Let's take an example. We have a color in ARGB format as (100, 255, 50, 158) and you need to package them into a single ARGB integer. First, we see the bit versions of those integers.

1  
2  
3  
4  
   A: 0000 0000 0000 0000 0000 0000 0110 0100
   R: 0000 0000 0000 0000 0000 0000 1111 1111
   G: 0000 0000 0000 0000 0000 0000 0011 0010
   B: 0000 0000 0000 0000 0000 0000 1001 1110

So, now if you OR them, the contents will be damaged and cannot be retrieved. So we shift the bits, in-order to place all them in the same single 32-bit package. First, we shift A by 24 bits to make it the first in the package. We shift R by 16 bits to make it second, G by 8 bits to make it third. We don't shift B since it is already in place. After doing that, the values look like this.

1  
2  
3  
4  
   A: 0110 0100 0000 0000 0000 0000 0000 0000
   R: 0000 0000 1111 1111 0000 0000 0000 0000
   G: 0000 0000 0000 0000 0011 0010 0000 0000
   B: 0000 0000 0000 0000 0000 0000 1001 1110

Finally, you OR them together to package them into a 32-bit ARGB integer. So the ARGB looks like this.

1  
ARGB: 0110 0100 1111 1111 0011 0010 1001 1110

That's the ARGB integer. This is the way you follow to pack the integers. Instead of just applying this, pay an attention to the pixel format, in this case, it is ARGB. There are also other formats like ABGR, RGBA, BGRA, etc., The shift to be done depends on the pixel format you are packing into. By the way, the value of that integer in decimal system is (1694446238)10 very large, isn't it?

Hope this helps.

Explains visually how they are shifted which is where I got stuck on, I couldn't quiet visualize this which led me to confusion. The + | OR's are a bit confusing but I guess thats how its rolls as Richie explained.

Think the Topic has been cracked Smiley
16  Game Development / Newbie & Debugging Questions / Re: Bitshift Operators in RGB values? on: 2014-11-10 16:06:41
Got it thanks a lot.

I never knew it'd be that technical, I've done some ASM on 6502, not much but knowing 'some' made me understand this.

Technical as in tweaking the value like that with an integer, in Java. I only really know:

int a = 1;
int b = 2;
int c = a + b;

So in reality, its tweaking values of the binary values at its address (kind of... stack isnt it?)

The | OR still confuses me, I'd of thought you would use & to join the numbers together into one int...

@CodeHead - as Richierich says, is why I added 256
17  Game Development / Newbie & Debugging Questions / Re: Bitshift Operators in RGB values? on: 2014-11-10 14:18:56
4 8-bit values packed into a 32-bit package.

And how does that work? Please be more specific if possible, How can it be packed if it has the bitwise OR | ? Thanks
18  Game Development / Newbie & Debugging Questions / Bitshift Operators in RGB values? on: 2014-11-10 12:48:07
I've been trying to figure this out for a while, I've come to terms with a lot of things thanks to this forum and I always do a good google search before I ask here but they seem to be quiet hard to understand hence asking so if someone could please explain why the bitshift operators are needed in this random pixel generator:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
         
      File f = null;
      for(int y = 0; y < height; y++) {
         for(int x = 0; x < width; x++) {
           
            int a = (int)(Math.random()*256); //alpha
            int r = (int)(Math.random()*256); //red
            int g = (int)(Math.random()*256); //green
            int b = (int)(Math.random()*256); //blue

           
            int p = (a<<24) | (r<<16) | (g<<8) | b;  //<<<------HERE
           
            img.setRGB(x, y, p);
           
         }
      }


I notice this ususage with a lot of tutorials and its where I'd normally get confused with, what is its purpose? When I took away the operators it was giving me an image of some kind. I know that if the value is 40 in binary it shifts by 1,2,3,4,5,6 along the 010101000(i.e ?40) if this makes sense but what is the purpose here for these RGB values? Thanks
19  Game Development / Newbie & Debugging Questions / Re: Confused with BufferedImage on: 2014-11-07 18:03:42
Thanks, I think this will be the last question regarding the subject....

If the BufferedImage is an array of pixels of 800x600, then how would you print out the values out of interest to the log/console/sysout.... I tried this before but gave me some hex number which I'm guessing is some kind of memory address for the VM
20  Game Development / Newbie & Debugging Questions / Re: Confused with BufferedImage on: 2014-11-07 16:17:52
How does a BufferedImage compare to a Canvas? Isn't this to do with flickering, are they simular classes with simular methods but a does better than b? Cheers
21  Game Development / Newbie & Debugging Questions / Re: Confused with BufferedImage on: 2014-11-07 15:04:20
Ahhh, thanks peeps! I love this forum... Hit the nail on the head here...

So if I'm correct, working with pixel arrays, per pixel as in for example... this.setSize(800,600); in a constructor(obviously) <--- You would have access per pixels? 800 * 600 is 480000 pixels, so using the setPixel method BurntPizza mentioned you could add a red pixel after you have created a BufferedImage object on the empty canvas?


And going a bit far here.... lets say in the future I'd be able to create effects destructable terrain working with pixel arrays?

I like and prefer the idea of working at a pixel array level rather than what you call 'blitting' so you 2 have mentioned it quiet well so thanks
22  Game Development / Newbie & Debugging Questions / Confused with BufferedImage on: 2014-11-07 11:03:54
I have googled and youtubed. But, I learn much easier from this forum so here we go...

My last post I asked about animation which I've near enough cracked to the point I can code from scratch a JFrame and do some bouncing balls etc...

I've been struggling and confused for a while now with this BufferedImage thing, I've been watching tutorials and there is many on java game programming on youtube as you may all know. But when it gets passed setting up the fps counter loop, basic setup engine, screen etc and gets onto the bufferedImage and pixel thing I'm lost and like I say I have to been googling but still dont get it. Things like:

1  
var = ((DataBufferByte) m_displayImage.getRaster().getDataBuffer()).getData();


and...

1  
2  
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
         BufferedImage.TYPE_INT_RGB);


At the moment Im guessing it creates a blank image onto the canvas but obviously theres more to it? Why do they setup a pixel array when you could add sprites with Image? Eventually though I'll be wanting to draw sprites with code like they do on Java4K I'm always mentioning on my posts, I'm in no competion about this I just find it fasinating using pure Java so no replys on other game engines please.

If you could enlighten me on this subject so I can understand it better that would be excellent....
23  Game Development / Newbie & Debugging Questions / Re: Calling all Experienced Java Programmers.... on: 2014-11-02 13:18:59
We have rockstar games where we live in this town

Little off-topic, Edinburgh? I can literally see the building from my street.

Naa mate, Lincoln UK - I think its more a test than dev though. I know there were some jobs going advertising for experienced gamers who can finish a game on hard settings when GTAVI was in development. I didn't bother applying though, I'm not really good with games I'm just fascinated by the technical side of it. Nice to see your from the UK though (and 'off topic' I thoughts are the votes were rigged!!) I thought it would be mostly american on here but I guess thats just me being steretypical in a sense, probably because I started off on Java Ranch!!
24  Game Development / Newbie & Debugging Questions / Re: Calling all Experienced Java Programmers.... on: 2014-11-02 11:27:07
Thanks peeps - and thanks especially for that long previous post Gibbo, philfrei was inspiring and a bit of a kick for swing- just what I needed. I have actually read the Game Loop Topic before - Like I say I just wanted some response from it, some views. I've been signed up for a while now and not made many posts, I don't know anyone locally to hook up with to talk about stuff like Java with so had this in mind. So apologises if the questions have been asked numerous times before, I have checked things like this up, but its just what I said really ^^^

We have rockstar games where we live in this town but Gaming isnt something I 100% want for a career, I wouldnt mind if its applications but Ive read places that learning game programming is a bonus if your wanting to get into applications/web (tomcat etc)

If theres anything anyone else would like to share regarding Graphics2D, Graphics g, paint() etc with loops for animation that'd be wicked. I basically have Java4K on my head, its so fasinating! Plus the pure Java on lundum dare. And no, as much as Notch is inspiring its not something I'm trying to copy just incase your wondering why because of the subjects I've chosen Smiley
25  Game Development / Newbie & Debugging Questions / Re: Calling all Experienced Java Programmers.... on: 2014-11-02 02:07:56
I totally agree. Java2D is deprecated, and uses a thing called 'software rendering'.

Java2D is not deprecated. It just isn't ideal for games because it doesn't take advantage of the graphics card. Although I think that JavaFX is aimed at replacing it? I'm not too sure on that though.

Yes, there pushing JavaFX more to replace swing so I've read numerous places and quiet official as well...
Quote

@OP If you're just talking about a general Java career (not gaming oriented), then don't worry about LibGDX. Instead, learn Swing (Others who are in the profession can tell you much more about what you should learn than I can). Also, keep learning about Collections no matter what route you take!

Yes, This is what I am doing from my 'OP'



26  Game Development / Newbie & Debugging Questions / Re: Calling all Experienced Java Programmers.... on: 2014-11-02 01:04:43
Thanks for the quick responses. I know about OpenGL, I've got loads of books on it C++ etc. I know about Slick2D, LibGDX, LWJGL (as we all know Notch implemented with minecraft). I must have over 100GB of tutorials on them downloaded from youtube etc from when I got cut offline to keep myself busy. Among other game theory books on other engines, unity, udk, cryengine

But my question was more aimed towards my peoples way of just creating a moving animation as described as my original post using pure java's 'Software Renderer', how do you know I'm not interested for future entrys for the Java4K comps? I mentioned that my interest in Gaming was to add more skill to possible future Java careers where I live and there is many. I don't mean to be fussy or come across cocky here but I really wanted answers and example code of simple things like described - peoples coding techniques of what I mentioned..... For instance I was watching a tutorial today which was very different as they used collections for storing objects for there game and I've only just started studying collections in Java and got lost, I know about Vectors and Iterators in C++ 11 though when I've been using QT but Java is fasinating

Also, thanks for the Pong and Space Invaders ideas, but if anyone could please demo the code I've mentioned plus some other ideas on some swing gui mini game ideas or whatever that'd be great !!  Grin
27  Game Development / Newbie & Debugging Questions / Calling all Experienced Java Programmers.... on: 2014-11-02 00:26:46
Just have a keen few questions I have been thinking about posting for a while now, I've been learning Java on and off for a few years now and lately bang on it hours on end as I'm looking for a career with the language itself eventually. Its really good fun learning.... Anyway... I'm learning Java game development for practice and need some tips on what projects to start work with, I know theres pong, I need really simple ideas really... What steps should I take when learning basic animation with keyboard input (obviously using the KeyListener class as I know about this).

The thing is, I struggle with making something move, I can make an JFrame window so far coding from scratch and implementing JButtons, JSliders with the ActionListener etc. But if someone could be so kind and give me some examples, from different people if possible... So I've got some confidence that there is multiple ways of doing something when it comes to OOP...

Like example of a bouncing ball in lets say, setSize(600,480) JFrame window or something, then (OPTIONAL) some keyboard input with a second drawn box if you could be so kind to share the knowledge! It is something I am really stuck with, I'm always thinking its as easy as just setting up some method or class, but when I'm looking at tutorials for bits like this it goes into x,y,vel,gravity etc etc which is some logic side of Java 2D Graphics side of it I'm struggling with like I say.

Thanks fellow programmers! Smiley
28  Game Development / Newbie & Debugging Questions / Re: How to make sprites in Java possibly using Arrays? on: 2014-01-14 23:37:46
@ Lcass....

Could you give me code above that I could actually run? Its ok explaining things in code but theres no example to run for me to understand..... Thanks for trying though. You must be good no doubts, i can kind of understand it but if i cant see what its doing im never gunna learn from ur efforts of explaining......
29  Game Development / Newbie & Debugging Questions / Adding More Animations on a Single JFrame on: 2014-01-13 18:47:05
No one could help me on another post but here we go:

If anyone can help with this code I basically started with adding the Spooky class like I say then went to the top of the code and got stuck on the getContentPane which isn't allowing me to add 2 lines of that to add 2 of the shapes to animated...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class test extends JFrame {

   public Gunman g = new Gunman();
   public Spooky j = new Spooky();

   public static void main(String[] args) {
      test t = new test();
      t.setSize(800, 600);
      t.setVisible(true);
      t.getContentPane().add(t.g);
      t.setBackground(Color.DARK_GRAY);

      while (true) {
         t.g.x = t.g.x + 1;
         t.g.y = t.g.y + 1;
         t.repaint();
         try {
            Thread.sleep(50);
         } catch (InterruptedException e) {
         }
      }
   }

   public void paintComponent(Graphics g) {
      g.clearRect(0, 0, 800, 600);
   }
}

class Gunman extends JComponent {

   // private static final long serialVersionUID = 1L;
   public int x = 20;
   public int y = 20;
   public int width = 20;
   public int height = 20;

   public void paintComponent(Graphics g) {
      g.setColor(Color.blue);
      g.fillRect(x, y, width, height);
   }
}
   class Spooky extends JComponent {
      public int x = 30;
      public int y = 30;
      public int width = 40;
      public int height = 50;

      public void paintComponent(Graphics g) {
         g.setColor(Color.RED);
         g.fillOval(x, y, width, height);
      }
   }


---- ORIGINAL CODE ----

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class Test extends JFrame {

    public Gunman g = new Gunman();

    public static void main( String[] args ) {
        Test t = new Test();
        t.setSize( 800, 600 );
        t.setVisible( true );
        t.getContentPane().add( t.g );

        while ( true ) {
            t.g.x = t.g.x + 1;
            t.g.y = t.g.y + 1;
            t.repaint();
            try {
                Thread.sleep( 100 );
            } catch ( InterruptedException e ) {
            }
        }
    }

    public void paintComponent( Graphics g ) {
        g.clearRect( 0, 0, 800, 600 );
    }
}


class Gunman extends JComponent {

    private static final long serialVersionUID = 1L;
    public int x = 10;
    public int y = 10;
    public int width = 8;
    public int height = 10;

    public void paintComponent( Graphics g ) {
        g.setColor( Color.red );
        g.fillRect( x, y, width, height );
    }
}


^^ You should see where I was going with it

Apologies for posting simular on another topic I made but I didn't get any response on that reply. I've learned a hell of a lot though from you people over the last week with helpful links, I'm glad I've joined!  Smiley
30  Game Development / Newbie & Debugging Questions / Slick2D Test Files Not Working / Compiling on: 2014-01-13 15:35:33
I have tried google but no luck, often I want a break from learning things from scratch and have a crack at Slick2D library, I want to look and load the test files but when I try to load something like... AnimationTest.Java it says:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

   at slick.tutorial.AnimationTest.main(AnimationTest.java:100)

Which is this line:

100: public static void main(String[] argv) {

I've tried alsorts but this should ideally work? it has the main method, no other errors. I just want to be able to load up examples and learn from it.

Thanks
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xFryIx (52 views)
2014-11-13 12:34:49

digdugdiggy (34 views)
2014-11-12 21:11:50

digdugdiggy (28 views)
2014-11-12 21:10:15

digdugdiggy (23 views)
2014-11-12 21:09:33

kovacsa (46 views)
2014-11-07 19:57:14

TehJavaDev (50 views)
2014-11-03 22:04:50

BurntPizza (49 views)
2014-11-03 18:54:52

moogie (65 views)
2014-11-03 06:22:04

CopyableCougar4 (63 views)
2014-11-01 23:36:41

DarkCart (148 views)
2014-11-01 14:51:03
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!