Show Posts
|
|
Pages: [1] 2
|
|
4
|
Java Game APIs & Engines / Java 2D / Beginnings of a Slick2D weather class
|
on: 2012-12-21 23:58:29
|
All, I wanted to share with you a quick class I drummed up based on examples I found on the Internet. This class will add lightning and rain to your game. It has several modes. You can set no rain, rainy, windy_rainy, and no storm, stormy and very stormy. Stormy level controls the amount of lightning. It is catered after the Slick2D interfaces... Initialize it, call update() in the update() loop call render(g) in the render() loop Hope someone finds this useful 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
| package slicktest;
import java.util.Random; import org.newdawn.slick.geom.Vector2f; import org.newdawn.slick.opengl.SlickCallable; import org.newdawn.slick.Color; import org.newdawn.slick.Graphics;
public class StormManager { public static final short numdrops = 900; public static final byte NO_RAIN = -1; public static final byte HARD_RAIN = 0; public static final byte HARD_WINDY_RAIN = 1; public static final byte LIGHT_RAIN = 2; public static final byte LIGHT_WINDY_RAIN = 3; public static final byte NO_STORM = -1; public static final byte RAINY = 0; public static final byte STORMY = 1; public static final byte VERY_STORMY = 2; public float WINDY_RAIN_X_CHANGE=-1.0f; public float HARD_RAIN_Y_CHNAGE = 4.0f; public float SOFT_RAIN_X_CHANGE = 0.0f; public float SOFT_RAIN_Y_CHANGE = 2.0f; private LightningBoltEffect bolt; private RainDrop[] drops; private float rainXSpeed; private float rainYSpeed; private byte rainMode; private byte stormMode; private byte lightningChance; public void changeStormyMode(byte mode) { stormMode = mode; if (mode == NO_STORM) { lightningChance = (short)(0); } if (mode == RAINY) { lightningChance = (short)(255.0f*.01); } if (mode == STORMY) { lightningChance = (short)(255.0f*.10); } if (mode == VERY_STORMY) { lightningChance = (short)(255.0f*.25); } } public void changeRainMode(byte mode) { rainMode = mode; if (mode == NO_RAIN) { rainXSpeed = 0; rainYSpeed = 0; return; } if (mode == HARD_RAIN) { rainYSpeed = HARD_RAIN_Y_CHNAGE; rainXSpeed = 0; return; } if (mode == HARD_WINDY_RAIN) { rainYSpeed = HARD_RAIN_Y_CHNAGE; rainXSpeed = WINDY_RAIN_X_CHANGE; return; } if (mode == LIGHT_RAIN) { rainYSpeed = SOFT_RAIN_Y_CHANGE; rainXSpeed = 0; return; } if (mode == LIGHT_WINDY_RAIN) { rainYSpeed = SOFT_RAIN_Y_CHANGE; rainXSpeed = WINDY_RAIN_X_CHANGE; return; } } public boolean isWeatherHappening() { return ((this.rainMode == NO_RAIN) && (this.stormMode == NO_STORM)); } public StormManager() { this.rainMode = NO_RAIN; this.stormMode = NO_STORM; this.lightningChance = 0; drops = new RainDrop[numdrops]; this.initializeRain(); System.out.printf("Add duration to this class!"); } void initializeRain() { drops=new RainDrop[numdrops]; for(int i=0; i < numdrops; i++) { drops[i]=new RainDrop((int) (Math.random() * 10 + 4)); drops[i].setX((float) ((Math.random() * 2000)+30)); drops[i].setY((float) ((Math.random() * 750))); } } public void update(int delta) { if (bolt != null) { bolt.update(delta); } if (this.stormMode != NO_STORM) { if (bolt == null) { if (this.lightningChance >= 0) { Random random = new Random(); short x =(short)random.nextInt(256); short y =(short)random.nextInt(256); short z =(short)random.nextInt(256); if ( (x <= this.lightningChance) && (y <= this.lightningChance) && (z <= this.lightningChance) ) { int duration = random.nextInt(600);
bolt = LightningBoltEffect.generateLightingBolt(new Vector2f(50, 240), new Vector2f(290, 240), duration); } } } } if (this.rainMode != NO_RAIN) { for(int i=0; i <this.drops.length; i++) {
drops[i].setY(drops[i].getY()+this.rainYSpeed);
drops[i].setX(drops[i].getX()+this.rainXSpeed);
if(drops[i].getY()>768) {
drops[i].setX((float) ((Math.random() * 2000)+30));
drops[i].setY((float) ((Math.random() * 5)));
} } } } public void render(Graphics g) { if (this.stormMode != NO_STORM) { if (bolt != null) { System.out.printf("I want to draw some lightning!\n"); if (bolt.currentTime <= 0) { bolt = null; }
if (bolt != null) { System.out.printf("I STILL want to draw some lightning!\n"); SlickCallable.enterSafeBlock(); bolt.render(); SlickCallable.leaveSafeBlock(); } } } if (this.rainMode != NO_RAIN) { g.setColor(new Color(188.0f,227.0f,229.0f,0.3f)); for(int i=0; i <this.drops.length; i++) { g.draw(drops[i]); } } } }
|
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / Re: Slick2d advantages?
|
on: 2012-12-18 20:33:40
|
That is the thing, for this game, for a first effort, I don't need or want stronger control over OpenGL. When I get to be a Knight on here, I will probably want that then.  I have a ways to go. This game, an old school RPG does just fine under Slick2D. Maybe Game #2 can be libGDX.
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / Re: Slick2d advantages?
|
on: 2012-12-18 20:27:54
|
|
I also had the same laggy problem with Java2D as well. I had locked it at 20-30fps, but my sprites never refreshed more than once-twice a second. I could never figure it out.
Not having that problem with Slick.
|
|
|
|
|
8
|
Java Game APIs & Engines / Java 2D / Re: Slick2d advantages?
|
on: 2012-12-18 20:26:31
|
|
This is a curious thread for me.
I started converting my 2D game over from AWT over to Slick last night for several reasons.
The input handler on AWT was missing mouse events The input handler on AWT was slow on keyboard event I finally maxed out the Java2D canvas painter, and 90% of of my CPU time was sitting on the call to Graphics.drawImage() which I could not do anything to optimize. Using Slick2D I am able to not have to fake the shading and other effects to keep performance. I used to keep 4 versions of my tiles in different shades to quickly achieve the desired shading effect. With Slick2D, I am able to pull the shading off on the fly using the same logic.
However, Slick2D is over-simplified for my tastes. If you use BasicGame you don't have direct control over which GL "canvas" you are writing to it seems. The draw logic for an sprite/image seems to be in the Image() class and not in the rendering method. You call a whole bunch of methods to draw the images individually. This seems counter intuitive to me. There is probably some reason for it that is beyond my limited knowledge.
What I do know is I went from 20 fps in my game to 160fps. The memory footprint also went down because my images are now stored in VRAM, and the CPU went down a whole helluva lot (now it runs at 20% instead of 100%
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / rounding issues with isometric mousex,y to tile
|
on: 2012-12-16 18:33:17
|
Howdy... I have really enjoyed all the dialogue so far with the questions and answers to my questions. This is an awesome community. Today, I seem to be having a possible rounding issue with translating mousexy coordinates back to the exact isometric tile. I use two functions: 1 2 3 4 5 6 7 8 9
| public RPGUtil.point ScreenToIsoPos(int screenX, int screenY) { float isoX = (((float)screenX) / ((float)this.terrain_width / 2.0f) + ((float)screenY) / ((float)this.terrain_height / 2.0f)) / 2.0f; float isoY = (((float)screenY) / ((float)this.terrain_height / 2.0f) - ((float)screenX) / ((float)this.terrain_width / 2.0f)) / 2.0f; return new RPGUtil.point((short)Math.floor(isoX), (short)(Math.floor(isoY))); } |
I have tried floor() and round() and it does the same thing. 1 2 3 4 5 6 7 8
| public RPGUtil.point VirtualScreenToIsoPos(int screenX, int screenY) { Point xy = new Point(screenX,screenY); xy.x-=(short)(this.vp_startX)+this.terrain_width/2; xy.y-=(short)(this.vp_startY)+this.terrain_height/2; return this.ScreenToIsoPos(xy.x, xy.y); } |
The issue seems to be if the mouse is toward the edges of the tile it *should* be on, it hops over to the adjacent tile. Any one else fixed this issue?
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / Re: Isometric item placement?
|
on: 2012-12-16 14:15:38
|
|
I appreciate the feedback. I have 6 layers in the world.
Layer 0 is terrain Layer 6 is roof layer 1-5 could be anything. I guess you are suggesting that layer 0 and layer 6 are drawn as isometric only, and I go back to standard 32x32 tile placement on the layers 1-5, or say layers 1-2 are isometric and layers 3-4-5 are standard 32x32flat tile placement?
|
|
|
|
|
14
|
Java Game APIs & Engines / Java 2D / Isometric item placement?
|
on: 2012-12-15 16:05:48
|
|
Howdy.
So today I am working on the best way to add items into the world. Things like tables, chairs etc...
My isometric grid is based on a 64x32 terrain. Charis are obviously smaller than 64x32, and tables can be larger.
The tile writing method I use basically makes a grid and puts images on the map in a grid. I am having a little difficulty getting larger items to line up with smaller items etc...
Does anyone have any good solutions they would like to share about this issue? Trying to place an item on the table is my biggest challenge right now.
Should the tables just be forced to be some large size multiple of 64x32?
Should I create little decoration bundle tiles that take 1,2,3,4 items put them together logically and then decorate with bundles?
Should I try to come up with a way to place items in the world in a pixel-perfect precision manner?
I am kinda stumped and it makes me have sad faces.
Any help would let me turn my frown upside down.
Cheers,
|
|
|
|
|
15
|
Game Development / Game Mechanics / Re: How hard (or easy) is a foe?
|
on: 2012-12-15 00:55:22
|
|
I appreciate all the help and points of view.
The game I am creating is kind of a world simulation, and the fear factor is really more for tiny little creatures running around, rather than whether dragon A and defeat dragon B.
Plus in the later levels, if I don't scale the spawn levels, I want the lower level creepy crawlies to fear you and run away from you.
Additionally, there are fights between spawn and creatures in the world completely independent of the character, so I wanted something in the ball park, and not necessarily exactly exact.
I also now have the idea of using this rating in a chance to fear roll in the game as well.
I am continuing to experiment with the algo so I can ball park it.
Cheers for all your thoughts.
|
|
|
|
|
17
|
Game Development / Game Mechanics / Re: Optimization help?
|
on: 2012-12-14 14:22:40
|
|
I guess maybe I just went into optimization overdrive? I had a horrid issue with screen painting last night, and after fixing it, this was the method that floated to the top of the execution time.
This is the most expensive thing that happens once per turn for the hero, and once per turn for any NPC/spawn that is attempting to move somewhere. During my last profile test, this function was called 81 times in the 5 or so moves I made.
The hero uses this function like a radar and going completely around himself to see what he can see and stop when he can't. It works like a wind shield wiper blade.
The monsters simply do it to see if they can see the nearest prey for possible attack persons.
|
|
|
|
|
18
|
Game Development / Game Mechanics / Optimization help?
|
on: 2012-12-14 13:08:32
|
Greetings. So I have been profiling my code, and I have smoothed out almost all of the rough edged. I have this one though that kinda baffles me. I have a function that returns a series of points when drawing a line. Kind of like an itinerary of points. It is used for several things. I use it to calculate a projectile's path, and I also use it to calculate line of sight. Lots of stuff. Problem is it sucks. I am guessing a large part of the suckiness is the allocating of new points in the loop as the path grows. Can some nice person on here help me optimize it, or give me ideas on how I could optimize it myself? 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
| public static void calc_line(ArrayList<RPGUtil.point> xitinerary,RPGUtil.point source, RPGUtil.point dest, int max_size) { RPGUtil.point lp;
xitinerary.clear(); int x2 = dest.x; int y2 = dest.y; int x = source.x; int y = source.y;
int dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1; int dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1; int err = (dx>dy ? dx : -dy)/2;
while (!(x == x2 && y == y2)) { lp = new RPGUtil.point(x,y); xitinerary.add(lp); if ( (max_size !=0 ) && (xitinerary.size() >= max_size) ) { xitinerary.clear(); break; } int e2 = err; if (e2 > -dx) { err -= dy; x += sx; } if (e2 < dy) { err += dx; y += sy; } } } |
|
|
|
|
|
22
|
Game Development / Game Mechanics / Re: How hard (or easy) is a foe?
|
on: 2012-12-14 00:39:51
|
|
I will ponder that approach as well. I would have to take into account the transparency of the shape as well.
Here is my current approach, I could just switch out the logic in the lifeSize() method if I want to do sprite size
public static class RunAwayFromNearTargetIfStronger extends Thought { public RunAwayFromNearTargetIfStronger(LifeFormInventory l) { super(l); this.name = consts.thoughtRunAwayFromNearTargetIfStronger; } public void runAway(LifeForm targetToDistance) { } public boolean action(NPC me) { if (me.Target != null) { if (Math.abs(me.Target.lifeSize() - me.lifeSize())>= 2) { runAway(me.Target); return true; } } LifeForm l = me.findNearestTarget(); if (Math.abs(me.gps.distance(l.gps)) <= 2) { if (Math.abs(l.lifeSize() - me.lifeSize()) >= 2) { runAway(me.Target); return true; } } return false; } }
|
|
|
|
|
23
|
Game Development / Game Mechanics / Re: How hard (or easy) is a foe?
|
on: 2012-12-14 00:29:30
|
|
I will try this approach:
public static final byte lifeSizeXSmall = 0; public static final byte lifeSizeSmall = 1; public static final byte lifeSizeNormal = 2; public static final byte lifeSizeMedium = 3; public static final byte lifeSizeLarge = 4; public static final byte lifeSizeXLarge = 5; public static final byte lifeSizeGigantic = 6;
|
|
|
|
|
25
|
Game Development / Game Mechanics / Re: How hard (or easy) is a foe?
|
on: 2012-12-14 00:21:23
|
|
A level 1 dragon has different stats than a level 1 mouse. I really need to try and do it at the stat level. Here is what I have tried currently:
public short rating() { short r = this.magic_offense(); r += this.magic_offense(); r += this.offense_physical(); r += this.defense_physical()/2; r += this.hp/10; return (short)((r)>0?(r):1); }
|
|
|
|
|
26
|
Game Development / Game Mechanics / How hard (or easy) is a foe?
|
on: 2012-12-13 23:45:30
|
Howdy all, I have been trying to come up with a formula based on the stats of a foe in my game ( http://www.indiedb.com/games/fabuladivina) to determine how much more dangerous or how much easier a foe is than any other foe (including you.) I have tried a bunch of different formulas of attack power, defense, health, skills etc... and I can't find one that 'works' for me. What I am trying to do is figure out whether certain creatures (like a little field mouse) should run away from the big bad dragon, while it may want to attack the cockroach. Has anyone else tackled this issue? I was looking for a formula since my spawn are also rolled, and some may be more dangerous, and some may not be. Thanks.
|
|
|
|
|
30
|
Java Game APIs & Engines / Java 2D / Re: Stupid Question... Screen/Mouse to Isometric tile?
|
on: 2012-11-16 05:16:34
|
|
My method basically starts the diamond in the center of the screen at the top.
The whole method is this:
public void WriteTile(Image i, int tilex, int tiley) { Point xy = getScreenIsoPos(tilex, tiley); xy.x+=(short)(this.vp_startX); xy.y+=(short)(this.vp_startY); xy.x -= (i.getWidth(null)-terrain_width); xy.y -= (i.getHeight(null)-terrain_height); vp.WriteImage(i, xy.x,xy.y); //vp.WriteDebug(i, xy.x,xy.y,tilex,tiley); if (tilex == 0) { if (tiley == 0) { System.out.printf("0:0 was written at %d:%d\n", (xy.x)+terrain_width,xy.y); } } }
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|