Halloween Costume ideas 2015

BGE / Game Logic 2

Simple game where players control the Box and collect Spheres.
I decided to continue with this BGE post series right away to keep the ball rolling.

From the previous post, you should be able to create a simple BGE setup where user/player can control an object or a hero character.

In this post, you will learn how this hero character can collect points or store values. Very simple but super important concept to understand.

BGE: Point Collecting / Property + Value

There are probably many ways you can set this up, but let see one way that I can explain.

From the above screenshot:
  • We have a simple game environment, from a Top View ortographic camera. 
  • Our hero character is that Box that moves in 4 directions (up, down, left, right).
  • There is that green sphere that this hero character must collect to get points.
Ok, now how to make it happen?

1.
For the Ball object to collect, we create this setup:
SENSORS: Collission -> Property: Hero
CONTROLLERS: And
ACTUATORS: Edit Object -> End Object


2.
For the Box object (Hero character), we create this setup:
SENSORS: Collision -> Property: Ball
CONTROLLERS: And
ACTUATORS: Property -> Add -> pointP, with a value of 1


What is really happening here? A lot:
  • We basically use SENSORS called Collision here and it will detect collisions event, all kind of collisions in fact even when our Box character is touching or colliding with the floor as Dynamic physic object. For our purpose, we only want to specifically detect collision event when Box is touching a Sphere. To do this, we created special Game Property for our Box (we call it "Hero"), and our Sphere (we call it "Ball").
  • Your noticed there is another Game Property called "pointP" as Integer value, for Box object. You can actually attach this Game Property into anything, maybe even on an Empty that stores everything Value related, and this is probably a better practice. Anyhow, for now, I added pointP as Game Property of the Box. This stores the number of POINT and keep adding the value whenever Box is Touching a Sphere.
  • With our Sphere, we also have SENSORS Collision that detects collision from Box only. But for Sphere ACTUATORS, we tell it to end/kill itself with ACTUATOR: Edit Object -> End Object.
In short, what we setup for BGE is really simple but very useful: 
Whenever box collides with sphere, add +1 point.

Property and Value play a very important part in Game. 

There is an alternative to this below.

BGE: Point Collecting via Message ACTUATOR and SENSOR

This is a really nice trick shown by Ian Scott, I will have to point the YouTube links again because I learned this nice trick from him: 

So, this is a cool technique and probably a concept that you will use more often, especially when you started to use Python for the BGE.

Basically, instead of relying so much on Collision SENSORS and ACTUATORS, we also use Message SENSORS and ACTUATORS.

The Logic Network becomes like this: (here we use Near SENSORS)

1.
On the Sphere:

SENSORS: Near
CONTROLLERS: And
ACTUATORS: Edit Object -> End Object
ACTUATORS: Message -> ping (this subject can be anything)

Now, with that setup, whenever our Hero Box got near the Sphere, it will "broadcast" a message to the whole scene, and hopefully the message got delivered, only if we specify a listener.

2.
On the Box:

SENSORS: Message -> ping
CONTROLLERS: And
ACTUATORS: Property -> Add -> PointP -> value of 5

By using Message SENSORS and ACTUATORS, we can have something that is more logical.

The same concept is used again and again: TRIGGER and ACTION. You also learn a new things here: to store and update a value inside Game Property.

It maybe quite a lot to digest already, but hopefully by now you understand how you can CONTROL and then STORE POINT.

TIPS: Showing Debug Property / Show Property + Value as HUD
To show the Game Property and its Value while you are in game, you activate the "Show Debug Properties".  This of course will be updated in real time in game. It gives a quick easy feedback for user.



So, now, for every Game Property with (i) toggle active (like above), it shows up as game HUD that you can track and evaluate.

Text In Game:
For text in game using UV, I probably cannot explain it any clearer than this video tutorial by Ian Scott:
http://www.youtube.com/watch?v=GKO4jfAHtjk

(I might make additional note here later.)

Dynamic Text Object In Game Using Python:
From the Blender Artist Forum:
http://blenderartists.org/forum/archive/index.php/t-246300.html

Maybe clearer explained in this video:
http://www.youtube.com/watch?v=XJloTwG-mnU

My quick attempt to Python code a Dynamic Text that is reading Property Value is like this:


Well, that seems to work. The script basically keeps on monitoring and updating the value and assigned it back to the Text dynamically.

But maybe not very efficient or there is a better way? Anyone knows?

import bge

def main():
    scene = bge.logic.getCurrentScene()
    player = scene.objects['Cube']
    dynamicText = scene.objects['Text']

    def Update():
        moves = player.get('pointP')
        dynamicText.text = str(moves)

    Update()
main()

(I bet I will need to revise this code in the near future.)

I guess the reason game written in code eventually is just because things are still faster to modify and to recreate as a code or module, but more logical and easy to visual as nodes/brick and noodles when you are still prototyping.

I am not from programmer background so I am more used to the node based system compared to code.

MYSTERY: Text Game Property
What does Text Game Property do anyway?


BGE: SOUND

I am going over a lot of things very quickly, hopefully your brain can still take it.

You learn above how you can use Message SENSORS and ACTUATORS as messenger to trigger something? The same setup can be used to broadcast Message to trigger Sound.

On Empty: (to store all kind of Sound Message SENSORS)

On Sphere:

Above, we are using the non-direct way to trigger Sound: An object send/broadcast Message to the Scene and another object listen to Message the do something.

Sometimes if the object end/kill itself, it tends to disappear before Sound being triggered, but it will still send Message. Maybe there is some kind of Logic Order in BGE.

Anyhow, it seems to be a lot safer if you use the non-direct method via Message.

In simpler Sound setup, you may directly hook the Sound ACTUATOR triggered by Keyboard SENSORS, say if the character is shooting and the sound can be triggered at the same time.

SOUND IS IMPORTANT(!)
Remember: Sound is really super important feedback in a game, apart from visual or animation feedback. For example: Coin sound and 1UP sound in Super Mario Bros is so enchanting that you remember it forever and the game will not be the same without it!

Read this article about Sound Design of Journey from Gamasutra:
http://www.gamasutra.com/view/feature/179039/the_sound_design_of_journey.php

SOUND: Pacman Paku Paku Sound
Another example: The sound that Pacman made whenever it moves and eats the yellow sphere.

Recall your Pacman game memory here:

Download this sound:

Recreate the sound in Blender: (I found this by accident)


WHAT WE HAVE SO FAR
So this is a very rough prototype of potential game already:


Here we have our CONTROL, HERO Character, SCORE, and SOUND.

What else can we add: Objective? Enemy? Obstacle? Actions Animations? More Colorful Environment? You see that how quickly now you started to have the "game logic" happening inside your brain.

Try making the environment more pretty and have your own model with texture.

GAME: Snake
Can you create SNAKE game from here? That will be an interesting challenge.

Logically, whenever the Box eats the Sphere, the Box will duplicate itself and have a delayed Box that trails and follows behind the original Box, so it gets longer and longer The original Box cannot touch the Box trails.

Well, probably not that simple, but I think it is possible.

STUDY OTHER GAMES
I think it is best to look at the many BGE Video Tutorial out there first. Many game artists already kind enough to share their knowledge.

Study some of the classic and popular games. Study Flash Games and also look at some recent creative Indy Games.

Look at some games created using Scratch:

Some of the most popular or the best games are using simple Game Mechanic.

Sooner or later you started to develop better understanding of Game Design.  Eventually you start to think about the Game Mechanic and maybe even come out with brand "new" nice idea for a game.

That is exactly what I will do:
To look at some games and try to deconstruct the game inside Blender Game Engine.

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget