Skip to content

Commit 0e86824

Browse files
committed
Merge branch 'master' into menu
2 parents f48dfdf + f8966e3 commit 0e86824

6 files changed

Lines changed: 110 additions & 41 deletions

File tree

Defold/map.tilesource

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ collision: ""
77
material_tag: "tile"
88
collision_groups: "default"
99
animations {
10-
id: "Coffee_Cup"
10+
id: "Cappucchino"
11+
start_tile: 8
12+
end_tile: 8
13+
playback: PLAYBACK_LOOP_FORWARD
14+
fps: 1
15+
flip_horizontal: 0
16+
flip_vertical: 0
17+
}
18+
animations {
19+
id: "Coffee"
1120
start_tile: 17
1221
end_tile: 17
1322
playback: PLAYBACK_LOOP_FORWARD
@@ -123,15 +132,6 @@ animations {
123132
flip_horizontal: 0
124133
flip_vertical: 0
125134
}
126-
animations {
127-
id: "Milk_Coffee_Cup"
128-
start_tile: 8
129-
end_tile: 8
130-
playback: PLAYBACK_LOOP_FORWARD
131-
fps: 1
132-
flip_horizontal: 0
133-
flip_vertical: 0
134-
}
135135
animations {
136136
id: "Milk_Empty"
137137
start_tile: 25
Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,67 @@
11
function init(self)
2-
self.item = {}
2+
self.items = {}
33
self.item_count = 0
4+
5+
end
6+
7+
function delete_items(items)
8+
if items then
9+
for _, id in pairs(items) do
10+
go.delete(id)
11+
end
12+
end
13+
end
14+
15+
function update_item_positions(items)
16+
if items then
17+
local position = go.get_position();
18+
for pos, id in pairs(items) do
19+
msg.post(id, "Game State", {x = position.x, y = position.y - (pos-1) * 20})
20+
end
21+
end
422
end
523

624
function on_message(self, message_id, message, sender)
25+
if message.sprite_id then
26+
sprite.play_flipbook("#sprite",hash("Customer_".. message.sprite_id))
27+
end
728
if message.y then
829
local position = go.get_position();
930
position.y = message.y;
1031
go.set_position(position);
32+
update_item_positions(self.items)
33+
end
34+
if message.x then
35+
local position = go.get_position();
36+
position.x = message.x;
37+
go.set_position(position);
38+
update_item_positions(self.items)
1139
end
40+
1241
if message.type then
1342
--sprite.play_flipbook("#sprite",hash(message.type))
1443
end
1544
if message.order and not self.order then
45+
--delete_items(self.items)
1646
for k, v in pairs(message.order) do
17-
if type(k) == "string" and type(v) == "number" then
47+
if k ~= '__keys' then
1848
local position = go.get_position();
1949
created_id = factory.create("#order_factory", vmath.vector3(position.x , position.y- self.item_count * 20,0.1), vmath.quat(),{},1)
2050
if created_id then
2151
self.order = true
2252
msg.post(created_id, "Game State", {item = k, amount = v})
23-
self.item = created_id
53+
table.insert(self.items, created_id)
2454
self.item_count = self.item_count +1
2555
end
26-
end
56+
57+
end
2758
end
2859
end
2960

3061
end
3162

63+
64+
3265
function final(self)
33-
go.delete(self.item)
66+
delete_items(self.items)
3467
end

Defold/scripts/game_controller.script

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,49 @@ local spriteCenter = 50;
1414
local other_players = {}
1515
local customers = {}
1616

17-
function drawCustomers(change)
18-
if table.maxn(room.state.customers) > table.maxn(customers) then
19-
created_id = factory.create("default:/customer_factory#factory", vmath.vector3(50,0,0.1), vmath.quat(),{},3.125)
20-
customers[table.maxn(customers) +1] = created_id
21-
elseif table.maxn(room.state.customers) < table.maxn(customers) then
22-
go.delete(customers[table.maxn(customers)])
23-
table.remove(customers)
17+
function setContains(set, key)
18+
return set[key] ~= nil
19+
end
20+
21+
function gamestateHasCustomer(id)
22+
for k,v in pairs(room.state.customers) do
23+
if v.id == id then
24+
return true
25+
end
2426
end
25-
for pos,customer_id in pairs(customers) do
27+
return false
28+
end
29+
30+
function drawCustomers(change)
31+
--update and add customers from gamestate
32+
33+
34+
for pos, customer in pairs(room.state.customers) do
35+
36+
-- called out of order
37+
if not setContains(customers, customer.id) then
38+
-- create new customer if not yet created
39+
created_id = factory.create("default:/customer_factory#factory", vmath.vector3(50,0,0.1), vmath.quat(),{},3.125)
40+
customers[customer.id] = created_id
41+
customer_go = customers[customer.id]
42+
msg.post(customer_go, "Game State", {sprite_id = customer.sprite_id})
43+
44+
45+
end
46+
--update all customer
2647
--lua starts indexing at 1 instead of 0 like everything else
2748
newy = (pos-1) * scaling + spriteCenter;
28-
newtype = nil
29-
if room.state.customers[pos].wants["Kolle"] then
30-
newtype = "KolleCustomer"
31-
elseif room.state.customers[pos].wants["Zotrine"] then
32-
newtype = "ZotrineCustomer"
33-
elseif room.state.customers[pos].wants["Premium"] then
34-
newtype = "PremiumCustomer"
49+
customer_go = customers[customer.id]
50+
msg.post(customer_go, "Game State", {y = newy, order = customer.wants})
51+
end
52+
53+
-- remove customers not in gamestate
54+
55+
for customer_id, customer_go in pairs(customers) do
56+
if not gamestateHasCustomer(customer_id) then
57+
go.delete(customers[customer_id])
58+
customers[customer_id] = nil;
3559
end
36-
msg.post(customer_id, "Game State", {y = newy, type = newtype, order = room.state.customers[pos].wants})
3760
end
3861
end
3962

@@ -86,6 +109,11 @@ end
86109

87110
function onStateChange(change)
88111
Move(change)
112+
for k, v in pairs(change) do
113+
if v['field'] == 'customers' then
114+
drawCustomers(change)
115+
end
116+
end
89117
end
90118

91119

@@ -142,10 +170,6 @@ function on_message(self, message_id, message, sender)
142170
room:send("move",message.dir);
143171
elseif (message_id == hash("use")) then
144172
room:send("use")
145-
elseif (message_id == hash("drop")) then
146-
room:send("drop");
147-
elseif (message_id == hash("refill")) then
148-
room:send("refill",message.item);
149173
end
150174

151175
end

Defold/scripts/player.script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function init(self) -- [1]
1414
origRotation = go.get_rotation();
1515
self.has_inventory = false
1616
self.direction = 'down'
17+
1718
end
1819

1920
function final(self) -- [7]
@@ -36,6 +37,7 @@ function on_input(self, action_id, action)
3637
msg.post(game_controller, "drop");
3738
elseif action_id == hash("use") then
3839
msg.post(game_controller, "use");
40+
print('use')
3941
elseif action_id == hash("refill") then --just for testing
4042
msg.post(game_controller, "refill", {item = "all"});
4143
end

Server/Ascii.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ class Player extends Schema {
2424
class Customer extends Schema {
2525
@type({ map: "number" }) wants = new MapSchema<number>();
2626
@type("number") pays : number = 0;
27+
@type("boolean") waiting : boolean = true;
28+
@type("number") id : number;
29+
@type("number") sprite_id : number;
2730

28-
constructor(wants:MapSchema<number>,){
31+
constructor(wants:MapSchema<number>, id:number){
2932
super();
3033
this.wants = wants;
31-
}
34+
this.id = id;
35+
this.sprite_id = Math.floor(Math.random() * 1.99) + 1; // numbers between 1 and 2
36+
37+
}
3238
}
3339

3440
//state of the game in the current room
@@ -39,11 +45,11 @@ class State extends Schema {
3945
//function to create a new player for given id
4046
createPlayer (id: string) { this.players[ id ] = new Player(Object.keys(this.players).length); }
4147
@type([Customer]) customers = new ArraySchema<Customer>();
42-
createCustomer (wants: MapSchema<number>) { this.customers.push(new Customer(wants)); }
48+
createCustomer (wants: MapSchema<number>, id: number) { this.customers.push(new Customer(wants, id)); }
4349
}
4450

4551
export class Ascii extends Room {
46-
52+
customerMaxId = 0;
4753
//single Tick of the Timer
4854
gametick() {
4955
this.generateCustomer();
@@ -305,6 +311,8 @@ export class Ascii extends Room {
305311
setInterval(() => {
306312
this.gametick()
307313
}, 1500);
314+
315+
this.customerMaxId = 0;
308316
}
309317

310318
onJoin(client: Client, options: any) {
@@ -341,7 +349,9 @@ export class Ascii extends Room {
341349
wants[order_item] = 1
342350
}
343351
}
344-
this.state.createCustomer(wants)
352+
this.customerMaxId = this.customerMaxId +1;
353+
354+
this.state.createCustomer(wants, this.customerMaxId)
345355
}
346356
}
347357
}

Server/hitbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var hitbox = new Map([
66
[96,"Zotrine"],[95,"Premium"],[94,"Kolle"], //get full bottle
77
[92,"sink"],[91,"sink"], //just hitbox as of now
88
[55,"Milk"],[53,"Espresso_Beans"],[54,"Crema_Beans"], //get refill stuff for coffee machine
9-
[32,"machine coffee"],[33,"machine milk"], //coffee machine sides differ for refill
9+
[32,"Coffee"],[33,"Cappucchino"], //coffee machine sides differ for refill
1010
[31,"php"], //php gives hard penalties when served to any customer
1111
[70,"trash"], //trashcan allows to empty inventory
1212
[37,"table"],[93,"table"],[90,"table"],[52,"table"] //hitboxes with no specific meaning

0 commit comments

Comments
 (0)