forked from Habrador/Unity-Programming-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController.cs
More file actions
67 lines (51 loc) · 1.6 KB
/
Copy pathGameController.cs
File metadata and controls
67 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BytecodePattern
{
//Bytecode code pattern from the book "Game Programming Patterns"
public class GameController : MonoBehaviour
{
void Start()
{
//Test
int[] bytecode = new int[]
{
(int)Instruction.INST_LITERAL, 0, //wizard id
(int)Instruction.INST_LITERAL, 75, //amount
(int)Instruction.INST_SET_HEALTH
};
VM vm = new VM(gameController: this);
vm.Interpret(bytecode);
}
void Update()
{
}
//0 means the player's wizard and 1, 2, ... means the other wizards in the game
//This way we can heal our own wizard while damage other wizards with the same method
public void SetHealth(int wizardID, int amount)
{
Debug.Log($"Wizard {wizardID} gets health {amount}");
}
public void SetWizdom(int wizardID, int amount)
{
Debug.Log($"Wizard {wizardID} gets wisdom {amount}");
}
public void SetAgility(int wizardID, int amount)
{
Debug.Log($"Wizard {wizardID} gets agility {amount}");
}
public void PlaySound(int soundID)
{
Debug.Log($"Play sound {soundID}");
}
public void SpawnParticles(int particleType)
{
Debug.Log($"Spawn particle {particleType}");
}
public int GetHealth(int wizardID)
{
return 50;
}
}
}