sprite or entity

Blitz3D Forums/Blitz3D Programming/sprite or entity

I am writnig a game... I know... shock and amazement that ANYONE on this forum would be writing a game... ;]

BUT

I am writing an othello game. I have had a lot of very well intentioned advice... a lot of very good advice though sometimes the two types of advice aren't the same...

So I took WolRons advice to heart and recoded the game the way I know how.

It works... after a fashion.

I am currently using mesh entitys to represent the pieces and all the squares on the board.

When a legal move is selected the game puts the new piece color info in the correct location of the array... GOOD

Then the setupboard() plunks the pieces down on the screen.

But I don't know how to delete the old peices before it does this so the old pieces still remain and you can't really see the new piece.

I thought of hideentity... but where to start...

Should I just use sprites??? I don't want to use sprites! They don't look as good.

;
; Hexathello (OK Othello but I hope to get the square thing figured out
; then nail a hex thing!
; Ralph Dunn
Graphics3D 800,600,16,2
SetBuffer BackBuffer()

player=CreatePivot()
camera=CreateCamera(player)
light=CreateLight()
RotateEntity light,45,45,0
AmbientLight 48,48,48    ; was 32,32,32

EntityType camera,1
PositionEntity camera,0,90,8
RotateEntity camera,90,0,0

Dim boardarea(9,9)
Dim boardx(9)
Dim boardz(9)
Dim turnpiecex(9)
Dim turnpiecez(9)

Global square
Global xx
Global zz
Global what
Global wp
Global bp
Global colorflag
Global musicflag
Global numfreespace
Global numbpieces
Global numwpieces
; now create an array called boardarea of 10 by 10 and
; fill in the entire matrix with 0
For fillx = 0 To 9
	For fillz=0 To 9
		boardarea(fillx,fillz)=0
	Next
Next
; ################################## Initial Pieces Start Location
boardarea(4,4)=1
boardarea(4,5)=2
boardarea(5,4)=2
boardarea(5,5)=1

numfreespace=97 ; have to add one becuae the setupboard funct - 1
numbpieces=2
numwpieces=2

boardx(0)=-45
boardx(1)=-35
boardx(2)=-25
boardx(3)=-15
boardx(4)=-5
boardx(5)=5
boardx(6)=15
boardx(7)=25
boardx(8)=35
boardx(9)=45

boardz(0)=-45
boardz(1)=-35
boardz(2)=-25
boardz(3)=-15
boardz(4)=-5
boardz(5)=5
boardz(6)=15
boardz(7)=25
boardz(8)=35
boardz(9)=45

annoy=LoadSound("anoy1.ogg")
LoopSound annoy
Global play_annoy=PlaySound(annoy)

; #######################################  Load Mesh Objects
gameboard=LoadMesh("squareboard.b3d")
UpdateNormals gameboard
ScaleEntity gameboard,5.5,5.5,5.5
EntityShininess gameboard,1

Global empty=LoadMesh("square.b3d")
EntityPickMode empty,2
HideEntity empty

Global wpiece=LoadMesh("piece2.b3d")
EntityShininess wpiece,1
HideEntity wpiece

Global bpiece=CopyMesh(wpiece)
RotateEntity bpiece,180,0,0
EntityShininess bpiece,1
HideEntity bpiece

; ######################################  Plunk Tiles
For xx=0 To 9
	For zz=0 To 9
		e=CopyEntity (empty)
		PositionEntity e,boardx(xx),1,boardz(zz)
	Next
Next
; ############################################## Start of Game Loop
ShowPointer 

colorflag=1 ; white piece gets put first so computer can countermove
musicflag=1 ; For the rasta othello player in each of us!

setupboard()

While Not KeyDown(1)

x=MouseX()
y=MouseY()

e=CameraPick(camera,x,y)
	If e<>entity#
		If entity Then EntityColor entity,255,255,255 
		entity#=e
	EndIf
	
If KeyHit(29)=True Then
	PositionEntity camera,0,53,-69
	RotateEntity camera,35,0,0
EndIf

If KeyHit(50)>=1 Then musicflag=1-musicflag

If KeyHit(56)=True Then
	PositionEntity camera,0,90,8
	RotateEntity camera,90,0,0
EndIf

If MouseHit(1) = True Then
	hat=CameraPick(camera,x,y)
	If hat=0 Then Goto outme
	colorflag=1-colorflag
		Select empty 
			Case empty
			xx=EntityX(entity)
			zz=EntityZ(entity) 
			Default 
			pp=0
		End Select

If colorflag = 0 Then put_white()
If colorflag = 1 Then put_black()

setupboard()

.outme

EndIf

If entity#
	EntityColor entity,54,80,232
; 73,253,146 lime 254,216,38 gold 254,80,232 magenta
EndIf

If numfreespace=0 Then Goto thatsall
If numbpieces=0 Then Goto thatsall
If numwpieces=0 Then Goto thatsall

If musicflag=1 Then ChannelVolume play_annoy,0.4 Else ChannelVolume play_annoy,0


UpdateWorld
RenderWorld

Text 0,10,"X: "+x
Text 0,20,"Y: "+y
Text 0,30,"Z: "+z
Text 0,50,"THING: "+e
Text 0,60,"XX "+xx
Text 0,70,"ZZ "+zz
Text 0,80,"Free: "+numfreespace
xp=turnpiecex(0)
zp=turnpiecez(0)
Text 0,100,"XP: "+xp
Text 0,110,"ZP: "+zp
Text 0,120,"ROW: "+wp
Text 0,130,"COL: "+bp

Flip

Wend

.thatsall

End

Function put_white()
Select xx
	Case -45
	row=0
	Case -35
	row=1
	Case -25
	row=2
	Case -15
	row=3
	Case -5
	row=4
	Case 5
	row=5
	Case 15
	row=6
	Case 25
	row=7
	Case 35
	row = 8
	Case 45
	row=9
End Select

Select zz
	Case -45
	col=0
	Case -35
	col=1
	Case -25
	col=2
	Case -15
	col=3
	Case -5
	col=4
	Case 5
	col=5
	Case 15
	col=6
	Case 25
	col=7
	Case 35
	col= 8
	Case 45
	col=9
End Select
;###################################### CHECK IF ITS LEGAL
If boardarea(row,col)=0 Then
	lc=col+1
	For lcheck=lc To 9
	If boardarea(row,lc)= 1 Then Goto badmove	
		If boardarea(row,lc)=2 Then
				For x= 0 To 9
				turnpiecex(x)=row
				turnpiecez(x)=lc 
				turnblack = turnblack+1
				If boardarea(row,lcheck)=1 Then Goto islegal; breakout as soon as you hit a 1
				Next				
		EndIf
	Next
EndIf
.islegal
For w=1 To turnblack
	wp=row ; this so I could check where it thinks it has to put the piece
	bp=col ; I also checked the first location of turnpiecex and turnpiecez
	boardarea(turnpiecex(w-1),turnpiecez(w-1))=1
	boardarea(row,col)=1
turnblack=0
Next

.badmove
colorflag=1

End Function

Function put_black()
; AI starts here!


End Function

Function setupboard()
Cls
For row=0 To 9
	For col=0 To 9
		what=boardarea(row,col)
			If what = 1 Then
			 g=CopyEntity (wpiece)
				PositionEntity g,boardx(row),2,boardz(col)
			ElseIf what = 2 Then
			 h=CopyEntity (bpiece)
				PositionEntity h,boardx(row),2,boardz(col)
			EndIf
	Next
Next
numfreespace=numfreespace-1
End Function
;
EDIT::: Sorry about forgetting the end statement to codebox there!

If you wish to update your board from the array each time, why not place a piece (entity/mesh) at each board position and hide the ones you do not want to see. Show piecies (entities) that you do want to display and set thier colour accordingly (or use two meshes at each location).

Rhy Out

That is an interesting idea... I could also just use one mesh and change the color...