Several newb questions

What is a Uzebox? How can I get one? Check here!
User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Wed Jul 08, 2020 3:55 pm

Thanks for that very comprehensive response Artcfox!

So it turns out what I wrote was a fluke and wasn't correct at all then! :D

I have made this effort at correcting my code but it clearly has some work to be done yet as I don't see anything being drawn to the screen.

Yes, I'm just trying to move 1x 8x8 sprite around the screen. In one of you snippets you mention `sprites[3]` but I'm not sure what that is referring to, how your are intending that be instantiated.

Here is my latest attempt that builds but doesn't show anything. I used mysprites for the variable name in tileset.inc.

I think a working version of this would be make a good demo to include in the repo as a mid-point example between hello world and pong.

Code: Select all

#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <uzebox.h>

#include "data/tileset.inc"

int btnPrev = 0;     // Previous button
int btnHeld = 0;     // buttons that are held right now
int btnPressed = 0;  // buttons that were pressed this frame
int btnReleased = 0; // buttons that were released this frame 

struct PlayerStruct
 {
   u8 x;
   u8 y;
   u8 tileIndex;
   u8 flags;		
 };	

struct PlayerStruct Player;

int main()
{
	ClearVram();
	SetSpritesTileBank(0, mysprites);
	Player.x = 100;
	Player.y = 100;
	Player.tileIndex = 1;
	SetSpriteVisibility(true);
	
	while(1){
        WaitVsync(1);
    
        btnHeld = ReadJoypad(0);
        btnPressed = btnHeld & (btnHeld ^ btnPrev);
        btnReleased = btnPrev & (btnHeld ^ btnPrev);
    
        if(btnHeld & BTN_RIGHT){
            Player.x+=3;
        }
        if(btnHeld & BTN_LEFT){
            Player.x-=3;
        }
        if(btnHeld & BTN_UP){
            Player.y-=3;
        }
        if(btnHeld & BTN_DOWN){
            Player.y+=3;
        }
        btnPrev = btnHeld;
    }
}

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Fri Jul 10, 2020 10:08 am

The UB docs would benefit greatly from having complete, runnable code examples instead of just giving code snippets.

You can't beat runnable/buildable examples for clarity.

feluga
Posts: 5
Joined: Sat Jun 27, 2020 12:44 am

Re: Several newb questions

Post by feluga » Fri Jul 10, 2020 5:20 pm

danboid wrote:
Fri Jul 10, 2020 10:08 am
The UB docs would benefit greatly from having complete, runnable code examples instead of just giving code snippets.
Actually there is a GitHub for UB which is a great source of complete runnable coded games and examples.
Demos and games can be found at https://github.com/Uzebox/uzebox/tree/master/demos

User avatar
Artcfox
Posts: 1060
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Several newb questions

Post by Artcfox » Sat Jul 11, 2020 7:45 am

I encapsulated all of the sprite stuff in a render function in my game, you should read that function because it will show you what you are missing: https://github.com/artcfox/bugz/blob/ma ... ity.c#L860

The variable:

Code: Select all

sprites
exists within the kernel in a mode 3 Uzebox game, so pay close attention to any line that references that variable, because you will need to set it's tileIndex, flags, x, and y.

That function chooses a tileIndex and flags based on the internal state of the entity object, and then it sets the actual sprite's tileIndex, flags, x, and y.

If you're starting out, just try something with sprites[0], set it's tileIndex, x, and y. Also, read some of the example code, there is a ton of code out there.

Edit: You can also see how I animate my sprites, by using a frameCounter to select a different tileIndex every N frames.

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Tue Sep 01, 2020 11:20 pm

I didn't have the time to do any UB stuff for a while but I'm back into poking at it again.

IMO the Uzebox could be a great way for people to learn both electronics and C if there were better, more accessible docs. For example, the API docs should use full buildable, runable examples instead of giving code snippets that are useless by themselves.

ghostyghost is a simple game and it is very heavily commented - pretty much every line is explained so it would make a good learning resource if it was fixed to build against the current kernel. It could potentially be turned into a beginners tutorial, if fixed.

https://github.com/kivan117/gghost/issues/1

User avatar
Artcfox
Posts: 1060
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Several newb questions

Post by Artcfox » Wed Sep 02, 2020 5:33 am

The kernel hasn't changed that much. I think these errors are from 3 things:

1. The master branch is likely not the branch we should be building from
2. Hardcoded Windows pathnames
3. Windows filenames not being case sensitive, but on Linux they are

First I went into my main uzebox directory and cloned this repo. Then I did a

Code: Select all

git checkout localonly
to switch to that branch, and after making the following changes to the Makefile, I was able to successfully build on Linux, but it looks like parts of the tileset are still messed up.

Code: Select all

diff --git a/ghostyghost/default/Makefile b/ghostyghost/default/Makefile
index d564257..bd15dcf 100644
--- a/ghostyghost/default/Makefile
+++ b/ghostyghost/default/Makefile
@@ -4,15 +4,15 @@
 
 ## General Flags
 PROJECT = ghostyghost
-GAME= GGHOST
+GAME= gghost
 MCU = atmega644
 TARGET = $(GAME).elf
 CC = avr-gcc
 INFO=../gameinfo.properties
-UZEBIN_DIR = c:/uze_workspace/uzebox_bin_Win32_dev_trunk_r212/bin/
+UZEBIN_DIR = ../../../bin/
 
 ## Kernel settings
-KERNEL_DIR = c:/git-repo/Uzebox/uzebox/kernel
+KERNEL_DIR = ../../../kernel
 KERNEL_OPTIONS  = -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_MIXER=1 -DSOUND_CHANNEL_5_ENABLE=0
 KERNEL_OPTIONS += -DUART=1 -DDEBUG=1 -DUART_RX_BUFFER_SIZE=64 -DUART_TX_BUFFER_SIZE=64
 KERNEL_OPTIONS += -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24
@@ -57,7 +57,7 @@ LINKONLYOBJECTS =
 INCLUDES = -I"$(KERNEL_DIR)" 
 
 ## Build
-all: $(TARGET) $(GAME).HEX $(GAME).eep $(GAME).lss $(GAME).UZE size
+all: $(TARGET) $(GAME).hex $(GAME).eep $(GAME).lss $(GAME).uze size
 
 ## Compile Kernel files
 uzeboxVideoEngineCore.o: $(KERNEL_DIR)/uzeboxVideoEngineCore.s
@@ -83,7 +83,7 @@ $(GAME).o: ../gghost.c
 $(TARGET): $(OBJECTS)
 	 $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
 
-%.HEX: $(TARGET)
+%.hex: $(TARGET)
 	avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@
 
 %.eep: $(TARGET)
@@ -92,8 +92,8 @@ $(TARGET): $(OBJECTS)
 %.lss: $(TARGET)
 	avr-objdump -h -S $< > $@
 
-%.UZE: $(TARGET)
-	-$(UZEBIN_DIR)packrom $(GAME).HEX $@ $(INFO)
+%.uze: $(TARGET)
+	-$(UZEBIN_DIR)packrom $(GAME).hex $@ $(INFO)
 
 UNAME := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 AVRSIZEFLAGS := -A ${TARGET}
@@ -108,7 +108,7 @@ size: ${TARGET}
 ## Clean target
 .PHONY: clean
 clean:
-	-rm -rf $(OBJECTS) $(GAME).* dep/* *.UZE
+	-rm -rf $(OBJECTS) $(GAME).* dep/* *.uze
 
 
 ## Other dependencies
gghost-tileset.png
gghost-tileset.png (57.88 KiB) Viewed 3229 times

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Thu Sep 03, 2020 7:31 pm

Thanks artcfox!

I've now got ghostyghost to build and I can start the game but its pretty glitchy.

Thankfully it looks like the author is going to fix it up soon so we might have a good contender for a game tutorial that could replace the existing one which is pretty poor as it's incomplete and doesn't work, any more.

I would like to see the UB project get a beginners tutorial similar to the step-by-step your first game tutorial that godot has:

https://docs.godotengine.org/en/stable/ ... _game.html

This tutorial shows you how to make a basic game game in godot. It's understandable even if you have no previous coding experience. A UB equivalent likely won't be quite as easy to follow because C is a bit more involved than GDscript (godots scripting language, v.similar to python) and it might need to be a bit longer but I still think it should be doable.

If I ever learn enough to write a basic game myself then I'll write it and the more experienced devs on here can tweak it so it's as good as it can be whilst still being easy to understand. Such a tutorial would follow on perfectly from where Artcfox's excellent videos left off.

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Mon Oct 05, 2020 5:03 pm

I've lamented the lack of very basic examples but I think I've almost got one here, although I've not quite got it working properly yet:

https://github.com/danboid/tanktest

All I want here is the most basic example of how to move a single 8x8 sprite so I stripped down the intro screen of ghosty ghost to almost its bare minimum and tried to replace the ghost with my own sprite although what I see on screen does not in anyway resemble the sprite I expect to see.

I'm sure Artcfox will fix it or tell me where I'm going wrong in the blink of an eye, once he sees it! :)

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Tue Oct 06, 2020 6:23 pm

Fixed it and before Artcfox has had chance to reply so I consider that a success. I've successfully got it to scroll my custom sprites across the screen but currently it's showing all of 'em instead of just one (EDIT: fixed this too, and trimmed it down further). Plus it seems I've not set the alpha channel / bg colour properly yet or something.

Step 0 on a very long ladder almost complete. Learning through "subtractive coding"

User avatar
danboid
Posts: 162
Joined: Sun Jun 14, 2020 12:14 am

Re: Several newb questions

Post by danboid » Thu Oct 08, 2020 11:06 am

I have tweaked tanktest a little bit more and I'm almost done with this initial experiment, I now just need to fix the 'alpha channel' sprite issue.

When I move my tank sprite over the UB logo, you can see a black box around it so I expect I need to re-create the tile data so it uses 'blank pixels' in place of the black pixels in the background of the sprite? I'm not sure how transparencies are supposed to work.

I would like to see this tidied up, improved however possible without making it more complex and included in the UB repo as a beginners demo. Does anyone else think something this simple would be worth adding to the repo demos? The included demos were too much for a beginner in C like me to take in, with a couple of exceptions but non of the sprite using demos were simple enough for me to discern how they worked. I'd expect other beginners will have no issue understanding tanktest and it almost resembles a game, which helps a lot.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests