aboutsummaryrefslogtreecommitdiff
path: root/src/game.moon
blob: 037511a4d7c5a09cf1604a0ead024a4f5fd2d2b0 (plain)
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
state = require "global"
level1 = require "level1"
level2 = require "level2"
level3 = require "level3"
level3p2 = require"level3p2"
level4 = require "level4"
level5 = require "level5"
level6 = require "level6"
level7 = require "level7"
level8 = require "level8"
level9 = require "level9"
level10 = require "level10"
level11 = require "level11"
level12 = require "level12"
game_complete = require "complete"
ui = require "ui"
mod = ...

mod.ship_move_in_co = () ->
	while true
		while ui.manager_talking
			coroutine.yield!
		state.ship("sprite").color = vec4(1,1,1,1)
		state.game_grid.hidden = true
		state.layers.hidden = true
		dist = state.ship("position").x - (state.win.left + 256) - 3
		if dist > 3
			state.ship("position").x = state.ship("position").x - (20*math.sin(dist / 512))
		else
			state.ship("sprite").color = vec4(0.5, 0.5, 0.5, 1)
			state.game_grid.hidden = false
			state.layers.hidden = false
			break
		coroutine.yield!
	coroutine.yield true

mod.ship_move_out_co = () ->
	start_pos = state.ship("position").x
	state.layers.hidden=true
	state.game_grid.hidden =true
	while true
		print("Doing ship move out co...")
		state.ship("sprite").color = vec4(1,1,1,1)
		dist = state.ship("position").x - (state.win.left - 600 - 3)
		if dist > 3
			state.ship("position").x = state.ship("position").x - (20*math.sin(-start_pos / 512))
		else 
			break
		coroutine.yield!
	state.move_out_done = true
	coroutine.yield true

mod.hint_mouse = () ->
	mousepos = state.win\mouse_position!
	mod.mouse_hint("position").x = mousepos.x
	mod.mouse_hint("position").y = mousepos.y

mod.gen_scene = () ->
	state.selected_state = "electrical"
	state.game_background = am.translate(0,0) ^ am.rotate(0) ^ am.scale(2) ^ am.sprite("data/space.jpg")
	state.game_grid = am.translate(0,0) ^ am.scale(2) ^ am.rotate(0) ^ am.sprite("data/numbered_grid.png")\tag("sprite")
	--state.game_grid = am.translate(0,0) ^ am.scale(2) ^ am.rotate(0) ^ am.sprite("data/grid.png")\tag("sprite")
	state.game_grid("sprite").color = vec4(1,1,1,0.2)
	state.ship = am.translate(1024,0)\tag("position") ^ am.scale(1) ^ am.rotate(math.pi / 2) ^ (am.sprite("data/test_ship.png")\tag("sprite"))
	state.money = 100
	gui = ui.make_ui!
	ret = am.group! ^ {state.game_background, state.ship, state.game_grid, state.layers, gui}
	state.layers.hidden = true
	state.game_grid.hidden = true
	state.mouse_hint = am.translate(0,0)\tag("position") ^ am.scale(1) ^ am.text("hint hint")\tag("sprite")
	state.mouse_hint\action(coroutine.create(() ->
		while true
			state.mouse_hint("position").y -= 1
			state.mouse_hint("sprite").color.a -= 0.01
			coroutine.yield!
	))
	state.ship\action(coroutine.create(() ->
		ui.manager_say("Welcome to the drydocks, newbie. We're here to fix\nships as cheaply as possible. I'll start you off\nhooking up broken fuel lines.")
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level1.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("If there are multiple tanks, you only need to\nconnect thrusters to one of them.")
		level2.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level3.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level3p2.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("I think you're ready for the big time, use [1]\nand [2] to toggle between the fuel and electrical\ngrid. Ion thrusters need power to operate.")
		level4.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("The credits from salvageing components from one grid\ncan be used in the other grid.")
		level5.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level6.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level7.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level8.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("Some ships use generators instead of batteries.\nConnect the generator to the fuel and the ion\nthrusters.")
		level9.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		level10.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("Some ships have laser weapons, they need High\nvoltage power, which can't be next to regular\nvoltage or it'll interfere.")
		level11.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		ui.manager_say("Ah, we're at the last ship already. You must have\nbeen quite clever to make it this far.")
		level12.setup_level!
		while not state.move_out_done or ui.manager_talking
			coroutine.yield!
		state.win.scene = game_complete.create_scene!
		
	))
	--state.ship\action(coroutine.create(ship_move_in_co))
	ret