Tutorial de ZX Basic + Fourspriter #13: Empezando el proyecto

Bueno, ya que tenemos las cosas básicas (fondos y sprites) listos, vamos a gastar este capítulo corto en empezar montar el proyecto para hacer nuestro güego. Vamos a crear el esqueleto del programa principal, que grabaremos como feoncio.bas, pero antes creemos engine.bas con nuestras dos subrutinas útiles y las constantes necesarias:

'' engine.bas
''
'' Rutinas del juego

Const MAPSCREENWIDTH As uByte = 12
Const MAPSCREENHEIGHT As uByte = 12
Const TILESIZE As uByte = 2

Sub pintaTile (x as uByte, y as uInteger, n as uByte)
   Dim addr as uInteger
   addr = 22528 + x + (y << 5)
   Poke addr, tileset (n, 0): Poke addr + 1, tileset (n, 2)
   Poke addr + 32, tileset (n, 4): Poke addr + 33, tileset (n, 6)
   Print Paper 8; Ink 8; _
      At y, x; Chr (tileset (n, 1)); Chr (tileset (n, 3)); _
      At y + 1, x; Chr (tileset (n, 5)); Chr (tileset (n, 7));
End Sub

Sub pintaMapa (x as uByte, y as uByte, n as uInteger)
   Dim idx as uInteger
   Dim i as uByte
   Dim screenSize as uByte
   Dim mapScreenWidthInChars as uByte
   Dim xx, yy as uByte
   ' Size in bytes:
   screenSize = MAPSCREENWIDTH * MAPSCREENHEIGHT
   mapScreenWidthInChars = TILESIZE * MAPSCREENWIDTH
   ' Read from here:
   idx = n * screenSize
   ' Loop
   xx = x
   yy = y
   For i = 1 To screenSize
      pintaTile (xx, yy, mapa (idx))
      xx = xx + TILESIZE
      If xx = x + mapScreenWidthInChars Then
         xx = x
         yy = yy + TILESIZE
      End If
      idx = idx + 1
   Next i
End Sub

Ahora crearemos feoncio.bas con esta estructura básica: los includes para incluirlo todo (gráficos, mapa, bibliotecas, funciones…), una sección de variables (vacía por ahora), el código principal con su inicialización (por lo pronto, ponemos la pantalla a negro, activamos los UDG y definimos el spriteset para fourspriter) y una sección para funciones y subrutinas (aún vacío).

'' feoncio.bas
''
'' Archivo principal

'' includes
#include once "fsp2.1.bas"
#include once "spriteset.bas"
#include once "udg.bas"
#include once "tileset.bas"
#include once "mapa.bas"
#include once "engine.bas"

'' variables

'' main

' Inicializarlo todo:

Border 0: Paper 0: Ink 7: Bright 0: Cls
Poke uInteger 23675, @udg (0)
fsp21SetGfxAddress (@spriteset (0))

' Empezar

End

'' subs

¡Ya estamos listos para empezar!

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: