UNITY: USING FIREBALL TO ELIMINATE ENEMIES

 Code user in the video:

Fireball Controller

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FireballController : MonoBehaviour {
  Transform player;
  Rigidbody2D rb;
  float speed = 400.0f;
  float direction = 1;

  // Use this for initialization
  void Start () {
    rb= GetComponent<Rigidbody2D>();
    player = GameObject.Find("Player").transform;

    if(player.localScale.x == -1){
      direction = -1;
    }
  }
 
  // Update is called once per frame
  void Update () {
    rb.velocity = new Vector2(direction * speed * Time.deltaTime, rb.velocity.y);
  }

  private void OnCollisionEnter2D(Collision2D other) {
    if(other.gameObject.tag == "Enemy"){
      other.transform.localScale = new Vector2(1, -1);
      other.transform.GetComponent<BoxCollider2D>().enabled = false;

      Destroy(other.gameObject, 2.0f);
    }
    //remove/destroy the fireball
    Destroy(gameObject);
  }
}



Player Controller

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour {
  Rigidbody2D playerRB;
  BoxCollider2D playerCollider;

  float moveSpeeed = 200.0f;
  float direction;

  float jumpHeight = 8.0f;
  LayerMask groundLayer;
  bool playerIsGrounded = false;
  bool doubleJumped = false;
  AudioSource[] audioSources;
  Animator playerAnimator;

  [SerializeField] GameObject fireball;
  [SerializeField] Transform firePoint;

  // Use this for initialization
  void Start () {
    playerRB = GetComponent<Rigidbody2D>();
    playerCollider = GetComponent<BoxCollider2D>();
    groundLayer = LayerMask.GetMask("Ground");
    audioSources = GetComponents<AudioSource>();
    playerAnimator = GetComponent<Animator>();
  }

  private void FixedUpdate() {
    playerIsGrounded = Physics2D.IsTouchingLayers(playerCollider, groundLayer);
  }
 
  // Update is called once per frame
  void Update () {
    direction = Input.GetAxisRaw("Horizontal");
    move(direction);

    // JUMP ROUTINE
    if(playerIsGrounded){
      doubleJumped = false;
    }
    //for the first jump
    if(Input.GetKeyDown(KeyCode.Space) && playerIsGrounded){
      jump();
    }
    //for the second jump
    if(Input.GetKeyDown(KeyCode.Space) && !playerIsGrounded && !doubleJumped){
      jump();
      doubleJumped = true;
    }
    // END JUMP ROUTINE

    // =============== ANIMATIONS =============================

    playerAnimator.SetFloat("Speed", Mathf.Abs(direction));
    playerAnimator.SetBool("Grounded", playerIsGrounded);

    // =============== END ANIMATIONS =============================

    if(transform.position.y < -3){
      //game over
      SceneManager.LoadScene("GameOverScene");
    }

    if(Input.GetKeyDown(KeyCode.L)){
      //play gunshot audio
     
      //fire the fireball
      Instantiate(fireball, firePoint.position, firePoint.rotation);
    }

  }

  void move(float direction){
    if(direction == 1){
      transform.localScale = new Vector3(1, 1, 1);
    }else if(direction == -1){ //should use this condition so that the character will not always face the left
      transform.localScale = new Vector3(-1, 1, 1);
    }
    float velocity = direction * moveSpeeed * Time.deltaTime;
    playerRB.velocity = new Vector2(velocity,playerRB.velocity.y);
  }
  void jump(){
    playerRB.velocity = new Vector2(playerRB.velocity.x, jumpHeight);
    audioSources[0].Play();
  }

  private void OnCollisionEnter2D(Collision2D otherObject) {
    if(otherObject.transform.tag.Equals("Obstacle")){
      PlayAudio(1);
    }else if(otherObject.transform.tag.Equals("Enemy")) {
      PlayAudio(2);
      SceneManager.LoadScene("GameOverScene");
    }
  }

  private void OnTriggerEnter2D(Collider2D otherObject) {
    if(otherObject.transform.tag.Equals("Enemy")){
      Debug.Log("Game Over!");
    }
  }

  void PlayAudio(int index){
    StopAllAudio();
    audioSources[index].Play();
  }

  void StopAllAudio(){
    for(int i=0;i<audioSources.Length;i++){
      if(audioSources[i].isPlaying){
        audioSources[i].Stop();
      }
    }
  }


}





UNITY : ENEMY BASIC AI

 Code as seen in the video:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAI : MonoBehaviour {
  [SerializeField] Transform player;
  Rigidbody2D enemyRB;
  float moveSpeeed = 1.0f;
  float attackRange = 5.0f;

  void Start () {
    enemyRB = GetComponent<Rigidbody2D>();
  }
 
  // Update is called once per frame
  void Update () {
    float distanceToPlayer = Vector2.Distance(transform.position, player.position);

    if(distanceToPlayer <= attackRange){
      attack();
    }
  }
  void attack(){
    if(player.transform.position.x < transform.position.x){
      transform.localScale = new Vector3(1, 1, 1);
    }else{
      transform.localScale = new Vector3(-1, 1, 1);
    }


    transform.position = Vector2.MoveTowards(transform.position, player.position, moveSpeeed * Time.deltaTime);
  }

}





UNITY : DESIGNING ENEMIES FOR YOUR GAME

 Code used in the video:


EnemyController

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyController : MonoBehaviour {
  Rigidbody2D enemyRB;
  float moveSpeeed = 200.0f;
  [SerializeField] float direction;

  // Use this for initialization
  void Start () {
    enemyRB = GetComponent<Rigidbody2D>();
  }
 
  // Update is called once per frame
  void Update () {
    if(direction == 1){
      transform.localScale = new Vector3(-1, 1, 1);
    }else if(direction == -1){
      transform.localScale = new Vector3(1, 1, 1);
    }
    enemyRB.velocity = new Vector2(direction * moveSpeeed * Time.deltaTime, enemyRB.velocity.y);
  }

  private void OnCollisionEnter2D(Collision2D other) {
    direction *= -1;
  }

  private void OnTriggerEnter2D(Collider2D other) {
    direction *= -1;
  }
}


GETTING STARTED WITH JAVASCRIPT

 Code used in the video:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>

      const greet = (name) => {
        console.log(`Hello ${name}`);
      }
      greet('Pablo');

      function add(a, b){
        return a+b;
      }

      const add2 = (a, b) => a+b;

      // function greet(name) {
      //   console.log(`Hello ${name}`);
      // }

      const buttonClicked = () => {
        var hdr = document.getElementById('main-header');
        hdr.style.color = 'green';
        //hdr.innerHTML = "<span style='color: red;'>Hello World!</span>";
     
        document.getElementById('bike-image').src = "bike2.jpg";

        //create element
        var subHeader = document.createElement('h2');
        subHeader.innerText = "This is a subheader";
        //create element
        var subHeader2 = document.createElement('h3');
        subHeader2.innerText = "This is a subheader 2";
        //add to main-div
        var mainDiv = document.getElementById('main-div');
        mainDiv.appendChild(subHeader);
        mainDiv.appendChild(subHeader2);

        //remove element
        mainDiv.removeChild(subHeader2);
      }

      document.addEventListener('DOMContentLoaded', () =>{
        var btn = document.createElement('button');
        btn.innerText = "Button Inside the Div!";
        btn.addEventListener('click', () => {
          alert('Button clicked!');
        });

        var mainDiv = document.getElementById('main-div');
        mainDiv.appendChild(btn);
      });
    </script>
     
  </head>
  <body>
    <h1 id="main-header">Hello World!</h1>

    <img src="bike.jpg" id="bike-image" alt="placeholder image" width="200px" height="100px">

    <div id="main-div">
     
    </div>

    <button type="button" onclick="buttonClicked()">Click me!</button>

  </body>
</html>

DISPLAY LIST IN A LISTVIEW - BASIS DATA STRUCTURE IN DART/FLUTTER

 Code as seen in the video:

import 'package:flutter/material.dart';
import 'package:lessons/widget_creator.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _controller = TextEditingController();
  List<String> _namesList = ["Micky", "Donald", "Goofy", "Pluto"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Column(
            children: [
              createHeaders("Flutter University hehehe", "Working with Lists"),
              vSpacer(10.0),
              createTextField(
                  _controller, "Name", "Enter your name here", Icons.abc),
              vSpacer(10.0),
              ElevatedButton(
                onPressed: () {
                  setState(() {
                    _namesList.add(_controller.text);
                    _namesList.sort();
                  });
                },
                style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
                child: const Text(
                  "Add To List",
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ),
              vSpacer(15.0),
              Expanded(
                child: createListview(),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget createListview() {
    return ListView.builder(
      itemCount: _namesList.length,
      itemBuilder: (context, index) {
        return Card(
          child: ListTile(
            title: Text(_namesList[index]),
            onTap: () => showDialogBox("Selected Student", _namesList[index]),
          ),
        );
      },
    );
  }

  void showDialogBox(String title, String content) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: Text(content),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text(
                  "Close",
                ),
              ),
            ],
          );
        });
  }
}


WORKING WITH LISTS - BASIC DATA STRUCTURE IN DART/FLUTTER

 Code as seen in the video:

main.dart

import 'package:flutter/material.dart';
import 'package:lessons/widget_creator.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _controller = TextEditingController();
  List<String> _namesList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Column(
            children: [
              createHeaders("Flutter University hehehe", "Working with Lists"),
              vSpacer(10.0),
              createTextField(
                  _controller, "Name", "Enter your name here", Icons.abc),
              vSpacer(10.0),
              ElevatedButton(
                onPressed: () {
                  _namesList.add(_controller.text);
                  print(_namesList);
                  print("First Student: ${_namesList.first}");
                  print("Last Student: ${_namesList.last}");
                  print("Student at index 0: ${_namesList[0]}");
                  print("Number of students: ${_namesList.length}");
                },
                style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
                child: const Text(
                  "Add To List",
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void showDialogBox(String title, String content) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: Text(content),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text(
                  "Close",
                ),
              ),
            ],
          );
        });
  }
}







UNITY: USING FIREBALL TO ELIMINATE ENEMIES

 Code user in the video: Fireball Controller using System . Collections ; using System . Collections . Generic ; using UnityEngine ; publ...