Tuesday, June 17, 2014

Simple Platformer Day 09

Static: everything used by a static function needs to also be static.
(still not super clear on what can and cannot be static, research reading later)

Crazy hackery to refer to an otherwise non-static class:

Protected static  |class| |instance name| = null;

void Awake() {
|instance name| = this;
}

Notes:
 protected = just means "members of flowerScript can see this, everyone else go away"
static = "this variable is shared by every member of this class, and you don't need to be a member to use it"
flowerScript = this is the type of our variable
m_instance = the name I picked out
"type" is like int, string, etc.
Any class you make is a type too.
null = I don't have an initial value for this, so I'm leaving it empty for now
Singleton: a clean way for static objects to be able to accept and use editor links.

  • Made a killfloor.
  • Restart function currently cannot reposition player due to  "NullReferenceException: Object reference not set to an instance of an object"

  • Need to figure out a way for restart function to wipe out all remaining flowers on screen.
  • Need to get a restart button to display on player death.

Simple Platformer Day 09

Static: everything used by a static function needs to also be static.
(still not super clear on what can and cannot be static, research reading later)

Crazy hackery to refer to an otherwise non-static class:

Protected static  |class| |instance name| = null;

void Awake() {
|instance name| = this;
}

Notes:
 protected = just means "members of flowerScript can see this, everyone else go away"
static = "this variable is shared by every member of this class, and you don't need to be a member to use it"
flowerScript = this is the type of our variable
m_instance = the name I picked out
"type" is like int, string, etc.
Any class you make is a type too.
null = I don't have an initial value for this, so I'm leaving it empty for now
Singleton: a clean way for static objects to be able to accept and use editor links.

Monday, June 16, 2014

Simple Platformer Day 08

Today: 15ish minutes to follow a tutorial, and an hour with the help of Herbie to try to unravel why I can't get the text to show up.

Lesson learned:
Do NOT attach GUI as a child or component to... everything else, because its position works differently than... everything else.

Forumer's post that helped me discover this mistake:
"Please do what I said and make the GUIText a separate object. It should not be a child of the camera, it should not be a component on the camera. It must be a totally separate independent object because it uses viewport space, not world space. It works 100% correctly: GameObject > Create Other > GUIText. Do not move it away from the 0..1 range in x/y or it won't be visible."

Solution:
Created a separate script for GUI.
 void OnGUI(){
        gameObject.guiText.text = "Score:" + GM_Cs.theScore;
    }

How position works: 0.5, 0.9 would be "upper middle of the screen".

noted for later use, changing something's position in script:

gameObject (or score.gameObject) .transform.position

Friday, June 13, 2014

Simple Platformer Day 07

Never has easy as it could be, but I learned how to define and call static functions from different scripts today.
 GM_Cs.addScore();

GetComponent only works on components that are attached to the same object.
FindObjectByName calls for object if you already know its name.

Still unsure how to use the above two to refer to non-static functions between scripts.  Need to learn eventually.

I got the score to work and to add up.  Next up: figuring out basic GUI display for the score.

Tuesday, June 10, 2014

Simple Platformer Day 06

Day 6:
With Herbie's help, figured out how to destroy flowers using both trigger and collision.

Trigger:
check "is trigger" box in unity

void OnTriggerEnter2D() { Destroy (this.gameObject);}

Collision:
uncheck the trigger box in unity

void OnCollisionEnter2D (Collsion2D col) {}
(also accidentally killed player by using Destroy (col.gameObject);  need to learn parameters correctly.)

Lunch plans:

Do the score thing, including UI.

Tomorrow+'s plan:

  • Make kill floor.
  • Make player death function that calls a reset button.
  • Spawn an enemy that walks around the right platform.
  • Make sure flowers do not collide with enemy (likely adding if tag to the collision function)
  • Allow player to kill enemy by jumping on it.
  • Trigger player death if player collides with enemy.

Monday, June 9, 2014

Simple Platformer Day 05

Got a sprite to spawn after looking up 3 different tutorials to figure out 1 phrase...

"Instantiate"!!!

Syntax: Instantiate (name, position, rotation);

Below is my cobbled-together power-up spawn script.


Next Steps:
  • Make the flowers disappear when colliding with player;
  • Create a counter that goes up by one each time a flower is walked over;
  • Display said counter in the middle of the screen.

Friday, May 9, 2014

Simple Platformer Day 4

Day 4: 
Thanks to Herbie Piland for the fantastic teaching session in lists.


Figured out the first bit of the spawning pick-up puzzle: picking randomized yet pre-determined positions.

yay!  Just a console message now but so happy :)


Next up: 
  • Figure out how to spawn objects using that coordinate.
  • Bonus: randomly pick from 3 objects.
  • Make pick-up disappear on collision with player.
Learned stuff:

For loop:
for (int i = Random.Range(3,6); i>0; i--) {}

Write to debug log:
Debug.Log("hello");

List of Vector2 coordinates:
protected List<Vector2> coordinatePool = new List<Vector2>(new Vector2[]{new Vector2(5.0f,5.0f),new Vector2(10.0f,10.0f)};

Making templist to keep original list intact:
List<Vector2> tempCoordinatePool = new List<Vector2>(coordinatePool);

Picking a random item from the list:
int randomNumber = Random.Range(0,tempCoordinatePool.Count);
Vector2 spawnCoordinate = tempCoordinatePool[randomNumber];


Removing said item from list to prevent duplicate:
tempCoordinatePool.RemoveAt(randomNumber);

Wednesday, May 7, 2014

Simple Platformer 1 Day 03




Day 3

  • Converted gamecontrol script to C#
  • Figured out how to create a multi-dimensional array for potential flower spawning
  • Could not get a random number generator to work
  • Could not figure out how to pull coordinates from the array

Next
  • Extensively look into random number generator and array
  • Figure out how to spawn objects in predetermined coordinates
  • If I cannot figure out randomized coordinate-picking in 2 days, will instead go for randomly picking on/off switch at the start of the level on pre-determined pickup locations

Tuesday, May 6, 2014

Simple Platformer 1 Day 02

Day 2:
  • Created ground check using layer masks and improved jump function
  • Created background
  • Created invisible blocking boxes
  • Created art for pick-up but no functionality yet
  • Bonus: learned how to make character flip to face walking direction
Next Steps:
  • Figure out how to make flowers spawn randomly
  • Make flowers disappear when walked over by player
  • Kill floor - bottom collision box kills player and restarts game

Monday, May 5, 2014

Learning Project 1: Simple Platformer 1

Target Feature list:
  • Player that can move left, right, and jump (once before landing)
  • Simple platforms that collide with player
  • Scene boundries
  • A background layer
  • Score board
  • 1 pickup item that adds 1 to score
  • 1 enemy that moves on a pre-determined path, kills player on contact
  • restart button that appears after player dies
BTL features:
  • 1 new pickup item that grands double-jump
  • Win condition and win screen
  • Player shoots a projectile that kills enemies
  • 1 new enemy that chases the player
  • Trap tile that kills the player
  • Player health bar
  • 1 new pickup item that restores player health
  • High score board


Day 1:

Made 1 platform that collides with player.
Made 1 player that can be controlled to move left, right, and jump - currently unlimited.

Day 1 Lunch:

Downloaded sample project bundle http://u3d.as/content/m2h/c-game-examples/1sG
Converted player control script to C#.

Plans for Day 2:

Figure out how to limit the player to jump only once before landing.
Make a background image
Make scene boundries
Make a pickup item that spawns randomly