Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 37
» Latest member: Ludwig
» Forum threads: 195
» Forum posts: 1,502
Full Statistics
|
Online Users |
There are currently 59 online users. » 0 Member(s) | 56 Guest(s) Applebot, Bing, Google
|
|
|
Backspace Key |
Posted by: 1micha.elok - 04-23-2025, 03:22 AM - Forum: NaaLaa 7 Questions
- Replies (7)
|
 |
Hi
I am working with some keydown event codes, but I can't seem to find the key code for the backspace key.
Could you kindly advise me? Thank you!
Code: #win32
set window "KEYDOWN",200,100,false,4
set redraw off
while not keydown(KEY_ESCAPE)
set color 0,0,0
cls
set color 255,255,255
set caret 10,10
if keydown(KEY_INSERT) wln "Insert"
if keydown(KEY_DELETE) wln "Delete"
if keydown(KEY_HOME) wln "Home"
if keydown(KEY_END, true) wln "End"
if keydown(KEY_PAGE_UP) wln "Page Up"
if keydown(KEY_PAGE_DOWN) wln "Page Down"
'if keydown(KEY_BACKSPACE) wln "Backspace"
redraw
fwait 10
wend
|
|
|
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?
|
|
|
|