Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 37
» Latest member: Ludwig
» Forum threads: 191
» Forum posts: 1,483
Full Statistics
|
Online Users |
There are currently 74 online users. » 0 Member(s) | 74 Guest(s)
|
Latest Threads |
RW3
Forum: NaaLaa 7 Code
Last Post: Marcus
04-11-2025, 05:22 AM
» Replies: 3
» Views: 130
|
City Fighter
Forum: NaaLaa 7 Code
Last Post: Marcus
04-10-2025, 04:52 AM
» Replies: 1
» Views: 78
|
ugBASIC! Good BASIC!
Forum: Programming
Last Post: luwal
04-04-2025, 11:35 PM
» Replies: 6
» Views: 492
|
Happy Birthday
Forum: Everything else
Last Post: johnno56
04-03-2025, 10:52 PM
» Replies: 3
» Views: 343
|
Pool - Cue Sports (Simple...
Forum: NaaLaa 7 Code
Last Post: johnno56
04-03-2025, 06:41 PM
» Replies: 3
» Views: 339
|
Nintendo Switch 2
Forum: Everything else
Last Post: johnno56
04-03-2025, 05:41 AM
» Replies: 2
» Views: 267
|
Pixel Editor
Forum: NaaLaa 7 Code
Last Post: kevin
03-31-2025, 06:52 PM
» Replies: 12
» Views: 1,051
|
Shell
Forum: NaaLaa 7 Questions
Last Post: johnno56
03-29-2025, 08:11 AM
» Replies: 3
» Views: 332
|
Rectangle (simple physics...
Forum: NaaLaa 7 Code
Last Post: johnno56
03-25-2025, 07:26 PM
» Replies: 3
» Views: 477
|
Some textures
Forum: Everything else
Last Post: 1micha.elok
03-23-2025, 10:24 AM
» Replies: 5
» Views: 601
|
|
|
RW3 |
Posted by: Marcus - 04-10-2025, 03:36 PM - Forum: NaaLaa 7 Code
- Replies (3)
|
 |
I'm doing "a micha" here and post about a future game, so that you don't think I've died.
Progress is really slow (I'm very busy). But here are three really weird robot enemies from rw3 (robowack 3). I recorded them before drawing their "final" textures and after doing so. I always start with a dummy texture, where I mark all different areas of the model.
<video width="320" height="240" controls><source src="https://naalaa.com/tmp/squares.mp4" type="video/mp4">Your browser does not support the video tag.</video>
<video width="320" height="240" controls><source src="https://naalaa.com/tmp/foots.mp4" type="video/mp4">Your browser does not support the video tag.</video>
<video width="320" height="240" controls><source src="https://naalaa.com/tmp/thumper.mp4" type="video/mp4">Your browser does not support the video tag.</video>
They may look kind, even cute. But they're evil af.
|
|
|
Pool - Cue Sports (Simple Physics) |
Posted by: 1micha.elok - 04-03-2025, 05:54 AM - Forum: NaaLaa 7 Code
- Replies (3)
|
 |
click the image to zoom in
Pool - Cue Sports
Code: '====================================
'
' Pool - Cue Sports (Simple Physics)
'
'====================================
'
' * Friction:
' Friction is simulated by multiplying the velocity (vx and vy) by a FRICTION.
' This gradually reduces the speed of the ball until it comes to a stop.
'
' * Elastic Collisions:
' When two balls collide, their velocities are adjusted based on
' the laws of conservation of momentum and energy.
' The collision is resolved by decomposing the velocities into components
' along the collision normal and tangent vectors.
' The normal components of the velocities are swapped between the two balls,
' while the tangent components remain unchanged.
'
' * Wall Collisions:
' When a ball hits a wall, its velocity along the direction perpendicular
' to the wall is reversed and scaled by the ELASTICITY.
' This simulates energy loss during the collision.
'
' * Cue Stick Mechanics:
' The cue stick's direction is determined by the angle
' between the cue ball and the mouse position.
' The velocity of the cue ball is calculated using trigonometry:
' vx = power * cos(angle) and vy = power * sin(angle).
'
' * Stopping Condition:
' A ball is considered stopped if its velocity is below a threshold.
' This prevents the simulation from continuing indefinitely due to very small residual velocities.
#win32
' Constants
constant FRICTION = 0.99 ' Friction reduces ball speed over time
constant ELASTICITY = 0.99 ' Elasticity determines how much energy is conserved during collisions
' Cue
visible Cue = []
' Ball
visible Ball = [] ' Array to store all balls (cue ball + others)
Ball.r = 10 ' Ball radius
Ball.m = 15 ' Maximum power for shooting the cue ball
Ball.n = 9 ' The number of the balls
for i = 0 to Ball.n
Ball[i] = []
Ball[i].vx = 0
Ball[i].vy = 0
next
'----------------
' MAIN LOOP
'----------------
init_game()
while not keydown(KEY_ESCAPE, true)
' Event handling
if keydown(KEY_SPACE, true) and Cue.aiming then
' Shoot the cue ball by applying velocity based on the cue angle and power
Ball[0].vx = Cue.power * cos(Cue.angle) ' X velocity = power * cosine(angle)
Ball[0].vy = Cue.power * sin(Cue.angle) ' Y velocity = power * sine(angle)
Cue.aiming = false ' Exit aiming mode after shooting
endif
' Calculate aim angle based on mouse position
if Cue.aiming then
Cue.power = Ball.m
else
Cue.power = 0 ' Reset power if not aiming
endif
' Check if all balls have stopped moving
all_stopped = true
for i = 0 to Ball.n
if Ball[i].vx <> 0 or Ball[i].vy <> 0 then
all_stopped = false ' At least one ball is still moving
break
endif
next
if all_stopped then Cue.aiming = true ' Allow aiming again if all balls have stopped
' Update ball positions and handle collisions
update_Balls()
' Draw the game
draw_game()
' Wait for next frame
redraw
fwait 60
wend
'-------------
' FUNCTIONS
'-------------
' Initialize the game
function init_game()
' Set up the game window
set window "Pool Game with Physics", 800, 400, false
set redraw off
randomize time()
' Create balls and initialize their positions and colors
Ball[0].x = 100 ; Ball[0].y = rnd(50,height()-50) ; Ball[0].c = [255, 255, 255] ' Cue ball (white)
for i = 1 to Ball.n
Ball[i].x = rnd(50,width()-50)
Ball[i].y = rnd(50,height()-50)
Ball[i].c = [rnd(100,200), rnd(50,200), rnd(50,200)]
next
' Initialize aiming variables
Cue.angle = 0 ' Initial angle of the cue stick
Cue.power = 0 ' Initial power of the shot
Cue.aiming = true ' Start in aiming mode
endfunc
' Update ball positions and handle collisions
function update_Balls()
for i = 0 to Ball.n
' Apply friction to simulate resistance on the table
Ball[i].vx = Ball[i].vx * FRICTION
Ball[i].vy = Ball[i].vy * FRICTION
' Update position based on velocity
Ball[i].x = Ball[i].x + Ball[i].vx
Ball[i].y = Ball[i].y + Ball[i].vy
' Bounce off walls (elastic collision with boundaries)
if Ball[i].x - Ball.r < 0 or Ball[i].x + Ball.r > 800 then
Ball[i].vx = -Ball[i].vx * ELASTICITY ' Reverse X velocity and apply elasticity
endif
if Ball[i].y - Ball.r < 0 or Ball[i].y + Ball.r > 400 then
Ball[i].vy = -Ball[i].vy * ELASTICITY ' Reverse Y velocity and apply elasticity
endif
' Stop the ball if velocity is very low (to prevent infinite sliding)
if abs(Ball[i].vx) < 0.5 then Ball[i].vx = 0
if abs(Ball[i].vy) < 0.5 then Ball[i].vy = 0
next
' Handle collisions between balls (elastic collisions)
for i = 0 to Ball.n-1
for j = i + 1 to Ball.n
' Calculate distance between the centers of two balls
dx = Ball[j].x - Ball[i].x
dy = Ball[j].y - Ball[i].y
distance = sqr(dx * dx + dy * dy)
' If the distance is less than or equal to the sum of their radii, they are colliding
if distance <= Ball.r * 2 then
' Move the balls apart to prevent sticking
overlap = (Ball.r * 2 - distance) / 2
nx = dx / distance
ny = dy / distance
Ball[i].x = Ball[i].x - overlap * nx
Ball[i].y = Ball[i].y - overlap * ny
Ball[j].x = Ball[j].x + overlap * nx
Ball[j].y = Ball[j].y + overlap * ny
' Calculate the normal vector (direction of collision)
nx = dx / distance
ny = dy / distance
' Calculate the tangent vector (perpendicular to the normal)
tx = -ny
ty = nx
' Project velocities onto the normal and tangent vectors
dp_self_n = Ball[i].vx * nx + Ball[i].vy * ny ' Dot product for ball i
dp_other_n = Ball[j].vx * nx + Ball[j].vy * ny ' Dot product for ball j
' Swap normal components of velocities (conservation of momentum)
Ball[i].vx = Ball[i].vx + (dp_other_n - dp_self_n) * nx
Ball[i].vy = Ball[i].vy + (dp_other_n - dp_self_n) * ny
Ball[j].vx = Ball[j].vx + (dp_self_n - dp_other_n) * nx
Ball[j].vy = Ball[j].vy + (dp_self_n - dp_other_n) * ny
endif
next
next
endfunc
' Draw the game
function draw_game()
' Clear screen
set color 0, 0, 0
cls
' Draw balls
for i = 0 to Ball.n
set color Ball[i].c[0], Ball[i].c[1], Ball[i].c[2]
draw ellipse Ball[i].x, Ball[i].y, Ball.r, Ball.r, true
next
' Draw cue stick and trajectory if aiming
if Cue.aiming then
mx = mousex() ' Mouse X position
my = mousey() ' Mouse Y position
dx = mx - Ball[0].x ' Difference in X between mouse and cue ball
dy = my - Ball[0].y ' Difference in Y between mouse and cue ball
Cue.angle = atan2(dy, dx) ' Calculate angle using arctangent
' Draw white circle around the cue ball to reflect cue power
set color 255, 255, 255
draw ellipse Ball[0].x, Ball[0].y, Ball.r + Cue.power, Ball.r + Cue.power, false
' Simulate and draw cue ball trajectory
set color 255, 255, 255
px = Ball[0].x
py = Ball[0].y
vx = Cue.power * cos(Cue.angle)
vy = Cue.power * sin(Cue.angle)
prev_x = px
prev_y = py
t = 0
for steps = 1 to 100
px = px + vx
py = py + vy
' Bounce off walls
if px - Ball.r < 0 or px + Ball.r > width() then
vx = -vx * ELASTICITY
t = t + 1
endif
if py - Ball.r < 0 or py + Ball.r > height() then
vy = -vy * ELASTICITY
t = t + 1
endif
if t > 1 then break 'limit only 2 trajectory lines
' Draw trajectory segment
draw line int(prev_x), int(prev_y), int(px), int(py)
prev_x = px
prev_y = py
next
endif
endfunc
Simple Physics in Naalaa
- Pool - Cue Sports
https://naalaa.com/forum/thread-222.html
Inspired by "A game of pool by Kevin"
https://naalaa.com/forum/thread-87.html
- Rectangle
https://naalaa.com/forum/thread-210.html
- Primitive Angry Bird
https://naalaa.com/forum/thread-205.html
- Bridge
https://naalaa.com/forum/thread-206.html
|
|
|
Happy Birthday |
Posted by: 1micha.elok - 04-01-2025, 06:52 AM - Forum: Everything else
- Replies (3)
|
 |
Sixty-nine years, a journey so vast,
A life full of wisdom, love, and joy to last.
If today’s your birthday, Johnno, let joy unfold,
With laughter, stories, and memories gold
Johnno’s birthday today, is it true?
Or just a prank—an April fool’s coup?
Cake or a trick, what’s on the plate?
Blow out the candles… or take the bait?
|
|
|
Pixel Editor |
Posted by: kevin - 03-29-2025, 06:27 PM - Forum: NaaLaa 7 Code
- Replies (12)
|
 |
Hi,
Attached is a project that I have actually managed to persevere with, so that it is nearly finished. It's yet another picture/tileset/character designer - there are many of these available to download, all of which will be more complete, and more polished, but I have just wanted to make this for my own enjoyment .
I've included 2 things that I haven't been able to find elsewhere:
1 - the functionality to save finished images as both png files and text files. The text files are there to include in N7 files, so that the images can be generated within the program, rather than having to include png files in your projects. I'm using a variation of some code that Marcus provided for this, and there is an example program to illustrate.
2 - to the lower right of the screen is a button that can be used to test your tileset (to make sure that the tiles fit together correctly), before saving it.
I've added some pop up hints to explain what most of the buttons do, but if you have any questions, please ask.
A quick explanation of what you need to do:
1 - choose the image size in pixels (max is 64 * 64) in the top right of the screen. There are some pre-sets available also.
2 - Press the "start drawing" button - this is important, and I keep forgetting this step!
3 - Draw in the main frame, using the brush options to the right. Colours can be changed below the main frame, from the colour palette (other paletts are available to load, or you can make and save your own).
4 - New frames can be added using the button to the left. If you have more than one frame, the active one is shown with a red bar to the left. If you are drawing an animated sprite, the animation can be previewed in the bottom left of the screen.
5 - When ready, save the frames as png or text files using the green buttons to the bottom right. There are also options here to load and edit previous png files, or png files that have been created in different programs.
There is other functionality in the program, which hopefully is self-expanatory.
I've not been able to test this as much as I would like, so please let me know what issues you find. I have tested it up to 8 * 32pixel * 32pixel frames (8000 active pixels) and it works fine, albeit a little slow - this is something that I am till working on.
Pixel Editor 2 - published v4.zip (Size: 1.73 MB / Downloads: 5)
|
|
|
Shell |
Posted by: johnno56 - 03-29-2025, 05:18 AM - Forum: NaaLaa 7 Questions
- Replies (3)
|
 |
Quick question. Does N7 possess the ability to issue system shell commands? I could not find any reference in 'The Manual'...
J
|
|
|
Rectangle (simple physics) |
Posted by: 1micha.elok - 03-23-2025, 10:16 AM - Forum: NaaLaa 7 Code
- Replies (3)
|
 |
click the image to zoom in
The code is simply an attempt to simulate a rectangle falling from the top to the ground. Please be aware that there are still some bugs and errors, which do not accurately reflect real-world physics.
Code: '===================================
'
' Physics Simulation of a Rectangle
'
'===================================
set window "Rectangle", 800, 600, false
set redraw off
' Initialize variables
x = 400 ' Center x-coordinate of the rectangle
y = 100 ' Center y-coordinate of the rectangle
width1 = 100 ' Width of the rectangle
height1 = 50 ' Height of the rectangle
' Physics
vx = 0 ' Horizontal velocity
vy = 0 ' Vertical velocity
gravity = 0.5 ' Gravity acceleration
elasticity = 0.7 ' Bounciness factor (0 to 1)
damping = 0.98 ' Damping factor to simulate softness
friction = 0.02 ' Friction coefficient
ground = 450 ' Y-coordinate of the ground
angle = 0 ' Initial angle of rotation (in degrees)
angularVelocity = 15 ' Angular velocity (rotation speed)
momentOfInertia = (width1^2 + height1^2) / 12 ' Moment of inertia for a rectangle
torqueFactor = 0.01 ' Factor for torque applied during collision
' miscellaneous
visible newX, newY
contact_x1 = 0
contact_x2 = 0
' Function to rotate a point around the origin
function rotatePoint(px, py, angleDeg)
cosA = cos(rad(angleDeg))
sinA = sin(rad(angleDeg))
newX = px * cosA - py * sinA
newY = px * sinA + py * cosA
endfunc
' Function to find the lowest value among four numbers
function lowestValue(a, b, c, d)
smallest = a
if b < smallest then smallest = b
if c < smallest then smallest = c
if d < smallest then smallest = d
return smallest
endfunc
' Determine the sign of the input value vx
function sign(vx)
if vx > 0 then
return 1
else if vx < 0 then
return -1
else
return 0
endif
endfunc
'-----------
' Main loop
'-----------
while not keydown(KEY_ESCAPE, true)
' Clear the screen
set color 0, 0, 0
cls
' Update velocities and positions
vy = vy + gravity ' Apply gravity
y = y + vy ' Update vertical position
x = x + vx ' Update horizontal position
angle = angle + angularVelocity ' Update rotation angle
' Calculate the four corners of the rectangle after rotation
cx1 = -width1/2
cy1 = -height1/2
cx2 = width1/2
cy2 = -height1/2
cx3 = width1/2
cy3 = height1/2
cx4 = -width1/2
cy4 = height1/2
' Rotate the corners around the center of the rectangle
rotatePoint(cx1, cy1, angle); cx1 = newX; cy1 = newY
rotatePoint(cx2, cy2, angle); cx2 = newX; cy2 = newY
rotatePoint(cx3, cy3, angle); cx3 = newX; cy3 = newY
rotatePoint(cx4, cy4, angle); cx4 = newX; cy4 = newY
' Translate the corners to the rectangle's position
x1 = x + cx1; y1 = y + cy1
x2 = x + cx2; y2 = y + cy2
x3 = x + cx3; y3 = y + cy3
x4 = x + cx4; y4 = y + cy4
' Check for collision with the floor
min_y = lowestValue(y1, y2, y3, y4) ' Find the lowest point of the rectangle
if min_y >= ground then
' Prevent the rectangle from going below the ground
penetration = min_y - ground
y = y - penetration
' Reverse and reduce vertical velocity
vy = -vy * elasticity
' Identify the contact points (corners touching the ground)
contact_x1 = 0; contact_x2 = 0
if abs(y1 - ground) < 1 then contact_x1 = x1
if abs(y2 - ground) < 1 then contact_x2 = x2
if abs(y3 - ground) < 1 then contact_x2 = x3
if abs(y4 - ground) < 1 then contact_x1 = x4
' Ensure contact_x1 <= contact_x2
if contact_x1 > contact_x2 then
temp = contact_x1
contact_x1 = contact_x2
contact_x2 = temp
endif
' Calculate torque based on contact points
torque = 0
if contact_x1 <> 0 then torque = torque + (contact_x1 - x) * torqueFactor
if contact_x2 <> 0 then torque = torque + (contact_x2 - x) * torqueFactor
angularVelocity = angularVelocity + torque / momentOfInertia
' Apply friction to horizontal velocity
if abs(vx) > 0 then
frictionForce = sign(vx) * friction
vx = vx - frictionForce
endif
' Gradually reduce angular velocity due to damping
angularVelocity = angularVelocity * damping
endif
' Simulate softness by gradually reducing velocities
vy = vy * damping
vx = vx * damping
' Stability check: Determine if the rectangle should topple
com_x = x ' Center of mass x-coordinate
com_y = y ' Center of mass y-coordinate
' Check if the center of mass is outside the base of support
if com_x < contact_x1 or com_x > contact_x2 then
' Apply additional torque to simulate toppling
angularVelocity = angularVelocity + sign(com_x - x) * 0.1
endif
' Draw the rotated rectangle by connecting the corners
set color 255, 255, 255
draw poly [x1, y1, x2, y2, x3, y3, x4, y4]
' Refresh
fwait 60
redraw
wend
|
|
|
|