Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (206)
games submitted by our members
Games in WIP (781)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 3 4 [5] 6 7 ... 10
 41 
 on: 2017-01-16 06:50:30 
Started by Vierarmig - Last post by Vierarmig
<a href="http://www.youtube.com/v/y-O8p0M_2PE?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/y-O8p0M_2PE?version=3&amp;hl=en_US&amp;start=</a>
https://youtu.be/y-O8p0M_2PE

 42 
 on: 2017-01-16 04:42:11 
Started by DayTripperID - Last post by philfrei
Quote
Whew! Java sure is verbose. Anyway, I was wondering if anybody had a good explanation of the difference between <? super >and <? extends>. I googled around and found some explanations, but it didn't really sink in for me.

They are kind of like a greater than or less than, but referring to the extends chain. One gets the class and all super classes, the other gets the class and all sub classes.

 43 
 on: 2017-01-16 00:49:36 
Started by orange451 - Last post by orange451
Seems to be working fine for me. I changed the download link as we talked about in our PMs Smiley

 44 
 on: 2017-01-15 23:39:03 
Started by BurntPizza - Last post by theagentd
Finished my last exam! Now I just have a small essay left and I'm freeeeeee... until school starts again on Tuesday...

 45 
 on: 2017-01-15 22:15:38 
Started by DayTripperID - Last post by DayTripperID
OK, so I implemented generic typing on MobState and it worked swimmingly:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public interface MobState<T extends Mob> extends Visitable, Visitor {
   
   public MobState<T> init(T t);
   
   public MobState<T> update();
   
   public void render(Screen screen);
   
   public void processCollision(Mob m);
   
   public T getMob();
   
   public void setMob(T t);
   
   public Visitor getVisitor();
}


So now Mob looks like this (Minus a bunch of fields and methods irrelevant to the thread, to save space):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public abstract class Mob {
   
   private MobState<? extends Mob> ms = null;
   
   private double x = 0;
   private double y = 0;
   
   public Mob(int x, int y) {
      this.x = x;
      this.y = y;
   }
   
   public final MobState<? extends Mob> getMobState() {
      return ms;
   }
   

   public final void setMobState(MobState<? extends Mob> s) {
      ms = s;
   }
}


And an example of a concrete MobState object looks like this:

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  
public class BrickStateSolid extends AbstractMobState<Brick> {
   
   private Brick brick = null;
   
   @Override
   public MobState<Brick> init(Brick b) {
      brick = b;
      brick.setCol(0x808080);
      return this;
   }
   
   @Override
   public MobState<Brick> update() {
      return this;
   }

   @Override
   public void render(Screen screen) {
      int c = brick.getCol();
      int x = (int)brick.getx();
      int y = (int)brick.gety();
      int w = brick.getWidth();
      int h = brick.getHeight();
     
      for(int i = 0; i < brick.getHeight() / 2; i++) {
         screen.drawRect(x++, y++, w, h, c);
         w -= 2;
         h -= 2;
         c -= 0x202020;  
      }
   }

   @Override
   public void processCollision(Mob m) {
      accept(m.getMobState().getVisitor());
   }

   @Override
   public Brick getMob() {
      return brick;
   }

   @Override
   public void setMob(Brick b) {
      brick = b;
   }
   
   @Override
   public void visit(BallStateNormal visitable) {
      Ball ball = visitable.getMob();
      brick.bounceBall(ball);
   }

   @Override
   public void accept(Visitor visitor) {
   }
}


Advantage: no type casting and no "instanceof", meaning bad type-checks are caught at compile time.
So something like MobState<Ball> mobState = new PlayerStateAlive().init(player); won't compile, and once the type is set, there is no way to pass a bad object to a visitor object.

Disadvantage: kind of hard to read if you aren't used to it. Specifically, I'm using <? extends Mob> in the Mob class, which is apparently the right one, because <? super Mob> generates this error at the return statement of MobState<? super Mob> getMobState(MobState<?super Mob>):
1  
Type mismatch: cannot convert from MobState<capture#1-of ? extends Mob> to MobState<? super Mob>


However, <? super Mob> generates NO error in setMobState(MobState<? super Mob> ms)

<? extends Mob> was my first guess, but I tried <? super Mob> for the hell of it, and I really have no idea what the difference between the two is, other than I used <? super Object> in a data structures class that used it in a binary node interface:

1  
public interface BinaryNodeInterface<T extends Comparable<? super T>>


Whew! Java sure is verbose. Anyway, I was wondering if anybody had a good explanation of the difference between <? super >and <? extends>. I googled around and found some explanations, but it didn't really sink in for me.

EDIT: as it turns out, the reason I was getting an error in MobState<? super Mob> getMobState() was because I hadn't set the type of the ms field to MobState<? super Mob> and it was still MobState<? extends Mob>. Once that was corrected, <? super Mob> still generated compiler errors wherever I actually tried to set the MobState:

1  
2  
MobState<Brick> mobState = new BrickStateDestructible().init(brick);
      brick.setMobState(mobState);


The above statement would generate the error:

1  
The method setMobState(MobState<? super Mob>) in the type Mob is not applicable for the arguments (MobState<Brick>)


Simple enough: keep it <? extends Mob>. My best understanding is that with <? super Mob> brick.setMobState(mobState) would only accept  of MobState<Mob> and not MobState<Player>, MobState<Ball>, etc. Since Mob is not specific enough, I don't think that would be very useful, as it would defeat the purpose of what I'm trying to accomplish in the first place.

 46 
 on: 2017-01-15 20:23:39 
Started by DayTripperID - Last post by delt0r
And all this discussion, interesting discussion at that, could be solved with double dispatch.

The visitor pattern, indeed quite a few of the GoF patterns solve problems that often functional languages solve directly.  Having said that double dispatch is not in many. Lisp and in particular CLOS in lisp and its derivatives.

In fact the Entity system i use does sort of do Generic methods like CLOS. It works pretty good.

 47 
 on: 2017-01-15 19:05:11 
Started by buddyBro - Last post by Archive
Added ships, i.e. moving cluster of blocks. There's graphical bug with some surfaces being drawn on top of other surfaces when they shouldn't be, but I hope to fix that soon.
You don't have a z-buffer?

Edit: just remembered that you use java2d

 48 
 on: 2017-01-15 19:00:21 
Started by buddyBro - Last post by buddyBro
Added ships, i.e. moving cluster of blocks. There's graphical bug with some surfaces being drawn on top of other surfaces when they shouldn't be, but I hope to fix that soon.

<a href="http://www.youtube.com/v/fsdF4Uid7BM?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/fsdF4Uid7BM?version=3&amp;hl=en_US&amp;start=</a>

 49 
 on: 2017-01-15 18:00:45 
Started by orange451 - Last post by TGStudiosDE
Could anyone download it ? Smiley

 50 
 on: 2017-01-15 13:27:44 
Started by BurntPizza - Last post by delt0r
So i have a video showing debug/placeholder effects, a dev map and all the rest that is implied with pre alpha.
<a href="http://www.youtube.com/v/Jox1h9Vsrnw?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/Jox1h9Vsrnw?version=3&amp;hl=en_US&amp;start=</a>

Pages: 1 ... 3 4 [5] 6 7 ... 10
 
Galdo (308 views)
2017-01-12 13:44:09

Archive (468 views)
2017-01-02 05:31:41

0AndrewShepherd0 (929 views)
2016-12-16 03:58:39

0AndrewShepherd0 (869 views)
2016-12-15 21:50:57

Lunch (1001 views)
2016-12-06 16:01:40

ral0r2 (1232 views)
2016-11-23 16:08:26

ClaasJG (1333 views)
2016-11-10 17:36:32

CoffeeChemist (1349 views)
2016-11-05 00:46:53

jay4842 (1430 views)
2016-11-01 19:04:52

theagentd (1227 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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!