Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Game Programming Lab: Name-Asmt Gupta REG NO.-18BCE0904

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

GAME PROGRAMMING LAB

LAB FAT
NAME-ASMT GUPTA
REG NO.-18BCE0904

. Create an ocean environment. The player has to collect the


pearl containing shells from the ocean. Each cell collection will
increase the point. When enemies are attacking, player health
will come down. When the player health becomes zero game
over

Aim:
To make an ocean environment where player has to collect pearls contained in the shells
and also implementing player health deteriorating system
PROCEDURE:-
1. ADD THE PANEL WITH BACKGROUND IMAGE
2. ADD THE CHARACTER ADD SCRIPT FILE TO IT
3. ADD HEALTH WITH IT SCRIPT FILE
4. ADD ENEMY WITH SCIPT FILE
5. ADD GROUND WITH RIGIB BODY
OUTPUT
CODE:-
Playerctrl.cs
health,cs
using UnityEngine;
using System.Collections;

public class Health : MonoBehaviour {

public enum deathAction {loadLevelWhenDead,doNothingWhenDead};

public float healthPoints = 1f;


public float respawnHealthPoints = 1f; //base health points

public int numberOfLives = 1; //lives and variables for


respawning
public bool isAlive = true;
public GameObject explosionPrefab;

public deathAction onLivesGone = deathAction.doNothingWhenDead;

public string LevelToLoad = "";

private Vector3 respawnPosition;


private Quaternion respawnRotation;

// Use this for initialization


void Start ()
{
// store initial position as respawn location
respawnPosition = transform.position;
respawnRotation = transform.rotation;

if (LevelToLoad=="") // default to current scene


{
LevelToLoad = Application.loadedLevelName;
}
}

// Update is called once per frame


void Update ()
{
if (healthPoints <= 0) { // if the object is 'dead'
numberOfLives--
; // decrement # of lives, update lives GUI

if (explosionPrefab!=null) {
Instantiate (explosionPrefab, transform.position, Quaternion.i
dentity);
}

if (numberOfLives > 0) { // respawn


transform.position = respawnPosition; // reset the player to
respawn position
transform.rotation = respawnRotation;
healthPoints = respawnHealthPoints; // give the player full he
alth again
} else { // here is where you do stuff once ALL lives are gone)
isAlive = false;

switch(onLivesGone)
{
case deathAction.loadLevelWhenDead:
Application.LoadLevel (LevelToLoad);
break;
case deathAction.doNothingWhenDead:
// do nothing, death must be handled in another way elsewh
ere
break;
}
Destroy(gameObject);
}
}
}

public void ApplyDamage(float amount)


{
healthPoints = healthPoints - amount;
}

public void ApplyHeal(float amount)


{
healthPoints = healthPoints + amount;
}

public void ApplyBonusLife(int amount)


{
numberOfLives = numberOfLives + amount;
}

public void updateRespawn(Vector3 newRespawnPosition, Quaternion newRespaw


nRotation) {
respawnPosition = newRespawnPosition;
respawnRotation = newRespawnRotation;
}
}

You might also like