Need Help Making a "You Won!" Screen

I have a game where there are some targets, and after the shooter has shot down all the targets, I want a screen to appear that says something along the lines of “You Won!” or “Congratulations!”. Does anyone know how to do this?
Thanks in advance for your help.

You could use Bgui Library from Moguri.
Here is one link:
http://code.google.com/p/bgui/

You could use an overlay scene with an animation. Each time a target is put down you send a message to an empty which will use it to decrement a variable, when the variable = 0 the empty activate an overlay scene containing the message.

I’ll give you an example blend file and also I explain how to use overlay scene in this tutorial : http://www.youtube.com/watch?v=PR4RIMSCLB8&list=PLFE83629D3C417640&index=7&feature=plpp_video

Win Actions
You could do what you want:
e.g. start a new scene, add a scene, start a new (or other) game …
Most of that can be done with one or two actuators.

Win condition
The thing you need is to sense the “win” condition.That can be tricky or simple.

“all targets down” can be a win condition. How to measure this?

Options
A) Count all not-shoot targets
when?
A1) all the time -> inefficient
A2) after a target could be shot down (after a shoot) -> you need to define ALL situations to bring a target down
A3) after a target recognized it was shot down.

B) If no more target says it is still alive (inefficient)

Example
I would go for A3)
what do you need

  • the notification of a dying target (you can use a message for that)
  • the target counter (activated by the above message)

the safest way is to use a Python script to count the living targets. Example:
(needs the module Finder.py from ObjectFinder.

MyModule.py:


import GameLogic
import Finder

def allTargetsDown(cont):
  livingTargets = Finder.findObjects( Finder.byPropertyValue, ["target", True] )
  if not livingTargets:
    activateAllActuators(cont)

def activateAllActuators(cont):
  for actuator in cont.actuators:
    cont.activate(actuator)

Requires:
the property “target” on the targets. The value must be True if alive.
The target must send a message on dying an chang its property to a non-True value:
e.g.
Sensor “dying”
-> AND
----> Property sensor prop “target” value:False + Message Sensor “target down”

Usage:
message sensor -> Python controller MODULE: MyModule.allTargetsDown -> all actuators you want active on win

(the code is untested)

I hope it helps

@Guillaume Cote:
I watched your tutorial and thank you! I have been looking for a way to set up a menu screen for a while now, and you tutorial was amazing. However, when I tried using the “Play” button on the menu, some of my textures were messed up:
intended:



what happened:


Do you know a solution to this problem?

@Monster:
I am using a Python script to cause my objects to disappear after 5 hits from bullets using the “endObject()” command.

import bge


def main():

    cont = bge.logic.getCurrentController()
    targets = cont.owner
    keyboard = bge.logic.keyboard
    scene = bge.logic.getCurrentScene()
    
    if 'hp' not in targets:
        start(targets)
    
        
    targets.color = (targets['hp'], targets['hp'], targets['hp'], 1)
    if targets['hp'] >= 1.0:
        die(targets, scene)
    
def start(targets):
    targets['hp'] = 0.0
    
def die(targets, scene):
    targets.endObject()

I’m still pretty new at scripting, what should I put into this script that would send the message that the target has been shot down and where should I send it?

You can send messages with the message actuator or via Python code. With a well chosen subject you can filter the messages (e.g.“a target died”).

multiple Options:
A)
The target sends the message when hit
( I think that is what you need)

B)
The bullet sends the message when hitting the target (but the target might not be dead with one shot/a target might die on other effects)

C)
A control object evaluates the “shoot result” and sends the message

I like your first option, Monster. I want to do it using Python because that is how my targets are set up, but I have never sent messages with Python before. Would you be able to show me how to do this?

@Guillaume Cote
I looked at the .blend file that you attached, and it looked like it worked really well. However, I have done nearly all of my game using Python, so the logic brick setup won’t work for my game. If you know how to translate those logic bricks into Python code, it would be very helpful.

Well, I don,t know how to change logic bricks into python. I’m trying to learn python at the moment since I’m not that good with it. Sorry about that.^^’

For your texture problem, it is hard for me to say with only that. Could you send an example .blend file? Doesn’t need to be all your game, just the part that is going wrong so that I can poke around and try different possibilities.

sure:
http://www.blender.org/documentation/blender_python_api_2_60_6/bge.logic.html
look for sendMessage(

Sounds like you got a very compact implementation.
Finally the Python controller is only a logic brick too :wink:

@Guillaume Cote
Here is the .blend file for my game. I have no idea what the problem might be, so I just sent the whole game.
game.blend (1.26 MB)

@Monster
I was able to use the link you posted to make the target send a message when it died. I now want to be able to do 2 things:

  1. set up my empty that is receiving the messages to go to my Game Over scene only after it has received the target died message from all the targets. I was thinking of doing this by having the empty wait until its subjects list contains a message from all the targets, but I am unsure of how to do this.
  2. I want the empty to wait a little before going to my Game Over scene, because as it is now I feel that it goes too fast.

My first recommendation: Switch to module mode - so you can get rid of all this little text blocks.

You can simply send the “Target died” message from your die() function.

A) If the goal is to reach a specified amount of living targets (e.g. none). You can simply count the remaining targets.
example (see above):


  livingTargets = finder.findObjects( finder.byPropertyValue, ["target", True] )
  if not livingTargets:
    <to Win scene>

B) If the goal is to “kill” a specific amount of targets, you need to know how many targets died. You can do that by counting the “Target died” messages.
needs a message sensor listening to “Target died”:


  messageSensor = ...
  numKills = len(messageSensor.bodies)
  obj["totalKills"] += numKills

now you can check property “totalKills” against a given number.

I added both logic into your file.
For education I setup several configurations:

  • all new Python code is called via Module mode
  • not all targets have the property “target” -> see what happens with the target counter
  • not all targets sends the message “Target died” on kill
  • one target sends the message via actuator
  • other targets sends the message via Python
  • Added an overlay with the number of targets and number of kills
  • Added logic to sense the win-situation on KillCounter AND TargetCounter
    —> it is configurable via properties
  • Added an object to deal with a “Game succeeded” message -> switching to Win scene

current win situations:
A) 4 kills (not reachable as one target does not send the “Target died” message)
B) 0 targets remain (Only achievable if the last killed target sends the “Target died” message/be aware one target is not marked as target!)

Remarks:

  • Your targets do not share the same logic. This is confusing. Especially as the snippets look quite similar.
  • The shards are named "target?#### is a bit misleading :wink:
  • you have an error in you bullet code

I hope it helps

Attachments

game_revised.blend (1.12 MB)

Thank you for looking at my game, Monster. I looked at your remarks, and I agree with all of them. I went back and changed all my targets to use the same script, I fixed the naming on the shards because I realized that my method of naming them didn’t make much sense. As for the error in the bullet code, I have been having problems with my bullets, but I don’t know what the problem is. Do you know anything more about the error other than that there is one?

As for your solutions to ending the game, I think your A) option will work best for my purposes. I looked at the scripts attached with the revised .blend file, and you have proven to me just how little I actually know about scripting:o. I am assuming that the finder.py you included is used for your A) option, but as for how to implement it into my game, I am at a total loss. Would you be able to show me what I need to do?

Also, thank you so much for all the help you have been thus far. When I first found out about Blender, I was extremely excited to start making games, but I would be unable to if not for people like you who are so patient when dealing with someone like me that has very little idea what they are doing.

@Guillaume Cote
I figured out the problem with my textures. I noticed another thread on the forum that was talking about problems with graphics that were very similar to mine. They said the problem was something about GLSL and multitexture, and when I went into my game I checked my render settings and my game scene was set to GLSL, but my menu scene was set to multitexture. I changed this and now everything works fine.

Hi DarkFire7,

Do not worry, really everybody joins the game developing with a great vision … and no clue how to do that :D. If I say everybody, it includes me. By knowing that, it is much easier to help other, to look into the right direction. The point is there are an awful lot of options, we just need a push to see them.

Anyway:
With Python Errors it is important to read them carefully to understand what they say and what the mean. They usually tell you exactly what is going on.

In your case: KeyError
The code looks in a dictionary with a key but did not find an entry.
It shows you what code produced the error. So you can see what causes it (On reason, why it is important to have as less as possible statements in one line).
In you case: I is simply missing a property. The code tells you which one.
If you want to know what object the dictionary belongs to, you have to dig into your Python code.

Finder
The finder is a helper module. It contains functions to enable you to find objects of you choice. You can do the same by yourself if you want to train. It is not that hard. But I do not want to write the same code all the time ;).
You can get some more information here: http://blenderartists.org/forum/showthread.php?238849

Monster, I set up my game using your finder.py and your counter.py, and it is working really well so far! I now have a HUD that displays how many targets are left in the game, but I haven’t quite gotten around to setting up the logic/Python (not really sure which I am going to use right now) that will be used to run my Game Over scene. Those 2 scripts that you wrote are lifesavers. I don’t know what I would have done without them. Is it OK with you if I use these scripts in other games that I make?

fell free to do so, that’s why they are there :wink:

Hello Monster,

I looked into the error in my bullet code, and the problem may be that my bullet is hitting objects such as the background plane or one of the 2 floor planes, none of which I want to have a HP property. The background plane I can make a ghost, but I am unsure of what to do with the 2 floor planes. Any suggestions?

I set up my sensor as you suggested, Monster, but now my timer doesn’t count up. I meant make the timer stop after a certain event, such as the same event that triggers the end of game scene.