Possible stupid BMax mistakes???

BlitzMax Forums/BlitzMax Beginners Area/Possible stupid BMax mistakes???

Jeremy Alessi(Posted 2004) [#1]
So I've written a little program ... should be quite easy ... all it does is create a little ship for you to move around the screen. My program doesn't error ... it just runs and then says process complete ... there's a loop in there but it just doesn't seem to stay running ... what the heck ... all the other BMax code runs just fine and I can't quite see anything wrong with the code.


AdrianT(Posted 2004) [#2]
hey jeremy I did just that today lol. took me a while to figure it out too as I'm having trouble understanding the samples that come with Bmax.

Here's my really simple example: I isolated just the ship moving around when you use cursor keys.


Incbin "ship.png" 

Graphics 800,600


Global player = LoadImage("incbin::ship.png")
Global player_x= 356
Global player_y= 400

While Not KeyDown(Key_Escape) 
Cls


'****** ship movement Keyboard ******
'************************************
If  KeyDown (key_up)
     Player_y=Player_y-4  
      If Player_y<0 Then Player_y=0
EndIf

If  KeyDown (key_down)
     Player_y=Player_y+4  
      If Player_y>536 Then Player_y=536
EndIf


If  KeyDown (key_left)
     Player_x=Player_x-4  
      If Player_x<0 Then Player_x=0
EndIf

If  KeyDown (key_right)
     Player_x=Player_x+4  
      If Player_x>736 Then Player_x=736
EndIf

'************************************
'************************************

DrawImage player,player_x,player_y


Flip 
Wend



Jeremy Alessi(Posted 2004) [#3]
Oh ... I see an error now ... nevermind ... I thought it was compiling just fine but I realized it's saying some null object is trying to be accessed.


AdrianT(Posted 2004) [#4]
oops didn't see your last post till after I posted the above. I'm doing a 1942 style shooter which I figured a good game to get to learn the basics with.


Jeremy Alessi(Posted 2004) [#5]
Maybe someone can see which object I'm screwing up with ... I guess it's the Create function or the UpdateAll() function but they seem to fit inline with the other BMax examples ... <shrugs> sure it's simple ...

Strict
'====== ROCKET RALLY ========================
'====== JEREMY ALESSI =======================

'====== GLOBALS =============================

Global entity2DCount
Global entity2DList:TList

'============================================

'====== INCBIN ==============================

Incbin "Media/entity2DImages/boing.png"

'============================================

'====== TYPES ===============================

'====== ENTITY 2D SUPER TYPE ================

Type entity2D

	Field image
	Field x, y
	Field vX, vY
	
	Function UpdateAll()
	
		Local e2D:entity2D
		If entity2DList = Null Then Return
		For e2D:entity2D = EachIn entity2DList
			e2D.Update()
			e2D.Draw()
		Next
	
	End Function
	
	Method New()
	
		If entity2DList = Null Then entity2DList = New TList
                entity2DList.AddLast(Self)
                entity2DCount = entity2DCount + 1
	
	End Method
	
	Method Destroy()
    
		entity2DList.Remove(Self)
		entity2DCount = entity2DCount - 1
  
	End Method

	Method Update() Abstract
	
	Method Draw() Abstract
	
End Type

'============================================

'====== PLAYER SUB TYPE =====================

Type player Extends entity2D

	Field playState$
	
	Function Create:player(x, y)
	
		Local p:player
		p:player = New player
		p.x = x
		p.y = y
		p.image = LoadImage("incbin::boing.png")
		MidHandleImage(p.image)
		p.playState$ = "Action"
		Return p
				
	End Function
	
	Method Update()
		
		Select Self.playState$
		
			Case "Calculation"
			
			Case "Action"
				If KeyDown(KEY_W) Then Self.y = Self.y - 1
				If KeyDown(KEY_S) Then Self.y = Self.y + 1
				If KeyDown(KEY_A) Then Self.x = Self.x - 1
				If KeyDown(KEY_D) Then Self.x = Self.x + 1
				
		
		End Select
	
	End Method
	
	Method Draw()
	
		AutoImageFlags MASKEDIMAGE
		SetMaskColor(255, 0, 255)
		SetRotation 0
		SetScale 1, 1
		DrawImage(Self.x, Self.y, Self.image)
	
	End Method

End Type

'============================================

'====== MAIN LOOP ===========================

Graphics(640, 480, 32, 60)

Local p:player = player.Create(320, 240)

SetClsColor(0, 0, 0)

Repeat

	Cls
	p.UpdateAll()	
	FlushMem
	Flip	
	
Until KeyHit (KEY_ESCAPE)

End

'============================================



AdrianT(Posted 2004) [#6]
sucks that you can't copy and paste in the IDE, it all comes out in one line without formatting. I hear protean has a bmax Beta that would probably work though.


Jeremy Alessi(Posted 2004) [#7]
Yeah that does stink ...


Jeremy Alessi(Posted 2004) [#8]
Ugh ... come one no one saw that I was totally putting DrawImage(x, y, image) instead of DrawImage(image, x, y) lol... nice one!


Damien Sturdy(Posted 2004) [#9]
Muhahah. i do that all too many times!

Hye, about the formatting issue? it used to happen in b3d's IDE too sometimes. I wonder whats causing it?


Hotcakes(Posted 2004) [#10]
Hye, about the formatting issue? it used to happen in b3d's IDE too sometimes. I wonder whats causing it?

Bad coding ;]


{cYan|de}(Posted 2004) [#11]
everyone seems to be going mad with incbin, you know you dont have to use that:P;)


skn3(Posted 2004) [#12]
Incbin is great :D Especialy if you just wanted to include a few images for some little micro game.


RiK(Posted 2004) [#13]
sucks that you can't copy and paste in the IDE, it all comes out in one line without formatting. I hear protean has a bmax Beta that would probably work though.


and from Mark's BETA release notes:-
These are beta versions. There will be problems and issues with them. The Win32 and Linux version of BlitzMax will not be officially released until such problems have been solved to the best of our ability.


* The IDE is highly experimental! More work to be done on it, so no complaints yet please.



assari(Posted 2004) [#14]
in the meantime you can cut&paste from the sample to notepad and cut&paste from there to the IDE.


RiK(Posted 2004) [#15]
or use Protean :)


AdrianT(Posted 2004) [#16]
heh, I'll probably get visual blitz for bmax when its out. Pretty simple but has some really nice extras for a newbie like me. Like the autocomplete drop down menu's, line numbers folding functions, and the quick nav list on the right.

A bargain at $15, really tempted to get Protean but even with the Xmas discount price I can't afford it right now. If I get some good news = $ to spare in the next couple of weeks I'll probably get Protean since its out allready :)