Author Topic: Auto Typing  (Read 8170 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Auto Typing
« on: June 16, 2011 »
Hi guys,
I am trying to create a kind of terminal display where by my program will type text to the screen with returns
next sentence etc.. but I also want a flashing cursor but the cursor has to be an image 16x17 here is my code
that I have been playing with I almost had it but it's not right any help would be great.
Thanks.

Code: [Select]
rem

 Typing Simulator
 First created 13/06/2011

 By Pot Noodle

end rem
 
Const xRes = 800
Const yRes = 600

Graphics xRes, yRes, 32, 60, GRAPHICS_BACKBUFFER

Global txt:String = "BlitzMax Typing Simulator"
Global Cursor:TImage = LoadImage("cur.bmp")' 16x17 blue rectangular cursor

Local fonts:TImageFont = LoadImageFont("petme64.ttf", 16, BOLDFONT)
SetImageFont(fonts)

Local x:Int
Local y:Int

Repeat
Cls

For y = 189 To 200
For x = 80 To 189 Step 16
DrawCursor(x, y)
DrawText(Mid(txt, 1, 1), x, y)
Next
Next

Flip
Until KeyHit(KEY_ESCAPE)

EndGraphics
End

Function DrawCursor(cx:Int, cy:Int)
If MilliSecs() / 500 Mod 2 = 0 Then ' flashing cursor
DrawImage(Cursor, cx, cy, 1)
End If
End Function

[Edit : Code tags added to post - SW]
« Last Edit: June 18, 2011 by Shockwave »

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Auto Typing
« Reply #1 on: June 16, 2011 »
Hello there

can you upload the petme64.ttf then I can check it for you :)

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Auto Typing
« Reply #2 on: June 16, 2011 »
No problem thanks for looking.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Auto Typing
« Reply #3 on: June 17, 2011 »
Is this the kind of thing you want to make;

[youtube]npyqsIGTVTU[/youtube]

?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Auto Typing
« Reply #4 on: June 17, 2011 »
I was trying to get your letters coming out but all I could see what a white blocks each of them!
I try to increase block of letters to make letters stand out but no success!

I think what you trying to do is what Shockwave Show you on youtube video :)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Auto Typing
« Reply #5 on: June 17, 2011 »
I was trying to get your letters coming out but all I could see what a white blocks each of them!
I try to increase block of letters to make letters stand out but no success!

I think what you trying to do is what Shockwave Show you on youtube video :)

Well it's not going to work.. The code seems to draw the first letter in the string over and over again.
If none of the Blitz people have helped by tomorrow I'll put something >quick< together but it will just be a simple one.

Do you plan your effects and what they'll need to do before you start making them ?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Auto Typing
« Reply #6 on: June 18, 2011 »
Thanks Hotshot for your time, Shockwave I find it hard to come up with ideas but when I do I write them the best way I know how but as you can tell I get stuck when it all goes wrong I tried lots of different ways but nun of them worked
Like Hotshot said I was trying to do the same as your intro on Youtube, I need a book or two on BM I think.
« Last Edit: June 18, 2011 by Pot Noodle »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Auto Typing
« Reply #7 on: June 18, 2011 »
I need a book or two on BM I think.

There's not a book out there to show you this kind of thing in Bmax as far as I know.

It's a pity some of the Bmax guys here haven't helped you so far - I am sorry it takes me a while to reply - Bmax is not my native language and I don't get a lot of free time but I'm working on a solution for you now which I will post as soon as it's done.

A few things about the typer - you need a few things..

A font, some text and some way of controlling the cursor.

The font I'll use will be a bitmap font, the flashing cursor will be part of the font and I'll use the lower case letter to control what the routine does (new lines, new pages, pause the cursor etc).

It would help you when you're trying to work out an effect to make a little list like this which means that you've broken the problem down into smaller steps that are easier to deal with :)

All I hope is that you're not learning any bad habits from my code!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Auto Typing
« Reply #8 on: June 18, 2011 »
Well thanks mate,  I think it's the DrawText command that is the problem but can't find a way to print to the screen
In other languages I have used it was not a problem as there was more than one way Having said that I bet you wont even use DraeText()  ::)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Auto Typing
« Reply #9 on: June 18, 2011 »
Here you go Mr. Noodle, hope it helps you on your quest for code domination :)

Code: [Select]

' *************************************************
' *                                               *
' * Text Typer For Pot Noodle by Shockwave        *
' * WWW.DBFINTERACTIVE>COM                        *
' *                                               *
' *************************************************


' *********************************************************************
' * Open Screen                                                       *
' *********************************************************************

SetGraphicsDriver GLMax2DDriver()

Const xRes = 800
Const yRes = 600

Graphics xRes,yRes,32,60,GRAPHICS_BACKBUFFER


Global Font = LoadAnimImage("sfont16.bmp",16,16,0,59)

Global TyperText:String
TyperText="pa"

' ==========================
' =                        =
' = Terminate Line With: n =
' = Pause Short: a         =
' = Pause Long : b         =
' = Terminate Page With: p =
' =                        =
' ==========================

' ========
' =Page 1=
' ========
TyperText=TyperText+"****************************n"
TyperText=TyperText+"*    SHOCKWAVE PRESENTS    *n"
TyperText=TyperText+"****************************n"
TyperText=TyperText+"n"
TyperText=TyperText+"       A TEXT WRITER!an"
TyperText=TyperText+"n"
TyperText=TyperText+"A BIT BASIC BUT OK I GUESS..bp"

' ========
' =Page 2=
' ========

TyperText=TyperText+"WELL - YOU CAN FIND LOTS OF STUFF LIKE THIS AT:nnn"
TyperText=TyperText+"           WWW.DBFINTERACTIVE.COMnnna"
TyperText=TyperText+"GREETINGS TO POT NOODLE AS I WROTE THIS FORn"
TyperText=TyperText+"HIM/HER (NOT SURE WHAT GENDER POT NOODLES ARE)nnna"
TyperText=TyperText+"   THAT'S ALL I HAVE TIME FOR!!!!   BYE!!nnap  "


' Leave this here for safety;

TyperText=typertext +" "

Global Tpos:Int ' End Position In Text
Global Tstart:Int ' Start Position In Text
Global Tpause:Double ' Pause Between Letters (Set by the program)
Global Curtime: Int ' Cursor Blink Control


Curtime = 0
Tstart = 1
Tpos   = 1

' ===================================================================
' = Main Loop                                                       =
' ===================================================================

Repeat


Typer()

Flip(-1)
Cls

Until KeyDown(KEY_ESCAPE)
End

' ===================================================================
' = Typer Function                                                  =
' ===================================================================

Function Typer()

' ====================
' = Blink The Cursor =
' ====================

Curtime=curtime+1

If Curtime>10 Then Curtime=0
Tpause = Tpause - .1

Local XP:Int' Screen X
Local YP:Int' Screen Y
Local LP:Int' Draw Loop
Local Letter : Int' Letter Number in font

XP=0' Cursor positions at start of loop
YP=0'

' =======================================================================
' = Check and see if the pause variable is <=0 if so advance one letter =
' =======================================================================

If Tpause<=0 Then

Tpos=Tpos+1

If Tpos>Len(TyperText) Then Tpos=1
Tpause = Tpause + .2 ' Standard delay (to make it look like human typing make this random.

If Mid(TyperText,Tpos,1)="a" Then Tpause =10' Check For Short Pause
If Mid(TyperText,Tpos,1)="b" Then Tpause =50' Check For Long Pause
If Mid(TyperText,Tpos,1)="p" Then '   Check For Page Break

Tpause =0
Tstart=Tpos+1
Tpos=Tpos+1

End If



If Mid(TyperText,Tpos,1)="" Then Tpause = 0 ' We wont pause for spaces because it would take too long to read the text.



End If

For Lp=Tstart To Tpos

' ==============
' = Get Letter =
' ==============

Letter=(Asc(Mid(TyperText,(Lp),1))-32)

' ===================
' = Bounds Checking.=
' ===================

If Letter<0 Or Letter>59 Then Letter = 0

' ===================
' = Draw the letter =
' ===================

DrawImage Font,XP,YP,Letter

' =============================================================
' = We don't want blank spaces showing for control characters =
' =============================================================

If Mid(TyperText,lp,1)<>"n" And Mid(TyperText,lp,1)<>"p" And Mid(TyperText,lp,1)<>"a" And Mid(TyperText,lp,1)<>"b" Then
XP=XP+16
End If

' ==================================================
' = We have to check for newlines in the draw loop =
' ==================================================

If Mid(TyperText,lp,1)="n" Then
YP=YP+16
XP=0
End If

Next

' ================================================================================================
' = Cursor has to be drawn when all the letters have been so it appears at the end automatically =
' ================================================================================================

If Curtime<5 Then DrawImage Font,XP,YP,32


End Function

Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Auto Typing
« Reply #10 on: June 18, 2011 »
 :goodpost:
Thanks mate you could write a book and make a fortune, give up working and have more time to spend on the comp ;D
The cursor shows up at the end of each line I was trying to have it look like some one typing so you would see the cursor at each letter pos but hay I will change my mind and rethink things out, thanks again brill..

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Auto Typing
« Reply #11 on: June 18, 2011 »
The cursor is actually there all the way, it's probably flashing a bit fast for you to notice!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Auto Typing
« Reply #12 on: June 20, 2011 »
That is Excellent Type writer as the code of it look so simple!

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Auto Typing
« Reply #13 on: June 20, 2011 »
I have put both of them together for you and look even more Simple!
Hope that Help :) ;)

Code: [Select]
' *************************************************
' *                                               *
' * Text Typer and 3D Chequerboard                *
' * For Pot Noodle by Shockwave                   *
' * WWW.DBFINTERACTIVE>COM                        *
' *                                               *
' *************************************************

Type Type_Writer

Function Typer()

' ====================
' = Blink The Cursor =
' ====================

Curtime=curtime+1

If Curtime>10 Then Curtime=0
Tpause = Tpause -.1

Local XP:Int' Screen X
Local YP:Int' Screen Y
Local LP:Int' Draw Loop
Local Letter:Int' Letter Number in font

XP = 0' Cursor positions at start of loop
YP = 0'

' =======================================================================
' = Check and see if the pause variable is <=0 if so advance one letter =
' =======================================================================

If Tpause <= 0 Then

Tpos = Tpos + 1

If Tpos > Len(TyperText) Then Tpos = 1
Tpause = Tpause +.2 ' Standard delay (to make it look like human typing make this random.

If Mid(TyperText, Tpos, 1) = "a" Then Tpause = 10' Check For Short Pause
If Mid(TyperText, Tpos, 1) = "b" Then Tpause = 50' Check For Long Pause
If Mid(TyperText, Tpos, 1) = "p" Then '   Check For Page Break

Tpause =0
Tstart=Tpos+1
Tpos=Tpos+1

End If

If Mid(TyperText, Tpos, 1) = "" Then Tpause = 0 ' We wont pause for spaces because it would take too long to read the text.

End If

For LP = Tstart To Tpos

' ==============
' = Get Letter =
' ==============

Letter = (Asc(Mid(TyperText, (LP), 1)) - 32)

' ===================
' = Bounds Checking.=
' ===================

If Letter < 0 Or Letter > 59 Then Letter = 0

' ===================
' = Draw the letter =
' ===================

DrawImage Font, XP, YP, Letter

' =============================================================
' = We don't want blank spaces showing for control characters =
' =============================================================

If Mid(TyperText, LP, 1) <> "n" And Mid(TyperText, LP, 1) <> "p" And Mid(TyperText, LP, 1) <> "a" And Mid(TyperText, LP, 1) <> "b" Then
XP = XP + 16
End If

' ==================================================
' = We have to check for newlines in the draw loop =
' ==================================================

If Mid(TyperText, LP, 1) = "n" Then
YP = YP + 16
XP = 0
End If

Next

' ================================================================================================
' = Cursor has to be drawn when all the letters have been so it appears at the end automatically =
' ================================================================================================

If Curtime < 5 Then DrawImage Font, XP, YP, 32


End Function

Function DrawGrid()

Local Z:Int
Local X:Int

Local TX:Int
Local TY:Int

Local Clr:Int
Local Shade:Int
Local ClrStrt:Int

ClrStrt = 1

Local PolyTransform:Float[8]

For Z = 0 To Grid - 2

ClrStrt = ClrStrt + 1
If ClrStrt > 2 Then ClrStrt = 1
Clr = ClrStrt
For X = 0 To Grid - 2

Clr = Clr + 1
If Clr > 2 Then Clr = 1

TX = (GridX[X, Z] / (GridZ[X, Z] - Move)) + halfX
TY = (GridY[X, Z] / (GridZ[X, Z] - Move)) + halfY

PolyTransform[0] = TX
PolyTransform[1] = TY
TX = (GridX[X + 1, Z] / (GridZ[X + 1, Z] - Move)) + halfX
TY = (GridY[X + 1, Z] / (GridZ[X + 1, Z] - Move)) + halfY
PolyTransform[2] = TX
PolyTransform[3] = TY
TX = (GridX[X + 1, Z + 1] / (GridZ[X + 1, Z + 1] - Move)) + halfX
TY = (GridY[X + 1, Z + 1] / (GridZ[X + 1, Z + 1] - Move)) + halfY

PolyTransform[4] = TX
PolyTransform[5] = TY
TX = (GridX[X, Z + 1] / (GridZ[X, Z + 1] - Move)) + halfX
TY = (GridY[X, Z + 1] / (GridZ[X, Z + 1] - Move)) + halfY

PolyTransform[6] = TX
PolyTransform[7] = TY

Shade = (TY / 4) - 75
If Shade < 0 Then Shade = 0

If Clr = 1 Then SetColor(Shade, Shade, Shade)
If Clr = 2 Then SetColor(0, 0, Shade)

DrawPoly(PolyTransform)

Next

Next

End Function


Function SetGrid()

Local Xpos:Double
Local Zpos:Double
Local Ypos:Double
Local Jump:Double
Local Xscale:Double

Local Z:Int
Local X:Int

Jump = Size / Grid

Xscale = 25
Ypos = 400
Zpos = 8.4

For Z = 0 To Grid - 1

Xpos = -((Size * Xscale) / 2)

For X = 0 To Grid - 1

GridX[X, Z] = Xpos
GridY[X, Z] = Ypos
GridZ[X, Z] = Zpos

Xpos = Xpos + (Jump * Xscale)

Next

Zpos = Zpos - (Jump / 20)

Next

End Function

End Type

SetGraphicsDriver GLMax2DDriver()

Const xRes = 800
Const yRes = 600

Const halfX = 400
Const halfY = 250

       ' *********************************************************************
       ' * Open Screen                                                       *
       ' *********************************************************************

Graphics xRes,yRes,32,60,GRAPHICS_BACKBUFFER


Global Font = LoadAnimImage("sfont16.bmp",16,16,0,59)
        Local _Draw:Type_Writer = New Type_Writer

Global TyperText:String
TyperText = "pa"

Const Grid = 30:Int
Const Size = 150 : Int

Global GridX : Double[Grid,Grid]
Global GridY : Double[Grid,Grid]
Global GridZ : Double[Grid,Grid]

Global Move : Double

Move = 0.0
_Draw.SetGrid()

' ==========================
' =                        =
' = Terminate Line With: n =
' = Pause Short: a         =
' = Pause Long : b         =
' = Terminate Page With: p =
' =                        =
' ==========================

' ========
' =Page 1=
' ========
TyperText=TyperText+"****************************n"
TyperText=TyperText+"*    SHOCKWAVE PRESENTS    *n"
TyperText=TyperText+"****************************n"
TyperText=TyperText+"n"
TyperText=TyperText+"       A TEXT WRITER!an"
TyperText=TyperText+"n"
TyperText=TyperText+"A BIT BASIC BUT OK I GUESS..bp"

' ========
' =Page 2=
' ========

TyperText=TyperText+"WELL - YOU CAN FIND LOTS OF STUFF LIKE THIS AT:nnn"
TyperText=TyperText+"           WWW.DBFINTERACTIVE.COMnnna"
TyperText=TyperText+"GREETINGS TO POT NOODLE AS I WROTE THIS FORn"
TyperText=TyperText+"HIM/HER (NOT SURE WHAT GENDER POT NOODLES ARE)nnna"
TyperText=TyperText+"   THAT'S ALL I HAVE TIME FOR!!!!   BYE!!nnap  "


' Leave this here for safety;

TyperText=typertext +" "

Global Tpos:Int ' End Position In Text
Global Tstart:Int ' Start Position In Text
Global Tpause:Double ' Pause Between Letters (Set by the program)
Global Curtime: Int ' Cursor Blink Control

Curtime = 0
Tstart = 1
Tpos = 1

' ===================================================================
' = Main Loop                                                       =
' ===================================================================
Repeat
  SetColor (255, 255, 255)

  _Draw.Typer()
  _Draw.DrawGrid()

  Move = Move + .025
  If Move >= .5 Then Move =Move -.5
  Flip(-1)
  Cls

Until KeyDown(KEY_ESCAPE)
EndGraphics
End
   
« Last Edit: June 20, 2011 by Hotshot »

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Auto Typing
« Reply #14 on: June 20, 2011 »
Thanks Shockwave, I am trying to write a demo as you know the opening screen would contain the text typer like on some of the old Amiga games I/e Green text black background, with a sci-fi font style as each letter is drawn it would make a sound like a dumb terminal, then once all the text is finished it then goes in to the checkered board and sine scroll-er and then I would like a few effects to appear above the checkered board like a cube etc..
Thanks for thinking of me once again  :)