tag:blogger.com,1999:blog-9121642240025958832.post1941735420979853205..comments2024-03-28T22:59:25.233-07:00Comments on Trystan's blog: roguelike tutorial 05: stationary monstersTrystanhttp://www.blogger.com/profile/15653418292042541807noreply@blogger.comBlogger39125tag:blogger.com,1999:blog-9121642240025958832.post-20813073575014793752017-12-11T10:41:26.206-08:002017-12-11T10:41:26.206-08:00I keep getting a nullpointer error for this line
...I keep getting a nullpointer error for this line<br /><br />for (Creature c : creatures){<br /><br /><br />When I debug the program, the application says it can find source. I reviewed the Creature file and did not see a reason to encounter this error. Has anybody else encountered this program as well.Anonymoushttps://www.blogger.com/profile/14930871530648507617noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-2493490804691749972017-11-05T13:02:10.875-08:002017-11-05T13:02:10.875-08:00There is some crucial typos in here (i.e. creature...There is some crucial typos in here (i.e. creature -> Creature). Not really a problem if someone rewrites your code instead of copying it, like I did.<br /><br />List is an interface, I think you should be explicit that a way to initialize it is to provide an implementation, i.e. ArrayList (which you mention later on).izdwuuthttps://www.blogger.com/profile/15481865332001055235noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-56796996311343458772017-10-30T07:17:30.908-07:002017-10-30T07:17:30.908-07:00instantiate the creatures List with:
this.creature...instantiate the creatures List with:<br />this.creatures = new ArrayList();<br />in the World Constructor.<br /><br /> public World(Tile[][] tiles) {<br /> this.tiles = tiles;<br /> this.width = tiles.length;<br /> this.height = tiles[0].length;<br /> this.creatures = new ArrayList();<br /> }<br /><br />you'll also need to import:<br />import java.util.ArrayList;<br /><br />hope it helps. (had the same problem btw. )<br />Anonymoushttps://www.blogger.com/profile/06993218649153434365noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-20091468792948918032017-04-03T01:44:31.037-07:002017-04-03T01:44:31.037-07:00I am in the step before adding the fungus. When I ...I am in the step before adding the fungus. When I run the main application it throws the nullpointer exception:<br /><br />at rltut.World.creature(World.java:58)<br />at rltut.World.addAtEmptyLocation(World.java:50)<br />at rltut.CreatureFactory.newPlayer(CreatureFactory.java:14)<br />at rltut.screens.PlayScreen.(PlayScreen.java:50)<br /><br />How can I fix this? Thanks in advance for your response!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-34180468389002071402015-02-10T14:31:37.200-08:002015-02-10T14:31:37.200-08:00New Comment
To to avoid the copy you could use the...New Comment<br />To to avoid the copy you could use the "CopyOnWriteArrayList" Class for the creatures-array.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-38674256683985137602015-02-10T14:24:36.070-08:002015-02-10T14:24:36.070-08:00I have the same code like you. Works nice and perf...I have the same code like you. Works nice and perfect.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-78561443930151937362015-02-10T14:21:08.388-08:002015-02-10T14:21:08.388-08:00This comment has been removed by the author.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-24720666881665309132015-02-10T14:12:27.358-08:002015-02-10T14:12:27.358-08:00Hi, you can uses this code
public boolean canEnt...Hi, you can uses this code <br /><br />public boolean canEnter(int wx, int wy) {<br /> return world.tile(wx, wy).isGround() && world.creature(wx, wy) == null;<br /> }<br /><br />put it into your Creature.java Class FileAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-25546061268393490822015-01-05T08:29:52.745-08:002015-01-05T08:29:52.745-08:00Where does canEnter come from?
I have a different ...Where does canEnter come from?<br />I have a different class structure so I'll check my alt classes.<br />If not I'll have to make my own canEnter boolean method :PAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-27533991948654356582014-06-05T21:28:20.922-07:002014-06-05T21:28:20.922-07:00Derp, the check also needs a >= clause on the l...Derp, the check also needs a >= clause on the lower bounds for each dimension. If anyone else is stuck on this here is the code I have used, and is now working:<br /><br />private void displayTiles(AsciiPanel terminal, int left, int top) {<br /> //display all the tiles, then loop through creatures and display them if in range<br /> for(int x = 0; x < screenWidth ; x++) {<br /> for(int y = 0; y < screenHeight; y++) {<br /> int wx = x + left;<br /> int wy = y + top;<br /> terminal.write(world.glyph(wx, wy), x, y, world.color(wx, wy));<br /> }<br /> } ///// Up until this point we have just displayed the world tiles, now we will loop through creatures, check if in bounds, and display<br /> <br /> for(Creature c : world.creatures) {<br /> if((c.x >= left && c.x < left + screenWidth) && (c.y >= top && c.y < top + screenHeight)) {<br /> terminal.write(c.glyph(), c.x - left, c.y - top, c.color());<br /> }<br /> }<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-64502290638023177532014-06-05T21:22:39.930-07:002014-06-05T21:22:39.930-07:00Hmmm... should the line that actually writes it to...Hmmm... should the line that actually writes it to the terminal look like this?<br /><br /> terminal.write(c.glyph(), c.x - left, c.y - top, c.color());<br /><br />Otherwise it draws the player on a spot on the screen further away from what it actually is in the game's reality. Only problem is, it doesn't draw the player when they are hard up against the world border. Wonder why that could be... any ideas?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-5822763099701629792014-04-06T12:10:28.890-07:002014-04-06T12:10:28.890-07:00The way I figured I should replace the inefficient...The way I figured I should replace the inefficient bit of the loop was<br /><br />for(Creature c : world.creatureList) {<br /> if((c.x > left && c.x < left + screenWidth) && (c.y > top && c.y < top + screenHeight)) {<br /> terminal.write(c.glyph(),c.x,c.y,c.color());<br /> }<br /> }<br /><br />after making World#creatureList publicAnonymoushttps://www.blogger.com/profile/00747202037048366666noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-11232375185533243252013-11-22T02:32:33.966-08:002013-11-22T02:32:33.966-08:00I already did it :)I already did it :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-36572418471255253832013-11-21T15:37:41.619-08:002013-11-21T15:37:41.619-08:00Awesome tutorial!
But I've got one problem - m...Awesome tutorial!<br />But I've got one problem - my fungus don't appear. I've no idea why :(Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-64973730188775924432013-06-24T03:52:17.492-07:002013-06-24T03:52:17.492-07:00In what way did you modify it? In what way did you modify it? Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-63665714526411388652013-01-23T16:40:34.689-08:002013-01-23T16:40:34.689-08:00That actually is a design choice. Caves that overf...That actually is a design choice. Caves that overflow with fungi is oddly funny to me.Trystanhttps://www.blogger.com/profile/15653418292042541807noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-17594406680360455862013-01-18T22:14:01.019-08:002013-01-18T22:14:01.019-08:00Out of curiosity, maybe this is a "feature&qu...Out of curiosity, maybe this is a "feature", but it looks a bit like a bug. The way the spreadcount mechanic is handled, since the spreadcount is attached to the FungusAi, which gets its own instance each time a new fungus is created, there is no upper limit to how many fungus there could be? Sure there is a maximum of 5 per fungus, but since we keep creating new fungus... DPShttps://www.blogger.com/profile/05479545676995681089noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-37446164910453898762013-01-02T17:55:51.830-08:002013-01-02T17:55:51.830-08:00I tried something like that when I first started p...I tried something like that when I first started playing with roguelikes in java. I gave up on it because I had problems with the input, output, and main loop being on separate threads. Or maybe they weren't on separate threads - I don't remember exactly. Java multithreading isn't my strong suit so hopefully you can make it work. I'm not sure how that would be loosely coupled though. I would still want separate classes to deal with interpreting input, maintaining the current state, and displaying the correct output.Trystanhttps://www.blogger.com/profile/15653418292042541807noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-54733674898637437352013-01-02T17:23:54.759-08:002013-01-02T17:23:54.759-08:00I did some thinking on this. Using a SwingWorker, ...I did some thinking on this. Using a SwingWorker, to create a second thread in the background to handle the main loop, would do the trick. The callbacks from the window send the input to the main loop and the window get the things it has to draw from the second thread. This would make the code even more loosely coupled, which should/would be a good thing in software engineering, atleast I think so.Nakohttps://www.blogger.com/profile/13144908648908833285noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-51967559820675062702013-01-02T07:45:43.402-08:002013-01-02T07:45:43.402-08:00From what I understand of Java - and most modern G...From what I understand of Java - and most modern GUI frameworks - you don't have access to the main loop. The framework controls that and you supply the callbacks and overrides. If you need to know how often it gets updated or repainted then you can track that yourself. The game is still turn based but painting the window happens whenever it's needed: after resizing, after another window is no longer obscuring it, or when we update the game state and tell it to repaint. Having a main loop would make some things easier, but I don't know how to get a window based app to work that way and it goes against how everything else in the framework works.<br /><br />TL;DR: no main loop - just callbacks and overrides.Trystanhttps://www.blogger.com/profile/15653418292042541807noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-49350833920467829002013-01-02T03:01:44.616-08:002013-01-02T03:01:44.616-08:00I've worked through the tut to this point and ...I've worked through the tut to this point and I'm wondering, it seems that you let the window handle the main loop through the update window repaint/paint method. Is there any way to check how often the window gets updated? Until this point, is our tutrl real-time and not turn-based? I find this method of avoiding a main loop a bit confusing.Nakohttps://www.blogger.com/profile/13144908648908833285noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-9393857720019695142012-11-15T02:01:19.800-08:002012-11-15T02:01:19.800-08:00could you show me an example of the code you said ...could you show me an example of the code you said you SHOULD have wrote. please :)<br />sylvesterhttps://www.blogger.com/profile/16033717232824194563noreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-61252993383254499572012-05-09T19:13:41.175-07:002012-05-09T19:13:41.175-07:00I actually figured it out. I modified the update ...I actually figured it out. I modified the update script in the creatures to run only if the player can see them, and if the player couldn't they now just wander. This increased speed to a point where I quadrupled the size of the map and the amount of enemies and it was lagging about 10% what it did before. Just a tip for anyone who runs into a any lag issues.Lukasnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-31273420110290735092012-05-08T18:54:14.001-07:002012-05-08T18:54:14.001-07:00I finished the tutorial by the way, and I remember...I finished the tutorial by the way, and I remember the creature class got modified so it returned the creatures glyph, that way we just looped through all the spaces and set the spaces glyph instead of looping through both... Is there any changes that should be made to that to improve speed? I don't see anything looking at it right now, but I'm probably not even half the programmer you are :). I'm talking about the update that was made in tutorial 8 (the one with FOV and stuff.)Lukasnoreply@blogger.comtag:blogger.com,1999:blog-9121642240025958832.post-84165493123389178602012-05-08T18:47:06.307-07:002012-05-08T18:47:06.307-07:00Alright, thanks! I'll try that tomorrow. Than...Alright, thanks! I'll try that tomorrow. Thanks for answering!Lukasnoreply@blogger.com