-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpong.html
142 lines (132 loc) · 4.51 KB
/
pong.html
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
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="scrolling-nav.css" rel="stylesheet">
<link href="https://bootswatch.com/flatly/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top" data-target=".navbar-fixed-top">
<nav class="navbar navbar-inverse navbar-fixed-top top-nav-collapse">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand page-scroll" href="index.html">Quine8</a>
<a class="navbar-brand page-scroll" href="mult.html">Previous</a>
<a class="navbar-brand page-scroll" href="bubble.html">Next</a>
</div>
</div>
</nav>
<section style="margin-top: 5em; max-width: 50em;">
<h1>Graphics Fun with Q8</h1>
<p>To mix things up a little, this project is no math, just visuals.
Here we are going to write a little code to bounce a "ball" from
one side of the screen to the other. We're going to do this the simple
way, with two loops. One loop to go across the screen right, and one to
go back left again. A keen reader might spot a way to make this a single loop,
probably reducing the code redundancy considerably. I encourage you to explore
that avenue as a fun little bonus challenge.</p>
</section>
<section>
<div class="multi_code_container">
<div class="c_and_img">
<div>
<h3>C-like Program</h3>
<pre><code class="language-c; line-numbers">while (true) {
int position = 240;
for (int i = 15; i > 0; i--) {
//draw 0 @ array[position]
position++;
//draw 1 @ array[position]
}
for (int i = 15; i > 0; i--) {
//draw 0 @ array[position]
position--;
//draw 1 @ array[position]
}
}
</code></pre>
</div>
<div class="img_col_container">
<h3>Bytecode Program</h3>
<a href="q8.html#AwRgHMwExiwKwE5IDZEhAQypXf8GFHGQjrggDGALKLUnMpAOxNmg5KTJyujYkSFBOUzxBgshliVS9dMCbA+oHvO6hlPMRN16JAM0hH9ps+YuWr1m7bv38QA=">
<img class="img_link" style="width: 70%; margin-left: 1.5em;" src="pong.gif">
</a>
</div>
</div>
<div>
<h3>Assembly Program</h3>
<pre><code class="language-none; line-numbers">>0
inc-init:
LOAD A ball_start ; read in ball start position
LOAD B bounce_len ; read in bounce size
STORE A ball_pos ; make copy of ball start position
STORE B i ; make copy of bounce size as new i
JMP inc-loop
>32
inc-loop:
LOAD A i ; read in i
ISZERO A ; is i == 0?
JZ dec-init
DEC A ; i--
STORE A i ; write new i
>40
inc-draw:
SET A 0 ; load ball clear
STOREI A ball_pos ; clear old position
LOAD A ball_pos ; read position
INC A ; position++
STORE A ball_pos ; write position to grid
SET A 1 ; load ball
STOREI A ball_pos ; write ball to new position
JMP inc-loop
>64
dec-init:
LOAD A bounce_len ; read in bounce size
STORE A i ; make copy of bounce size as new i
JMP dec-loop
>80
dec-loop:
LOAD A i ; read in i
ISZERO A ; is i == 0?
JZ inc-init
DEC A ; i--
STORE A i ; write new i
>88
dec-draw:
SET A 0 ; load ball clear
STOREI A ball_pos ; clear old position
LOAD A ball_pos ; read position
DEC A ; position--
STORE A ball_pos ; write position to grid
SET A 1 ; load ball
STOREI A ball_pos ; write ball to new position
JMP dec-loop
; DATA
>128
ball_start: $240
bounce_len: $15
>144
ball_pos: $0
i: $0</code></pre>
</div>
</div>
</section>
<link rel="stylesheet" href="prism.css">
<link href="tutorial_style.css" rel="stylesheet">
<script src="prism.js"></script>
</body>
<footer style="margin-top: 4em; padding-bottom: 4em; background-color: #555"></footer>
</html>