ruby-glfw 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/README.API +73 -0
- data/Rakefile +120 -0
- data/examples/boing.rb +519 -0
- data/examples/gears.rb +327 -0
- data/examples/keytest.rb +117 -0
- data/examples/listmodes.rb +20 -0
- data/examples/mipmaps.rb +104 -0
- data/examples/mipmaps.tga +0 -0
- data/examples/particles.rb +837 -0
- data/examples/pong3d.rb +741 -0
- data/examples/pong3d_field.tga +0 -0
- data/examples/pong3d_instr.tga +0 -0
- data/examples/pong3d_menu.tga +0 -0
- data/examples/pong3d_title.tga +0 -0
- data/examples/pong3d_winner1.tga +0 -0
- data/examples/pong3d_winner2.tga +0 -0
- data/examples/splitview.rb +432 -0
- data/examples/triangle.rb +89 -0
- data/examples/wave.rb +294 -0
- data/ext/glfw/glfw.c +1094 -0
- data/ext/glfw/mkrf_conf.rb +70 -0
- data/glfw-src/Makefile +220 -0
- data/glfw-src/compile.ami +61 -0
- data/glfw-src/compile.bat +217 -0
- data/glfw-src/compile.sh +607 -0
- data/glfw-src/docs/Makefile +57 -0
- data/glfw-src/docs/Reference.pdf +0 -0
- data/glfw-src/docs/UsersGuide.pdf +0 -0
- data/glfw-src/docs/cleanup.bat +22 -0
- data/glfw-src/docs/glfwdoc.sty +80 -0
- data/glfw-src/docs/glfwrm.tex +3034 -0
- data/glfw-src/docs/glfwug.tex +2024 -0
- data/glfw-src/docs/readme.txt +80 -0
- data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
- data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
- data/glfw-src/examples/Makefile.dos.djgpp +71 -0
- data/glfw-src/examples/Makefile.macosx.gcc +96 -0
- data/glfw-src/examples/Makefile.win32.bcc +75 -0
- data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
- data/glfw-src/examples/Makefile.win32.cygwin +79 -0
- data/glfw-src/examples/Makefile.win32.lcc +74 -0
- data/glfw-src/examples/Makefile.win32.mgw +75 -0
- data/glfw-src/examples/Makefile.win32.msvc +74 -0
- data/glfw-src/examples/Makefile.win32.ow +74 -0
- data/glfw-src/examples/Makefile.win32.pellesc +74 -0
- data/glfw-src/examples/Makefile.x11.in +54 -0
- data/glfw-src/examples/boing.c +606 -0
- data/glfw-src/examples/bundle.sh +46 -0
- data/glfw-src/examples/gears.c +382 -0
- data/glfw-src/examples/keytest.c +264 -0
- data/glfw-src/examples/listmodes.c +48 -0
- data/glfw-src/examples/mipmaps.c +126 -0
- data/glfw-src/examples/mipmaps.tga +0 -0
- data/glfw-src/examples/mtbench.c +301 -0
- data/glfw-src/examples/mthello.c +48 -0
- data/glfw-src/examples/particles.c +1148 -0
- data/glfw-src/examples/pong3d.c +839 -0
- data/glfw-src/examples/pong3d_field.tga +0 -0
- data/glfw-src/examples/pong3d_instr.tga +0 -0
- data/glfw-src/examples/pong3d_menu.tga +0 -0
- data/glfw-src/examples/pong3d_title.tga +0 -0
- data/glfw-src/examples/pong3d_winner1.tga +0 -0
- data/glfw-src/examples/pong3d_winner2.tga +0 -0
- data/glfw-src/examples/splitview.c +506 -0
- data/glfw-src/examples/triangle.c +108 -0
- data/glfw-src/examples/wave.c +397 -0
- data/glfw-src/images/opengl.gif +0 -0
- data/glfw-src/images/osicert.gif +0 -0
- data/glfw-src/include/GL/glfw.h +486 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
- data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
- data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
- data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
- data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
- data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
- data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
- data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
- data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
- data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
- data/glfw-src/lib/amigaos/platform.h +337 -0
- data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
- data/glfw-src/lib/dos/dos_enable.c +51 -0
- data/glfw-src/lib/dos/dos_events.c +173 -0
- data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
- data/glfw-src/lib/dos/dos_glext.c +59 -0
- data/glfw-src/lib/dos/dos_init.c +105 -0
- data/glfw-src/lib/dos/dos_irq.s +246 -0
- data/glfw-src/lib/dos/dos_joystick.c +94 -0
- data/glfw-src/lib/dos/dos_keyboard.c +694 -0
- data/glfw-src/lib/dos/dos_mouse.c +337 -0
- data/glfw-src/lib/dos/dos_thread.c +267 -0
- data/glfw-src/lib/dos/dos_time.c +309 -0
- data/glfw-src/lib/dos/dos_window.c +563 -0
- data/glfw-src/lib/dos/platform.h +341 -0
- data/glfw-src/lib/enable.c +295 -0
- data/glfw-src/lib/fullscreen.c +95 -0
- data/glfw-src/lib/glext.c +201 -0
- data/glfw-src/lib/image.c +629 -0
- data/glfw-src/lib/init.c +108 -0
- data/glfw-src/lib/input.c +280 -0
- data/glfw-src/lib/internal.h +210 -0
- data/glfw-src/lib/joystick.c +101 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
- data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
- data/glfw-src/lib/macosx/macosx_enable.c +42 -0
- data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
- data/glfw-src/lib/macosx/macosx_glext.c +52 -0
- data/glfw-src/lib/macosx/macosx_init.c +194 -0
- data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
- data/glfw-src/lib/macosx/macosx_thread.c +414 -0
- data/glfw-src/lib/macosx/macosx_time.c +112 -0
- data/glfw-src/lib/macosx/macosx_window.c +1279 -0
- data/glfw-src/lib/macosx/platform.h +349 -0
- data/glfw-src/lib/stream.c +194 -0
- data/glfw-src/lib/tga.c +405 -0
- data/glfw-src/lib/thread.c +340 -0
- data/glfw-src/lib/time.c +83 -0
- data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
- data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
- data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
- data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
- data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
- data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
- data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
- data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
- data/glfw-src/lib/win32/glfwdll.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
- data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
- data/glfw-src/lib/win32/libglfw.pc.in +11 -0
- data/glfw-src/lib/win32/platform.h +474 -0
- data/glfw-src/lib/win32/win32_dllmain.c +60 -0
- data/glfw-src/lib/win32/win32_enable.c +155 -0
- data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
- data/glfw-src/lib/win32/win32_glext.c +85 -0
- data/glfw-src/lib/win32/win32_init.c +356 -0
- data/glfw-src/lib/win32/win32_joystick.c +234 -0
- data/glfw-src/lib/win32/win32_thread.c +511 -0
- data/glfw-src/lib/win32/win32_time.c +146 -0
- data/glfw-src/lib/win32/win32_window.c +1714 -0
- data/glfw-src/lib/window.c +727 -0
- data/glfw-src/lib/x11/Makefile.x11.in +243 -0
- data/glfw-src/lib/x11/platform.h +415 -0
- data/glfw-src/lib/x11/x11_enable.c +51 -0
- data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
- data/glfw-src/lib/x11/x11_glext.c +69 -0
- data/glfw-src/lib/x11/x11_init.c +275 -0
- data/glfw-src/lib/x11/x11_joystick.c +371 -0
- data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
- data/glfw-src/lib/x11/x11_thread.c +507 -0
- data/glfw-src/lib/x11/x11_time.c +154 -0
- data/glfw-src/lib/x11/x11_window.c +1746 -0
- data/glfw-src/license.txt +21 -0
- data/glfw-src/readme.html +927 -0
- data/glfw-src/support/d/examples/Makefile +59 -0
- data/glfw-src/support/d/examples/boing.d +610 -0
- data/glfw-src/support/d/examples/gears.d +379 -0
- data/glfw-src/support/d/examples/keytest.d +272 -0
- data/glfw-src/support/d/examples/listmodes.d +48 -0
- data/glfw-src/support/d/examples/mipmaps.d +126 -0
- data/glfw-src/support/d/examples/mtbench.d +304 -0
- data/glfw-src/support/d/examples/mthello.d +54 -0
- data/glfw-src/support/d/examples/particles.d +1150 -0
- data/glfw-src/support/d/examples/pong3d.d +840 -0
- data/glfw-src/support/d/examples/splitview.d +486 -0
- data/glfw-src/support/d/examples/triangle.d +108 -0
- data/glfw-src/support/d/examples/wave.d +400 -0
- data/glfw-src/support/d/imports/gl.d +4539 -0
- data/glfw-src/support/d/imports/glfw.d +349 -0
- data/glfw-src/support/d/imports/glu.d +328 -0
- data/glfw-src/support/d/lib/glfwdll.def +64 -0
- data/glfw-src/support/d/lib/glu32.def +56 -0
- data/glfw-src/support/d/lib/makefile +12 -0
- data/glfw-src/support/d/lib/opengl32.def +372 -0
- data/glfw-src/support/d/readme.html +83 -0
- data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
- data/glfw-src/support/delphi/lib/glfw.pas +437 -0
- data/glfw-src/support/delphi/readme.html +97 -0
- data/glfw-src/support/lua/examples/gears.lua +383 -0
- data/glfw-src/support/lua/examples/test1.lua +68 -0
- data/glfw-src/support/lua/readme.html +128 -0
- data/glfw-src/support/lua/src/luaglfw.c +1179 -0
- data/glfw-src/support/lua/src/luaglfw.h +48 -0
- data/glfw-src/support/lua/src/runlua.c +82 -0
- data/glfw-src/support/masm/examples/fpc.mac +47 -0
- data/glfw-src/support/masm/examples/makeit.bat +66 -0
- data/glfw-src/support/masm/examples/triangle.asm +232 -0
- data/glfw-src/support/masm/include/glfw.inc +326 -0
- data/glfw-src/support/masm/include/glu32.inc +55 -0
- data/glfw-src/support/masm/include/opengl32.inc +372 -0
- data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
- data/glfw-src/support/masm/readme.html +170 -0
- data/glfw-src/support/msvc80/GLFW.sln +26 -0
- data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
- data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
- data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
- data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
- data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
- data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
- data/glfw-src/support/visualbasic/readme.html +164 -0
- data/website/index.html +84 -0
- data/website/style.css +110 -0
- metadata +301 -0
data/examples/pong3d.rb
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
#========================================================================
|
|
2
|
+
# This is a small test application for GLFW.
|
|
3
|
+
# This is an OpenGL port of the famous "PONG" game (the first computer
|
|
4
|
+
# game ever?). It is very simple, and could be improved alot. It was
|
|
5
|
+
# created in order to show off the gaming capabilities of GLFW.
|
|
6
|
+
#========================================================================
|
|
7
|
+
# Converted to ruby from GLFW example pong3d.c
|
|
8
|
+
|
|
9
|
+
require 'opengl'
|
|
10
|
+
require 'glfw'
|
|
11
|
+
include Gl,Glu,Glfw,Math
|
|
12
|
+
|
|
13
|
+
#========================================================================
|
|
14
|
+
# Constants
|
|
15
|
+
#========================================================================
|
|
16
|
+
|
|
17
|
+
# Screen resolution
|
|
18
|
+
WIDTH = 640
|
|
19
|
+
HEIGHT = 480
|
|
20
|
+
|
|
21
|
+
# Player size (units)
|
|
22
|
+
PLAYER_XSIZE = 0.05
|
|
23
|
+
PLAYER_YSIZE = 0.15
|
|
24
|
+
|
|
25
|
+
# Ball size (units)
|
|
26
|
+
BALL_SIZE = 0.02
|
|
27
|
+
|
|
28
|
+
# Maximum player movement speed (units / second)
|
|
29
|
+
MAX_SPEED = 1.5
|
|
30
|
+
|
|
31
|
+
# Player movement acceleration (units / seconds^2)
|
|
32
|
+
ACCELERATION = 4.0
|
|
33
|
+
|
|
34
|
+
# Player movement deceleration (units / seconds^2)
|
|
35
|
+
DECELERATION = 2.0
|
|
36
|
+
|
|
37
|
+
# Ball movement speed (units / second)
|
|
38
|
+
BALL_SPEED = 0.4
|
|
39
|
+
|
|
40
|
+
# Menu options
|
|
41
|
+
MENU_NONE = 0
|
|
42
|
+
MENU_PLAY = 1
|
|
43
|
+
MENU_QUIT = 2
|
|
44
|
+
|
|
45
|
+
# Game events
|
|
46
|
+
NOBODY_WINS = 0
|
|
47
|
+
PLAYER1_WINS = 1
|
|
48
|
+
PLAYER2_WINS = 2
|
|
49
|
+
|
|
50
|
+
# Winner ID
|
|
51
|
+
NOBODY = 0
|
|
52
|
+
PLAYER1 = 1
|
|
53
|
+
PLAYER2 = 2
|
|
54
|
+
|
|
55
|
+
# Camera positions
|
|
56
|
+
CAMERA_CLASSIC = 0
|
|
57
|
+
CAMERA_ABOVE = 1
|
|
58
|
+
CAMERA_SPECTATOR = 2
|
|
59
|
+
CAMERA_DEFAULT = CAMERA_CLASSIC
|
|
60
|
+
|
|
61
|
+
#========================================================================
|
|
62
|
+
# Textures
|
|
63
|
+
#========================================================================
|
|
64
|
+
|
|
65
|
+
TEX_TITLE = 0
|
|
66
|
+
TEX_MENU = 1
|
|
67
|
+
TEX_INSTR = 2
|
|
68
|
+
TEX_WINNER1 = 3
|
|
69
|
+
TEX_WINNER2 = 4
|
|
70
|
+
TEX_FIELD = 5
|
|
71
|
+
NUM_TEXTURES = 6
|
|
72
|
+
|
|
73
|
+
# Texture names
|
|
74
|
+
$tex_name = [
|
|
75
|
+
"pong3d_title.tga",
|
|
76
|
+
"pong3d_menu.tga",
|
|
77
|
+
"pong3d_instr.tga",
|
|
78
|
+
"pong3d_winner1.tga",
|
|
79
|
+
"pong3d_winner2.tga",
|
|
80
|
+
"pong3d_field.tga"
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
# OpenGL texture object IDs
|
|
84
|
+
$tex_id = []
|
|
85
|
+
|
|
86
|
+
#========================================================================
|
|
87
|
+
# Global variables
|
|
88
|
+
#========================================================================
|
|
89
|
+
|
|
90
|
+
# Display information
|
|
91
|
+
$width = $height = 0
|
|
92
|
+
|
|
93
|
+
# Frame information
|
|
94
|
+
$thistime = $oldtime = $dt = $starttime = 0.0
|
|
95
|
+
|
|
96
|
+
# Camera information
|
|
97
|
+
$camerapos = 0
|
|
98
|
+
|
|
99
|
+
# Player information
|
|
100
|
+
class Player
|
|
101
|
+
attr_accessor :ypos,:yspeed
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
$player1 = Player.new
|
|
105
|
+
$player2 = Player.new
|
|
106
|
+
|
|
107
|
+
# Ball information
|
|
108
|
+
class Ball
|
|
109
|
+
attr_accessor :xpos,:ypos
|
|
110
|
+
attr_accessor :xspeed,:yspeed
|
|
111
|
+
end
|
|
112
|
+
$ball = Ball.new
|
|
113
|
+
|
|
114
|
+
# And the winner is...
|
|
115
|
+
$winner = 0
|
|
116
|
+
|
|
117
|
+
# Lighting configuration
|
|
118
|
+
$env_ambient = [1.0,1.0,1.0,1.0]
|
|
119
|
+
$light1_position = [-3.0,3.0,2.0,1.0]
|
|
120
|
+
$light1_diffuse = [1.0,1.0,1.0,0.0]
|
|
121
|
+
$light1_ambient = [0.0,0.0,0.0,0.0]
|
|
122
|
+
|
|
123
|
+
# Object material properties
|
|
124
|
+
$player1_diffuse = [1.0,0.3,0.3,1.0]
|
|
125
|
+
$player1_ambient = [0.3,0.1,0.0,1.0]
|
|
126
|
+
$player2_diffuse = [0.3,1.0,0.3,1.0]
|
|
127
|
+
$player2_ambient = [0.1,0.3,0.1,1.0]
|
|
128
|
+
$ball_diffuse = [1.0,1.0,0.5,1.0]
|
|
129
|
+
$ball_ambient = [0.3,0.3,0.1,1.0]
|
|
130
|
+
$border_diffuse = [0.3,0.3,1.0,1.0]
|
|
131
|
+
$border_ambient = [0.1,0.1,0.3,1.0]
|
|
132
|
+
$floor_diffuse = [1.0,1.0,1.0,1.0]
|
|
133
|
+
$floor_ambient = [0.3,0.3,0.3,1.0]
|
|
134
|
+
|
|
135
|
+
#========================================================================
|
|
136
|
+
# LoadTextures() - Load textures from disk and upload to OpenGL card
|
|
137
|
+
#========================================================================
|
|
138
|
+
|
|
139
|
+
def LoadTextures
|
|
140
|
+
# Generate texture objects
|
|
141
|
+
$tex_id = glGenTextures( NUM_TEXTURES )
|
|
142
|
+
|
|
143
|
+
# Load textures
|
|
144
|
+
NUM_TEXTURES.times do |i|
|
|
145
|
+
# Select texture object
|
|
146
|
+
glBindTexture( GL_TEXTURE_2D, $tex_id[ i ] )
|
|
147
|
+
|
|
148
|
+
# Set texture parameters
|
|
149
|
+
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT )
|
|
150
|
+
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )
|
|
151
|
+
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
|
|
152
|
+
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR )
|
|
153
|
+
|
|
154
|
+
# Upload texture from file to texture memory
|
|
155
|
+
glfwLoadTexture2D( $tex_name[ i ], 0 )
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
#========================================================================
|
|
161
|
+
# DrawImage() - Draw a 2D image as a texture
|
|
162
|
+
#========================================================================
|
|
163
|
+
|
|
164
|
+
def DrawImage(texnum,x1,x2,y1,y2)
|
|
165
|
+
glEnable( GL_TEXTURE_2D )
|
|
166
|
+
glBindTexture( GL_TEXTURE_2D, $tex_id[ texnum ] )
|
|
167
|
+
glBegin( GL_QUADS )
|
|
168
|
+
glTexCoord2f( 0.0, 1.0 )
|
|
169
|
+
glVertex2f( x1, y1 )
|
|
170
|
+
glTexCoord2f( 1.0, 1.0 )
|
|
171
|
+
glVertex2f( x2, y1 )
|
|
172
|
+
glTexCoord2f( 1.0, 0.0 )
|
|
173
|
+
glVertex2f( x2, y2 )
|
|
174
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
175
|
+
glVertex2f( x1, y2 )
|
|
176
|
+
glEnd()
|
|
177
|
+
glDisable( GL_TEXTURE_2D )
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
#========================================================================
|
|
181
|
+
# GameMenu() - Game menu (returns menu option)
|
|
182
|
+
#========================================================================
|
|
183
|
+
|
|
184
|
+
def GameMenu
|
|
185
|
+
option = MENU_NONE
|
|
186
|
+
|
|
187
|
+
# Enable sticky keys
|
|
188
|
+
glfwEnable( GLFW_STICKY_KEYS );
|
|
189
|
+
|
|
190
|
+
# Wait for a game menu key to be pressed
|
|
191
|
+
while option == MENU_NONE
|
|
192
|
+
# Get window size
|
|
193
|
+
$width,$height = glfwGetWindowSize()
|
|
194
|
+
|
|
195
|
+
# Set viewport
|
|
196
|
+
glViewport( 0, 0, $width, $height )
|
|
197
|
+
|
|
198
|
+
# Clear display
|
|
199
|
+
glClearColor( 0.0, 0.0, 0.0, 0.0 )
|
|
200
|
+
glClear( GL_COLOR_BUFFER_BIT )
|
|
201
|
+
|
|
202
|
+
# Setup projection matrix
|
|
203
|
+
glMatrixMode( GL_PROJECTION )
|
|
204
|
+
glLoadIdentity()
|
|
205
|
+
glOrtho( 0.0, 1.0, 1.0, 0.0, -1.0, 1.0 )
|
|
206
|
+
|
|
207
|
+
# Setup modelview matrix
|
|
208
|
+
glMatrixMode( GL_MODELVIEW )
|
|
209
|
+
glLoadIdentity()
|
|
210
|
+
|
|
211
|
+
# Display title
|
|
212
|
+
glColor3f( 1.0, 1.0, 1.0 )
|
|
213
|
+
DrawImage( TEX_TITLE, 0.1, 0.9, 0.0, 0.3 )
|
|
214
|
+
|
|
215
|
+
# Display menu
|
|
216
|
+
glColor3f( 1.0, 1.0, 0.0 )
|
|
217
|
+
DrawImage( TEX_MENU, 0.38, 0.62, 0.35, 0.5 )
|
|
218
|
+
|
|
219
|
+
# Display instructions
|
|
220
|
+
glColor3f( 0.0, 1.0, 1.0 )
|
|
221
|
+
DrawImage( TEX_INSTR, 0.32, 0.68, 0.65, 0.85 )
|
|
222
|
+
|
|
223
|
+
# Swap buffers
|
|
224
|
+
glfwSwapBuffers()
|
|
225
|
+
|
|
226
|
+
# Check for keys
|
|
227
|
+
if( glfwGetKey( ?Q ) == GLFW_PRESS || glfwGetWindowParam( GLFW_OPENED ) == false )
|
|
228
|
+
option = MENU_QUIT
|
|
229
|
+
elsif( glfwGetKey( GLFW_KEY_F1 ) == GLFW_PRESS )
|
|
230
|
+
option = MENU_PLAY
|
|
231
|
+
else
|
|
232
|
+
option = MENU_NONE
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# To avoid horrible busy waiting, sleep for at least 20 ms
|
|
236
|
+
glfwSleep( 0.02 )
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Disable sticky keys
|
|
240
|
+
glfwDisable( GLFW_STICKY_KEYS )
|
|
241
|
+
|
|
242
|
+
return option
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
#========================================================================
|
|
246
|
+
# NewGame() - Initialize a new game
|
|
247
|
+
#========================================================================
|
|
248
|
+
|
|
249
|
+
def NewGame
|
|
250
|
+
# Frame information
|
|
251
|
+
$starttime = $thistime = glfwGetTime()
|
|
252
|
+
|
|
253
|
+
# Camera information
|
|
254
|
+
$camerapos = CAMERA_DEFAULT
|
|
255
|
+
|
|
256
|
+
# Player 1 information
|
|
257
|
+
$player1.ypos = 0.0
|
|
258
|
+
$player1.yspeed = 0.0
|
|
259
|
+
|
|
260
|
+
# Player 2 information
|
|
261
|
+
$player2.ypos = 0.0
|
|
262
|
+
$player2.yspeed = 0.0
|
|
263
|
+
|
|
264
|
+
# Ball information
|
|
265
|
+
$ball.xpos = -1.0 + PLAYER_XSIZE
|
|
266
|
+
$ball.ypos = $player1.ypos
|
|
267
|
+
$ball.xspeed = 1.0;
|
|
268
|
+
$ball.yspeed = 1.0;
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
#========================================================================
|
|
272
|
+
# PlayerControl() - Player control
|
|
273
|
+
#========================================================================
|
|
274
|
+
|
|
275
|
+
def PlayerControl
|
|
276
|
+
# Get joystick X & Y axis positions
|
|
277
|
+
joy1pos = glfwGetJoystickPos( GLFW_JOYSTICK_1 )
|
|
278
|
+
joy2pos = glfwGetJoystickPos( GLFW_JOYSTICK_2 )
|
|
279
|
+
if (joy1pos == nil)
|
|
280
|
+
joy1pos = [0.0,0.0]
|
|
281
|
+
end
|
|
282
|
+
if (joy2pos == nil)
|
|
283
|
+
joy2pos = [0.0,0.0]
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Player 1 control
|
|
287
|
+
if( glfwGetKey( ?A ) == GLFW_PRESS || joy1pos[ 1 ] > 0.2 )
|
|
288
|
+
$player1.yspeed += $dt * ACCELERATION
|
|
289
|
+
if( $player1.yspeed > MAX_SPEED )
|
|
290
|
+
$player1.yspeed = MAX_SPEED
|
|
291
|
+
end
|
|
292
|
+
elsif( glfwGetKey( ?Z ) == GLFW_PRESS || joy1pos[ 1 ] < -0.2 )
|
|
293
|
+
$player1.yspeed -= $dt * ACCELERATION
|
|
294
|
+
if( $player1.yspeed < -MAX_SPEED )
|
|
295
|
+
$player1.yspeed = -MAX_SPEED
|
|
296
|
+
end
|
|
297
|
+
else
|
|
298
|
+
$player1.yspeed /= exp( DECELERATION * $dt )
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# Player 2 control
|
|
302
|
+
if( glfwGetKey( ?K ) == GLFW_PRESS || joy2pos[ 1 ] > 0.2 )
|
|
303
|
+
$player2.yspeed += $dt * ACCELERATION
|
|
304
|
+
if( $player2.yspeed > MAX_SPEED )
|
|
305
|
+
$player2.yspeed = MAX_SPEED
|
|
306
|
+
end
|
|
307
|
+
elsif( glfwGetKey( ?M ) == GLFW_PRESS || joy2pos[ 1 ] < -0.2 )
|
|
308
|
+
$player2.yspeed -= $dt * ACCELERATION
|
|
309
|
+
if( $player2.yspeed < -MAX_SPEED )
|
|
310
|
+
$player2.yspeed = -MAX_SPEED
|
|
311
|
+
end
|
|
312
|
+
else
|
|
313
|
+
$player2.yspeed /= exp( DECELERATION * $dt )
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Update player 1 position
|
|
317
|
+
$player1.ypos += $dt * $player1.yspeed
|
|
318
|
+
if( $player1.ypos > 1.0 - PLAYER_YSIZE )
|
|
319
|
+
$player1.ypos = 1.0 - PLAYER_YSIZE
|
|
320
|
+
$player1.yspeed = 0.0
|
|
321
|
+
elsif ( $player1.ypos < -1.0 + PLAYER_YSIZE )
|
|
322
|
+
$player1.ypos = -1.0 + PLAYER_YSIZE;
|
|
323
|
+
$player1.yspeed = 0.0
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# Update player 2 position
|
|
327
|
+
$player2.ypos += $dt * $player2.yspeed
|
|
328
|
+
if( $player2.ypos > 1.0 - PLAYER_YSIZE )
|
|
329
|
+
$player2.ypos = 1.0 - PLAYER_YSIZE;
|
|
330
|
+
$player2.yspeed = 0.0
|
|
331
|
+
elsif( $player2.ypos < -1.0 + PLAYER_YSIZE )
|
|
332
|
+
$player2.ypos = -1.0 + PLAYER_YSIZE;
|
|
333
|
+
$player2.yspeed = 0.0
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
#========================================================================
|
|
338
|
+
# BallControl() - Ball control
|
|
339
|
+
#========================================================================
|
|
340
|
+
|
|
341
|
+
def BallControl
|
|
342
|
+
# Calculate new ball speed
|
|
343
|
+
ballspeed = BALL_SPEED * (1.0 + 0.02*($thistime-$starttime))
|
|
344
|
+
$ball.xspeed = $ball.xspeed > 0 ? ballspeed : -ballspeed
|
|
345
|
+
$ball.yspeed = $ball.yspeed > 0 ? ballspeed : -ballspeed
|
|
346
|
+
$ball.yspeed *= 0.74321
|
|
347
|
+
|
|
348
|
+
# Update ball position
|
|
349
|
+
$ball.xpos += $dt * $ball.xspeed
|
|
350
|
+
$ball.ypos += $dt * $ball.yspeed
|
|
351
|
+
|
|
352
|
+
# Did the ball hit a top/bottom wall?
|
|
353
|
+
if( $ball.ypos >= 1.0 )
|
|
354
|
+
$ball.ypos = 2.0 - $ball.ypos
|
|
355
|
+
$ball.yspeed = -$ball.yspeed
|
|
356
|
+
elsif( $ball.ypos <= -1.0 )
|
|
357
|
+
$ball.ypos = -2.0 - $ball.ypos
|
|
358
|
+
$ball.yspeed = -$ball.yspeed
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
# Did the ball hit/miss a player?
|
|
362
|
+
event = NOBODY_WINS
|
|
363
|
+
|
|
364
|
+
# Is the ball entering the player 1 goal?
|
|
365
|
+
if( $ball.xpos < -1.0 + PLAYER_XSIZE )
|
|
366
|
+
# Did player 1 catch the ball?
|
|
367
|
+
if( $ball.ypos > ($player1.ypos-PLAYER_YSIZE) &&
|
|
368
|
+
$ball.ypos < ($player1.ypos+PLAYER_YSIZE) )
|
|
369
|
+
$ball.xpos = -2.0 + 2.0*PLAYER_XSIZE - $ball.xpos
|
|
370
|
+
$ball.xspeed = -$ball.xspeed
|
|
371
|
+
else
|
|
372
|
+
event = PLAYER2_WINS
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# Is the ball entering the player 2 goal?
|
|
377
|
+
if( $ball.xpos > 1.0 - PLAYER_XSIZE )
|
|
378
|
+
# Did player 2 catch the ball?
|
|
379
|
+
if( $ball.ypos > ($player2.ypos-PLAYER_YSIZE) &&
|
|
380
|
+
$ball.ypos < ($player2.ypos+PLAYER_YSIZE) )
|
|
381
|
+
$ball.xpos = 2.0 - 2.0*PLAYER_XSIZE - $ball.xpos
|
|
382
|
+
$ball.xspeed = -$ball.xspeed;
|
|
383
|
+
else
|
|
384
|
+
event = PLAYER1_WINS;
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
return event
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
#========================================================================
|
|
392
|
+
# DrawBox() - Draw a 3D box
|
|
393
|
+
#========================================================================
|
|
394
|
+
|
|
395
|
+
TEX_SCALE = 4.0
|
|
396
|
+
|
|
397
|
+
def DrawBox(x1,y1,z1,x2,y2,z2)
|
|
398
|
+
# Draw six sides of a cube
|
|
399
|
+
glBegin( GL_QUADS )
|
|
400
|
+
# Side 1 (down)
|
|
401
|
+
glNormal3f( 0.0, 0.0, -1.0 )
|
|
402
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
403
|
+
glVertex3f( x1,y2,z1 )
|
|
404
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
405
|
+
glVertex3f( x2,y2,z1 )
|
|
406
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
407
|
+
glVertex3f( x2,y1,z1 )
|
|
408
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
409
|
+
glVertex3f( x1,y1,z1 )
|
|
410
|
+
# Side 2 (up)
|
|
411
|
+
glNormal3f( 0.0, 0.0, 1.0 )
|
|
412
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
413
|
+
glVertex3f( x1,y1,z2 )
|
|
414
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
415
|
+
glVertex3f( x2,y1,z2 )
|
|
416
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
417
|
+
glVertex3f( x2,y2,z2 )
|
|
418
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
419
|
+
glVertex3f( x1,y2,z2 )
|
|
420
|
+
# Side 3 (backward)
|
|
421
|
+
glNormal3f( 0.0, -1.0, 0.0 )
|
|
422
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
423
|
+
glVertex3f( x1,y1,z1 )
|
|
424
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
425
|
+
glVertex3f( x2,y1,z1 )
|
|
426
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
427
|
+
glVertex3f( x2,y1,z2 )
|
|
428
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
429
|
+
glVertex3f( x1,y1,z2 )
|
|
430
|
+
# Side 4 (forward)
|
|
431
|
+
glNormal3f( 0.0, 1.0, 0.0 )
|
|
432
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
433
|
+
glVertex3f( x1,y2,z2 )
|
|
434
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
435
|
+
glVertex3f( x2,y2,z2 )
|
|
436
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
437
|
+
glVertex3f( x2,y2,z1 )
|
|
438
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
439
|
+
glVertex3f( x1,y2,z1 )
|
|
440
|
+
# Side 5 (left)
|
|
441
|
+
glNormal3f( -1.0, 0.0, 0.0 )
|
|
442
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
443
|
+
glVertex3f( x1,y1,z2 )
|
|
444
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
445
|
+
glVertex3f( x1,y2,z2 )
|
|
446
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
447
|
+
glVertex3f( x1,y2,z1 )
|
|
448
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
449
|
+
glVertex3f( x1,y1,z1 )
|
|
450
|
+
# Side 6 (right)
|
|
451
|
+
glNormal3f( 1.0, 0.0, 0.0 )
|
|
452
|
+
glTexCoord2f( 0.0, 0.0 )
|
|
453
|
+
glVertex3f( x2,y1,z1 )
|
|
454
|
+
glTexCoord2f( TEX_SCALE, 0.0 )
|
|
455
|
+
glVertex3f( x2,y2,z1 )
|
|
456
|
+
glTexCoord2f( TEX_SCALE, TEX_SCALE )
|
|
457
|
+
glVertex3f( x2,y2,z2 )
|
|
458
|
+
glTexCoord2f( 0.0, TEX_SCALE )
|
|
459
|
+
glVertex3f( x2,y1,z2 )
|
|
460
|
+
glEnd()
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
#========================================================================
|
|
464
|
+
# UpdateDisplay() - Draw graphics (all game related OpenGL stuff goes
|
|
465
|
+
# here)
|
|
466
|
+
#========================================================================
|
|
467
|
+
|
|
468
|
+
def UpdateDisplay
|
|
469
|
+
# Get window size
|
|
470
|
+
$width,$height = glfwGetWindowSize()
|
|
471
|
+
|
|
472
|
+
# Set viewport
|
|
473
|
+
glViewport( 0, 0, $width, $height )
|
|
474
|
+
|
|
475
|
+
# Clear display
|
|
476
|
+
glClearColor( 0.02, 0.02, 0.02, 0.0 )
|
|
477
|
+
glClearDepth( 1.0 )
|
|
478
|
+
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
|
|
479
|
+
|
|
480
|
+
# Setup projection matrix
|
|
481
|
+
glMatrixMode( GL_PROJECTION )
|
|
482
|
+
glLoadIdentity()
|
|
483
|
+
gluPerspective(
|
|
484
|
+
55.0, # Angle of view
|
|
485
|
+
$width.to_f/$height.to_f, # Aspect
|
|
486
|
+
1.0, # Near Z
|
|
487
|
+
100.0 # Far Z
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
# Setup modelview matrix
|
|
491
|
+
glMatrixMode( GL_MODELVIEW )
|
|
492
|
+
glLoadIdentity()
|
|
493
|
+
case ( $camerapos )
|
|
494
|
+
when CAMERA_ABOVE:
|
|
495
|
+
gluLookAt(
|
|
496
|
+
0.0, 0.0, 2.5,
|
|
497
|
+
$ball.xpos, $ball.ypos, 0.0,
|
|
498
|
+
0.0, 1.0, 0.0
|
|
499
|
+
)
|
|
500
|
+
when CAMERA_SPECTATOR:
|
|
501
|
+
gluLookAt(
|
|
502
|
+
0.0, -2.0, 1.2,
|
|
503
|
+
$ball.xpos, $ball.ypos, 0.0,
|
|
504
|
+
0.0, 0.0, 1.0
|
|
505
|
+
)
|
|
506
|
+
when CAMERA_CLASSIC:
|
|
507
|
+
gluLookAt(
|
|
508
|
+
0.0, 0.0, 2.5,
|
|
509
|
+
0.0, 0.0, 0.0,
|
|
510
|
+
0.0, 1.0, 0.0
|
|
511
|
+
)
|
|
512
|
+
else
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
# Enable depth testing
|
|
516
|
+
glEnable( GL_DEPTH_TEST )
|
|
517
|
+
glDepthFunc( GL_LEQUAL )
|
|
518
|
+
|
|
519
|
+
# Enable lighting
|
|
520
|
+
glEnable( GL_LIGHTING )
|
|
521
|
+
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, $env_ambient )
|
|
522
|
+
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE )
|
|
523
|
+
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE )
|
|
524
|
+
glLightfv( GL_LIGHT1, GL_POSITION, $light1_position )
|
|
525
|
+
glLightfv( GL_LIGHT1, GL_DIFFUSE, $light1_diffuse )
|
|
526
|
+
glLightfv( GL_LIGHT1, GL_AMBIENT, $light1_ambient )
|
|
527
|
+
glEnable( GL_LIGHT1 )
|
|
528
|
+
|
|
529
|
+
# Front face is counter-clock-wise
|
|
530
|
+
glFrontFace( GL_CCW )
|
|
531
|
+
|
|
532
|
+
# Enable face culling (not necessary, but speeds up rendering)
|
|
533
|
+
glCullFace( GL_BACK )
|
|
534
|
+
glEnable( GL_CULL_FACE )
|
|
535
|
+
|
|
536
|
+
# Draw Player 1
|
|
537
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, $player1_diffuse )
|
|
538
|
+
glMaterialfv( GL_FRONT, GL_AMBIENT, $player1_ambient )
|
|
539
|
+
DrawBox( -1.0, $player1.ypos-PLAYER_YSIZE, 0.0,
|
|
540
|
+
-1.0+PLAYER_XSIZE, $player1.ypos+PLAYER_YSIZE, 0.1 )
|
|
541
|
+
|
|
542
|
+
# Draw Player 2
|
|
543
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, $player2_diffuse )
|
|
544
|
+
glMaterialfv( GL_FRONT, GL_AMBIENT, $player2_ambient )
|
|
545
|
+
DrawBox( 1.0-PLAYER_XSIZE, $player2.ypos-PLAYER_YSIZE, 0.0,
|
|
546
|
+
1.0, $player2.ypos+PLAYER_YSIZE, 0.1 )
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
# Draw Ball
|
|
550
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, $ball_diffuse )
|
|
551
|
+
glMaterialfv( GL_FRONT, GL_AMBIENT, $ball_ambient )
|
|
552
|
+
DrawBox( $ball.xpos-BALL_SIZE, $ball.ypos-BALL_SIZE, 0.0,
|
|
553
|
+
$ball.xpos+BALL_SIZE, $ball.ypos+BALL_SIZE, BALL_SIZE*2 )
|
|
554
|
+
|
|
555
|
+
# Top game field border
|
|
556
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, $border_diffuse )
|
|
557
|
+
glMaterialfv( GL_FRONT, GL_AMBIENT, $border_ambient )
|
|
558
|
+
DrawBox( -1.1, 1.0, 0.0, 1.1, 1.1, 0.1 )
|
|
559
|
+
# Bottom game field border
|
|
560
|
+
glColor3f( 0.0, 0.0, 0.7 )
|
|
561
|
+
DrawBox( -1.1, -1.1, 0.0, 1.1, -1.0, 0.1 )
|
|
562
|
+
# Left game field border
|
|
563
|
+
DrawBox( -1.1, -1.0, 0.0, -1.0, 1.0, 0.1 )
|
|
564
|
+
# Left game field border
|
|
565
|
+
DrawBox( 1.0, -1.0, 0.0, 1.1, 1.0, 0.1 )
|
|
566
|
+
|
|
567
|
+
# Enable texturing
|
|
568
|
+
glEnable( GL_TEXTURE_2D )
|
|
569
|
+
glBindTexture( GL_TEXTURE_2D, $tex_id[ TEX_FIELD ] )
|
|
570
|
+
|
|
571
|
+
# Game field floor
|
|
572
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, $floor_diffuse )
|
|
573
|
+
glMaterialfv( GL_FRONT, GL_AMBIENT, $floor_ambient )
|
|
574
|
+
DrawBox( -1.01, -1.01, -0.01, 1.01, 1.01, 0.0 )
|
|
575
|
+
|
|
576
|
+
# Disable texturing
|
|
577
|
+
glDisable( GL_TEXTURE_2D )
|
|
578
|
+
|
|
579
|
+
# Disable face culling
|
|
580
|
+
glDisable( GL_CULL_FACE )
|
|
581
|
+
|
|
582
|
+
# Disable lighting
|
|
583
|
+
glDisable( GL_LIGHTING )
|
|
584
|
+
|
|
585
|
+
# Disable depth testing
|
|
586
|
+
glDisable( GL_DEPTH_TEST )
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
#========================================================================
|
|
590
|
+
# GameOver()
|
|
591
|
+
#========================================================================
|
|
592
|
+
|
|
593
|
+
def GameOver
|
|
594
|
+
# Enable sticky keys
|
|
595
|
+
glfwEnable( GLFW_STICKY_KEYS )
|
|
596
|
+
|
|
597
|
+
# Until the user presses ESC or SPACE
|
|
598
|
+
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetKey( GLFW_KEY_SPACE ) != GLFW_PRESS &&
|
|
599
|
+
glfwGetWindowParam( GLFW_OPENED ) == true )
|
|
600
|
+
# Draw display
|
|
601
|
+
UpdateDisplay()
|
|
602
|
+
|
|
603
|
+
# Setup projection matrix
|
|
604
|
+
glMatrixMode( GL_PROJECTION )
|
|
605
|
+
glLoadIdentity()
|
|
606
|
+
glOrtho( 0.0, 1.0, 1.0, 0.0, -1.0, 1.0 )
|
|
607
|
+
|
|
608
|
+
# Setup modelview matrix
|
|
609
|
+
glMatrixMode( GL_MODELVIEW )
|
|
610
|
+
glLoadIdentity()
|
|
611
|
+
|
|
612
|
+
# Enable blending
|
|
613
|
+
glEnable( GL_BLEND )
|
|
614
|
+
|
|
615
|
+
# Dim background
|
|
616
|
+
glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA )
|
|
617
|
+
glColor4f( 0.3, 0.3, 0.3, 0.3 )
|
|
618
|
+
glBegin( GL_QUADS )
|
|
619
|
+
glVertex2f( 0.0, 0.0 )
|
|
620
|
+
glVertex2f( 1.0, 0.0 )
|
|
621
|
+
glVertex2f( 1.0, 1.0 )
|
|
622
|
+
glVertex2f( 0.0, 1.0 )
|
|
623
|
+
glEnd()
|
|
624
|
+
|
|
625
|
+
# Display winner text
|
|
626
|
+
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR )
|
|
627
|
+
if( $winner == PLAYER1 )
|
|
628
|
+
glColor4f( 1.0, 0.5, 0.5, 1.0 )
|
|
629
|
+
DrawImage( TEX_WINNER1, 0.35, 0.65, 0.46, 0.54 )
|
|
630
|
+
elsif( $winner == PLAYER2 )
|
|
631
|
+
glColor4f( 0.5, 1.0, 0.5, 1.0 )
|
|
632
|
+
DrawImage( TEX_WINNER2, 0.35, 0.65, 0.46, 0.54 )
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
# Disable blending
|
|
636
|
+
glDisable( GL_BLEND )
|
|
637
|
+
|
|
638
|
+
# Swap buffers
|
|
639
|
+
glfwSwapBuffers()
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
# Disable sticky keys
|
|
643
|
+
glfwDisable( GLFW_STICKY_KEYS )
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
#========================================================================
|
|
647
|
+
# GameLoop() - Game loop
|
|
648
|
+
#========================================================================
|
|
649
|
+
|
|
650
|
+
def GameLoop
|
|
651
|
+
# Initialize a new game
|
|
652
|
+
NewGame()
|
|
653
|
+
|
|
654
|
+
# Enable sticky keys
|
|
655
|
+
glfwEnable( GLFW_STICKY_KEYS )
|
|
656
|
+
|
|
657
|
+
# Loop until the game ends
|
|
658
|
+
playing = true
|
|
659
|
+
while( playing && glfwGetWindowParam( GLFW_OPENED ) == true )
|
|
660
|
+
# Frame timer
|
|
661
|
+
$oldtime = $thistime
|
|
662
|
+
$thistime = glfwGetTime()
|
|
663
|
+
$dt = $thistime - $oldtime
|
|
664
|
+
|
|
665
|
+
# Get user input and update player positions
|
|
666
|
+
PlayerControl()
|
|
667
|
+
|
|
668
|
+
# Move the ball, and check if a player hits/misses the ball
|
|
669
|
+
event = BallControl()
|
|
670
|
+
|
|
671
|
+
# Did we have a winner?
|
|
672
|
+
case ( event )
|
|
673
|
+
when PLAYER1_WINS:
|
|
674
|
+
$winner = PLAYER1
|
|
675
|
+
playing = false
|
|
676
|
+
when PLAYER2_WINS:
|
|
677
|
+
$winner = PLAYER2
|
|
678
|
+
playing = false
|
|
679
|
+
else
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
# Did the user press ESC?
|
|
683
|
+
if( glfwGetKey( GLFW_KEY_ESC ) == GLFW_PRESS)
|
|
684
|
+
playing = false
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
# Did the user change camera view?
|
|
688
|
+
if( glfwGetKey( ?1 ) == GLFW_PRESS )
|
|
689
|
+
$camerapos = CAMERA_CLASSIC
|
|
690
|
+
elsif( glfwGetKey( ?2 ) == GLFW_PRESS )
|
|
691
|
+
$camerapos = CAMERA_ABOVE
|
|
692
|
+
elsif( glfwGetKey( ?3 ) == GLFW_PRESS )
|
|
693
|
+
$camerapos = CAMERA_SPECTATOR
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
# Draw display
|
|
697
|
+
UpdateDisplay()
|
|
698
|
+
|
|
699
|
+
# Swap buffers
|
|
700
|
+
glfwSwapBuffers()
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
# Disable sticky keys
|
|
704
|
+
glfwDisable( GLFW_STICKY_KEYS )
|
|
705
|
+
|
|
706
|
+
# Show winner
|
|
707
|
+
GameOver()
|
|
708
|
+
end
|
|
709
|
+
|
|
710
|
+
#========================================================================
|
|
711
|
+
# main() - Program entry point
|
|
712
|
+
#========================================================================
|
|
713
|
+
|
|
714
|
+
menuoption = MENU_NONE
|
|
715
|
+
|
|
716
|
+
# Initialize GLFW
|
|
717
|
+
|
|
718
|
+
# Open OpenGL window
|
|
719
|
+
if( glfwOpenWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) == false )
|
|
720
|
+
exit
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
# Load all textures
|
|
724
|
+
LoadTextures()
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
# Main loop
|
|
728
|
+
while( menuoption != MENU_QUIT )
|
|
729
|
+
# Get menu option
|
|
730
|
+
menuoption = GameMenu()
|
|
731
|
+
|
|
732
|
+
# If the user wants to play, let him...
|
|
733
|
+
if( menuoption == MENU_PLAY )
|
|
734
|
+
GameLoop()
|
|
735
|
+
end
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
# Unload all textures
|
|
739
|
+
if( glfwGetWindowParam( GLFW_OPENED ) == true)
|
|
740
|
+
glDeleteTextures( $tex_id )
|
|
741
|
+
end
|