Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 8:46 am

All times are UTC




Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 12  Next
Author Message
 Post subject:
PostPosted: Mon Jul 04, 2011 8:05 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
FlowState wrote:
Well basically, what I need is an alarm that is triggered every time the player hits the dash button, and after X seconds, sets isDashing to false. Any chance you could write up a code example for that? Or perhaps it's already in StarCleaner? :D

I'm sorry. It's not in StarCleaner :cry:

But it's in "Back to the past" :lol:

Download the source code here.

Have a look at the Mage class.

At the start of the update method of Mage you will find this code:
Code:
      // deal with shooting stuff
      if (canShoot && check(CMD_FIRE) && (mana >= fireballManaCost)) {
         canShoot = false;
         mana -= fireballManaCost;
         this.setAlarm("shootDelay", 30, true, true);
         this.shootFireBall();
      }

I check if "canShoot" is true and the fire button is pressed and there is enough mana left.
If yes, canShoot is set to false (so we can't fire again) and a new alarm "shootDelay" is started which will trigger in 30 ticks (the game runs at 60 FPS so this is half a second). This alarm will only trigger once and start immediately to measure time.

In the method alarmTriggered() you'll find the second part of the logic:
Code:
      if (name.equals("shootDelay")) {
         canShoot = true;
      }

So after 30 ticks the alarm fires and the boolean "canShoot" is set back to true.

That's it :wink:

You could solve your "isDashing" problem exactly the same way.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2011 12:25 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
wow, that's pretty much exactly what I had, but I made Entity.alarms protected instead of public... and boom! not working code.

Thanks much, sir!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2011 2:27 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
You're welcome!

Are you working on your own copy of MarteEngine? Because alarms is private inside of Entity (which I already explained earlier).

Just wondering :wink:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2011 8:46 pm 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
I think that's what I'm going to end up doing. Simple reason is, the extensions that I want to make on top of it are so different that it won't mesh well with the direction that the engine is going in general.

However, I would be more than happy (pending your approval) to share, push, and/or make tutorials about what I'm doing (I prefer video tutorials, but it's up to you).

I might throw together a mini-tutorial about what I've got going now, which is dashing, air dashing, double jumping, and wall jumping.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2011 6:56 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
I'm fine with whatever you come up with!

Video tutorials are good IMHO, but I would also love to have a look at your source code. Maybe we can integrate it into an MarteEngine example for some platformer with enhanced features like dashing and air dashing.
Double and wall jumping is already working in StarCleaner but maybe your approach is better / smoother? Let's have a look :lol:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2011 7:32 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
I need to refactor a bit, as to be honest, this game code is the first Java I've written in my life ( :oops: ).

My idea is a speed model system, where you define models, which have attributes like friction amounts, max speeds, acceleration amounts, etc. You define them like you define Entity commands (in PlatformerEntity, I believe?),
and then all you would do is switch which model you're in, based on input.

I'm just not sure if that's a best-practices approach, because as I said, I'm completely new to Java.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2011 10:41 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Sigh, I have another ResourceManager problem. I'm getting this error:

"ERROR:No SpriteSheet for key playerStanding found!"

My spritesheet is named 'standingSheet.png' and it's in the 'player' folder.

Here's the important part of my resources file:

Code:
<sheet key="playerStanding" file="player/standingSheet.png" width="108" height="108" />


I really can't see what I'm doing wrong here, and the error message is a bit ambiguous. I'm not sure if it means that it's tried to find the file and couldn't, or what.

I'm wondering if it has something to do with the way the map is loaded, as far as the location of the player. My player image is 36x36, and I'm afraid I don't understand how that will affect things.

Thank you for all the help!

Edit: I'd say that it has to do with the size of the image I'm trying to use, though that error message makes no sense in that case. I really hope I can find a way around this, because this is rather frustrating.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2011 8:05 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
have you set into your resource.xml base dir?

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 4:56 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Okay, I started all over again, with the Wiki tutorials, so that I could narrow down the problem. I'm about ready to break my monitor, this is so infuriating.

In 'data/' I have the file 'staticStanding.png'.

My resources file looks as such:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
   <!-- basedir -->
   <basedir path="data" />
   <!-- sounds -->
   <!-- songs -->
   <!-- images -->
   <image key="player" file="staticStanding.png" />
   <!-- sheets -->
   <!-- fonts -->
</resources>


This code works:

Code:
public Player(float x, float y) throws SlickException
   {
      super(x, y);
      
      setGraphic(new Image("data/staticStanding.png"));
   }


This code doesn't:

Code:
   public Player(float x, float y) throws SlickException
   {
      super(x, y);
      
      Image img = ResourceManager.getImage("player");
      
      setGraphic(img);
   }


Produces: No image for key player found!

ALL of my code is exactly the same as the tutorial, and yet I can't get the ResourceManager to function correctly. I don't want to abandon Marte Engine, but that's my only recourse if I can't get something this simple to work correctly.

Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 6:54 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Are you sure you call
Code:
ResourceManager.loadResources("data/resources.xml");

before you try to instantiate a Player?
You must call this somewhere at the beginning of your game, for example in the init() method of your first state.

If the resource manager can't find a resource file he throws an error.

The fact that you get "No image for key player found!" is a hint that you didn't load the resources using the above line of code.

There's no need to abandon Marte Engine - it's working fine in several games now. It just requires a bit of learning and gathering experience - you'll get there shortly, I'm sure :wink:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 8:04 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
As I said, I'm following the Wiki tutorial exactly, and the ResourceManager.loadResources("data/resources.xml") call is the first line in 'initStates()'.

I know that it must be my error, but I copied the tutorial exactly, and it still doesn't work.

I've got the animations and images working without using ResourceManager, but I would really like to use it. Would it help if I just zipped everything up and shipped it to you?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 8:15 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
FlowState wrote:
Would it help if I just zipped everything up and shipped it to you?

Waiting for your email :wink:
Don't forget to include your own (modified?) version of ME if it is required.

Let's find this bug 8)

Did I ever mention that I'm convinced that every developer should have a parrot sitting on his shoulder that shouts every few minutes "Polly found a bug! Polly found a bug!" :lol:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 9:16 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Email sent!

I agree with your parrot idea, on one condition: when a customer buys software, it should come with a parrot to sit on their shoulder and say "It's not a bug, it's a feature! It's not a bug, it's a feature!"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 10:29 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Answer sent!
Your code is fixed now. My assumption was right, you somehow forgot to load the resources before you used them :wink:

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 11:42 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
Hi, can you check again this:

https://github.com/Gornova/MarteEngine/ ... -and-world

I think your problem derive from this tutorial: we must specify better that ResourceManager MUST be loaded before use of resource?

If it so, can you please open an issue on Github? Thanks :D

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 12  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group