-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.gd
130 lines (99 loc) · 3.16 KB
/
player.gd
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
extends KinematicBody2D
signal rocket_launched
signal flashlight_increased
signal flashlight_decreased
var packed_scene
var packed_scene2
var velocity = Vector2(0,0)
const SPEED = 300
const BASE_GRAVITY = 30
const JUMPFORCE = -1000
const NOGRAVITY = -500
const ROCKETPOWER = 300
var side = 1
var gravity = BASE_GRAVITY
var gravity_out = false
var use = false
var pc_number = 0
func _ready():
$Light2D.texture_scale = 0
func _physics_process(delta):
$Sprite.flip_h = false
$Sprite.play("idle")
$Particles2D.emitting=false
$Particles2D.position=Vector2(-15.62,8)
if Input.is_action_pressed("right"):
velocity.x = SPEED
$Sprite.play("run")
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$Sprite.flip_h = true
$Particles2D.position=Vector2(15.62,8)
$Sprite.play("run")
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE
$Sprite.play("jetpack")
if Input.is_action_pressed("rocket_launch") and global.rocket_capacity>0:
$Particles2D.emitting=true
if not gravity_out:
velocity.y = -ROCKETPOWER*side
$Particles2D.process_material.gravity=Vector3(0,100,0)
else:
velocity.y = ROCKETPOWER*side
$Particles2D.process_material.gravity=Vector3(0,-100,0)
$Sprite.play("jetpack")
emit_signal("rocket_launched")
velocity.y += gravity*side
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2)
# handle flashlight
if Input.is_action_pressed("increase_light") and global.light_battery>0:
$Light2D.texture_scale -= 0.015
emit_signal("flashlight_increased")
elif Input.is_action_pressed("decrease_light"):
if $Light2D.texture_scale < 0:
$Light2D.texture_scale += 0.015
emit_signal("flashlight_decreased")
if gravity_out:
velocity.y = NOGRAVITY*side
if Input.is_action_just_pressed("interaction") and use and pc_number!=0:
use = false
# ResourceSaver.save("res://tmp"+String(pc_number)+".tscn", packed_scene)
if pc_number==1:
packed_scene = PackedScene.new()
packed_scene.pack(get_tree().get_current_scene())
ResourceSaver.save("res://tmp1.tscn", packed_scene)
if pc_number==2:
packed_scene2 = PackedScene.new()
packed_scene2.pack(get_tree().get_current_scene())
ResourceSaver.save("res://tmp2.tscn", packed_scene2)
if pc_number==3:
packed_scene2 = PackedScene.new()
packed_scene2.pack(get_tree().get_current_scene())
ResourceSaver.save("res://tmp3.tscn", packed_scene2)
get_tree().change_scene("res://computer"+String(pc_number)+".tscn")
if Input.is_action_just_pressed("main_menu"):
global.reset_game()
get_tree().change_scene("res://startmenu.tscn")
func _on_root_gravity_out():
gravity_out = true
func _on_root_gravity_on():
gravity_out = false
func _on_laptop_permit_computer_interaction():
pc_number = 1
use = true
func _on_laptop_unpermit_computer_interaction():
pc_number = 0
use = false
func _on_laptop2_permit_computer2_interaction():
pc_number = 2
use = true
func _on_laptop2_unpermit_computer2_interaction():
pc_number = 0
use = false
func _on_laptop3_permit_computer3_interaction():
pc_number = 3
use = true
func _on_laptop3_unpermit_computer3_interaction():
pc_number = 0
use = false