Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Hourunze1997 authored Sep 28, 2019
1 parent 20183e4 commit 9209ec5
Show file tree
Hide file tree
Showing 36 changed files with 1,046 additions and 0 deletions.
45 changes: 45 additions & 0 deletions AudioManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
public static AudioManager Instance;

private AudioSource player;

public AudioClip jump;
public AudioClip die1;
public AudioClip die2;

// Start is called before the first frame update
void Start()
{
Instance = this;
player = GetComponent<AudioSource>();
}

//播放跳跃音效
public void PlayJump()
{
player.PlayOneShot(jump);
}

//播放死亡音效
public void PlayDie()
{
//BGM停止
player.Stop();
//播放死亡音效
player.PlayOneShot(die1);
//1s后调用PlayDie2
Invoke("PlayDie2", 1f);
}

//后续音效
void PlayDie2()
{
player.PlayOneShot(die2);
}

}
11 changes: 11 additions & 0 deletions AudioManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions BgControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class BgControl : MonoBehaviour
{
private float offset = 0;

// Start is called before the first frame update
void Start()
{

}
public void move(float dir)
{
if(dir >0 )
{
GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(offset += 0.3f * Time.deltaTime, 0));
}
else
{
GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(offset -= 0.3f * Time.deltaTime, 0));
}
}

}
11 changes: 11 additions & 0 deletions BgControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions FireControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FireControl : MonoBehaviour
{
private PlayerControl pc;

void Start()
{
pc = GameObject.FindWithTag("Player").GetComponent<PlayerControl>();

}

void Update()
{
//如果玩家死亡
if(pc.hp < 1)
{ return; }
//如果出屏幕,销毁
if(transform.position.x < -3f)
{
Destroy(gameObject);
}
//移动
transform.Translate(Vector3.left * Time.deltaTime * 1f);
}
}
11 changes: 11 additions & 0 deletions FireControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions FireManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FireManager : MonoBehaviour
{

public GameObject Fire;

//间隔时间
private float cd = 2f;

private PlayerControl pc;
void Start()
{
pc = GameObject.FindWithTag("Player").GetComponent<PlayerControl>();
}

// Update is called once per frame
void Update()
{
if(pc.hp < 1)
{
return;
}
cd -= Time.deltaTime;
if(cd <= 0)
{
//创建火圈
Instantiate(Fire, transform.position, Quaternion.identity);
//重置CD
cd = 2f + Random.Range(-0.5f, 0.5f);
}
}
}
11 changes: 11 additions & 0 deletions FireManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions PlayerControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControl : MonoBehaviour
{
public BgControl bgControl;
public int hp = 1;

private Animator ani;
private Rigidbody2D rBody;


//是否在地面
private bool isGround;
// Start is called before the first frame update
void Start()
{
ani = GetComponent<Animator>();
rBody = GetComponent<Rigidbody2D>();

}

// Update is called once per frame
void Update()
{
//玩家死亡
if(hp <= 0)
{ return; }
//水平轴
float horizontal = Input.GetAxis("Horizontal");
if(horizontal != 0)
{
//移动
ani.SetBool("isRun",true);
//背景后移
bgControl.move(horizontal);
}
else
{
ani.SetBool("isRun", false);
}

//跳跃
if(Input.GetKeyDown(KeyCode.Space)&&isGround == true)
{
rBody.AddForce(Vector2.up * 170);
AudioManager.Instance.PlayJump();
}
}
//进入碰撞
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
isGround = true;
ani.SetBool("isJump", false);
}
}
//离开碰撞
private void OnCollisionExit2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
isGround = false;
ani.SetBool("isJump", true);
}
}

//进入火圈触发区域
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Fire")
{
hp--;
Destroy(rBody);
ani.SetBool("Die", true);
AudioManager.Instance.PlayDie();
}
}

}
11 changes: 11 additions & 0 deletions PlayerControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added 小丑1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions 小丑1.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added 小丑2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9209ec5

Please sign in to comment.