The JGO Bar!!: SixtyGig - Open World Retro RPG.

Imagine how I felt while coding it. >_>

Really it’s practical purpose will be short shake bursts less than a second when say, an explosion goes off or the player gets hit. :smiley:

Heh camera shake/rumble is awesome.

I use this in my game:



	private final void processShake(float delta) {
		/*
		 * If the current shake time is less than the desired shake time, shake
		 * away
		 */
		if (currentShakeTime <= shakeTime) {
			/*
			 * We take the current shake power and give it the value of
			 * shakepower - current shake time and divide it by a blend factor,
			 * then divide by shake time
			 */
			currentShakePower = shakePower
					* ((shakeTime - currentShakeTime / 1.15f) / shakeTime);

			/*
			 * Randomly increase/decrease the position on x by a random factor
			 * multiplied by the shakepower
			 */
			shakeX = (MathUtils.random(-0.5f, 0.5f) * MathUtils.random(1.25f,
					1.5f)) * currentShakePower;
			/*
			 * Randomly increase/decrease the position on y by a random factor
			 * multiplied by the shakepower
			 */
			shakeY = (MathUtils.random(-0.5f, 0.5f) * MathUtils.random(1.25f,
					1.5f)) * currentShakePower;

			/* Move the camera to the new values */
			translate(-shakeX, -shakeY);
			/* increase our current shake time */
			currentShakeTime += delta;
		} else {
			/*
			 * The current shake time has exceeded the desired shake time, lets
			 * stop the shaking process
			 */
			shaking = false;
		}

	}


I am using LibGDX and and my own camera that extends from the normal ortho cam. It works pretty well, however the LibGDX Ortho cam does make it much better because it interpolates between the 2 positions and moves smoothly back into place.

Do you have something similar? Yours looks really good for arcade shoot em’ ups!

Those pool balls must be stuck to the table. :wink:

“Those poor balls must be stuck in the table. ;)” I have no Idea why I read it like that :persecutioncomplex:

Actually my screenshake code is really rough right now. I put it together more as a concept than anything else, I still need to flesh it out. I plan to have a “ScreenShake” class that allows you to input all kinds of variables, like how long and what amplitude the shaking will be. Right now it’s just really rough code that cycles up and down. I just liked the results so much I posted them anyway. :stuck_out_tongue:


	public void screenShakeTest() throws SlickException{
		screenShake += 1;
		if ((screenShake >= 1) && (screenShakeStep == 0)){
			mapX += shakeAmount;
			mapY += shakeAmount;
			screenShake = 0;
			screenShakeStep = 1;
		}
		if ((screenShake >= 1) && (screenShakeStep == 1)){
			mapX -= shakeAmount;
			mapY -= shakeAmount;
			screenShake = 0;
			screenShakeStep = 2;
		}
		if ((screenShake >= 1) && (screenShakeStep == 2)){
			mapX -= shakeAmount;
			mapY -= shakeAmount;
			screenShake = 0;
			screenShakeStep = 3;
		}
		if ((screenShake >= 1) && (screenShakeStep == 3)){
			mapX += shakeAmount;
			mapY += shakeAmount;
			screenShake = 0;
			screenShakeStep = 0;
			if (shakeDirection){
				shakeAmount += 1;
			}else{
				shakeAmount -= 1;
			}
		}
		if (shakeAmount >= 4){shakeDirection = false;}
		if (shakeAmount <= 0){shakeDirection = true;}
	}

In it’s current state, all you really can do with it is change the second to last line, if (shakeAmount >= 4){shakeDirection = false;}, up or down to increase the shake amplitude and duration or change the screenShake >= 1 in all the if statements to slow down the speed of the shakes.

It’s really not any code to be proud of, it’s just a lot of booleans and ints being used to step. :smiley: I have much better way to rewrite it I’m going to use once I actually implement the screen shake in my game in a proper manner. :wink:

:persecutioncomplex:


public void screenShakeTest() throws SlickException{

What would generate a SlickException then?

And why dont you use something like this: (not tested)


   public void screenShakeTest(){
        screenShake += 1;
      
         mapX += screenShake <= 4 ? shakeAmount : -shakeAmount;
         mapY += screenShake <= 4 ? shakeAmount : -shakeAmount;

         if(screenShake %8 == 0){
             screenShake  = 0;

             if (shakeDirection){
                shakeAmount += 1;
             }else{
                shakeAmount -= 1;
             }
         }

      if (shakeAmount >= 4){shakeDirection = false;}
      if (shakeAmount <= 0){shakeDirection = true;}
   }

Just reading through, reminded me of a time when I was adding particles to my game and it looked like you were spewing little green chunks everywhere.

Nothing what so ever now, I just forgot to remove it. d’oh!

That is definitely a much cleaner way to write it. :wink:

The final product will have a ton of settings though, I’m planing on amplitude, direction (diagonal, left/right or up/down), shake speed, shake time, etc since I plan to use it for all sorts of things like getting hit, firing heavy weapons, earthquakes(?), explosions and what not.

Cool idea, probably impractical: shake the screen according to audio data.

A little easier, would still likely produce interesting results: use the function of a musical chord:

(via Desmos)

Looks pretty rumble-y, no? Also would be easier than pretty much anything else for adjusting amplitude / frequency.
Certain other intervals would also likely produce interesting shake patterns.

huh, that’s a really neat idea. I never though to use actual sound waves. In theory once you wrote the class to handle one audio file it could handle anything you throw at it, be really easy after the code is written to add more rumble effects. Just add more “rumble” sounds!

EDIT:
That gives me a cool idea; Use images to make rumbles. Take a VERY small image (16x64?) and use black/white dots, the location of the dots determines the shake pattern. Maybe a sine/square wave pattern, have it translated through the image buffer and boom, custom/flexible rumble patterns that can be “written” outside the code. Since I’m planning for Coding-free mod support, that could turn into an interesting feature.

[quote]EDIT:
That gives me a cool idea; Use images to make rumbles. Take a VERY small image (16x64?) and use black/white dots, the location of the dots determines the shake pattern. Maybe a sine/square wave pattern, have it translated through the image buffer and boom, custom/flexible rumble patterns that can be “written” outside the code. Since I’m planning for Coding-free mod support, that could turn into an interesting feature.
[/quote]
Well, you could just use a random number array…

Well, you could just use a random number array…
[/quote]
Yeah, I could just stick them all in a screenshake.properties file, and people can simply configure it however they want. Just give each shake type a name, and assign variables to it, then call up that property in game to load the shake.

A lot of my engine uses .properties files for that sort of data, because I’m trying to design the game to be 100% code-free plain English modding. It can already handle adding new NPCs (partially), maps, items, dialog, item colors, containers and much more with absolutely zero programming. :smiley:

The “big plan” is to make the game engine flexible enough people can add entire new/complete sections to the game without actually having to code anything. So allowing them to customize or add more screen shakes would just be another random thing they can change. :wink:

That’s a great idea. Custom content can really enhance a game far beyond anything you ever imagined and making it easy to implement is one step further. I tried to do something similar with my game and it actually worked pretty well, but 100% plain-English modding would be much better and more appealing to people.

Yeah, that’s what I am going for. Once I push into Alpha I am going to setup a professional-looking website, and have very detailed step by step tutorials on how the engine works and how to add content, but really aside from the more advanced topics (Like adding entire new maps) most of it is pretty straight forward.

For example, currently if you wanted to add a new item to the game:

  1. Make some art for your item (16x16), or just repurpose something already drawn
  2. Make a sameNameasImage.properties file, only with the information you want to not = 0. For example, here is a super simple item. Just a “bottle”. Serves no purpose, it’s just junk loot.
    bottle0.properties
type=junk
name=bottle0
nameProper=A Glass Bottle!
color=cyan
value=5
weight=1
description=Just a ordinary glass bottle, why are you lugging this around with you again?
  1. put both the image and the .properties file in /res/items/
  2. Add the item to a loot table for an NPC, a container type, or a store.
    4a. For this example, let’s assume a container, open up res/items/container_containerName.properties and add it to the list:
    Example of container_trashCan.properties: (No, the final product trashcans wont be full of clothes, lol)
type=trashCan
nameProper=Trash Can
size=3
fill=5
item0=bottle0
item0_chance=10
item0_color=indigo

item1=shirt_tshirt
item1_chance=1
item1_color=pink

item2=face_aviatorSunglasses
item2_chance=1
item2_color=blue

item3=gloves_woolGloves
item3_chance=1

item4=shoes_shoes
item4_chance=1

item5=belt_leatherBelt
item5_chance=1
item5_color=maroon

item6=pants_jeans
item6_chance=1
item6_color=chestnut

item7=shirt_tshirt
item7_chance=1
item7_color=dodgerBlue

item8=face_aviatorSunglasses
item8_chance=1
item8_color=purple

item9=gloves_woolGloves
item9_chance=1
item9_color=cyan

item10=belt_leatherBelt
item10_chance=1
item10_color=slateGray

Boom done, you’ve just added an indigo colored glass bottle to my game, that will now spawn in all trashcans randomly.

Should also be noted that there will be “color sets” you can pick instead of specific colors,so if you wanted the trashcan to spawn say, a bunch of different color bottles you wouldn’t have to make an entry for every single color you wanted, you could do something like item_color=random (for all 144 color options) or a collection of colors, like item_color=reds (for all 20-something reddish tones).

…and on the note of adding colors, adding a entire color to my game takes 2 whole lines, just open up colors.properties and add something like this:

darkOrchid_name=Dark Orchid
darkOrchid_hex=0xFF9932CC

The hex code is in ARGB format, and all you have to do to use darkOrchid is assign it to an items default color, or in the case of the example above, make it the item_color= assignment.

Sounds like you’ve put a lot of thought into it.

I made a quick demo of the chord-shake: Rumble.jar
Click anywhere to shake. I hope you don’t mind me using your screenshot :stuck_out_tongue:

Source here: http://pastebin.java-gaming.org/bc7e396908f

That’s using the minor chord I posted earlier.
Works OK, but could definitely be “tuned” (pun intended) to look better.

[sarcasm]
WHAT?! How DARE you use MY intellectual property!!? >:(
[/sarcasm]

Only problem I see is right as the shake stops it kind of “jolts” back in place awkwardly. But, like you said, it needs tuned a bit, I imagine the jolt is coming from the start and finish of the waveform not being at the same spot.

Still very cool regardless though. I like it! :smiley:

You are exactly right, and it is also because I was too lazy to have it smoothly interpolate back into position when the wave finished. Head over to the “Mathematical curves” or whatever thread for all your easing function needs!

The duke has been spotted in the city! :o

http://sixtygig.com/junk/InDev-2014-04-18-1.png

[quote]Boom done, you’ve just added an indigo colored glass bottle to my game, that will now spawn in all trashcans randomly.
[/quote]
Will you add a method so that people can release “mod packs”? ie: a single file that other users can download, stick in their game directory, turn on/off in options menu. And when it loads up it will slot entries into what ever parts of the game that it needs to. having to directly edit a variety of individual files will make it difficult for people to share their modifications.