You can now use 'pixeli(x, y)' or 'pixeli(image_id, x, y)' to get the color of an image's pixel as a single number. You can also use 'set colori' to set the current drawing color using such a number.
If you need to convert RGB or RGBA values to a single number color, you can use functions like these:
Code:
function ToRGB(r, g, b)
return 255*16777216 + r*65536 + g*256 + b
endfunc
function ToRGBA(r, g, b, a)
return a*16777216 + r*65536 + g*256 + b
endfunc
And to get the RGBA components of a single number color:
Code:
function Alpha(c)
return int(c/16777216)
endfunc
function Red(c)
return int((c/65536))%256
endfunc
function Green(c)
return int((c/256))%256
endfunc
function Blue(c)
return c%256
endfunc
2024-04-14
Added the 'pixeli' function and 'set colori' command to get and set colors as single numbers
A question, if I have two objects and one is the player who can move with the keys and the other is the enemy who is stationary in one place on the screen.
The question would be how can I make it so that when the player is close to the enemy he starts chasing the player and if the player moves away the enemy stops chasing him and returns to the starting position.
' Just in case 'pixel' fails... lol
if BoxY > height(primary)
vSpeed = 0
wait 1000
end
endif
endfunc
function Draw()
' Ground
set color ground
draw rect 0, 460, 640, 20, 0
' Box
set color Box
draw rect BoxX, BoxY, BoxW, BoxH, 0
' Pixel
' This indicator pixel is drawn one pixel below the box center.
' The actual pixel being tested is below the left corner of the box.
set color 255, 0, 255
draw pixel BoxX + 15, BoxY + BoxH
endfunc
Unfortunately this did not work... "Read the manual", I hear you say... "pixel(x,y) Returns the color at position (x, y) as an array [r, g, b, a] with RGBA intensities in the range [0 .. 255].
I am hoping that my programing skills are the source of the problem otherwise this maybe another "can of worms".... sorry...
I'm taking a break from working on the s3d (simple 3d) library. It's included in this release, and now I want to see if it's possible to make a game using it. It is quite slow now, but I promise you that it will get faster when I implement better ways to do hidden surface removal and optimize all the sloppy code. I wrote some documentation for the library yesterday (S3D.pdf) and there are some examples under n7/examples/s3d_library, but you really need to have some basic knowledge about 3D programming and maybe played around with legacy OpenGL to use this thing. As I mentioned earlier, it's not meant to be a game engine - that comes later.
I have found a slight problem with the TM on Linux. If you look at the GUI there is a cosmetic difference.
The cosmetics do not bother me... The lower 4 radio buttons cannot be selected. At the moment, it is not really an issue, as I seem to be using only the to top 3 buttons. Just to confirm the problem, I ran N7 TM in Windows 7 via Virtualbox (refer to image) and the Win7 version looked fine.
As I am only starting to work my way through the Editor, I am not requiring the use of the "angled" collision detection yet... but you never know.... Moo Ha Ha Ha...
As I stated earlier, I am not concerned about the cosmetic differences, but those lower buttons could end being an issue...
I was going through some old drives and noticed that I have a tendency to concentrate on "old" games... Cannot figure out why... lol
I found an old text-based Moon Lander from the late 70's... and got to thinking... (Ok. Stop laughing...) I have seen "many" versions of this game for most machines that I have owned in the past... For nostalgia, I was thinking of trying my hand at an N7 version... Which got me to thinking again... (Really. Still laughing? *sigh*)
I am pretty clear on the game elements... except for one... Collision...
Oh. I know how to do simple AABB and Circular collisions but, when it comes to colliding with the "landscape", I am at a loss as to finding an efficient method of detection.
Most of my "programming" has been using Basic. Unless the "Basic" has a sprite collision system built in - detecting collision has been either by AABB, Circular or Colour detection. The latter would work for the "landscape" but it is SO inefficient... I cannot use AABB or Circular as the landscape is irregularly shaped... Oh. text was SO much easier... lol
I have always enjoyed the "old stuff"... It is probably because of the way I think... (Nope. I am not going to say it...)
Any suggestions, or constructive criticisms, are always appreciated.
J
(PS: I hope that everyone will have a great and safe Easter break...)
Question
Case 1 : I think ... [for...next] is not the best way to read text file
Case 2 : I think this is the best way, but [do..until frln(f) = "unset"] gives unexpectedly output
Please advice me what is the best way to read the whole text file ?
Thank you.
Code:
set window "readfile",400,400
f = openfile("story.txt")
'Case 1
'correctly read file
for i = 0 to 21
wln frln(f)
i = i + 1
next
'Case 2
'uncorrectly read file
do
wln frln(f)
until frln(f)="unset"