05-01-2006, 08:50 PM
Ok, I'm a real noob at this, but I'm trying to make a game (don't laugh). I've made some basic tiles, and the program runs. But the only tile it seems to load is the blank tile. Here is my code.
game.bas
game.bi
Edit: It appears that the program is not loading an image at all. But it is. Maybe the load function is loading the first pixel only?
game.bas
Code:
#include "game.bi"
InitGame
GameMain
'*******************************************************************************
'input: name of bmp
'output: pointer to loaded bmp in memory
'functional: returns null if bmp is not legit
'Thanks deleter
Function LoadSpr(file as string) as ubyte ptr
dim as integer ff,x,y
dim as integer ptr img
ff=freefile
open file for binary as #ff
if lof(ff)=0 then
kill file
return null
end if
get #ff,19,x
get #ff,23,y
close #ff
img=imagecreate(x,y,&h0)
bload file,img
return img
End Function
'*******************************************************************************
'Function: Loads sprites into the sprites array
Sub LoadSprites()
'Blank tile
spr(t_blank) = LoadSpr("img\blank.bmp")
'circle tile
spr(t_circle) = LoadSpr("img\circle.bmp")
'triangle tile
spr(t_triangle) = LoadSpr("img\triangle.bmp")
'square tile
spr(t_square) = LoadSpr("img\square.bmp")
'x tile
spr(t_x) = LoadSpr("img\x.bmp")
End Sub
'*******************************************************************************
'Function: Initializes game settings, loads sprites, etc.
Sub InitGame()
'640x480, 8 bit, 2 pages, Windowed
ScreenRes 640, 480, 8, 2, 0
'Load the sprites, duh
LoadSprites
'Random numbers
Randomize Timer
quit = false
End Sub
'*******************************************************************************
'Function: Gets Input from user, and acts accordingly
Sub GetInput()
If MultiKey(KEY_ESC) Then
quit = true
End If
End Sub
'*******************************************************************************
'Function: Updates variables
Sub Update()
End Sub
'*******************************************************************************
'Function: Draws screen
Sub DrawScreen()
ScreenSync
Put(1,1), spr(tile_x), trans
End Sub
'*******************************************************************************
'Function: Main game loop
Sub GameMain()
Do
GetInput
Update
DrawScreen
Loop While quit = false
End Sub
'*******************************************************************************
'Function: Deletes sprites from memory
Sub DeleteSprites()
'Blank tile
ImageDestroy(spr(t_blank))
'circle tile
ImageDestroy(spr(t_circle))
'triangle tile
ImageDestroy(spr(t_triangle))
'square tile
ImageDestroy(spr(t_square))
'x tile
ImageDestroy(spr(t_x))
End Sub
game.bi
Code:
Declare Function LoadSpr(file As String) as ubyte ptr
Declare Sub InitGame()
Declare Sub LoadSprites()
Declare Sub GetInput()
Declare Sub Update()
Declare Sub DrawScreen()
Declare Sub GameMain()
Declare Sub DeleteSprites()
#define null
#define true -1
#define false NOT true
'Keys
#define KEY_ESC &h01
Enum TileEnum
t_blank
t_circle
t_triangle
t_square
t_x
t_end
End Enum
Dim Shared spr(t_end-1) As uByte Ptr
Dim Shared quit As Byte
Edit: It appears that the program is not loading an image at all. But it is. Maybe the load function is loading the first pixel only?
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]