Game Programming and Development Tools

Help with Bible Dave code! – tonnyx

Tonnyx

Member

Posts: 140
From: Indiana, USA
Registered: 08-02-2005
I'm trying to tweak the Bible Dave code to do a project for a friend from the CGDC, and Clint is currently in L.A. doing a job interview. I can't exactly ask him right now.

I am doing a pretty basic level that focuses just on jumping, and dodging guavas. I would like it so that, if self.num_bibles < 3, then you can't exit. I've gotten that part down so far, but when the character hits the exit trigger, he keepts getting the message again and again, until, ever so slowly, he makes it to the next square. In pseudocode, that part looks something like this:

exit Trigger:
if self.num_bibles > 3:
(go to next level)
else:
self.hud.dialog("I think I see some more Bibles stuck in the tree branches. I should get them.")
--is it possible to have add something here that would automatically bump him to the left one square so he doesn't keep hitting the trigger?

If you couldn't tell, I actually don't "know" any python, or pygame stuff. I can edit levels, and add dialogs if I have some example code, but that's about it.

Thanks in advance.

------------------
it's pronounced "tonics"

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
I'm sure Joe should be the one answering this. Maybe this post should be taken as a recommendation for the Bible Dave engine.

Three ways I can think of to fix it:
* your suggestion of bumping the player back is a valid one.
* or, have the event trigger only when entering the trigger and another when exiting. kinda like a KeyPressed, Key Released set of events.
* or,Have a delay counter that will only display the message once every second or so, giving the player time to leave the trigger.

------------------
Sam Washburn

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
I haven't looked into the Bible Dave code, but I can do that tonight. I was trying to find something on my fifteen minute lunch break, but that finished too soon. Hopefully someone who worked on the project can help you, but I'll look into it tonight if necessary.

------------------
"To secure ourselves against defeat lies in our own hands." - Sun Tzu.

"He who walks in integrity walks securely,
But he who perverts his ways will be found out." - Proverbs 10:9 (NIV)

Tonnyx

Member

Posts: 140
From: Indiana, USA
Registered: 08-02-2005
Hmm. Unfortunately Joe (I'm assuming you mean Joe Q.), is on his way to a missions conference right now and won't be back until Sunday.

Do you know how to implement those suggestions that you mentioned? As I said, I know no python, and I'm not familiar with the Bible Dave code, so I haven't the faintest clue how to go about any of that.

Thanks for your input! Anyone want to take it up from here?

------------------
it's pronounced "tonics"

[This message has been edited by tonnyx (edited March 03, 2007).]

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
I've downloaded the source, what file are you adding to? A level.py? Can you post or pm me your code?

------------------
Sam Washburn

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
I hope this works. I don't have a python interpreter on this system.


# OK, at the top before all the defs add these variables
exitTriggered = false
exitCounter = 0
exitDelay = 50 # this is the delay counter, you may need to adjust this.

# Add this def somewhere, probably before def OnExit
def OnLoop(self):
if exitTriggered:
exitCounter = exitCounter + 1
else:
exitCounter = 0
pass

# Modify OnExit as follows
def OnExit(self):
exitTriggered = true
if exitCounter > exitDelay:

# Insert your OnExit code here. Be sure to indent it to this depth

exitCounter = 0
exitTriggered = false

------------------
Sam Washburn

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
Sorry I wasn't able to get to this last night. I saw Sam's post, thought it good, and reduced the priority I placed on looking into this. Anyway, like I said, Sam's code looks good. I'm just going to throw a few ideas in that reflect my understanding of what you want. I haven't tested this code, so I don't know that it will actually work, but it should work in theory.

<BLOCKQUOTE><table width=80% border=0 bgcolor="#FFFFF" CELLPADDING="2" CELLSPACING="2"><TR><TD><font size="3" face="Courier" color="#000000"><pre>
# OK, at the top before all the defs add these variables
# exitTriggered = false # I don't think you will need to throw this flag.
exitCounter = 0
exitDelay = 3 # This is going to be the necessary number of Bibles for exit.

/* I don't know if "/*" is valid in Python, but I mean to indicate that,
* in this case, this code isn't really needed; so far as I understand
* the problem anyway.
* # Add this def somewhere, probably before def OnExit
* def OnLoop(self):
* if exitTriggered:
* exitCounter = exitCounter + 1
* else:
* exitCounter = 0
* pass
*/

# Modify OnExit as follows
def OnExit(self):
exitCounter = BiblesCollected # I don't know what this variable is named.
if exitCounter > exitDelay:
self.gotoNextLevel()
else:
self.hud.dialog("I think I see some more Bibles stuck in the tree branches. I should get them.")
dave.rect.x -= 32 # I think this will move Dave
# back one tile space (approximately 32 pixels)
# However, I don't know what the player object is actually named.
</pre></font></TD></TR></TABLE></BLOCKQUOTE>

I don't know the specifics regarding the name of the player object, so that would be necessary for putting in place off "dave" above. I'm not sure what the BiblesCollected counter is actually called, so that would be a necessary fix. However, I think that this should more or less do what it is you want it to.

Good luck!

EDIT: HTML is not enabled for me, so the formatting didn't carry over. Sorry about that. I'll leave the HTML in place in case you want to paste it somewhere and view it as it should be.

------------------
"To secure ourselves against defeat lies in our own hands." - Sun Tzu.

"He who walks in integrity walks securely,
But he who perverts his ways will be found out." - Proverbs 10:9 (NIV)

[This message has been edited by Xian_Lee (edited March 03, 2007).]

[This message has been edited by Xian_Lee (edited March 03, 2007).]

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
In addition to above suggestion here's yet another way to do it, using two triggers:


def OnRunSpecial1(self, g, t, a):
def trigger(g, s, a):
if g.num_bibles < 3:
g.hud.add_dialog(_("""I think I see some more Bibles
stuck in the tree branches. I should get them."""))
s.agroups = None # don't allow this to be triggered again

self.addTriggerCallback(t.rect,trigger)

def OnRunSpecial2(self, g, t, a):
def trigger(g, s, a):
# 3 Bibles needed for next level
if g.num_bibles >= 3:
s.gotoNextLevel()
s.agroups = None

self.addTriggerCallback(t.rect,trigger)

When dave enters trigger #1 the dialog is displayed once if he doesnt have enough bibles. And when he enters trigger #2 he is being sent to the next level if he has at least 3 Bibles


Notice the _() inside the add_dialog() call for getText and internationalzation support.


[This message has been edited by jari (edited March 03, 2007).]

[This message has been edited by jari (edited March 03, 2007).]

Tonnyx

Member

Posts: 140
From: Indiana, USA
Registered: 08-02-2005
Wow, guys, thanks so much for all your help! The prize goes to Xian_Lee for implementing something I could understand. All the ideas were great, though. I think if Clint were implementing this, he'd use Jari's code, but I have to confess I didn't quite understand it. This is what happens when you try to tweak code in a language and a program you don't know much about. I poked around in the player.py file to see what it used, and I thrashed around with the variable names until something worked.

g.player.rectx, self.player.rectx, g.player.rect.x, and so on, until it turned out that what I needed was self.player.rect.x

Hooray! Samw3, thanks for the quick response, and your willingness to help. That was really encouraging, just to know that somebody was willing to think about it and offer ideas. I was feeling pretty desperate yesterday, and it helped to have something to wrestle with, rather than thrashing blindly.

You guys are awesome.

------------------
it's pronounced "tonics"

[This message has been edited by tonnyx (edited March 03, 2007).]

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
Awesome. I'm glad to have been of some help.

I've only briefly toyed with Python and PyGame. Honestly, I don't like the formatting of Python (in that there are no braces, and that indentation is what determines what code belongs to which if/while, function, class, etc.), but I definitely can see its usefulness and ease of use with a little practice.

Anyway, it sounds like you managed to get something to work for your modifications, yes? That's what's important. Well, again, I'm glad to have offered my services, limited and derivative of Sam's work as they may have been.

------------------
"To secure ourselves against defeat lies in our own hands." - Sun Tzu.

"He who walks in integrity walks securely,
But he who perverts his ways will be found out." - Proverbs 10:9 (NIV)