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
|
<!DOCTYPE html>
<html class="theme-dark" lang="en">
<head>
<base href="https://static.luevano.xyz/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test page -- Luévano's Site</title>
<meta name="description" content="Test page."/>
<link rel="alternate" type="application/rss+xml" href="https://blog.luevano.xyz/rss.xml" title="Luévano's Blog RSS">
<link rel="alternate" type="application/rss+xml" href="https://art.luevano.xyz/rss.xml" title="Luévano's Art RSS">
<link rel="icon" href="images/icons/favicon.ico">
<!-- general style -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="fork-awesome/css/fork-awesome.min.css">
<link rel="stylesheet" type="text/css" href="font-awesome/css/all.min.css">
<!-- highlight support for code blocks -->
<script type="text/javascript" src="hl/highlight.min.js"></script>
<!-- Specific to GDScript -->
<script type="text/javascript" src="hl/languages/gdscript.min.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
// hljs.initLineNumbersOnLoad();
</script>
<!-- theme related -->
<script type="text/javascript" src="scripts/theme.js"></script>
<link id="theme-css" rel="stylesheet" type="text/css" href="css/theme.css">
<link id="code-theme-css" rel="stylesheet" type="text/css" href="hl/styles/nord.min.css">
</head>
<body>
<header>
<nav>
<ul>
<li>
<a href="https://luevano.xyz/"><i class="fas fa-home" alt="Home"></i><span>Home</span></a>
</li>
<li>
<a href="https://blog.luevano.xyz/"><i class="fas fa-book-open" alt="Blog"></i><span>Blog</span></a>
</li>
<li>
<a href="https://art.luevano.xyz/"><i class="fas fa-paint-brush" alt="Art"></i><span>Art</span></a>
</li>
<li><i class="fab fa-git" alt="Git"></i><span>Git</span>
<ul>
<li><a href="https://git.luevano.xyz/" target="_blank"><i class="fab fa-git-alt" alt="Git-alt"></i></a></li>
<li><a href="https://github.com/luevano" target="_blank"><i class="fab fa-github" alt="Github"></i></a></li>
<li><a href="https://gitlab.com/dluevano" target="_blank"><i class="fab fa-gitlab" alt="Gitlab"></i></a></li>
</ul>
</li>
<li><i class="fas fa-box-open" alt="Stuff"></i><span>Stuff</span>
<ul>
<li><a href="https://gb.luevano.xyz/"><i class="fas fa-gamepad" alt="Gameboy"></i><span>Gameboy</span></a></li>
</ul>
</li>
</ul>
</nav>
<button class="theme-switcher" onclick="toggleTheme()"><i class="fas fa-moon"></i><i class="fas fa-sun"></i></button>
</header>
<main>
<h1>
Test page
</h1>
<div class="art-grid">
<img class="wide" src="images/gifs/contact_info_1.gif">
<img src="images/gifs/dollar_sign_spin_1.gif">
<img class="tall" src="images/gifs/head_talking_1_trans.gif">
<img class="wide tall" src="images/gifs/stars_1.gif">
<img src="images/gifs/under_construction_1.gif">
<img src="images/gifs/under_construction_2.gif">
</div>
<pre><code class="language-gdscript">class_name Player
extends KinematicBody2D
signal died
export(float, 1.0, 1000.0, 1.0) var SPEED: float = 180.0
export(float, 0.01, 100.0, 0.01) var ROT_SPEED: float = 10.0
export(float, 1.0, 1000.0, 1.0) var JUMP_VELOCITY: float = 380.0
export(float, 1.0, 100.0, 1.0) var DEATH_JUMP_VELOCITY: float = 250.0
onready var sprite: AnimatedSprite = $Sprite
onready var jump_sound: AudioStreamPlayer = $JumpSound
onready var hit_sound: AudioStreamPlayer = $HitSound
onready var dead_sound: AudioStreamPlayer = $DeadSound
var gravity: float = 10 * ProjectSettings.get_setting("physics/2d/default_gravity")
var velocity: Vector2 = Vector2.ZERO
var last_collision: KinematicCollision2D
var dead: bool = false
func _physics_process(delta: float) -> void:
velocity.x = SPEED
velocity.y += gravity * delta
if Input.is_action_just_pressed("jump") and not dead:
velocity.y = -JUMP_VELOCITY
jump_sound.play()
if velocity.y < 0.0:
sprite.play()
if rotation > -PI/8:
rotate(-0.05 * ROT_SPEED)
else:
_stop_sprite()
if rotation < PI/2:
rotate(0.01 * ROT_SPEED)
# maybe can be done with move_and_collide, but this works
velocity = move_and_slide(velocity)
last_collision = get_last_slide_collision()
if not dead and last_collision:
_emit_player_died()
func _stop_sprite() -> void:
if sprite.playing:
sprite.stop()
if sprite.frame != 0:
sprite.frame = 0
# when dying because of boundary
func _on_CeilingDetector_body_entered(body: Node2D) -> void:
_emit_player_died()
func _emit_player_died() -> void:
# bit 2 corresponds to pipe (starts from 0)
set_collision_mask_bit(2, false)
dead = true
SPEED = 0.0
emit_signal("died")
# play the sounds after, because yield will take a bit of time,
# this way the camera stops when the player "dies"
velocity.y = -DEATH_JUMP_VELOCITY
velocity = move_and_slide(velocity)
hit_sound.play()
yield(hit_sound, "finished")
dead_sound.play()
</code></pre>
</main>
<footer>
<span>
<i class="fas fa-address-card" alt="Contact"></i>
<a href="https://luevano.xyz/contact.html">Contact</a>
</span>
<span>
<i class="fas fa-donate" alt="Donate"></i>
<a href="https://luevano.xyz/donate.html">Donate</a>
</span>
<br>
<span class="copyright">
Copyright <i class="far fa-copyright" alt="Copyright"></i> 2021 David Luévano Alvarado
</span>
</footer>
</body>
</html>
|