Print Page | Close Window

Speech Bubble

Printed From: Mirage Source
Category: Tutorials
Forum Name: Temporary Archive (Read Only)
Forum Discription: Temporary 3.0.3 archive tutorials, will be deleted when converted.
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=228
Printed Date: 20 December 2006 at 5:53pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: Speech Bubble
Posted By: Sync
Subject: Speech Bubble
Date Posted: 11 February 2006 at 3:41pm
Difficulty: Medium 3/5

Originaly Posted By: GodSentDeath & Tristan

// Server Side //

Ok find:

Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " says, '" & Msg & "'", SayColor)

*which is in the social packet*

add:

Call MapMsg2(GetPlayerMap(Index), Msg, Index)


Now in that module add the following anywhere:

Sub MapMsg2(ByVal MapNum As Long, ByVal Msg As String, ByVal Index As Long)
Dim Packet As String

Packet = "MAPMSG2" & SEP_CHAR & Msg & SEP_CHAR & Index & SEP_CHAR & END_CHAR

Call SendDataToMap(MapNum, Packet)
End Sub


// Client Side //

Add these to the top of modTypes

Type ChatBubble
    Text As String
    Created As Long
End Type

Public Const DISPLAY_BUBBLE_TIME = 4500 ' In milliseconds.
Public DISPLAY_BUBBLE_WIDTH As Byte
Public Const MAX_BUBBLE_WIDTH = 6 ' In tiles. Includes corners.
Public Const MAX_LINE_LENGTH = 16 ' In characters.
Public Const MAX_LINES = 4
Public Bubble(1 To MAX_PLAYERS) As ChatBubble


Now in modClientTCP add this:

' ::::::::::::::
    ' :: Messages ::
    ' ::::::::::::::
    If (LCase(Parse(0)) = "mapmsg2") Then
        Bubble(Val(Parse(2))).Text = Parse(1)
        Bubble(Val(Parse(2))).Created = GetTickCount()
    Exit Sub
    End If


Now in modGameLogic in the game loop after

' Lock the backbuffer so we can draw text and names
        TexthDC = DD_BackBuffer.GetDC
        For i = 1 To MAX_PLAYERS
             If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                 Call BltPlayerName(i)
             End If
        Next i


add:

' Blit text and bubble
        For i = 1 To MAX_PLAYERS
             If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                 If Bubble(i).Text <> "" Then
                     Call BltPlayerText(i)
                 End If
                 If GetTickCount() > Bubble(i).Created + DISPLAY_BUBBLE_TIME Then
                     Bubble(i).Text = ""
                 End If
             End If
        Next i


Now at the bottom of the module add:

Sub BltTile2(ByVal x As Long, ByVal y As Long, ByVal Tile As Long)
    rec.top = Int(Tile / 7) * PIC_Y
    rec.Bottom = rec.top + PIC_Y
    rec.Left = (Tile - Int(Tile / 7) * 7) * PIC_X
    rec.Right = rec.Left + PIC_X
    
    Call DD_BackBuffer.BltFast(x, y, DD_TileSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
End Sub

Sub BltPlayerText(ByVal Index As Long)
Dim TextX As Long
Dim TextY As Long
Dim intLoop As Integer
Dim intLoop2 As Integer

Dim bytLineCount As Byte
Dim bytLineLength As Byte
Dim strLine(0 To MAX_LINES - 1) As String
Dim strWords() As String
strWords() = Split(Bubble(Index).Text, " ")

    If Len(Bubble(Index).Text) < MAX_LINE_LENGTH Then
        DISPLAY_BUBBLE_WIDTH = 2 + ((Len(Bubble(Index).Text) * 12) \ PIC_X)
       
        If DISPLAY_BUBBLE_WIDTH > MAX_BUBBLE_WIDTH Then
             DISPLAY_BUBBLE_WIDTH = MAX_BUBBLE_WIDTH
        End If
    Else
        DISPLAY_BUBBLE_WIDTH = 6
    End If

TextX = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X) - ((DISPLAY_BUBBLE_WIDTH * 32) / 2) - 6
TextY = GetPlayerY(Index) * PIC_Y + Player(Index).YOffset - Int(PIC_Y) + 75

Call DD_BackBuffer.ReleaseDC(TexthDC)

Call BltTile2(TextX - 10, TextY - 10, 2)
Call BltTile2(TextX + (DISPLAY_BUBBLE_WIDTH * PIC_X) - PIC_X - 10, TextY - 10, 3)

For intLoop = 1 To (DISPLAY_BUBBLE_WIDTH - 2)
    Call BltTile2(TextX - 10 + (intLoop * PIC_X), TextY - 10, 10)
Next intLoop

TexthDC = DD_BackBuffer.GetDC

For intLoop = 0 To UBound(strWords)

    bytLineLength = bytLineLength + Len(strWords(intLoop)) + 1

    If bytLineLength < MAX_LINE_LENGTH Then

    strLine(bytLineCount) = strLine(bytLineCount) & strWords(intLoop) & " "
   
    Else
   
        bytLineCount = bytLineCount + 1

        If bytLineCount = MAX_LINES Then
             bytLineCount = bytLineCount - 1
        Exit For
        End If

        strLine(bytLineCount) = Trim(strWords(intLoop)) & " "
        bytLineLength = 0
    End If
Next intLoop

Call DD_BackBuffer.ReleaseDC(TexthDC)

If bytLineCount > 0 Then
    For intLoop = 6 To (bytLineCount - 2) * PIC_Y + 6
        Call BltTile2(TextX - 10, TextY - 10 + intLoop, 12)
        Call BltTile2(TextX - 10 + (DISPLAY_BUBBLE_WIDTH * PIC_X) - PIC_X, TextY - 10 + intLoop, 11)
   
        For intLoop2 = 1 To DISPLAY_BUBBLE_WIDTH - 2
             Call BltTile2(TextX - 10 + (intLoop2 * PIC_X), TextY + intLoop - 10, 6)
        Next intLoop2
   
    Next intLoop
End If

Call BltTile2(TextX - 10, TextY + (bytLineCount * 16) - 4, 4)
Call BltTile2(TextX + (DISPLAY_BUBBLE_WIDTH * PIC_X) - PIC_X - 10, TextY + (bytLineCount * 16) - 4, 5)

For intLoop = 1 To (DISPLAY_BUBBLE_WIDTH - 2)
    Call BltTile2(TextX - 10 + (intLoop * PIC_X), TextY + (bytLineCount * 16) - 4, 9)
Next intLoop

TexthDC = DD_BackBuffer.GetDC

For intLoop = 0 To (MAX_LINES - 1)
    If strLine(intLoop) <> "" Then
        Call DrawText(TexthDC, TextX + (((DISPLAY_BUBBLE_WIDTH) * PIC_X) / 2) - ((Len(strLine(intLoop)) * 8) \ 2) - 7, TextY, strLine(intLoop), QBColor(White))
        TextY = TextY + 16
    End If
Next intLoop
End Sub


The original code was created by me *without bubbles*. Then perfected by Tristan *with bubbles*.

Use this this at the top of tiles.bmp

http://tristan.32studios.com/toptiles.bmp - http://tristan.32studios.com/toptiles.bmp

Well thats it for this tutorial. If you have any comments/suggestions/bugs/etc please post. Im sure someone will be happy to help you.



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info