Jump to content


Photo

Grid Based Snippet


  • Please log in to reply
2 replies to this topic

#1 flattspott

flattspott

    X-S Freak

  • Moderator
  • PipPipPipPipPip
  • 1,787 posts
  • Location:Southern California
  • Xbox Version:v1.0
  • 360 version:v1 (xenon)

Posted 28 July 2004 - 04:26 AM

CODE
MinimumBuild 1231
SetFunc ScriptPath FNPath %0%

// Basically the only values to change
Set Column 0        // The Intial PointerX
Set Row 0        // The Intial PointerY
Set Size 36
Set MaxRows 4
Set MaxColumns 4
Set PointerColor Blue

CreateBlankImage Pointer %Size% %Size%
Gosub CenterGrid

:PointerLoop
SetFunc Input IQPeekMsgID
If %Input% != "" Gosub InputHandler
Gosub DrawPointer
Goto PointerLoop

:InputHandler
IQWaitMsg Any
Switch %MSG_ID%
Case UI_UP
 If# %Row% != 0 Then
  Sub Row 1
 EndIf
EndCase
Case UI_DN
 If# %Row% != %MaxRows% Then
  Add Row 1
 EndIf
EndCase
Case UI_LF
 If# %Column% != 0 Then
  Sub Column 1
 EndIf
EndCase
Case UI_RT
 If# %Column% != %MaxColumns% Then
  Add Column 1
 EndIf
EndCase
Case UI_SELECT
 Gosub Click
EndCase
Case UI_BACK
 Quit
EndCase
EndSwitch
Return

:DrawPointer
Set TempPointer %Row%%Column%
For Y = 0 To %MaxRows%
For X = 0 To %MaxColumns%
 If# %TempPointer% == %Y%%X% Then
  Set PointerX %(X*Size+AlignX)%
  Set PointerY %(Y*Size+AlignY)%
  Break
 EndIf
Next
Next
BeginDrawTarget Pointer UseCurrent
Box %PointerX% %PointerY% %Size% %Size% %PointerColor% %PointerColor%
EndDraw
Return

:CenterGrid
Set ScreenLeft 0
Set ScreenTop 0
Set ScreenWidth 640
Set ScreenHeight 480
Set AlignX %((ScreenWidth-(MaxColumns*Size))/2)%
Set AlignY %((ScreenHeight-(MaxRows*Size))/2)%
Return


I'm trying to come up with a more effeciant way to draw and move the pointer around in my games, Lights Out, Concentration etc... This would be for grid base games.

Maybe someone else could make use of it too.



#2 geniusalz

geniusalz

    Team MXM

  • Head Moderators
  • PipPipPipPipPip
  • 1,827 posts
  • Gender:Male
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 28 July 2004 - 07:16 AM

Cool, but...

:DrawPointer
Set TempPointer %Row%%Column%
For Y = 0 To %MaxRows%
For X = 0 To %MaxColumns%
If# %TempPointer% == %Y%%X% Then
Set PointerX %(X*Size+AlignX)%
Set PointerY %(Y*Size+AlignY)%
Break
EndIf
Next
Next

BeginDrawTarget Pointer UseCurrent
Box %PointerX% %PointerY% %Size% %Size% %PointerColor% %PointerColor%
EndDraw
Return

Why is the loop there?

You can use :
Set PointerX %(Row*Size+AlignX)%
Set PointerY %(Column*Size+AlignY)%

#3 flattspott

flattspott

    X-S Freak

  • Moderator
  • PipPipPipPipPip
  • 1,787 posts
  • Location:Southern California
  • Xbox Version:v1.0
  • 360 version:v1 (xenon)

Posted 28 July 2004 - 10:33 AM

Actually I pulled it strait out of the revamped Lights Out games and changed a few things at the last minute




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users