HELP! - Beginner project from BlitzPlus

Blitz3D Forums/Blitz3D Beginners Area/HELP! - Beginner project from BlitzPlus

BlackGearGames(Posted 2013) [#1]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;PROTOTYPE SPACE SHEEP GAME;;;;;;;;;;;;;;;;;;;;;;;;;
;This idea of this project is to learn how to use BB ;;;;;;;;;;
;I will be creating various projects and commenting them ;;;;;;
;I will do my best to give as much detail as this program ;;;;;
;Develops further. I eventually want to use this code ;;;;;;;;;

;In later projects ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Copyright 2013 to 2014. Black Gear Games, all rights reserved;
;If you have answeres to some questions i might be asking ;;;;;
;Please contact me at shadow_wolf75@... Thank you ;;;;;

;This code will set up your constants.
Const g_ScreenWidth=1024, g_ScreenHeight=768

;Call the BB "Graphics" Routine to initialize DirectX
Graphics g_ScreenWidth, g_ScreenHeight

;Set up BB to support page-flipping
SetBuffer BackBuffer()

;Create a Global var for the player's image
Global g_PlayerImage

;Creat globals to keep track of the mouse positions
Global g_OldMouseX=1, g_OldMouseY=1

;Create a type (which is just like a C/C++ Struct)
Type MainShip
Field x#, y#
End Type

;Create an object of MainShip, called Ship
Ship.MainShip=New MainShip

;Set the x,y for the ship.
Ship\x#=1
Ship\y#=1

;Call BB's LoadImage function to Load the .BMP
;Make sure you put the proper path to the .BMP file image.
g_PlayerImage=LoadImage( "player.bmp" )

;Our main game loop is here.
;While the ESC key is not pressed
While Not KeyHit(1)

;If mouse position isn't the same as last loop.
;Update the X,Y coords for the ship.
If g_OldMouseX<>MouseX() Or g_OldMouseY<>MouseY()
	
;Update the X coord for the ship placement
Ship\x#=MouseX()

;Update the Y coord for the ship placement
Ship\x#=MouseY()

End If

;Save the current X,Y
g_OldMouseY=MouseX()
g_OldMouawY=MouseY()

;Call BB's DrawImage Function to put the ship
;up in the proper spot
DrawImage g_PlayerImage, Ship\x#, Ship\y#

;Call BB's Flip function to flip the pages
Flip

;Call the back Buffer
Cls

;end of out main loop
Wend

;Free the ship object
Delete Ship

;End the program
End


Ok. Before i continue further with this, hello everyone! my name is chris and i am an aspiring game designer. But i know absolutely NOTHING about programming, and i recently decided to try my hand with the BlitzPlus, IDE software. I want to learn how to use this software and take full advantage of it, but this is new to me and i am having a hard time trying to get this beginner project to work. I followed the code down to the very letter as it showed in the beginner tutorial that came with the blitzplus software. But when i try to compile and run it; it says "Invalid Image Handle" and the debugger points to this line of code

"DrawImage g_PlayerImage, Ship\x#, Ship\y#"

Is there something i am not doing right?


xlsior(Posted 2013) [#2]
- Does the "player.bmp" file exist in the same folder as your program?
- You can check if the loading was succesful:
g_PlayerImage=LoadImage( "player.bmp" )
if not g_PlayerImage then print "File could not be loaded!"



BlackGearGames(Posted 2013) [#3]
Thank you Xlsior. I put the image file in the correct folder along with the source code, but now there is an interesting problem I'm having. When the game starts, the ship moves horizontal. BUT! i have to move my mouse VERTICALLY! XD I'm looking over the tutorial on how to fix this. But not really finding anything related to it.


Yasha(Posted 2013) [#4]
;Update the X coord for the ship placement
Ship\x#=MouseX()

;Update the Y coord for the ship placement
Ship\x#=MouseY()


You might notice something off about the second one of those...

(i.e. it's just a typo causing the odd movement, not a logic problem as such.)


BlackGearGames(Posted 2013) [#5]
Yasha. I can't find the issue.


BlackGearGames(Posted 2013) [#6]
NVM found it.


BlackGearGames(Posted 2013) [#7]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;PROTOTYPE SPACE SHIP GAME;;;;;;;;;;;;;;;;;;;;;;;;;
;This idea of this project is to learn how to use BB ;;;;;;;;;;
;I will be creating various projects and commenting them ;;;;;;
;I will do my best to give as much detail as this program ;;;;;
;Develops further. I eventually want to use this code ;;;;;;;;;

;In later projects ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Copyright 2013 to 2014. Black Gear Games, all rights reserved;
;If you have answeres to some questions i might be asking ;;;;;
;Please contact me at shadow_wolf75@... Thank you ;;;;;

;This code will set up your constants.
; Setup our constants
Const g_ScreenWidth=1024, g_ScreenHeight=768

;Call the BB "Graphics" Routine to initialize DirectX
Graphics g_ScreenWidth, g_ScreenHeight

;Setup BB to support Page-Flipping
SetBuffer BackBuffer()

;Creat a global var for the player's Image
Global g_PlayerImage

;Create Globals to keep track of the mouse positions
Global g_OldMouseX=1, g_OldMouseY=1

;Creat a Type (Which is just like a C/C++ Struct)
Type MainShip
Field x#,y#
End Type

;Create an object of MainShip, called Ship
Ship.MainShip=New MainShip

;Set the x,y for the ship
Ship\x#=1
Ship\y#=1

;Call BB's LoadImage Function to load the .BMP
;Make sure you put the proper path to the .BMP
g_PlayerImage=LoadImage ( "Player.bmp" )

;Our main game look is here.
;while the ESC key is not pressed
While Not KeyHit(1)

;If mouse position isn't the same as Last loop
;update the x,y coords for the ship
If g_OldMouseX<>MouseX() Or g_OldMouseY<>MouseY()

;update the X coord for the ship placement
Ship\x#=MouseX()

;update the Y coord for the ship placement
Ship\y#=MouseY()
EndIf

;Save the current mouse x,y
g_OldMouseY=MouseX()
g_OlfMouseY=MouseY()

;Call BB's DraImage function to the ship
;up in the proper spot
DrawImage g_PlayerImage, Ship\x#, Ship\y#

;Call BB's Flip function to flip the pages
Flip

;Clear the back buffer
Cls

;end of our main loop
Wend

;Free the ship object
Delete Ship

;end of the program
End


Ok, so I've been tinkering with BlitzPlus. And the software works as predicted and the code shown is the same example code from the beginner tutorial on BlitzPlus' Help page. Now I'm able to load the prototype, move the ship around with the mouse. And look at the black screen. Not very exciting but I'm pleased with the progress That I've made so far.. Now, what I'm wondering is. What do i do next? It's obvious i got something here that works. Thanks to the help of the writer of the tutorial. And instead of copying and pasting the code, i hand wrote it so I'm not ripping the author off 100%. I'm wondering if there are others out there who are just starting out like me, and would be interested in showing me how to use this software even more. Also, i was wondering if anyone writes the code down and writes the explanations down as well. With that said, what do i do next?


Who was John Galt?(Posted 2013) [#8]
If you haven't done it already, take a look at the demos that come with blitz plus. I wouldn't say you really learn anything by retyping code. Take a look at the existing demos, think about what they are doing and tweak the odd line here and there and predict the effect it will have. Then run it and see if it does what you expected.

Also, read some basic tutorials if you aren't at the level to understand simple code examples.

And my best piece of advice... don't start trying to write a game until you've got a bit more knowledge. It will frustrate you. Just play with code snippets for a while.

Good luck.