#!/usr/bin/env ruby begin require__ 'RUDL' include RUDL module RUDL class SFont def print_centered(*args) end end end require "opengl" require "glut" require "mathn" require "rational" include Constant require "Maps/Map001.rb" $SCREEN = DisplaySurface.new([640,480],OPENGL|DOUBLEBUF) $SCREEN_W = 640 $SCREEN_H = 480 $SCREEN.set_caption($map_name, $map_name) #Camra Cordinations $camra_x = 0 $camra_y = 0 $camra_z = 0 STDOUT.sync = TRUE # flush all output to screen immediately $Texures = [] def loadGLTextures $Textures = GL.GenTextures($map_textures.size); for i in 0...$map_textures.size if ($map_textures[i].nil?) SDL_Quit exit (1) end # convert bmp from BGR to RGB - no BGR mask on Windows image= Surface.new($map_textures[i].size, SWSURFACE, 24, [0x000000FF, 0x0000FF00, 0x00FF0000, 0]) image.blit($map_textures[i], [0,0]) # texture 0 (linear scaling) GL.BindTexture(GL::TEXTURE_2D, $Textures[i]); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR); GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR); GL.TexImage2D(GL::TEXTURE_2D, 0, 3,$map_textures[i].w, $map_textures[i].h, 0, GL::RGB, GL::UNSIGNED_BYTE, $map_textures[i].pixels) end end def init(w,h) loadGLTextures GL.ClearColor(0.0, 0.0, 0.0, 0.0) GL.ClearDepth(1.0) GL.DepthFunc(GL::LESS) GL.Enable(GL::DEPTH_TEST) GL.MatrixMode(GL::PROJECTION) GL.LoadIdentity() GL.MatrixMode(GL::MODELVIEW) end def layer_1 for i in 0...$map.size for j in 0...$map[i].size GL.Begin(GL::QUADS); x ,y= 0.32 * j,0.32 * i GL.TexCoord 0, 0 GL.Vertex x, y # top left GL.TexCoord 1, 0 GL.Vertex x+0.32, y+0.00 # top right GL.TexCoord 1, 1 GL.Vertex x+0.32, y+0.32 # bottom left GL.TexCoord 0, 1 GL.Vertex x+0.00, y+0.32 #bottom right GL.End(); GL.BindTexture(GL::TEXTURE_2D, $Textures[$map[y][x]]); end end end display = Proc.new { GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) GL.Enable(GL::TEXTURE_2D); GL.Color(1.0, 1.0, 1.0) GL.LoadIdentity() GL.Translate($camra_x, $camra_y, 0) layer_1 GL.Disable(GL::TEXTURE_2D); } reshape = Proc.new { |w, h| GL.Viewport(0, 0, $SCREEN_W, $SCREEN_H) GL.MatrixMode(GL::PROJECTION) GL.LoadIdentity() GLU.Ortho2D(0, 6.4, 4.8, 0) GL.MatrixMode(GL::MODELVIEW) } init($SCREEN_W, $SCREEN_H) done=false while !done event = EventQueue.poll case event when QuitEvent done=true when KeyDownEvent case event.key when K_ESCAPE done=true end end $camra_z -= 0.1 if Key.pressed?[K_PAGEUP] $camra_z += 0.1 if Key.pressed?[K_PAGEDOWN] $camra_y -= 0.032 if Key.pressed?[K_UP] $camra_y += 0.032 if Key.pressed?[K_DOWN] $camra_x += 0.032 if Key.pressed?[K_LEFT] $camra_x -= 0.032 if Key.pressed?[K_RIGHT] reshape.call($SCREEN_W, $SCREEN_H) display.call $SCREEN.flip end rescue print "File error:\n" print "------------------\n" print "#{$!}\n" print "#{$!.backtrace}\n" print "------------------\n" end ~-------------------------------------------------- ~ MAP FILE ~-------------------------------------------------- $map_name = "Map001" $map_textures = [Surface.load_new("Graphics/Floors/grass.png"),Surface.load_new("Graphics/Floors/grass.png"),Surface.load_new("Graphics/Floors/shrub.png")] $map = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]