Pular para o conteúdo principal

GameDev Tutorial - Basic Circle Chain Engine Using Unity3D Part 2

This part 2 is not so detailed like before, so If you need you can see the part 1 here: http://alxcancado.tumblr.com/post/62482465038/gamedev-tutorial-basic-circle-chain-engine-using

Once again I want say that this is my port for Unity3D from Emanuele Feronato's tutorial: http://www.emanueleferonato.com/2013/05/21/from-zero-to-a-complete-game-with-cocos2d-html5-step-2-mouse-interaction/

 

Okay, time to put some mouse interaction.

1. add the new textures: red circle, bullet red; configure texture type to advanced, uncheck generate mipmap and filter mode to point.

Redbullet

Redcircle

1. add the new images

1. config textures

2. drag and drop the greencircleprefab from prefab folder to the hierarchy. drag and drop the red circle texture to this and rename to RedCircle. Remove the GreenCricle script from it. We will create a script to this object later.

2. red circle

3. But we still need create our Bullet prefab. To make it simple, just duplicate the RedCircle object from hierarchy panel with Command+D or (Control+D in windows?). Then rename this new object to RedBulletPrefab. Drag n drop the bullet texture to it. We will add a Bullet script later. All done, drag n drop the RedBulletPrefab from Hierarchy to your Prefab folder in your project files, so we create a Prefab of the bullet object. Since we will instantiate bullet objects by code, you can delete the RedBulletPrefab from the Hierarchy panel.

 

4. Bullet Object.png

4. Now lets add some player control to RedCircle: go to your script folder and create a new c# script RedCircle; Don't forget to add this script to the RedCircle.

using UnityEngine;

using System.Collections;

 

public class RedCircle : MonoBehaviour {

// for mouse controller

public float mousePos;

// for 2d position calc

public Camera cam;

 

 

// prefab to be instantieated

public GameObject redBulletPrefab;

public float redBulletXSpeed;

public float redBulletYSpeed;

public float bulletSpeed = 5;

 

 

// Use this for initialization

void Start () {

cam = Camera.main.GetComponent<Camera>(); // get the Main Camera instance

}

 

// Update is called once per frame

void Update () {

 

attachObjectToMouse ();

 

// if left mouse clicks instantiate our bullets

if (Input.GetMouseButtonDown(0)){

            

// 4 directions 

for (int i = 0; i < 4; i++) {

 

// calc the direction of the bullet

redBulletXSpeed = bulletSpeed * Mathf.Cos(i * Mathf.PI / 2); //redBullet.xSpeed=bulletSpeed*Math.cos(i*Math.PI/2);

            redBulletYSpeed = bulletSpeed * Mathf.Sin(i * Mathf.PI / 2); //redBullet.ySpeed=bulletSpeed*Math.sin(i*Math.PI/2);

 

// create a instance of bullet

GameObject clone = Instantiate(redBulletPrefab, transform.position, transform.rotation) as GameObject;

clone.SendMessage("setBulletXSpeed", redBulletXSpeed);

clone.SendMessage("setBulletYSpeed", redBulletYSpeed);

 

}

 

}

}

 

 

private void attachObjectToMouse () {

Vector3 screenPos = Input.mousePosition; 

 

// need convert 2d position (from mouse) to 3d world position

Vector3 worldPos = new Vector3(cam.ScreenToWorldPoint(screenPos).x, cam.ScreenToWorldPoint(screenPos).y, cam.ScreenToWorldPoint(screenPos).z); 

 

// set the red circle object position

gameObject.transform.position = worldPos;

 

}

 

}

5. Now you can movement the Red Circle with mouse! But we still need create a script to control the bullets and then add this script to our RedBulletPrefab prefab:

using UnityEngine;

using System.Collections;

 

public class Bullet : MonoBehaviour {

// objects pooling: http://channel9.msdn.com/Events/Windows-Camp/Building-Windows-Games-with-Unity/Deep-dive-Tips-tricks-for-porting-games-from-other-platforms-to-Windows-8

 

// bullet 

public float redBulletXSpeed;

public float redBulletYSpeed;

 

// for 2d position calc

public Camera cam;

public float screenX; // = Camera.current.ScreenToWorldPoint( new Vector3 (Screen.width, 0, 0)).x;

public float screenY; // = Camera.current.ScreenToWorldPoint( new Vector3 (0, Screen.height, 0)).y;

 

// Use this for initialization

void Start () {

cam = Camera.main.GetComponent<Camera>(); // get the Main Camera instance

}

 

// Update is called once per frame

void Update () {

transform.Translate( new Vector3(redBulletXSpeed, redBulletYSpeed, 0 ) * Time.deltaTime);

//transform.Translate( new Vector3(0f, ySpeed*Time.deltaTime, 0f) );

 

// get screen limits

getCurrentMaxWorldScreen();

 

// destroy bullets if off screen

deleteOffScreenObject();

}

 

// get our screen limits

public void getCurrentMaxWorldScreen(){

screenX = cam.ScreenToWorldPoint( newVector3 (Screen.width, 0, 0)).x;//Camera.current.ScreenToWorldPoint( new Vector3 (Screen.width, 0, 0)).x;

screenY = cam.ScreenToWorldPoint( new Vector3 (0, Screen.height, 0)).y;

}

 

public void deleteOffScreenObject(){

// if the GreenCircle goes out the screen we manage to put it back

if(transform.position.x > (screenX)){

Destroy(this.gameObject);

 

}

if(transform.position.x < -screenX){

Destroy(this.gameObject);

}

if(transform.position.y > screenY){

Destroy(this.gameObject);

}

if(transform.position.y < -screenY){

Destroy(this.gameObject);

}

 

}

 

public void setBulletXSpeed(float speedX){

redBulletXSpeed = speedX;

}

 

public void setBulletYSpeed(float speedY){

redBulletYSpeed = speedY;

}

}

 

6. Now it's possible "shot" when we press the left mouse button:

6. done

You can download the project here: 

https://mega.co.nz/#!khQFHRKS!U_vdc2tEL7gGQkNq3mKOKkQtTztF1VrOR-TOGr-OxcU

Open the scene in Assets > CircleChain02 > Scenes and try it!

Comentários

Postagens mais visitadas deste blog

Gamasutra's Postmorten: RiverMan Media's MadStone

Aqui vão os meus comentários sobre este postmortem. O jogo em questão, MadStone, foi desenvolvido para a plataforma WiiWare, vindo de um antigo sonho de publicar um jogo para Nintendo (dos fundadores da RiverMan). MadStone é um puzzle 2d, onde as peças vão caindo (assim como tetris) e que custa U$8.00 no WiiWare. Antes de publicar um jogo para WiiWare, a desenvolvedora havia já desenvolvido outros dois jogos casuais para PC, Cash Cow e Primate Panic. Tela do jogo MadStone Bom, vamos às dicas deixadas pelos desenvolvedores: O que funcionou: 1. Correr atrás da Nintendo: Entre contatar a Nintendo e se tornar um desenvolvedor autorizado, os desenvolvedores tiveram que correr um pouco atrás. A primeira lição é justamente essa, não é fácil correr atrás e muitas vezes temos que sair de nossa zona de conforto para conseguir as coisas. 2. Plataforma 2D: A decisão de desenvolver um jogo 2D foi tomada por algumas facilidades como ferramentas de arte mais simples, como o photoshop; Pouco código

Converter campo text para varchar – SQL Server 2000

Outro dia, conversando com um analista de sistemas no trabalho, este me perguntou, qual era melhor, usar o tipo text ou varchar no campo. Bom, baseado em minhas experiências, respondi que prefiro trabalhar com varchar. Mas antes, uma breve pesquisa no google nos mostrou que: text     Variable-length data with a maximum length of 2^31 - 1 characters varchar Variable-length data with a maximum of 8,000 characters fonte: Database Journal Depois de analisarmos o propósito a que o campo serviria, decidimos por um campo varchar(500). Se você, assim como eu, tentou utilizar uma alter table, alter column, deve ter visto um aviso do SQL Server de que isto não é possível de se fazer. Mas e agora? É isso mesmo que pensamos: temos que criar o novo campo e popular com o que havia no antigo campo. Exemplo: EXEC sp_rename 'tab_inf_nota.mensagem', 'mensagem_old', 'COLUMN'

My fist job @ game industry!

Yes, yes and yes! I have no words to describe this! Awesome, hot, wild! So, what I did? Work as Game Tester for  @LowpolyStudios The game Blowing Pixels Planet Defender for #iPhone was sended to Apple Store review in August 17 and is expected to launch in August 29, so stay tunned! Blowing Pixels Planet Defender, or just BPPD, is a Defender kind game, so you have to break the enemies invasion. Actually, this game is so addictive, like play Tetris! Your brain will enjoy, hwar, hwar, hawr... You can see more details @ developer's web sites: http://www.lowpoly-studios.com/ http://www.facebook.com/LowpolyStudios http://twitter.com/#!/lowpolystudios http://www.blowing-pixels.com/planet_defender.php Oh! Yeah, the Credit Screen: I'm in Testers part: ALEX CANCADO. So, fuck'n YEAH! Next related post I will write about how I get in touch with developer and my contribution about the game.