-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.html
More file actions
70 lines (58 loc) · 1.63 KB
/
examples.html
File metadata and controls
70 lines (58 loc) · 1.63 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Examples - PyLove2D</title>
<link rel="stylesheet" href="assets/style.css">
</head>
<body>
<header>
<h1>Examples</h1>
</header>
<nav>
<a href="index.html">Home</a>
<a href="getting_started.html">Getting Started</a>
<a href="api.html">API Reference</a>
<a href="examples.html">Examples</a>
</nav>
<main>
<h2>Pong Example</h2>
<pre><code>import pylove2d as love
# Simplified Pong
p1 = {'y': 200}
p2 = {'y': 200}
def load():
love.window.set_title('Pong')
def update(dt):
if love.input.key_down('w'): p1['y'] -= 200*dt
if love.input.key_down('s'): p1['y'] += 200*dt
if love.input.key_down('up'): p2['y'] -= 200*dt
if love.input.key_down('down'): p2['y'] += 200*dt
def draw(g):
g.clear(0,0,0)
g.set_color(1,1,1)
g.rectangle('fill', 50, p1['y'], 20, 100)
g.rectangle('fill', 730, p2['y'], 20, 100)</code></pre>
<h2>Platformer Example</h2>
<pre><code>import pylove2d as love
player = {'x': 100, 'y': 300, 'vx':0, 'vy':0, 'w':40, 'h':60, 'on_ground': False}
def update(dt):
# move left/right
if love.input.key_down('left'): player['vx']=-200
elif love.input.key_down('right'): player['vx']=200
else: player['vx']=0
# apply gravity
player['vy'] += 800*dt
player['x'] += player['vx']*dt
player['y'] += player['vy']*dt
def draw(g):
g.clear(0.1,0.1,0.2)
g.set_color(0.8,0.3,0.3)
g.rectangle('fill', player['x'], player['y'], player['w'], player['h'])</code></pre>
<p>Download the full examples from the <a href="https://github.com/">repository</a>.</p>
</main>
<footer>
© 2025 PyLove2D
</footer>
</body>
</html>