Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
astuce pour survivre fina...
Forum: Utilities
Last Post: coletteleger
05-14-2025, 04:47 AM
» Replies: 0
» Views: 11
|
trouver permis de conduir...
Forum: Utilities
Last Post: nicolasrene
05-05-2025, 05:24 AM
» Replies: 0
» Views: 19
|
LIGHTBAR Menu
Forum: Programs
Last Post: nicolasrene
05-05-2025, 05:08 AM
» Replies: 15
» Views: 945
|
Learning Pallet Rack Safe...
Forum: Utilities
Last Post: Sandrapew
04-03-2025, 09:36 AM
» Replies: 0
» Views: 39
|
Choosing New Versus or Pr...
Forum: Utilities
Last Post: Sandrapew
03-18-2025, 01:11 AM
» Replies: 0
» Views: 33
|
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 1,059
|
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 71
|
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 68
|
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 3,440
|
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 2,169
|
|
|
CreateFile library error |
Posted by: eoredson - 06-05-2023, 05:42 AM - Forum: Help Me!
- Replies (20)
|
 |
I have been using this code for awhile. It is a CreateFile library function call.
Problem it work in Qb64pe-32 bit but in 64-bit throws a GNU C++ compilation error and I wanted to know why!?
Erik.
Code: (Select All) Rem $Dynamic
DefLng A-Z
Declare Dynamic Library "kernel32"
Function CloseHandle& (ByVal hfile As _Offset)
End Declare
Rem hfind = CreateFileA(ASCIIZ, &H180, &H3, 0, 3, 0, 0)
' parameters:
' (1) pointer to filename
' (2) access:
' x80(128) - read
' x100(256) - write
' (3) sharing
' (4) security attributes
' (5) create file flag
' (6) flags (standard OSHA)
' (7) pointer to template file
' paramater 5
' 0 DEFAULT_OPEN_EXISTING = open only if exists
' 1 CREATE_NEW = create only if not exist
' 2 CREATE_ALWAYS = always create new file
' 3 OPEN_EXISTING = open only if exists
' 4 OPEN_ALWAYS = open file always
' 5 TRUNCATE_EXISTING = open/truncate to 0 only if exists
' 6 OPEN_DIRECTORY = open if directory exists
Declare Library
Function CreateFileA& (filename$, Byval access&, Byval sharing&, Byval sec_attr%&, Byval create&, Byval flags&, Byval template%&)
End Declare
Dim hfind As _Offset
' detect file
Print "Enter filename";
Input f$
If Len(f$) Then
f$ = f$ + Chr$(0)
hfind = CreateFileA(f$, &H180, 0, 0, 3, 0, 0)
If hfind Then
Print "File exists."
r = CloseHandle(hfind)
End If
End If
End
|
|
|
Simple SpriteSheet Editor step by step in QB64pe |
Posted by: TempodiBasic - 06-04-2023, 05:04 PM - Forum: Works in Progress
- Replies (5)
|
 |
Hi
this is a first version of a SpriteSheet editor: a program that loads a SpriteSheet and let you modify it painting with simple tools or/and lets to select an area as a single sprite into the sheet. After selected the sprites, you can save their cohordinates into a DATA file to use into your code with the original SpriteSheet and you can see the selected sprite shown on the screen.
![[Image: Selected-sprites-Sprite-Sheet-Editor.png]](https://i.ibb.co/F0Qnk9Y/Selected-sprites-Sprite-Sheet-Editor.png)
![[Image: Save-to-DATA-file-Sprite-Sheet-Editor.png]](https://i.ibb.co/vqTy3D1/Save-to-DATA-file-Sprite-Sheet-Editor.png)
It is a project step by step:
this first step brings a program with a main window that will be adapted to the spritesheet loaded and on this the user can define the 2 points to select an area of the picture to do a single sprite. You can accept/store or cancel each point selected before, after stored point 1 and 2 you get the sprite that is highlighted by a red square.
You can stop the selecting function pressing spacebar into the main loop or mousebutton2 while you are selecting the point 2.
the selected sprites will be displayed at the end of the procedure of selection.
![[Image: Selected-sprites-showed-on-the-screen-Sp...Editor.png]](https://i.ibb.co/WsN7R9V/Selected-sprites-showed-on-the-screen-Sprite-Sheet-Editor.png)
This program uses a second area /canvas to give output to the user as messages or warnings or instructions.
I have posted some screenshots.
It is really incomplete but it can grow up if I use Option _explicit avoiding to waste so much time with bugs going out from my typo errors!
Code: (Select All) Option _Explicit
Rem SPRITE SHEET EDITOR
Rem this software has the purpouse to load an image of a sprite sheet
Rem and in SELECT MODE it allows to the user to select an area,
Rem or in EDIT MODE to paint changing the images into the sprite sheet
_Title "SpriteSheet Editor"
Const W = 1200, H = 800
'global varables
Dim Shared Main&, Sprite&, NameFile$, SSheet&, HelpS&
ReDim Sprites&(1 To 1)
Dim Shared As Integer Xm(1 To 2), Ym(1 To 2), SprC(1 To 4, 1 To 100)
' main variables
Dim Mg As Integer, a As Integer, Mb1 As Integer, Mb2 As Integer, kb As Integer, spr As Integer
Main& = _NewImage(W, H, 32)
HelpS& = _NewImage(W, H / 4, 32)
Screen Main&
_PrintString ((W / 2) - (10 * 8), H / 2), "SPRITES SHEET EDITOR" ' the title is 20 characters
_Delay 3
_SetAlpha 125, HelpS& ' area of output is half transparent
LoadI
Mg = 13: a = 0 'Mg pixel between 2 lines of the reticulus, a is a counter
While kb <> 32 ' while user does not press spacebar, he can define area on the screen delimiting sprites to capture into single area/canvas
Helping " Press spacebar to end", 1
If MouseData(Mb1, Mb2) = -1 Then 'it evaluates mouseinput
If Mb1 Then 'did mouse button 1 trigger?
' it starts the procedure for storing X an Y of points 1 (topleft) and 2 (bottomright)
If StoreMouseData(1) = -1 Then ' it stores mouse data for topleft point of sprite
While 1
Helping " Press spacebar to end", 1
Helping Str$(_MouseX) + Str$(_MouseY) + Space$(8), 0
'_Dest HelpS&: Locate 4, 26: Print kb; Space$(10);
'Locate 5, 1: Print _MouseX, _MouseY; Space$(8);: _Dest 0
'_PutImage (0, 2 * (_Height(0))), HelpS&,
If MouseData(Mb1, Mb2) = -1 Then ' it evaluates mouse input
Helping " Press spacebar to end", 1
Helping Str$(_MouseX) + Str$(_MouseY) + Space$(8), 0
' it adjourns the keyboard and mouse information
'_Dest HelpS&: Locate 4, 26: Print kb; Space$(10);
'Locate 5, 1: Print _MouseX, _MouseY; Space$(8);: _Dest 0
'_PutImage (0, 2 * (_Height(0))), HelpS&,
If Mb1 Then 'did mousebutton 1 trigger?
If StoreMouseData(2) = -1 Then ' yes, it stores mouse data bottomright
' after confirming the two points of the sprite it memorizes their cohordinates into SprC array
spr = spr + 1 ' sprite counter
SprC(1, spr) = Xm(1): Xm(1) = 0 'X1
SprC(2, spr) = Ym(1): Ym(1) = 0 'Y1
SprC(3, spr) = Xm(2): Xm(2) = 0 'X2
SprC(4, spr) = Ym(2): Ym(2) = 0 'Y2
Line (SprC(1, spr), SprC(2, spr))-(SprC(3, spr), SprC(4, spr)), _RGB32(233, 0, 6), B
Helping Str$(spr) + "/" + Str$(SprC(1, spr)) + "+" + Str$(SprC(2, spr)) + "--" + Str$(SprC(3, spr)) + "+" + Str$(SprC(4, spr)), 0
_Delay 1
Exit While ' after storing point 2 of sprite it returns to external loop
Else
Helping "To exit press mouse button 2", 0
_Delay 2
End If
End If
If Mb2 = -1 Then Exit While
End If
Wend
End If
' if no data stored for point 1 topleft it runs again the loop
End If
End If
kb = _KeyHit
' escaping way
If kb = 13 Then Grid
Helping Str$(kb), 0
Helping Str$(_MouseX) + Str$(_MouseY), 0
While _MouseInput: Wend ' it voids the mouse buffer
_Limit 10
Wend
Screen Main&
Helping "Save data of sprites into a DATA code file (Y/N)?", 1
kb = 0
While kb = 0
kb = _KeyHit
If kb = 89 Or kb = 121 Then SaveDATAtoFile: Exit While 'Y or y
If kb = 78 Or kb = 110 Then Exit While ' N or n
kb = 0
Wend
' getting single sprites with newimage
ReDim Sprites&(1 To spr), x As Integer, y As Integer
For a = 1 To spr
Sprites&(a) = _NewImage(Abs(SprC(1, a) - SprC(3, a)), Abs(SprC(2, a) - SprC(4, a)), 32)
_PutImage , Sprite&, Sprites&(a), (SprC(1, a), SprC(2, a))-(SprC(3, a), SprC(4, a)) 'it copies area of spritesheet to single area/canvas
x = x + _Width(Sprites&(a)) ' it adjourns the cohordinates X for showing sprites in sequence
y = _Height(Sprites&(a))
_PutImage (x, y), Sprites&(a), 0 ' showing sprites from 1 to top
Next a
End
Sub SaveDATAtoFile
Rem Saveto DATA file
Rem save to file in DATA format the array SprC
Dim n As Integer
Open "Datafile.txt" For Output As #1
Helping "Saving data...", 0
Print #1, "Data";
For n = 1 To 100 Step 1
If SprC(1, n) = 0 Then _Continue ' if it finds a wrong value it exits from FOR loop
If (n Mod 9) = 0 Then Print #1,: Print #1, "Data"; Else If n > 1 Then Print #1, ",";
Print #1, SprC(1, n), ",", SprC(2, n), ",", SprC(3, n), ",", SprC(4, n);
Next
Close #1
Helping "Saved data!", 1
End Sub
Function MouseData (Mb1 As Integer, Mb2 As Integer)
MouseData = 0
While _MouseInput: Wend ' it waits that mouse input ends
Mb1 = _MouseButton(1)
Mb2 = _MouseButton(2)
If Mb1 <> 0 Or Mb2 <> 0 Then MouseData = -1 ' if no mousebutton then function returns failure
End Function
Function StoreMouseData (Index As Integer)
Dim kb As Integer, OldC As Long
StoreMouseData = 0
If _MouseX > 0 Then Xm(Index) = _MouseX Else Xm(Index) = 1 ' it corrects wrong 0 values
If _MouseY > 0 Then Ym(Index) = _MouseY Else Ym(Index) = 1
If Xm(Index) > 0 And Ym(Index) > 0 Then
' both cohordinates are good?
Helping "Storing point " + Str$(Index) + Str$(Xm(Index)) + "-" + Str$(Ym(Index)) + " Cancel/Store?", 0
OldC = Point(Xm(Index), Ym(Index))
PSet (Xm(Index), Ym(Index)), _RGB32(211, 255, 6)
While 1 'kb <> 83 Or kb <> 115
' here the loop to take cancel/store data
kb = _KeyHit
If kb = 67 Or kb = 99 Then
PSet (Xm(Index), Ym(Index)), OldC
Exit Function ' if key is c or C then exit function returning the failure
End If
If kb = 83 Or kb = 115 Then Exit While
Wend
Helping "Stored", 0
_Delay 1
StoreMouseData = -1
Else
Exit Function
End If
End Function
Sub Grid
Shared Mg As Integer, a As Integer
For a = 1 To W Step Mg
Line (a, 1)-(a, W), Mg
Next
For a = 1 To H Step Mg
Line (1, a)-(H, a), Mg
Next
End Sub
Sub LoadI
NameFile$ = ".\defendersprites.jpg" '<----- coming soon Open option to type name of file and better an Opendialog box
If _FileExists(NameFile$) Then
Helping "File founded", 1
Sprite& = _LoadImage(NameFile$)
Else
Helping "Error: image not loaded", 1
Sprite& = -1000 ' sprite& brings the failure flag
_Delay 2
Exit Sub
End If
_Delay 1
SSheet& = _NewImage(_Width(Sprite&), _Height(Sprite&), 32)
Screen SSheet&
_PutImage , Sprite&, 0
End Sub
Sub PaletteS
Dim n As Integer
For n = 1 To 256
'pset (n,1),n
Line (n, 1)-(n, 256), n, BF
Next n
Sleep 2
End Sub
Sub Helping (Msg As String, M As Integer)
_Dest HelpS&
If M = 1 Then Cls
Print Msg
_Dest 0
_PutImage (0, 2 * (_Height(0) / 3)), HelpS&,
End Sub
Welcome feedbacks and propositive criticisms.
I'm thinking to add a third way to select the area with a dragging of mouse like in the graphic editor in which you draw a square/rectangle.
Moreover I need an OpenDialog box to choose the file of the Spritesheet to modify. I think that the created/selected sprites must be managed like in a list box with a single/multiple selection for doing specific actions (Save, Cancel, Edit...).
I have never used a SpriteSheet Editor but I'm doing it from zero with poor plan... this will cause so much modifications! Sob. Better measures twice and cut ones.
this is the spritesheet that I have used as file, but use whatever do you want
|
|
|
Option _Explicit Keyword(s) of day XXX: |
Posted by: bplus - 06-04-2023, 04:29 PM - Forum: Keyword of the Day!
- Replies (27)
|
 |
This thread started so people can talk about Option _Explicit without hijacking other threads.
Use Option _Explicit in your code to save yourself from typos, probably the number one cause of grief to any coder on any level.
Yes it forces you to declare every variable you use. Yes Dimster that includes For ... Next index variables.
If declared variable is a Const, you don't have to DIM it, same goes for Static, same goes for ReDim (or should).
But there is an interesting by-pass, if I recall, stay tuned... Nope! the example I had in mind didn't work as I remembered.
|
|
|
Temporary Forum Oddities |
Posted by: admin - 06-04-2023, 05:04 AM - Forum: Announcements
- Replies (93)
|
 |
As some of you guys may have noticed, grymm has been hard at work on adding some nice new features into the forums. We now get reports of posts here over in the Discord channel, as well as being able to post better colored code inside custom codeboxes, while also adding much better QBJS support and capabilities. Go grymm!!
Another thing you might notice is that not all of these features have trickled down to all the extra themes which we offer, and our banner/logo may have changed, or things may not be quite as centered as they once was... These little quirks aren't any fault of grymmjacks; instead, they're an unfortunate side effect from us updating to forum software to the latest version available. Some of our custom theme settings got tweaked back to the defaults, and it'll take us a little while to sort out which themes were affected and what might be off with them.
Feel free to post any issues/changes that you guys notice where one of the themes isn't acting quite like it used to, (and include a screenshot if possible, along with browser make and model and such), and we'll see about addressing any issues once we're aware of them...
Well, we'll address them tomorrow. For tonight, I think we're all off to bed. Uncentered banners/images aren't the end of the world, and neither are missing buttons or whatnot. If you have issues and can't bare to wait for us to fix them, click back over to the "Default" them, as it appears to be working as advertised for now. We'll let you guys know once everything else is 100% again, as soon as we get all the little reported issues sorted out again.
|
|
|
qb bbcode now available! |
Posted by: grymmjack - 06-04-2023, 04:03 AM - Forum: Announcements
- Replies (32)
|
 |
You can now use [ q b ] code [ / q b ] to share QB64PE source code.
You can click the QB64 button in the toolbar to use the bbcode.
- CTRL-SHIFT-S to go into Source mode (optional but will maintain all white space!)
- Paste your code
- CTRL-A to select your code
- Click the QB64 button to wrap it in [ q b ][/ q b ]
We had to use this new bbcode because of the way the highlighter works. However, the colors match the QB64PE wiki export that was created by @RhoSigma 
Here is an example:
Code: (Select All)
$Debug
'$INCLUDE:'../include/QB64_GJ_LIB/_GJ_LIB.BI'
'$INCLUDE:'../include/Toolbox64/FileOps.bi'
'$INCLUDE:'../include/Toolbox64/ANSIPrint.bi'
CONST TRUE = -1, FALSE = NOT TRUE
DIM AS STRING BOARD_ANSI, BOARD_ANSI_NO_LABELS, BOARD_ANSI_LEVEL_SECTORS
BOARD_ANSI$ = LoadFileFromDisk$("../assets/ansi/board-132x50-no-secrets.ans")
BOARD_ANSI_LEVEL_SECTORS$ = LoadFileFromDisk$("../assets/ansi/board-132x50-no-secrets.ans")
DIM SHARED AS _UNSIGNED LONG YELLOW, BLACK, BROWN, BRIGHT_BLUE
YELLOW~& = _RGB32(&HFF, &HFF, &H55)
BLACK~& = _RGB32(&H00, &H00, &H00)
BROWN~& = _RGB32(&HAA, &H55, &H00)
BRIGHT_BLUE~& = _RGB32(&H55, &H55, &HFF)
DIM SHARED AS LONG CANVAS, CANVAS_COPY, LEVEL_SECTORS
CONST SW = 132 ' SCREEN WIDTH IN CHARACTERS
CONST SH = 51 ' SCREEN HEIGHT IN CHARACTERS + 1 MORE TO PREVENT SCOLLING OFF
CONST CW = 8 ' WIDTH OF 1 CHARACTER
CONST CH = 16 ' HEIGHT OF 1 CHARACTER
$RESIZE:ON
$RESIZE:STRETCH
CANVAS& = _NEWIMAGE(SW * CW, SH * CH, 32)
CANVAS_COPY& = _NEWIMAGE(SW * CW, SH * CH, 32)
LEVEL_SECTORS& = _NEWIMAGE(SW * CW, SH * CH, 32)
_FONT CH
_FULLSCREEN _SQUAREPIXELS, _SMOOTH
' clear canvas
SCREEN CANVAS&
_DEST CANVAS&
_SOURCE CANVAS&
CLS , BLACK~&
PrintANSI(BOARD_ANSI$)
' copy canvas to the copy
_DEST CANVAS_COPY&
CLS , BLACK~&
PrintANSI(BOARD_ANSI$)
_DEST CANVAS&
' load level sectors
_DEST LEVEL_SECTORS&
CLS , BLACK~&
PrintANSI(BOARD_ANSI_LEVEL_SECTORS$)
_DEST CANVAS&
TYPE SECTOR
start_x AS INTEGER
start_y AS INTEGER
end_x AS INTEGER
end_y AS INTEGER
w AS INTEGER
h AS INTEGER
kolor AS _UNSIGNED LONG
label AS STRING
END TYPE
DIM SHARED SECTORS(1 TO 9) AS SECTOR
TYPE CURSOR
x AS INTEGER
y AS INTEGER
prev_x AS INTEGER
prev_y AS INTEGER
cursor_color AS _UNSIGNED LONG
in_sector AS INTEGER
in_room AS INTEGER
on_path AS INTEGER
on_door AS INTEGER
on_secret_door AS INTEGER
END TYPE
DIM SHARED c AS CURSOR
' setup CURSOR
c.x% = 59*CW
c.y% = 24*CH
c.cursor_color~& = _RGB32(&HFF, &H00, &H00, &HAA)
c.prev_x% = c.x%
c.prev_y% = c.y%
' setup SECTORS
' LEVEL 1
SECTORS(1).kolor~& = _RGB32(&H55, &HFF, &H55) ' BRIGHT GREEN
SECTORS(1).label$ = "LEVEL 1 - MAIN GALLERY"
SECTORS(1).start_x% = 41
SECTORS(1).start_y% = 17
SECTORS(1).end_x% = 79
SECTORS(1).end_y% = 32
SECTORS(1).w% = SECTORS(1).end_x% - SECTORS(1).start_x%
SECTORS(1).h% = SECTORS(1).end_y% - SECTORS(1).start_y%
' LEVEL 2
SECTORS(2).kolor~& = _RGB32(&H00, &HAA, &H00) ' DARK GREEN
SECTORS(2).label$ = "LEVEL 2 - GUARD ROOM + KITCHEN"
SECTORS(2).start_x% = 1
SECTORS(2).start_y% = 17
SECTORS(2).end_x% = 40
SECTORS(2).end_y% = 33
SECTORS(2).w% = SECTORS(2).end_x% - SECTORS(2).start_x%
SECTORS(2).h% = SECTORS(2).end_y% - SECTORS(2).start_y%
' LEVEL 3
SECTORS(3).kolor~& = _RGB32(&HAA, &H00, &H00) ' DARK RED
SECTORS(3).label$ = "LEVEL 3 - ARMORY"
SECTORS(3).start_x% = 1
SECTORS(3).start_y% = 1
SECTORS(3).end_x% = 34
SECTORS(3).end_y% = 16
SECTORS(3).w% = SECTORS(3).end_x% - SECTORS(3).start_x%
SECTORS(3).h% = SECTORS(3).end_y% - SECTORS(3).start_y%
' LEVEL 4
SECTORS(4).kolor~& = _RGB32(&HFF, &H55, &H55) ' BRIGHT RED
SECTORS(4).label$ = "LEVEL 4 - STORE ROOM"
SECTORS(4).start_x% = 1
SECTORS(4).start_y% = 34
SECTORS(4).end_x% = 40
SECTORS(4).end_y% = 50
SECTORS(4).w% = SECTORS(4).end_x% - SECTORS(4).start_x%
SECTORS(4).h% = SECTORS(4).end_y% - SECTORS(4).start_y%
' LEVEL 5
SECTORS(5).kolor~& = _RGB32(&HFF, &H55, &HFF) ' BRIGHT PURPLE
SECTORS(5).label$ = "LEVEL 5 - TORTURE CHAMBER"
SECTORS(5).start_x% = 41
SECTORS(5).start_y% = 33
SECTORS(5).end_x% = 80
SECTORS(5).end_y% = 50
SECTORS(5).w% = SECTORS(5).end_x% - SECTORS(5).start_x%
SECTORS(5).h% = SECTORS(5).end_y% - SECTORS(5).start_y%
' LEVEL 6
SECTORS(6).kolor~& = _RGB32(&H00, &HAA, &HAA) ' DARK CYAN
SECTORS(6).label$ = "LEVEL 6 - KING'S QUARTERS"
SECTORS(6).start_x% = 80
SECTORS(6).start_y% = 17
SECTORS(6).end_x% = 117
SECTORS(6).end_y% = 32
SECTORS(6).w% = SECTORS(6).end_x% - SECTORS(6).start_x%
SECTORS(6).h% = SECTORS(6).end_y% - SECTORS(6).start_y%
' LEVEL 7
SECTORS(7).kolor~& = _RGB32(&H55, &HFF, &HFF) ' BRIGHT CYAN
SECTORS(7).label$ = "LEVEL 7 - WIZ'S QUARTERS"
SECTORS(7).start_x% = 79
SECTORS(7).start_y% = 1
SECTORS(7).end_x% = 117
SECTORS(7).end_y% = 16
SECTORS(7).w% = SECTORS(7).end_x% - SECTORS(7).start_x%
SECTORS(7).h% = SECTORS(7).end_y% - SECTORS(7).start_y%
' LEVEL 8
SECTORS(8).kolor~& = _RGB32(&H55, &H55, &H55) ' BRIGHT BLACK
SECTORS(8).label$ = "LEVEL 8 - QUEEN'S QUARTERS"
SECTORS(8).start_x% = 81
SECTORS(8).start_y% = 33
SECTORS(8).end_x% = 117
SECTORS(8).end_y% = 50
SECTORS(8).w% = SECTORS(8).end_x% - SECTORS(8).start_x%
SECTORS(8).h% = SECTORS(8).end_y% - SECTORS(8).start_y%
' LEVEL 9
SECTORS(9).kolor~& = _RGB32(&HAA, &H00, &HAA) ' DARK PURPLE
SECTORS(9).label$ = "LEVEL 9 - THE CRYPT"
SECTORS(9).start_x% = 35
SECTORS(9).start_y% = 1
SECTORS(9).end_x% = 78
SECTORS(9).end_y% = 16
SECTORS(9).w% = SECTORS(9).end_x% - SECTORS(9).start_x%
SECTORS(9).h% = SECTORS(9).end_y% - SECTORS(9).start_y%
' render initial labels for board
render_room_labels
' draw CURSOR one time to start
CURSOR.draw
' loop waiting for input to move CURSOR
DIM k AS STRING
DIM p AS INTEGER
DIM cur_sector AS INTEGER
DO:
_LIMIT 30
k$ = UCASE$(INKEY$)
IF k$ = "" THEN k$ = CHR$(0)
p% = INSTR("WASD", k$)
IF p% <> 0 THEN
CURSOR.move k$
END IF
CURSOR.update_state
_DISPLAY
LOOP UNTIL k$=CHR$(27)
_FULLSCREEN _OFF
SCREEN 0 : _DEST 0
_DELAY 1
_FREEIMAGE CANVAS&
_FREEIMAGE CANVAS_COPY&
_FREEIMAGE LEVEL_SECTORS&
SYSTEM
SUB CURSOR.move (k AS STRING)
c.prev_x% = c.x%
c.prev_y% = c.y%
IF k$ = "A" THEN c.x% = c.x% - CW
IF k$ = "D" THEN c.x% = c.x% + CW
IF k$ = "W" THEN c.y% = c.y% - CH
IF k$ = "S" THEN c.y% = c.y% + CH
CURSOR.keep_in_bounds
IF CURSOR.can_move = TRUE THEN
CURSOR.erase
CURSOR.draw
SOUND 350, 0.1
ELSE
c.x% = c.prev_x%
c.y% = c.prev_y%
SOUND 200, 0.1
END IF
END SUB
SUB CURSOR.keep_in_bounds
IF c.x% + CW > SW * CW THEN c.x% = SW-CW
IF c.y% + CH > SH * CH THEN c.y% = SH-CH
IF c.x% - CW < 0 THEN c.x% = 0
IF c.y% - CH < 0 THEN c.y% = 0
IF c.x% > SW * CW THEN c.x% = SW-CW
IF c.y% > SH * CH THEN c.y% = SH-CH
IF c.x% < 0 THEN c.x% = 0
IF c.y% < 0 THEN c.y% = 0
END SUB
SUB CURSOR.update_state
DIM AS LONG img_box
DIM cur_sector AS INTEGER
DIM in_sector AS SECTOR
DIM state AS STRING
state$ = ""
img_box& = _NEWIMAGE(CW, CH, 32)
_PUTIMAGE (0, 0)-(CW, CH), CANVAS_COPY&, img_box&, (c.x%, c.y%)-(c.x%+CW, c.y%+CH)
c.on_path% = is_path(img_box&)
c.in_room% = in_room(img_box&)
c.on_door% = is_door(img_box&)
c.on_secret_door% = is_secret_door(img_box&)
COLOR _RGB32(&HFF, &HFF, &HFF), _RGB32(&H00, &H00, &H00)
cur_sector% = SECTOR.get_by_xy(c.x%, c.y%)
in_sector = SECTORS(cur_sector%)
_PRINTSTRING(0, 50 * CH), "SECTOR(" + _TRIM$(STR$(cur_sector%)) + "): " + in_sector.label$
' show state
IF c.on_path% = TRUE THEN state$ = state$ + " ON PATH"
IF c.in_room% = TRUE THEN state$ = state$ + " IN ROOM"
IF c.on_door% = TRUE THEN state$ = state$ + " ON DOOR"
IF c.on_secret_door% = TRUE THEN state$ = state$ + " ON SECRET DOOR"
_PRINTSTRING(80 * CW, 50 * CH), " "
_PRINTSTRING(80 * CW, 50 * CH), state$
_FREEIMAGE img_box&
END SUB
FUNCTION CURSOR.can_move%
DIM AS LONG img_box
DIM AS INTEGER __on_path, __in_room, __on_door, __on_secret_door
img_box& = _NEWIMAGE(CW, CH, 32)
_PUTIMAGE (0, 0)-(CW, CH), CANVAS_COPY&, img_box&, (c.x%, c.y%)-(c.x%+CW, c.y%+CH)
__on_path% = is_path(img_box&)
__in_room% = in_room(img_box&)
__on_door% = is_door(img_box&)
__on_secret_door% = is_secret_door(img_box&)
_FREEIMAGE img_box&
CURSOR.can_move = __on_path% OR __in_room% OR __on_door% OR __on_secret_door%
END FUNCTION
SUB CURSOR.erase
_SOURCE CANVAS_COPY&
_DEST CANVAS&
_PUTIMAGE
_SOURCE CANVAS&
render_room_labels
END SUB
SUB CURSOR.draw
LINE (c.x%, c.y%)-(c.x%+CW-1, c.y%+CH-1), c.cursor_color~&, BF
END SUB
FUNCTION image_is_monochromatic% (img AS LONG, kolor AS _UNSIGNED LONG)
DIM AS INTEGER x, y, has_kolor
DIM AS _UNSIGNED LONG check_color
DIM AS LONG old_source
old_source& = _SOURCE
_SOURCE img&
FOR y% = 0 TO _HEIGHT(img&) - 1
FOR x% = 0 TO _WIDTH(img&) - 1
check_color~& = POINT(x%, y%)
IF (check_color~& <> kolor~&) THEN
_SOURCE old_source&
image_is_monochromatic = FALSE
EXIT FUNCTION
ELSE
IF check_color~& = kolor~& THEN has_kolor% = TRUE
END IF
NEXT x%
NEXT y%
_SOURCE old_source&
image_is_monochromatic = has_kolor%
END FUNCTION
FUNCTION image_is_diachromatic% (img AS LONG, kolor1 AS _UNSIGNED LONG, kolor2 AS _UNSIGNED LONG)
DIM AS INTEGER x, y, has_kolor1, has_kolor2
DIM AS _UNSIGNED LONG check_color
DIM AS LONG old_source
old_source& = _SOURCE
_SOURCE img&
FOR y% = 0 TO _HEIGHT(img&) - 1
FOR x% = 0 TO _WIDTH(img&) - 1
check_color~& = POINT(x%, y%)
IF (check_color~& <> kolor1~&) AND (check_color~& <> kolor2~&) THEN
_SOURCE old_source&
image_is_diachromatic = FALSE
EXIT FUNCTION
ELSE
IF check_color~& = kolor1~& THEN has_kolor1% = TRUE
IF check_color~& = kolor2~& THEN has_kolor2% = TRUE
END IF
NEXT x%
NEXT y%
_SOURCE old_source&
image_is_diachromatic = has_kolor1% AND has_kolor2%
END FUNCTION
FUNCTION is_path% (img AS LONG)
c.on_path% = image_is_monochromatic(img&, YELLOW~&)
is_path = c.on_path%
END FUNCTION
FUNCTION in_room% (img AS LONG)
DIM sector_color AS _UNSIGNED LONG
DIM sector AS INTEGER
sector% = SECTOR.get_by_xy(c.x%, c.y%)
sector_color~& = SECTORS(sector%).kolor~&
c.in_room% = ( _
image_is_diachromatic(img&, sector_color~&, BROWN~&) _
OR image_is_diachromatic(img&, sector_color~&, BRIGHT_BLUE~&) _
OR image_is_monochromatic(img&, sector_color~&) _
)
in_room = c.in_room%
END FUNCTION
FUNCTION is_door% (img AS LONG)
DIM AS INTEGER is_door_on_path, is_door_in_room, is_door_fullblock, sector
DIM sector_color AS _UNSIGNED LONG
sector% = SECTOR.get_by_xy(c.x%, c.y%)
sector_color~& = SECTORS(sector%).kolor~&
is_door_on_path% = image_is_diachromatic(img&, YELLOW~&, BROWN~&)
is_door_in_room% = image_is_diachromatic(img&, sector_color~&, BROWN~&)
is_door_fullblock% = image_is_monochromatic(img&, BROWN~&)
c.on_door% = is_door_on_path% OR is_door_in_room% OR is_door_fullblock%
is_door = c.on_door%
END FUNCTION
FUNCTION is_secret_door% (img AS LONG)
DIM AS INTEGER is_secret_door_on_path, is_secret_door_in_room, is_secret_door_fullblock, sector
DIM sector_color AS _UNSIGNED LONG
sector% = SECTOR.get_by_xy(c.x%, c.y%)
sector_color~& = SECTORS(sector%).kolor~&
is_secret_door_on_path% = image_is_diachromatic(img&, YELLOW~&, BRIGHT_BLUE~&)
is_secret_door_in_room% = image_is_diachromatic(img&, sector_color~&, BRIGHT_BLUE~&)
is_secret_door_fullblock% = image_is_monochromatic(img&, BRIGHT_BLUE~&)
c.on_secret_door% = is_secret_door_on_path% OR is_secret_door_in_room% OR is_secret_door_fullblock%
is_secret_door = c.on_secret_door%
END FUNCTION
SUB render_room_labels
DIM AS _UNSIGNED LONG fg_color_blue, fg_color_red
fg_color_blue~& = _RGB32(&H00, &H00, &HAA)
fg_color_red~& = _RGB32(&HFF, &H55, &H55)
COLOR fg_color_red~&, YELLOW~&
_PRINTSTRING(57*CW,23*CH), "START"
COLOR fg_color_blue~&, YELLOW~&
_PRINTSTRING(57*CW,25*CH), "MAIN"
_PRINTSTRING(56*CW,26*CH), "GALLERY"
_PRINTSTRING(14*CW,10*CH), "ARMORY"
_PRINTSTRING(47*CW,7*CH), "THE"
_PRINTSTRING(47*CW,8*CH), "CRYPT"
_PRINTSTRING(83*CW,9*CH), "WIZ'S"
_PRINTSTRING(84*CW,10*CH), "LAB"
_PRINTSTRING(93*CW,7*CH), "WIZ'S"
_PRINTSTRING(93*CW,8*CH), "TREASURE"
_PRINTSTRING(3*CW,26*CH), "KITCHEN"
_PRINTSTRING(18*CW,23*CH), "GUARD"
_PRINTSTRING(18*CW,24*CH), "ROOM"
_PRINTSTRING(18*CW,41*CH), "STORE"
_PRINTSTRING(18*CW,42*CH), "ROOM"
_PRINTSTRING(49*CW,39*CH), "TORTURE"
_PRINTSTRING(49*CW,40*CH), "CHAMBER"
_PRINTSTRING(88*CW,42*CH), "QUEEN'S"
_PRINTSTRING(88*CW,43*CH), "ANNEX"
_PRINTSTRING(87*CW,34*CH), "QUEEN'S"
_PRINTSTRING(87*CW,35*CH), "TREASURE"
_PRINTSTRING(90*CW,27*CH), "KING'S"
_PRINTSTRING(88*CW,28*CH), "LIBRARY"
_PRINTSTRING(104*CW,21*CH), "KING'S"
_PRINTSTRING(104*CW,22*CH), "TREASURE"
END SUB
' gets sector
FUNCTION SECTOR.get_by_xy% (x AS INTEGER, y AS INTEGER)
DIM i AS INTEGER
DIM s AS SECTOR
DIM AS INTEGER sx, ex, sy, ey
FOR i% = 1 TO 9
s = SECTORS(i%)
sx% = (s.start_x% - 1) * CW
ex% = (s.end_x% - 1) * CW
sy% = (s.start_y% - 1) * CH
ey% = (s.end_y% - 1) * CH
IF x% >= sx% AND x% <= ex% AND y% >= sy% AND y% <= ey% THEN
SECTOR.get_by_xy% = i%
EXIT FUNCTION
END IF
NEXT i%
SECTOR.get_by_xy% = 0
END FUNCTION
'$INCLUDE:'../include/QB64_GJ_LIB/_GJ_LIB.BM'
'$INCLUDE:'../include/Toolbox64/FileOps.bas'
'$INCLUDE:'../include/Toolbox64/ANSIPrint.bas'
|
|
|
QB64PE Programs being flagged as having trojans |
Posted by: hanness - 06-04-2023, 02:30 AM - Forum: General Discussion
- Replies (7)
|
 |
I have multiple programs that I have written in QB64PE that get flagged by Windows Defender on Windows 11 as having trojan malware.
For now I've been setting exceptions in the antivirus software, but I'm wondering if there is any other kind of strategy to avoiding this in the future.
|
|
|
|