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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
game.loadFont("default", "Assets/FreePixel.ttf", 16)
game.loadFont("dialog", "Assets/FreePixel.ttf", 16)
player = {
Player = 0,
EventListeners = {
MoveLeftPressed = function(self)
self.Velocity.x = self.Velocity.x - 3.0
self.Render.flipx = true
end,
MoveLeftReleased = function(self)
self.Velocity.x = self.Velocity.x + 3.0
end,
MoveRightPressed = function(self)
self.Velocity.x = self.Velocity.x + 3.0
self.Render.flipx = false
end,
MoveRightReleased = function(self)
self.Velocity.x = self.Velocity.x - 3.0
end,
JumpKeyPressed = function(self)
if self.Physics.standing == true then
game.play(self.Position, self.Audio)
end
end,
JumpKeyReleased = function(self)
end,
MousePressed = function(self, mx, my)
mp = game.uiToWorldCoord(mx, my)
if math.abs(mp.x - self.Position.x) < 1 and math.abs(mp.y - self.Position.y) < 1 then
game.dialog(30, 50, 400, 100)
game.puts("dialog", 36, 52, "What do you think you're doing?")
else
if mx > 30 and mx < 430 and my > 50 and my < 150 then
game.dialogClear()
end
end
end
},
Position = {
x = 15.0,
y = 20.0
},
Velocity = {
x = 0.0,
y = 0.0
},
Physics = {
hitbox = {
ll = {x = -0.5, y = -0.8},
lr = {x = 0.5, y = -0.8},
ul = {x = -0.5, y = 0.8},
ur = {x = 0.5, y = 0.8},
}
},
Name = "bord",
Audio = {
file = "Assets/jump.wav"
},
hellotrue = true,
hellofalse = false,
Render = {
texture = "Assets/player.png",
visible = true,
offset = {
ll = {x = -0.5, y = -0.8},
lr = {x = 0.5, y = -0.8},
ul = {x = -0.5, y = 0.8},
ur = {x = 0.5, y = 0.8},
}
},
Light = {
r = 1.0,
g = 1.0,
b = 1.0,
strength = 1.0
},
Idle = function(self)
end,
visibleTick = 0
}
ball = {
Position = {
x = 20,
y = 100
},
Velocity = {
x = 0.0,
y = 0.0,
},
Physics = 0,
Render = {
texture = "Assets/ball.png",
normal = "Assets/ball_normal.png",
visible = true,
},
Idle = function(self)
if self.Physics.standing == true then
game.play(self.Position, self.Audio)
self.Velocity.y = self.Velocity.y + 15
self.Velocity.x = math.random(-1, 1);
end
end,
Audio = {
file = "Assets/boing.wav"
},
}
npc = {
Position = {
x = 30,
y = 75
},
Velocity = {
x = 0.0,
y = 0.0
},
Physics = 0,
Name = "Paul",
Render = {
texture = "Assets/cat.png",
visible = true
},
Light = {
r = 1.0,
g = 1.0,
b = 1.0,
strength = 0.5
},
EventListeners = {
MousePressed = function(self, x, y, button)
self.Velocity.y = 3.0;
end
},
Idle = function(self)
if (self.visibleTick == 0) then
self.visibleTick = math.random(40, 60)
self.Velocity.x = math.random(-1, 1) * 1.0
else
self.visibleTick = self.visibleTick - 1
end
end,
visibleTick = 0
}
-- Create the world
dofile("Scripts/world.lua")
playerSpawn = game.spawn(player);
game.spawn(ball);
game.spawn(npc);
-------------------
-- SERIALIZING --
-------------------
--function serial (before_ser)
-- binary = string.dump(before_ser)
-- formatted_binary = ""
-- for i = 1, string.len(binary) do
-- dec, _ = ("\\%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0')
-- formatted_binary = formatted_binary .. dec
-- end
-- return formatted_binary
--end
--
--function hello(herro)
-- print("Hello world ".. herro)
--end
--
----print(serial(hello))
--
--local ser = string.dump(hello)
--f2 = (loadstring or load)(ser)
--f2("shite")
--
--local testPut = string.dump(animalSpawn.TestMe)
--testRun = (loadstring or load)(testPut)
--testRun(animalSpawn)
|