08-24-2026, 09:11 AM
Hi Marcus,
In the Space Pooper (N7 version) that I am currently working on, I’ve run into something that I can’t seem to resolve 'Joystick problem' by myself.
My joystick responds correctly when this part of the background music code is not included. I believe I may be doing something wrong in my coding.
If you have some free time when you’re not at work, would you mind taking a look at my code? Please don’t worry about it—it’s not urgent at all.
Thank you very much in advance for your time and help.
In the Space Pooper (N7 version) that I am currently working on, I’ve run into something that I can’t seem to resolve 'Joystick problem' by myself.
My joystick responds correctly when this part of the background music code is not included. I believe I may be doing something wrong in my coding.
Code:
' Background music
'title = loadmusic("assets/title.mp3")
'play music title, trueIf you have some free time when you’re not at work, would you mind taking a look at my code? Please don’t worry about it—it’s not urgent at all.
Thank you very much in advance for your time and help.
Code:
'===================================
' Joystick Demo
' - stage 2
' - joystick support (LEFT, RIGHT)
'===================================
include "tilemap.n7"
#win32
set window "Joystick Demo", 256, 240, false, 2
set redraw off
randomize time()
' Variables
visible player = []
visible scrollY , scrollTimer 'scrolling tilemap
visible title
' Background music
'title = loadmusic("assets/title.mp3")
'play music title, true
' Init Player
player.img = loadimage("assets/player.png") ;set image colorkey player.img, 255, 0, 255 ; set image grid player.img, 2, 1
player.x = (width() / 2) - (width(player.img) / 2)
player.y = 180
player.dx = 0
player.cel = 0
player.tickCounter = 0
' Init Tilemap
ResetTilemap()
'------------
' Main Loop
'------------
while not keydown(KEY_ESCAPE, true)
' Tilemap vertical scrolling
scrollTimer = (scrollTimer + 1) % 4
if scrollTimer = 0 then
scrollY = scrollY - 1
endif
' Keyboard & Joystick Input
if keydown(KEY_LEFT) player.dx = player.dx - 0.4
if keydown(KEY_RIGHT) player.dx = player.dx + 0.4
player.dx = player.dx + joyx() * 0.4
player.dx = player.dx * 0.9
player.x = player.x + player.dx
' Boundaries
if player.x < 0 then player.x = 0
if player.x + width(player.img) > width() then player.x = width() - width(player.img)
' Player Animation
player.tickCounter = (player.tickCounter + 1) % 8
if player.tickCounter = 0 then player.cel = 1 - player.cel
' Clear screen
set color 0, 0, 0 ; cls ; set color 255, 255, 255
' Tilemap camera
TM_SetCamera(int(player.x) * 32 / width(), scrollY)
TM_Render()
' Draw Player
draw image player.img, player.x, player.y, player.cel
' Draw Heads-Up-Display
set caret width() / 2, 4 ; center "SCORE"
set justification left ; set caret 4, 4 ; wln "SHIPS"
set justification right ;set caret width() - 4, 4; wln "STAGE" ; wln "2"
redraw
fwait 60
wend
'------------
' Functions
'------------
function ResetTilemap()
if TM_LoadMap("assets/2.txt") = 0 then end
scrollY = TM_MapHeight() * 16 - height()
scrollTimer = 0
TM_SetView(0, 0, width(), height())
TM_SetCamera(16, scrollY)
endfunc
