//================================================================

//
// Copyright (C)
// All Rights Reserved
//
// Author:小妖精Balous

//

//Summary:啊咧咧,小妖精Balous因为要应付学校的作业,同时要照顾新手程序员,所以把项目改成了东方project同人作了呢~

//      向神主大人致敬!然后,这是段自机代码的初稿呢~~不知米娜桑能不能看得小妖精Balous写的代码呢~~~~
//
//================================================================

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

public abstract class Player : MonoBehaviour
{
public GameObject baseBullet;
/// <summary>
/// 子机
/// </summary>
public GameObject subCraft;
private List<SubCraft> subCraftList;

/// <summary>
/// 残机,最大为8
/// </summary>
public int player
{
get
{
return _player;
}
set
{
if (value > 8) _player = 8;
else if (value < 0) _player = 0;
else _player = value;
}
}
private int _player;
/// <summary>
/// 残机碎片,收集5个增加1残机
/// </summary>
public int playerFragment
{
get
{
return _playerFragment;
}
set
{
if (value <= _playerFragment || player == 8) return;
_playerFragment++;
if(_playerFragment == 5)
{
_playerFragment = 0;
_player++;
}
}
}
private int _playerFragment;

/// <summary>
/// 力量,最大为4.00
/// </summary>
public float power
{
get
{
return _power;
}
set
{
if (value > 4f) _power = 4f;
else if (value < 0f) _power = 0f;
else _power = value;

if (subCraft != null)
{
int difference = (int)_power - subCraftList.Count;
while (difference > 0)
{
GameObject subCraftClone = Instantiate(subCraft);
subCraftList.Add(subCraftClone.GetComponent<SubCraft>());
difference--;
}
while (difference < 0)
{
SubCraft subCraftClone = subCraftList[subCraftList.Count - 1];
subCraftList.Remove(subCraftClone);
Destroy(subCraftClone.gameObject);
difference++;
}
}
}
}
private float _power;

/// <summary>
/// 炸弹,最大为8
/// </summary>
public int bomb
{
get
{
return _bomb;
}
set
{
if (value > 8) _bomb = 8;
else if (value < 0) _bomb = 0;
else _bomb = value;
}
}
private int _bomb;
/// <summary>
/// 炸弹碎片,收集5个增加1炸弹
/// </summary>
public int bombFragment
{
get
{
return _bombFragment;
}
set
{
if (value <= _bombFragment || bomb == 8) return;
_bombFragment++;
if(_bombFragment == 5)
{
_bombFragment = 0;
_bomb++;
}
}
}
private int _bombFragment;

/// <summary>
/// 擦弹
/// </summary>
public int graze
{
get
{
return _graze;
}
set
{
if (value <= 0) _graze = 0;
else if (value > _graze)
{
_graze++;
_score += 300;
}
}
}
private int _graze;

/// <summary>
/// 得分
/// </summary>
public int score
{
get
{
return _score;
}
set
{
if (value < 0) _score = 0;
else if (value > 999999999) _score = 999999999;
else _score = value;
}
}
private int _score;

/// <summary>
/// 无敌持续时间,大于0f为无敌
/// </summary>
protected float invincibleTime;
/// <summary>
/// 距离下次自机子弹生成的剩余时间,大于0f不会生成子弹
/// </summary>
private float shootTime;
/// <summary>
/// 距离下次可以使用炸弹的剩余时间,大于0f不能使用炸弹
/// </summary>
protected float bombTime;
/// <summary>
/// 自机子弹生成间隔
/// </summary>
public float timeInterval;

public float normalMoveSpeed;
public float slowMoveSpeed;
private float moveSpeed;

protected virtual void Move()
{
if (Controller.Slow()) moveSpeed = slowMoveSpeed;
else moveSpeed = normalMoveSpeed;

//up,left,down,right
int[] direction = new int[4] { 0, 0, 0, 0 };
if (Controller.LeftArrow()) direction[1] = 1;
if (Controller.DownArrow()) direction[2] = 1;
if (direction[1] == 0 && Controller.RightArrow()) direction[3] = 1;
if (direction[2] == 0 && Controller.UpArrow()) direction[0] = 1;

int count = 0;
foreach (int i in direction) count += i;

if (count == 0) return;
if (count == 1)
{
if (direction[1] == 1) transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
else if (direction[3] == 1) transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
else if (direction[2] == 1) transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);
else transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
}
else
{
if (direction[2] == 1) transform.Translate(Vector3.down * moveSpeed * Time.deltaTime * 0.7071067812f);
else if (direction[0] == 1) transform.Translate(Vector3.up * moveSpeed * Time.deltaTime * 0.7071067812f);
if (direction[1] == 1) transform.Translate(Vector3.left * moveSpeed * Time.deltaTime * 0.7071067812f);
else if (direction[3] == 1) transform.Translate(Vector3.right * moveSpeed * Time.deltaTime * 0.7071067812f);
}
}

protected virtual void Init()
{
player = 3;
power = 1f;
bomb = 3;
graze = 0;
score = 0;
invincibleTime = 3f;
shootTime = 0f;
bombTime = 0f;
_playerFragment = 0;
_bombFragment = 0;

subCraftList = new List<SubCraft>();
if (subCraft != null)
{
GameObject subCraftClone = Instantiate(subCraft);
subCraftList.Add(subCraftClone.GetComponent<SubCraft>());
}
}

protected virtual void Shoot()
{
GameObject baseBulletClone = Instantiate(baseBullet, transform.position + new Vector3(-0.1f, 0.2f, 0f), Quaternion.identity);
Destroy(baseBulletClone, 13f);
baseBulletClone = Instantiate(baseBullet, transform.position + new Vector3(0.1f, 0.2f, 0f), Quaternion.identity);
Destroy(baseBulletClone, 13f);
}

protected abstract void Bomb();

void Start ()
{
Init();
}

void Update ()
{
if (invincibleTime > 0f) invincibleTime -= Time.deltaTime;
if (bombTime > 0f) bombTime -= Time.deltaTime;
if (shootTime > 0f) shootTime -= Time.deltaTime;

Move();

if (shootTime <= 0f && Controller.Shoot() && baseBullet != null)
{
shootTime += timeInterval;
Shoot();
}

if (Controller.BombDown() && bombTime <= 0f) Bomb();
}

private void OnEnable()
{
if (GameManager.player != null) Debug.LogError("你尝试创建2个Player,这种情况不允许!");
GameManager.player = this;
}

private void OnDisable()
{
GameManager.player = null;
}
}

小妖精的完美游戏教室——东方project,同人,自机的更多相关文章

  1. 小妖精的完美游戏教室——东方PROJECT,同人,墙

    //================================================================//// Copyright (C) 东方同人社// All Rig ...

  2. 小妖精的完美游戏教室——东方PROJECT,同人,符卡系统

    //================================================================//// Copyright (C) 东方同人社// All Rig ...

  3. 小妖精的完美游戏教室——东方PROJECT,同人,th12灵梦A

    ╮(╯▽╰)╭没办法,小妖精Balous也很讨厌学院化的教育呀,一点意义都没有. 这次就上传东方地灵殿灵梦A逻辑部分的核心代码吧,估计连老师都看不懂.动画部分的代码就不放上来了. //======== ...

  4. 小妖精的完美游戏教室——东方PROJECT,同人,子机

    //================================================================//// Copyright (C)// All Rights Re ...

  5. 小妖精的完美游戏教室——人工智能,A*算法,引言

    今天也要直播魔法,求科学的! 欢迎来到小妖精Balous的完美游戏教室! 经过前两周的学习,相信米娜桑已经对状态机有所了解了呢~虽然状态机能够实现几乎所有的人工智能,但是,在实践中,你们有没有发现,自 ...

  6. 小妖精的完美游戏教室——人工智能,A*算法,启发因子篇

    //================================================================//// Copyright (C) 2017 Team Saluk ...

  7. 小妖精的完美游戏教室——人工智能,A*算法,导航网络篇

    //================================================================//// Copyright (C) 2017 Team Saluk ...

  8. 小妖精的完美游戏教室——人工智能,A*算法,结点篇

    //================================================================//// Copyright (C) 2017 Team Saluk ...

  9. 小妖精的完美游戏教室——人工智能,A*算法,实现篇

    //================================================================//// Copyright (C) 2017 Team Saluk ...

随机推荐

  1. linux --- 10.常见命令

    1.在登录Linux时,一个具有唯一进程ID号的shell将被调用,这个ID是什么()A.NID B.PID C.UID C.CID 2.下面那个用户存放用户密码信息()A./boot B./etc ...

  2. Ubuntu 16.04下vsftpd 安装配置实例

    从https://www.linuxidc.com/Linux/2017-06/144807.htm转载 第一步:安装VSFTPD sudo apt-get install vsftpd 安装完成后启 ...

  3. POJ 2774 Long Long Message (二分 + Hash 求最长公共子串)题解

    题意:求最长公共子串 思路:把两个串Hash,然后我们把短的作为LCS的最大可能值,然后二分长度,每次判断这样二分可不可以.判断时,先拿出第一个母串所有len长的子串,排序,然后枚举第二个母串len长 ...

  4. 【做题】SDOI2017苹果树——dfs序的运用

    原文链接 https://www.cnblogs.com/cly-none/p/9845046.html 题意:给出一棵\(n\)个结点的树,在第\(i\)个结点上有\(a_i\)个权值为\(v_i\ ...

  5. Linux md5sum 的用法

    MD5 算法常常被用来验证网络文件传输的完整性,防止文件被篡改.MD5 全称是报文摘要算法,此算法对任意长度 的信息逐位计算,产生一个二进制长度为 128 位(十六进制长度 32 位)的报文摘要,不同 ...

  6. WebApi实现验证授权Token,WebApi生成文档等(转)

    using System; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Security; ...

  7. iOS10 后 http 网页定位失效解决方案

    最近公司开发一个app项目H5+ MUI框架进行开发的,开发的相关人员离职后,我这个小菜鸟...都是泪(从未接触过app开发) 项目要嵌入百度地图,由于已经做了微信版本的,想着还是用js api 做吧 ...

  8. DOMContentLoaded方法

    document.addEventListener('DOMContentLoaded',function(){ alert("SSDD") },false);

  9. 【百度地图API】如何获取行政区域的边界?(转载)

    转自:http://www.cnblogs.com/milkmap/archive/2012/04/11/2442430.html 摘要:以前教过大家如何自行获取行政区域,或者自定义获取一个区域的边界 ...

  10. 『高性能模型』深度可分离卷积和MobileNet_v1

    论文原址:MobileNets v1 TensorFlow实现:mobilenet_v1.py TensorFlow预训练模型:mobilenet_v1.md 一.深度可分离卷积 标准的卷积过程可以看 ...