[TIGCC] Help with movement

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
Loki
Extreme Poster
Posts: 314
Joined: Thu 18 Aug, 2005 7:01 pm
Location: My world is in grayscale, but if i stand still long enough, i see it in black and white.
Contact:

[TIGCC] Help with movement

Post by Loki »

Hey, I'm having some trouble with this progect I'm working on. Its trying to be a simple little 'move the ship and shoot stuff' game, but all i got is the 'ship'. Here's my code:

Code: Select all

// C Source File
// Created 3/8/2006; 9:26:11 PM

#include <tigcclib.h>

// define the global constants
#define SPRITE_HEIGHT	8
#define LEFT		0
#define RIGHT		1

// Main Function
void _main(void)
{
	// declare the sprite positions
	int x1 = 8, y1 = 80;
	
	// keycode variable
	int key = 0;
	
	// declare the sprites (8,16,32) pixels wide x 8 pixels tall
	unsigned char sprite1[] = {0x18, 0x66, 0x99, 0x66, 0x24, 0xFF, 0x7E, 0x24};
	
	// clear the screen
	ClrScr();

	// draw the sprites
	Sprite8(x1, y1, SPRITE_HEIGHT, sprite1, LCD_MEM, SPRT_XOR);
	
	// wait until the user presses ESC
	while ((key = ngetchx()) != KEY_ESC) {
			}
		}
	}
}
Can anyone tell me how to make it move? I thought I had it but i didnt so i deleted it. BTW I'm very new at this. Cheers!
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

umm... where is the code to change the coordinate of the sprite? it should be in the while part right?
Image Image Image
User avatar
Fr0stbyte124
Regular Member
Posts: 75
Joined: Thu 16 Feb, 2006 9:59 pm

Post by Fr0stbyte124 »

Wouldn't you just detect arrow keys like you did with escape?
I forget, can C incorporate threading? I would suggest making one thread for key-detection and the other for real-time simulation, if it is availiable.
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Threading? No need for that.

You will have to put a few things inside the main loop. Namely the clearScreen, the drawSprite and the key detection for starters.

I have never coded on a 68k platform so i am not farmiliar with the key functions or equates. I do think that you should find an alternative to ngetchx() though as it appears to 'wait' until a key is pressed. This is unsuitable for a game.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Spencer
Extreme Poster
Posts: 346
Joined: Mon 17 Jan, 2005 8:56 am
Location: Indiana

Post by Spencer »

That's a lot of unexpected curly brackets.
User avatar
Loki
Extreme Poster
Posts: 314
Joined: Thu 18 Aug, 2005 7:01 pm
Location: My world is in grayscale, but if i stand still long enough, i see it in black and white.
Contact:

Post by Loki »

Yeah, thats bad code. I deleted a lot of stuff, put in a few things, then deleted them..and yeah. The result is that crap up there.
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Re: [TIGCC] Help with movement

Post by Liazon »

Code: Select all

	// draw the sprites
	Sprite8(x1, y1, SPRITE_HEIGHT, sprite1, LCD_MEM, SPRT_XOR);
	
	// wait until the user presses ESC
	while ((key = ngetchx()) != KEY_ESC) {
			}
		}
	}
}
The point is, all you are doing is detecting if the ESC is being pressed. It keeps checking until you've pressed it. In order for the sprite to move, you must change it's coordinates during an arrow keypress, phase out the old sprite, and draw the new one. It's the same idea for any language.

edit: I'd detect if kbhit() is true, then use ngetchx(). decent speed for this stuff, no good for gemini like stuff.

tr1p1ea: you can use low level, almost like direct input to read keys, but PedroROM does not support it, and you have to do lots of different key equates for the different calcs (89s, V200s, 92+s). You could however read something off the keyboard queue. a good compromise in my opinion, but it's throw errors at me for some reason.
Image Image Image
Post Reply