Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Rick3137

Pages: [1] 2 3
1
Showcase / Music Keyboard
« on: July 22, 2017 »
   I have recently been working on sound files . I have finished a set of notes with Audacity and created a keyboard to play them on.
   The files would not fit on this forum, so you need to go to my website to find them.
   
     http://rb23.yolasite.com/musickeyboard.php
   


Code: [Select]
visible:
 
 
 event = 1; Sound = 0 ; button = 0 ; mzone = 0
  mx; my; z1 = 0 ; z2 = 0 ; z3 = 0
 
ky[] = [ 0,1,2,1,2,1,1,2,1,2,1,2,1,1,2,1,2,1,1,2,1,2,1,2,1,1,2,1,2,1,1,2,1,2,1,2,1,1,2,1,2,1,1,2,1,2,1,2,1 ]
 
randomize time()
hidden:
set redraw off
procedure start()
 ThisIsAPlaceHolder = 1
endproc
set window 0, 0, 1350, 700
proc HowToPlay
proc Setup
proc SetupPieces
proc SetupPieces2
'proc SetupBlackKeys

proc SetupSound
proc SetupZones

   set color 0,0,0
   cls
   set color 255,255,255

    do
         wait 100
   
         set color 0,0,0
         cls;
         set color 255,255,255
                mx= mousex()
                my= mousey()
              z2 = z1
              z1 = zone(mx,my)
              if z1 <> z2 and z1 > 0
                 Sound = z1
                 play sound Sound
                 mzone = z1
              endif
 
         proc DrawBoard

         proc DisplayPieces
         proc PrintText
     
        redraw
    until event = 2
 
  end

procedure SetupZones()
       
           create zone 1,110,380,40,70
           create zone 3,150,380,40,70
           create zone 5,190,380,40,70
           create zone 6,230,380,40,70
           create zone 8,270,380,40,70
           create zone 10,310,380,40,70
           create zone 12,350,380,40,70
           create zone 13,390,380,40,70
           create zone 15,430,380,40,70
           create zone 17,470,380,40,70
           create zone 18,510,380,40,70
           create zone 20,550,380,40,70
           create zone 22,590,380,40,70
           create zone 24,630,380,40,70

           create zone 25,670,380,40,70
           create zone 27,710,380,40,70
           create zone 29,750,380,40,70
           create zone 30,790,380,40,70
           create zone 32,830,380,40,70
           create zone 34,870,380,40,70
           create zone 36,910,380,40,70
           create zone 37,950,380,40,70
           create zone 39,990,380,40,70
           create zone 41,1030,380,40,70
           create zone 42,1070,380,40,70
           create zone 44,1110,380,40,70
           create zone 46,1150,380,40,70
           create zone 48,1190,380,40,70

           create zone  2,140,300,20,80
           create zone  4,180,300,20,80

           create zone  7,260,300,20,80
           create zone  9,300,300,20,80
           create zone  11,340,300,20,80

           create zone  14,420,300,20,80
           create zone  16,460,300,20,80

           create zone  19,540,300,20,80
           create zone  21,580,300,20,80
           create zone  23,620,300,20,80

           create zone  26,140 + 560,300,20,80
           create zone  28,180 + 560,300,20,80

           create zone  31,260 + 560,300,20,80
           create zone  33,300 + 560,300,20,80
           create zone  35,340 + 560,300,20,80

           create zone  38,420 + 560,300,20,80
           create zone  40,460 + 560,300,20,80

           create zone  43,540 + 560,300,20,80
           create zone  45,580 + 560,300,20,80
           create zone  47,620 + 560,300,20,80


endproc

procedure SetupPieces()
      for a = 1 to 48
           
         if ky[a] = 1
            create image a,38,150
            set color 250,250,255
            set image a
            draw rect 0,0,38,150,1
         endif
         if ky[a] = 2
            create image a,18,80
            set color 5,10,15
            set image a
            draw rect 0,0,18,80,1
         endif

      next

  set image primary
  set color 255,255,255

endproc

procedure SetupBlackKeys()
      for a = 51 to 99
         create image a,18,80
      next
  for a = 51 to 99
     set color 10,20,30
     set image a
     draw rect 0,0,18,80,1
  next
  set image primary
  set color 255,255,255

endproc

procedure SetupPieces2()
   for a = 1 to 50
       set image a
     set color 0,0,0

     draw line 0,0,38,0
     draw line 0,0,0,150

     draw line 37,0,37,150
     draw line 0,149,38,149

    next
  set image primary
  set color 255,255,255

endproc

 

procedure Setup()
   rem Setup Variables and other things here.
   gameover = 0
   event = 1
endproc

procedure SetupSound()
     load sound 1,"data\c3.wav"
     load sound 2,"data\c3s.wav"
     load sound 3,"data\d3.wav"
     load sound 4,"data\d3s.wav"
     load sound 5,"data\e3.wav"
     load sound 6,"data\f3.wav"
     load sound 7,"data\f3s.wav"
     load sound 8,"data\g3.wav"
     load sound 9,"data\g3s.wav"
     load sound 10,"data\a3.wav"
     load sound 11,"data\a3s.wav"
     load sound 12,"data\b3.wav"
     load sound 13,"data\c4.wav"
     load sound 14,"data\c4s.wav"
     load sound 15,"data\d4.wav"
     load sound 16,"data\d4s.wav"
     load sound 17,"data\e4.wav"
     load sound 18,"data\f4.wav"
     load sound 19,"data\f4s.wav"
     load sound 20,"data\g4.wav"
     load sound 21,"data\g4s.wav"
     load sound 22,"data\a4.wav"
     load sound 23,"data\a4s.wav"
     load sound 24,"data\b4.wav"
     load sound 25,"data\c5.wav"
     load sound 26,"data\c5s.wav"
     load sound 27,"data\d5.wav"
     load sound 28,"data\d5s.wav"
     load sound 29,"data\e5.wav"
     load sound 30,"data\f5.wav"
     load sound 31,"data\f5s.wav"
     load sound 32,"data\g5.wav"
     load sound 33,"data\g5s.wav"
     load sound 34,"data\a5.wav"
     load sound 35,"data\a5s.wav"
     load sound 36,"data\b5.wav"
     load sound 37,"data\c6.wav"
     load sound 38,"data\c6s.wav"
     load sound 39,"data\d6.wav"
     load sound 40,"data\d6s.wav"
     load sound 41,"data\e6.wav"
     load sound 42,"data\f6.wav"
     load sound 43,"data\f6s.wav"
     load sound 44,"data\g6.wav"
     load sound 45,"data\g6s.wav"
     load sound 46,"data\a6.wav"
     load sound 47,"data\a6s.wav"
     load sound 48,"data\b6.wav"

     
endproc

procedure DrawBoard()
 
  rem cls
  set color 200,200,255
    draw rect 20,20,1300,665,1


endproc

procedure DisplayPieces()
   set color 255,255,255
  ' OK I may have too many images. I needed 2.  My bad habits keep me from getting confused. When I try the "right" way, confused is what I get.
           draw image 1,110,300
           draw image 3,150,300
           draw image 5,190,300
           draw image 6,230,300
           draw image 8,270,300
           draw image 10,310,300
           draw image 12,350,300
           draw image 13,390,300
           draw image 15,430,300
           draw image 17,470,300
           draw image 18,510,300
           draw image 20,550,300
           draw image 22,590,300
           draw image 24,630,300

           draw image 25,670,300
           draw image 27,710,300
           draw image 29,750,300
           draw image 30,790,300
           draw image 32,830,300
           draw image 34,870,300
           draw image 36,910,300
           draw image 37,950,300
           draw image 39,990,300
           draw image 41,1030,300
           draw image 42,1070,300
           draw image 44,1110,300
           draw image 46,1150,300
           draw image 48,1190,300

           draw image 2,140,300
           draw image 4,180,300

           draw image 7,260,300
           draw image 9,300,300
           draw image 11,340,300

           draw image 14,420,300
           draw image 16,460,300

           draw image 19,540,300
           draw image 21,580,300
           draw image 23,620,300

           draw image 26,140 + 560,300
           draw image 28,180 + 560,300

           draw image 31,260 + 560,300
           draw image 33,300 + 560,300
           draw image 35,340 + 560,300

           draw image 38,420 + 560,300
           draw image 40,460 + 560,300

           draw image 43,540 + 560,300
           draw image 45,580 + 560,300
           draw image 47,620 + 560,300

endproc

procedure PrintText()
      set caret 30,50
      write " MouseX = " ; wln str$(mx)
      write " MouseY = " ; wln str$(my)
      write " Zone = " ; wln str$( mzone )

endproc


procedure HowToPlay()
  a = 1
  create font 0, "arial", 24

  set color 255,255,255
  set caret 200,100
  wln "  The object of this puzzle is : "
  wln " to move all of the pieces from the Right Side Board to the Left Side Board."
  wln " "
  wln "  Each piece has 4 colors and when you place the piece on the left side board,  "
  wln " each color should match the color of the piece that it touches. "
  wln " "
  wln " "
  wln "  "
  wln "  "
  wln "  "
  wln "  "
  wln "  "
  wln "  "
  wln "  "
  wln "  "
  wln " Hit any key to continue. "

  wln
  wln " http://rb23.yolasite.com "
 
     redraw
   wait keydown
 

endproc

procedure AfterGame()
   play sound 2
   'set color 0,0,0
   'cls
   create font 0, "arial", 48

   set caret 300,40
   set color 255,255,255
   wln "PUZZLE SOLVED !"
   create font 0, "arial", 16
   set caret 20,300
   wln "  "
   wln "  "
   wln "  My Web Sites: "
   wln " http://rb23.yolasite.com "
   wln " http://rb27.synthasite.com "
   wln " http://scratch2.yolasite.com "
   wln " http://rb26.synthasite.com "
   wln " http://rb29.yolasite.com "
   wln;wln
   set caret 300,630
   wln " Hit any key to play again "
   event = 2
   redraw
   wait keydown


endproc


procedure SetColor( a )
     if a = 1 then   set color 60,255,50
     if a = 2 then   set color 20,20,255
     if a = 3 then   set color 250,50,50
     if a = 4 then   set color 50,250,250
     if a = 5 then   set color 250,50,250
     if a = 6 then   set color 250,250,50
     if a = 7 then   set color 150,20,180
     if a = 8 then   set color 20,130,130
     if a = 9 then   set color 20,130,130
     sqrcolor = a
     quadColor = a
endproc





2
Showcase / Splot (Board Game)
« on: June 01, 2017 »
  I made this simple board game for my grandkids, two of them, who are 5 year old twins, recently took a liking for the computer games on my laptop.
 It has a lot of sound effects to keep them busy. I did an experiment involving the addition of two sounds playing at the same time. In the past, I have had trouble with this sort of thing. NaaLaa did it with no trouble at all. I also did an experiment, drawing my own game marbles. There are no bitmaps in the data folder.


3
Showcase / TriQuad (logic puzzle)
« on: March 18, 2017 »

                                                                            The game of TriQuad.




                     A simple logic game. Move all of the Quads from the right side board

                to the left side board. All four colors on each quad needs to match nearby

                colors.

4
Code snippets / Swirl
« on: March 01, 2017 »
    Just a little computer art experiment.

    I was going to try an animation, but my circle command is too slow. Some day I hope to figure out another way to draw circles.

Code: [Select]
     visible:
  sw = 1200 ;
  sh = 700 ;
  sw2# = float(sw)
  sh2# = float(sh)
  x# = 1.0 ;   
  y# = 1.0 ;
  PI# = 3.14159265 ;
  pi2# = PI * 2.0 ;
  r2# = 0.0 ;
  r3# = 0.0 ;
hidden:
set redraw off
set window 0, 0, sw, sh
   proc Bang ;
   wait keydown
end
 
   procedure Bang()
radius# ;  cnt = 0
     angle# = 0.0
     StartAngle# = 0.0 
     size# = 0.1
    radius# = 0.1
    ds# = 0.1
    clr = 2
 
       while radius < 700.0 
                         x = cos( angle ) * radius
                       y = sin( angle ) * radius
                       
                       proc Circle sw2/2.0 + x, sh2/2.0 + y, size  , clr
                         proc Circle  sw2/2.0 + x, sh2/2.0 + y, size / 1.5, clr + 1
                         proc Circle  sw2/2.0 + x, sh2/2.0 + y, size / 2.0, clr + 2
                         proc Circle  sw2/2.0 + x, sh2/2.0 + y, size / 2.5, clr + 3
                     
                             angle = angle + 42.0
                             radius = radius + 1.0
                             clr = clr + 1
                             size = size + ds
                             ds = ds + 0.0001
                             if clr > 9 then clr = 2
                             redraw
          wend
          redraw
    endproc

procedure Circle(x1#,y1#,radius#,clr)
  dx# ; dy# ; angle# = 0.0
     proc MakeColor clr
     while angle < 360.1
        dy = sin(angle) * radius
        dx = cos(angle) * radius
       
        draw pixel int(x1) + int(dx),int(y1) + int(dy)
        angle = angle + 2.0
     wend
   set color 255,255,255 ;
endproc

procedure MakeColor(clr)
   
    if clr = 0 then set color 0,0,0 ;
    if clr = 1 then set color 200,100,100 ;
    if clr = 2 then set color 255,0,0 ;
    if clr = 3 then set color 150,255,0 ;
    if clr = 4 then set color 255,255,0 ;
    if clr = 5 then set color 0,255,0 ;
    if clr = 6 then set color 0,0,255 ;
    if clr = 7 then set color 255,0,255 ;
    if clr = 8 then set color 200,200,200 ;
    if clr = 9 then set color 255,255,255 ;


endproc
 

   
       
 


5
Showcase / JumpEm
« on: January 11, 2017 »
     
 This little board game is an experiment with Computer AI. The computer pieces actually think about their moves. I may make a version2 later when I get some new ideas.
 Don't expect too much. This AI stuff is harder than it looks. I have been working on it off 
and on since about April.

6
Showcase / Treasure Hunt 3D Version2
« on: November 07, 2016 »
    I've made this one 4 times larger.
    When I get some new ideas, I'll make a new one.
    This stuff reminds me of the old " Doom" series that I used to play. My old programs won't
  run on Windows10, so there is always the temptation to try a remake.

7
Showcase / Treasure Hunt 3D
« on: September 08, 2016 »
      This is a maze game using the Raycaster library.

      Move through the maze and find the 19 hidden objects.
      Avoid the Guardians.

8
Code snippets / Sound without DLL's
« on: August 11, 2015 »
 This little project is just an experiment to see if it could be done. It is a test to see if I could mix NaaLaa with C-Language.
 I wanted to use Visual C++ version 10, but ran into a little problem. After 30 days, the IDE told me I had to regester . Then it told me " Web Site Not Found"
 So I went back to my old Code Blocks IDE, which has a built in C compiler. My code would not work on version 13 so I went back to version 10
 The Idea is to make small programs with Clanguage to play sound and then call them from NaaLaa.
Code: [Select]
visible:
  mx = 31; my = 37 ; TheZone = 0
set window 0,0,800,600
set redraw off

set color 255,255,255
 proc Setup

Loop = 0
hidden:
 proc DrawScreen
 

do

 
  wait 20

  proc Input


until Loop = 10

end


procedure Setup()
   a = 0
   create zone 1, 200, 200, 50, 50
   create zone 2, 300, 200, 50, 50
   create zone 3, 400, 200, 50, 50
   create zone 4, 500, 200, 50, 50
   create zone 5, 600, 200, 50, 50
   create zone 6, 200, 300, 50, 50
   create zone 7, 300, 300, 50, 50
   create zone 8, 400, 300, 50, 50
   create zone 9, 500, 300, 50, 50
   create zone 10, 600, 300, 50, 50

endproc

procedure Input()
     if mousebutton(0,1)
          mx = mousex()
          my = mousey()
          z = zone( mx,my )
          TheZone = z
          proc DrawScreen
          proc OutPut z
     endif

endproc

procedure OutPut( z )
      if z = 1 then shellexecute "open", "PlaySnd1" , "", "", false
      if z = 2 then shellexecute "open", "PlaySnd2" , "", "", false
      if z = 3 then shellexecute "open", "PlaySnd3" , "", "", false
      if z = 4 then shellexecute "open", "PlaySnd4" , "", "", false
      if z = 5 then shellexecute "open", "PlaySnd5" , "", "", false
      if z = 6 then shellexecute "open", "PlaySnd6" , "", "", false
      if z = 7 then shellexecute "open", "PlaySnd7" , "", "", false
      if z = 8 then shellexecute "open", "PlaySnd8" , "", "", false
      if z = 9 then shellexecute "open", "PlaySnd9" , "", "", false
      if z = 10 then shellexecute "open", "PlaySnd10" , "", "", false


endproc

procedure DrawScreen()
       set color 40,50,60
       cls
       set caret 100,100
       set color 255,255,255
       wln "CLICK ON A BUTTON TO Play It's SOUND"
      rem  wln mx
      rem  wln my
       wln TheZone
       set color 75,75,180

       x = 200 ; y = 200
        for a = 1 to 10
            set color 75,75,180
            draw rect x,y,50,50,1
            set color 15,15,19
            draw rect x + 2,y + 2, 46, 46

            x = x + 100
            if a = 5
               x = 200 ; y = 300
            endif

        next
       redraw
endproc


end


9
Code snippets / Rotating cube with texture
« on: April 07, 2015 »
Code: [Select]
rem ==================================================================
rem 3D Shapes
rem
rem Visit the webside for full explanation of the code:
rem    http://nehe.gamedev.net/tutorial/3d_shapes/10035/
rem
rem ==================================================================

rem Import libraries.
import "OpenGL.lib"
import "gl_h.lib"
rem import "TD.lib"
import "Speed.lib"
visible :
  Angle1# = 60.0 ; Angle# = 0.0 ; x# = 35.0 ; y# = 113.0

rem Open gl window. Last parameter to glInit should be 'true' if you
rem wish to hide the default naalaa window. The naalaa window can be
rem used for debug output.
if not glInit("Textures", 64, 64, 800, 600, false) then end

rem Background color, set when calling glClear.
_glClearColor 0.05, 0.10, 0.15, 1.0

rem Triangle angle.
rtri#
rem Cube angle.
rquad#
  _glLoadIdentity
  _glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
 texture1
    _glEnable GL_TEXTURE_2D
proc MakeTextures

do
rem Call this once per frame, else window messages (keyboard, mouse
rem et.c. won't be forwarded to naalaa).
_glUpdate
rem Clear the screen and the depth buffer.
_glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
rem Decrease the rotation variable for the quad.
  rquad = rquad + 0.2
  if rquad > 360.0 then rquad = 0.0

rem _glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT

 
  proc DrawQuads

 

rem Flush graphics to window.
_glRender
rem Run at a maximum of 60 fps.
_SPD_HoldFrame 60
until keydown(27, true)
  _glDeleteTexture texture1
  _glDisable GL_TEXTURE_2D
procedure MakeTextures()
    create image 1, 128,128
    set color 10,15,20
    set image 1
    draw rect 0,0,128,128,1
    set color 220,220,255
    draw rect 2,2,125,125,1
    set color 10,15,200

    proc Fractal 4,60.0
    texture1 = glCreateTexture (1,true)
    set image primary
    set color 255,255,255
     free image 1
    proc glBindTexture GL_TEXTURE_2D,texture1
    _glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
_glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR

endproc





procedure DrawQuads()
    _glLoadIdentity
rem Move right and into the screen.
_glTranslatef 0.0, 0.0, -4.0
rem Rotate the cube on x, y and z.
_glRotatef -60.0, 1.0, 0.0, 0.0

_glRotatef rquad, 0.0, 0.0, 1.0
 
  rem proc glBindTexture GL_TEXTURE_2D,texture1
_glBegin GL_QUADS

     rem Front Face
  proc glBindTexture GL_TEXTURE_2D,texture1
 
   _glTexCoord2f 0.0,0.0 ; _glVertex3f -1.0, -1.0,  1.0
 
   rem Bottom Left Of The Texture and Quad

    _glTexCoord2f 1.0, 0.0; _glVertex3f 1.0, -1.0,  1.0;  rem Bottom Right Of The Texture and Quad

    _glTexCoord2f 1.0, 1.0; _glVertex3f 1.0,  1.0,  1.0;  rem Top Right Of The Texture and Quad

    _glTexCoord2f 0.0, 1.0; _glVertex3f -1.0,  1.0,  1.0;  rem Top Left Of The Texture and Quad

     rem Back Face

    _glTexCoord2f 1.0, 0.0 ; _glVertex3f -1.0, -1.0, -1.0;  rem Bottom Right Of The Texture and Quad

    _glTexCoord2f 1.0, 1.0 ; _glVertex3f -1.0,  1.0, -1.0;  rem Top Right Of The Texture and Quad

    _glTexCoord2f 0.0, 1.0 ; _glVertex3f 1.0,  1.0, -1.0;  rem Top Left Of The Texture and Quad

    _glTexCoord2f 0.0, 0.0 ; _glVertex3f 1.0, -1.0, -1.0;  rem Bottom Left Of The Texture and Quad

     rem Top Face

    _glTexCoord2f 0.0, 1.0 ; _glVertex3f -1.0,  1.0, -1.0;  rem Top Left Of The Texture and Quad

    _glTexCoord2f 0.0, 0.0 ; _glVertex3f -1.0,  1.0,  1.0;  rem Bottom Left Of The Texture and Quad

    _glTexCoord2f 1.0, 0.0 ; _glVertex3f 1.0,  1.0,  1.0;  rem Bottom Right Of The Texture and Quad

    _glTexCoord2f 1.0, 1.0 ; _glVertex3f 1.0,  1.0, -1.0;  rem Top Right Of The Texture and Quad

     rem Bottom Face

    _glTexCoord2f 1.0, 1.0 ; _glVertex3f -1.0, -1.0, -1.0 ;  rem Top Right Of The Texture and Quad

    _glTexCoord2f 0.0, 1.0 ; _glVertex3f 1.0, -1.0, -1.0 ;  rem Top Left Of The Texture and Quad

    _glTexCoord2f 0.0, 0.0 ; _glVertex3f 1.0, -1.0,  1.0 ;  rem Bottom Left Of The Texture and Quad

    _glTexCoord2f 1.0, 0.0 ; _glVertex3f -1.0, -1.0,  1.0 ;  rem Bottom Right Of The Texture and Quad

     rem Right face

    _glTexCoord2f 1.0, 0.0 ; _glVertex3f 1.0, -1.0, -1.0 ;  rem Bottom Right Of The Texture and Quad

    _glTexCoord2f 1.0, 1.0 ; _glVertex3f 1.0,  1.0, -1.0 ;  rem Top Right Of The Texture and Quad

    _glTexCoord2f 0.0, 1.0 ; _glVertex3f 1.0,  1.0,  1.0 ;  rem Top Left Of The Texture and Quad

    _glTexCoord2f 0.0, 0.0 ; _glVertex3f 1.0, -1.0,  1.0 ;  rem Bottom Left Of The Texture and Quad

     rem Left Face

    _glTexCoord2f 0.0, 0.0 ; _glVertex3f -1.0, -1.0, -1.0;  rem Bottom Left Of The Texture and Quad

    _glTexCoord2f 1.0, 0.0 ; _glVertex3f -1.0, -1.0,  1.0;  rem Bottom Right Of The Texture and Quad

    _glTexCoord2f 1.0, 1.0 ; _glVertex3f -1.0,  1.0,  1.0;  rem Top Right Of The Texture and Quad

    _glTexCoord2f 0.0, 1.0 ; _glVertex3f -1.0,  1.0, -1.0;  rem Top Left Of The Texture and Quad

 _glEnd


endproc

 procedure Fractal ( depth , distance# )

       cnt = 0
     if depth > 0 then
            while cnt < 6
                proc MoveSteps  distance
                proc RotateLeft
               
                proc Fractal depth - 1 , distance * 0.4
               
            cnt = cnt + 1
            wend
            depth = depth - 1
     endif
 endproc


 procedure RotateLeft()
      Angle = Angle + Angle1
      if Angle > 360.0 then Angle = Angle - 360.0
 
 endproc

 procedure MoveSteps ( distance# )
       
        dx# = (cos(Angle) * distance)
        dy# = (sin(Angle) * distance)
        x2# = x + dx
        y2# = y - dy
        x3 = int(x); y3 = int(y); x4 = int(x2) ; y4 = int(y2)
        draw line x3,y3,x4,y4
        x = x2 ; y = y2
 endproc






10
Code snippets / 250 cubes with openGL
« on: April 04, 2015 »
Code: [Select]
rem ==================================================================
rem 3D Shapes
rem
rem Visit the webside for full explanation of the code:
rem    http://nehe.gamedev.net/tutorial/3d_shapes/10035/
rem
rem ==================================================================

rem Import libraries.
import "OpenGL.lib"
import "gl_h.lib"
import "Speed.lib"
visible :
rem Open gl window. Last parameter to glInit should be 'true' if you
rem wish to hide the default naalaa window. The naalaa window can be
rem used for debug output.
if not glInit("Cubes", 64, 64, 800, 600, false) then end

rem Background color, set when calling glClear.
_glClearColor 0.0, 0.0, 0.0, 1.0

rem Triangle angle.
rtri#
rem Cube angle.
rquad#
  _glLoadIdentity
  _glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT

do
rem Call this once per frame, else window messages (keyboard, mouse
rem et.c. won't be forwarded to naalaa).
_glUpdate
rem Clear the screen and the depth buffer.
_glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
rem Decrease the rotation variable for the quad.
rquad = rquad - 0.2

rem _glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT

_glLoadIdentity
rem Move right and into the screen.
_glTranslatef -14.0, -8.0, -16.0
  _glRotatef -60.0, 1.0, 0.0, 0.0
 for a = 1 to 100
    for cnt = 1 to 10
         proc DrawCube
      _glTranslatef 3.0, 0.0, 0.0
    next
    _glTranslatef -30.0, 4.0, 0.0
 
  next
rem Flush graphics to window.
_glRender
rem Run at a maximum of 60 fps.
_SPD_HoldFrame 60
until keydown(27, true)



procedure DrawCube()
 

_glBegin GL_QUADS

rem Set the color to green.
_glColor3f 0.0, 1.0, 0.0
rem Top right of the quad (top).
_glVertex3f 1.0, 1.0, -1.0
rem Top left of the quad (top).
_glVertex3f -1.0, 1.0, -1.0
rem Bottom left of the quad (top).
_glVertex3f -1.0, 1.0, 1.0
rem Bottom right of the quad (top).
_glVertex3f 1.0, 1.0, 1.0

rem Set the color to orange.
_glColor3f 1.0, 0.5, 0.0
rem Top right of the quad (bottom).
_glVertex3f 1.0, -1.0, 1.0
rem Top left of the quad (bottom).
_glVertex3f -1.0, -1.0, 1.0
rem Bottom left of the quad (bottom).
_glVertex3f -1.0, -1.0, -1.0
rem Bottom right of the quad (bottom).
_glVertex3f 1.0, -1.0, -1.0

rem Set the color to red.
_glColor3f 1.0, 0.0, 0.0
rem Top right of the quad (front).
_glVertex3f 1.0, 1.0, 1.0
rem Top left of the quad (front).
_glVertex3f -1.0, 1.0, 1.0
rem Bottom left of the quad (front).
_glVertex3f -1.0, -1.0, 1.0
rem Bottom right of the quad (front).
_glVertex3f 1.0, -1.0, 1.0

rem Set the color to yellow.
_glColor3f 1.0, 1.0, 0.0
rem Bottom left of the quad (back).
_glVertex3f 1.0, -1.0, -1.0
rem Bottom right of the quad (back).
_glVertex3f -1.0, -1.0, -1.0
rem Top right of the quad (back).
_glVertex3f -1.0, 1.0, -1.0
rem Top left of the quad (back).
_glVertex3f 1.0, 1.0, -1.0

rem Set the color to blue.
_glColor3f 0.0, 0.0, 1.0
rem top right of the quad (left).
_glVertex3f -1.0, 1.0, 1.0
rem Top left of the quad (left).
_glVertex3f -1.0, 1.0, -1.0
rem Bottom left of the quad (left).
_glVertex3f -1.0, -1.0, -1.0
rem Bottom right of the quad (left).
_glVertex3f -1.0, -1.0, 1.0

rem Set the color to violet.
_glColor3f 1.0, 0.0, 1.0
rem Top right of the quad (right).
_glVertex3f 1.0, 1.0, -1.0
rem Top left of the quad (right).
_glVertex3f 1.0, 1.0, 1.0
rem Bottom left of the quad (right).
_glVertex3f 1.0, -1.0, 1.0
rem Bottom right of the quad (right).
_glVertex3f 1.0, -1.0, -1.0

_glEnd


endproc

11
Code snippets / Rotating 3d cube
« on: March 28, 2015 »
  I wanted to see if I could make a rotating cube with the simple 3d library.
  I almost did it. Now I know why such things are done with OpenGL.

Code: [Select]
rem ==================================================================
 
rem By Rick3137  http://rb23.yolasite.com
rem ==================================================================

rem Import libraries.
import "Simple3D.lib"
import "Speed.lib"
set redraw off

rem Create a grid of 3D points.
BlueColumn#[16][16]
BlueRow#[16][16]
SideC#[16][16]
SideR#[16][16]

  proc MakeImage
for z = 0 to 15
for x = 0 to 15
BlueColumn[x][z] = (float(x) - 8.0)/8.0
BlueRow[x][z] = (float(z) - 8.0)/8.0

SideC[x][z] = (float(x) - 8.0)/8.0
SideR[x][z] = (float(z) - 8.0)/8.0

next
next




rem Setup view.  Field of View, Z-Min, Z- Max
proc S3D_SetView 65.0, 0.1, 4.0
a# = 0.0

do
rem Update.
a = a + 0.5
  wait 10
rem Conditional drawing.
if shouldDraw
set color 10, 30, 50
cls
set color 255, 255, 255

set caret width(primary)/2, 16
center "*** ROTATING CUBE ***"
     wln a
    if a > 360.0 then a = 0.0
rem Clear transformation and jump into the screen.
proc S3D_ClearTransformation
proc S3D_Translate 0.0, 0.0, 5.0
rem Tilt the view a little around the x-axis.
proc S3D_RotateX 40.0
rem Spin around the y-axis.
proc S3D_RotateY a
   rem proc S3D_RotateY 90.0

rem Transform and draw all points as images.
 
for z = 0 to 15
for x = 0 to 15
sx#; sy#; sz#
proc S3D_Project_3f sx, sy, sz, SideC[x][z], 2.3, SideR[x][z]
rem proc DrawImageScaled 2, sx, sy, 10.0/sz  ; rem green
next
next
    for z = 0 to 15
  for x = 0 to 15
  proc S3D_Project_3f sx, sy, sz, SideC[x][z],SideR[x][z]+ 1.0,-1.0
  if a > 290.0 or a < 70.0 then proc DrawImageScaled 1, sx, sy, 10.0/sz  ; rem red

  next
  next
   

    for z = 0 to 15
  for x = 0 to 15
  proc S3D_Project_3f sx, sy, sz, 1.0 ,SideR[x][z] + 1.0 , SideC[x][z]
  if a > 20.0 and a < 170.0 then proc DrawImageScaled 0, sx, sy, 10.0/sz  ; rem yellow

  next
  next
   

    for z = 0 to 15
  for x = 0 to 15
  proc S3D_Project_3f sx, sy, sz, SideC[x][z],SideR[x][z]+1.0,1.0
  if a > 110.0 and a < 260.0 then proc DrawImageScaled 5, sx, sy, 10.0/sz  ; rem  orange

  next
  next
   

    for z = 0 to 15
  for x = 0 to 15
  proc S3D_Project_3f sx, sy, sz, -1.0 ,SideR[z][x] + 1.0 , SideC[z][x]
  if a > 200.0 and a < 340.0 then proc DrawImageScaled 4, sx, sy, 10.0/sz  ; rem white

  next
  next
   

    for z = 0 to 15
for x = 0 to 15

next
next


    for z = 0 to 15
for x = 0 to 15
sx#; sy#; sz#
proc S3D_Project_3f sx, sy, sz, BlueColumn[x][z], 0.0, BlueRow[x][z]
proc DrawImageScaled 3, sx, sy, 10.0/sz

next
next

 
redraw
endif

shouldDraw = SPD_HoldFrameDraw(60)
until keydown(27, true)

rem ==================================================================
rem Draw scaled image centered at x, y.
rem ==================================================================
procedure DrawImageScaled(img, x#, y#, s#)
clear transformation
translate x, y
scale s, s
draw image img
endproc

procedure MakeImage()
   create image 0,10,10
     set image 0
     set color 255,0,255
     set image colorkey 0,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,0  ; rem yellow
   create image 1,10,10
     set image 1
     set color 255,0,255
     set image colorkey 1,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,1 ; rem red
   create image 2,10,10
     set image 2
     set color 255,0,255
     set image colorkey 2,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,2 ; rem green
   create image 3,10,10
     set image 3
     set color 255,0,255
     set image colorkey 3,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,3 ; rem blue
   create image 4,10,10
     set image 4
     set color 255,0,255
     set image colorkey 4,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,4 ; rem white
   create image 5,10,10
     set image 5
     set color 255,0,255
     set image colorkey 5,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,5 ; rem orange

     set image primary
     set color 255,255,255

endproc


procedure DrawHexagon(x,y,radius,border,clr)
p1[12] ; p2[12]
  radius2 = radius - border ; xp = 0 ; yp = 1
for cnt = 0 to 5
    p# = float#(cnt)
p1[xp] = x + int(cos(p * 60.0) * float#(radius))
p1[yp] = y + int(sin(p * 60.0) * float#(radius))
p2[xp] = x + int(cos(p * 60.0) * float#(radius2))
p2[yp] = y + int(sin(p * 60.0) * float#(radius2))
     xp = xp + 2 ; yp = yp + 2
next
set color 100, 100, 100
draw poly p1, true
set color 255,0,0
  proc SetColor clr 
draw poly p2, true
 
endproc

procedure SetColor( a )
     if a = 0 then   set color 255,255,0  ; rem yellow
     if a = 1 then   set color 255,0,0    ; rem red
     if a = 2 then   set color 0,255,0    ; rem green
     if a = 3 then   set color 0,0,255    ; rem blue
     if a = 4 then   set color 255,255,255  ; rem white
     if a = 5 then   set color 255,200,100    ; rem orange
     if a = 6 then   set color 0,0,150    ; rem darkblue
     if a = 7 then   set color 250,0,250  ; rem purple
     if a = 8 then   set color 150,0,150  ; rem darkpurple
     if a = 9 then   set color 255,255,0  ; rem darkred
     if a = 10 then   set color 30,40,50  ; rem dark gray
 
     
     

     sqrcolor = a
     
endproc


Code: [Select]
rem ==================================================================
 
rem By Rick3137  http://rb23.yolasite.com
rem ==================================================================

rem Import libraries.
import "Simple3D.lib"
import "Speed.lib"
set redraw off

rem Create a grid of 3D points.
BlueColumn#[64][64]
BlueRow#[64][64]
 SideC#[64][64]
 SideR#[64][64]

  proc MakeImage
for za = 0 to 63
for xa = 0 to 63
BlueColumn[xa][za] = (float(xa) - 32.0)/32.0
BlueRow[xa][za] = (float(za) - 32.0)/32.0

SideC[xa][za] = (float(xa) - 32.0)/32.0
SideR[xa][za] = (float(za) - 32.0)/32.0

next
next




rem Setup view.  Field of View, Z-Min, Z- Max
proc S3D_SetView 65.0, 0.1, 4.0
a# = 0.0

do
rem Update.
a = a + 2.0
rem  wait 10
rem Conditional drawing.
if shouldDraw
set color 10, 30, 50
cls
set color 255, 255, 255

set caret width(primary)/2, 16
center "*** ROTATING CUBE ***"
     wln a
    if a > 360.0 then a = 0.0
rem Clear transformation and jump into the screen.
proc S3D_ClearTransformation
proc S3D_Translate 0.0, 0.0, 5.0
rem Tilt the view a little around the x-axis.
proc S3D_RotateX 40.0
rem Spin around the y-axis.
proc S3D_RotateY a
   rem proc S3D_RotateY 90.0
    sx2# = 0.0; sy2# = 0.0
 

    for za = 0 to 63
  for xa = 0 to 63
  proc S3D_Project_3f sx, sy, sz, SideC[xa][za],SideR[xa][za]+ 1.0,-1.0
  proc S3D_Project_3f sx2, sy2, sz, SideC[za][xa],SideR[xa][za]+ 1.0,-1.0
 
  if a > 290.0 or a < 70.0
           
                proc DrawSquare sx,sy,sx2,sy2,1
          endif
  next
  next
      set color 255,255,255

    for z = 0 to 63
  for x = 0 to 63
  proc S3D_Project_3f sx, sy, sz, 1.0 ,SideR[x][z] + 1.0 , SideC[x][z]
  proc S3D_Project_3f sx2, sy2, sz, 1.0 ,SideR[z][x] + 1.0 , SideC[x][z]
 
  if a > 20.0 and a < 170.0 then  proc DrawSquare sx,sy,sx2,sy2,0  ; rem yellow

  next
  next
     set color 255,255,255
   

    for z = 0 to 63
  for x = 0 to 63
  proc S3D_Project_3f sx, sy, sz, SideC[x][z],SideR[x][z]+1.0,1.0
  proc S3D_Project_3f sx2, sy2, sz, SideC[x][z],SideR[z][x]+1.0,1.0
 
  if a > 110.0 and a < 260.0 then proc DrawSquare sx,sy,sx2,sy2,5  ; rem  orange

  next
  next
     set color 255,255,255   

    for z = 0 to 63
  for x = 0 to 63
  proc S3D_Project_3f sx, sy, sz, -1.0 ,SideR[z][x] + 1.0 , SideC[z][x]
  proc S3D_Project_3f sx2, sy2, sz, -1.0 ,SideR[x][z] + 1.0 , SideC[z][x]
 
  if a > 200.0 and a < 340.0 then proc DrawSquare sx,sy,sx2,sy2,4  ; rem white

  next
  next
     set color 255,255,255     

    for z = 0 to 63
for x = 0 to 63

next
next


    for z = 0 to 63
for x = 0 to 63
sx#; sy#; sz#
proc S3D_Project_3f sx, sy, sz, BlueColumn[x][z], 0.0, BlueRow[x][z]
proc S3D_Project_3f sx2, sy2, sz, BlueColumn[z][x], 0.0, BlueRow[x][z]
        proc DrawSquare sx,sy,sx2,sy2,3  ; rem blue 
        set color 255,255,255   

next
next

 
redraw
endif

shouldDraw = SPD_HoldFrameDraw(60)
until keydown(27, true)

rem ==================================================================
rem Draw scaled image centered at x, y.
rem ==================================================================
procedure DrawImageScaled(img, x#, y#, s#)
clear transformation
translate x, y
scale s, s
draw image img
endproc

procedure DrawSquare( x#,y#,x2#,y2#,clr )
      proc SetColor clr
      draw line int(x),int(y),int(x2),int(y2)
endproc

procedure MakeImage()
   create image 0,10,10
     set image 0
     set color 255,0,255
     set image colorkey 0,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,0  ; rem yellow
   create image 1,10,10
     set image 1
     set color 255,0,255
     set image colorkey 1,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,1 ; rem red
   create image 2,10,10
     set image 2
     set color 255,0,255
     set image colorkey 2,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,2 ; rem green
   create image 3,10,10
     set image 3
     set color 255,0,255
     set image colorkey 3,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,3 ; rem blue
   create image 4,10,10
     set image 4
     set color 255,0,255
     set image colorkey 4,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,4 ; rem white
   create image 5,10,10
     set image 5
     set color 255,0,255
     set image colorkey 5,1
     draw rect 0,0,11,11,1
     proc DrawHexagon 5,5,4,1,5 ; rem orange

     set image primary
     set color 255,255,255

endproc


procedure DrawHexagon(x,y,radius,border,clr)
p1[12] ; p2[12]
  radius2 = radius - border ; xp = 0 ; yp = 1
for cnt = 0 to 5
    p# = float#(cnt)
p1[xp] = x + int(cos(p * 60.0) * float#(radius))
p1[yp] = y + int(sin(p * 60.0) * float#(radius))
p2[xp] = x + int(cos(p * 60.0) * float#(radius2))
p2[yp] = y + int(sin(p * 60.0) * float#(radius2))
     xp = xp + 2 ; yp = yp + 2
next
set color 100, 100, 100
draw poly p1, true
set color 255,0,0
  proc SetColor clr 
draw poly p2, true
 
endproc

procedure SetColor( a )
     if a = 0 then   set color 255,255,0  ; rem yellow
     if a = 1 then   set color 255,0,0    ; rem red
     if a = 2 then   set color 0,255,0    ; rem green
     if a = 3 then   set color 0,0,255    ; rem blue
     if a = 4 then   set color 255,255,255  ; rem white
     if a = 5 then   set color 255,200,100    ; rem orange
     if a = 6 then   set color 0,0,150    ; rem darkblue
     if a = 7 then   set color 250,0,250  ; rem purple
     if a = 8 then   set color 150,0,150  ; rem darkpurple
     if a = 9 then   set color 255,255,0  ; rem darkred
     if a = 10 then   set color 30,40,50  ; rem dark gray
 
     
     

     sqrcolor = a
     
endproc


12
General discussion / TD Maps,Tiles and Md2 objects
« on: March 02, 2015 »
   At this time I am working on Maps, tiles and md2 objects . If we had a library of this stuff, I think we could get more people to come over to NaaLaa.
   It's real hard to find Md2 files on internet, and to use the TD library we need a collection of files to use.
  I found an old md2 editor, but I am having trouble getting it to work. I intend to upload maps and tiles as I make them.
  Here is the map scanner I am using, made from TD example files:

Code: [Select]
rem Example 2 - Load and walk through a TD map with mouse control.
import "TD.lib"
import "Speed.lib"
import "Keycodes.lib"
if not TD_Init("Template2", 32, 32, 1300, 750, 65.0, 0.1, 16.0, true) then end
visible:

playerX#
playerY#
playerZ#
rem Direction.
playerDirection#
playerPitch#
dx# ; dz#

if not TD_LoadMap("data/maze3.bin") then end

rem Use camera position saved in map as starting position.
playerX = TD_CamX()
playerY = TD_CamY()
playerZ = TD_CamZ()
rem Same with direction.
playerDirection = TD_CamYaw()

rem Set some spooky fog.
proc TD_SetFog 120, 160, 190, 10.0, 100.0
rem  _glShowCursor false
rem _glMoveCursor TD_GetWidth()/2, TD_GetHeight()/2
_glMoveCursor 10,10
proc MainLoop

end

procedure MainLoop()

do
rem Call once every frame.
proc TD_Update

rem Move
dx# = 0.0
dz# = 0.0

rem Get mouse movement and re-center cursor.
mouseDX = mousex() - TD_GetWidth()/2
mouseDY = mousey() - TD_GetHeight()/2
rem _glMoveCursor TD_GetWidth()/2, TD_GetHeight()/2
if keydown(VK_UP)
dx = cos(playerDirection)*0.03
dz = sin(playerDirection)*0.03
endif
if keydown(VK_DOWN)
dx = -cos(playerDirection)*0.03
dz = -sin(playerDirection)*0.03
endif
if keydown(VK_LEFT) then playerDirection = playerDirection - 2.5
if keydown(VK_RIGHT) then playerDirection = playerDirection + 2.5


proc TD_Move playerX, playerY, playerZ, dx, -0.1, dz, 0.25, 1.1, 0.2


rem Set camera position and orientation.
_TD_SetCamPosition playerX, playerY + 0.3 , playerZ
_TD_SetCamOrientation playerDirection, playerPitch, 0.0

rem Render and flush graphics to window.
_TD_Render

_TD_Flush

_SPD_HoldFrame 60
until TD_Running() = false or keydown(VK_ESC, true)

endproc



13
General discussion / Problem with TD Editor
« on: February 21, 2015 »
  I am still trying to learn the TD Editor.
  I can get walls and floor, but when I try to do models something goes wrong. They load OK but when I try to put them on the floor they remain white with no texture.
  These models are from the examples and work fine if I load an example map. It's when I try to make my own map, things go wrong.

14
Showcase / Yukon card game (beta)
« on: February 12, 2015 »
 This is the first in a series, ( I hope )
 I am making a set of card games that actually allow me to win.

15
Showcase / AeroBlocks
« on: January 24, 2015 »
  This is a small and simple board game and I hope I don't bore you all too badly.
 
  Actually, the text file is one of the largest that I have ever made on NaaLaa. (1300 lines) Half way through it I had about decided it was more work than it was worth, but I made myself finish it anyway.

 

Pages: [1] 2 3