| View previous topic :: View next topic |
| Author |
Message |
lemm
Joined: 05 Jul 2009 Posts: 419
|
Posted: Sun Feb 21, 2010 3:50 am Post subject: Sprite Behaviours in C |
|
|
Hello,
It is now possible to write sprite behaviours in C. No more going through the trouble assembly to program our sprites. For this mod at least, I hope that some people with C knowledge will use this, because I sure as hell don't want to write 15 sprites worth of behaviours in assembly =).
Anyways, here is a slightly less sloppy example of the default garg movement code in C:
| Code: |
#include "keen1.h";
extern Sprite temp_sprite;
extern long int tick_count;
extern int sprite_sync;
extern int compute_sprite_delta(void);
extern void do_fall(void);
extern int get_random(void);
extern void think_4_garg_look(void);
void garg_move() {
if (temp_sprite.vel_y == 0 && temp_sprite.vel_x > -220 && temp_sprite.vel_x < 220) {
if (get_random() < sprite_sync) {
temp_sprite.think_ptr = think_4_garg_look;
temp_sprite.var_c = 0;
}
}
if (temp_sprite.vel_x > 0)
temp_sprite.frame = 0x40;
else
temp_sprite.frame = 0x42;
temp_sprite.frame += (int)(tick_count >> 4 & 1);
do_fall();
int csd = compute_sprite_delta();
if (csd & 4)
temp_sprite.vel_x = 0xffc4;
if (csd & 1)
temp_sprite.vel_x = 0x3C;
if (csd & 2)
temp_sprite.var_c = 0;
else {
int l = temp_sprite.vel_x;
int m = (l & 0xFFFF) ^ (l >> 16);
m -= (l >> 16);
if (m == 0xDC && temp_sprite.var_c == 0) {
temp_sprite.var_c = 1;
temp_sprite.vel_y = 0xFF38;
}
}
return;
} |
EDIT:
Here is a bare bones package if you want to try out writing stuff in C. It's still missing a few header files and the help is incomplete, but it contains a walkthrough to guide you through the process of making the garg code. You don't need any other patches to do the walkthrough.
There is one .zip; just dump all the contents into a keen v1.31 directory with ck1patch and follow the instructions. You need winXP.
http://www.mediafire.com/?tnimtdzk1mt
EDIT 2:
Slightly more user friendly. There is no need for hex-editing of object files anymore. Instead, run fixobj <object.obj> 0x#### , where 0x#### is the starting offset of your function, and then link. (It's in the instructions.)
http://www.mediafire.com/?ancwbdgyyym
Last edited by lemm on Thu Mar 04, 2010 11:24 am; edited 4 times in total |
|
| Back to top |
|
 |
Fleexy

Joined: 12 Dec 2008 Posts: 216 Location: Blogham Tower
|
Posted: Sun Feb 21, 2010 4:00 am Post subject: |
|
|
| Nice! However I don't know one character about C/C#/C++. Do you think you could rig up something like this for QuickBASIC, GML, or VBScript? Of these I am most experienced at QB. Of course I understand if it's impossible or too hard. |
|
| Back to top |
|
 |
Draik
Joined: 26 Jul 2008 Posts: 71
|
Posted: Sun Feb 21, 2010 8:52 am Post subject: |
|
|
Those other languages I would put at unlikely at best.
On another note, woo! C is much more manageable than assembly for me, so I might pitch in here. |
|
| Back to top |
|
 |
lemm
Joined: 05 Jul 2009 Posts: 419
|
Posted: Sun Feb 21, 2010 3:43 pm Post subject: |
|
|
I couldn't do it for basic, but there are basic to c translators out there which might work if you are adamantly opposed to C syntax =)
Here's one: http://www.bcxgurus.com/ |
|
| Back to top |
|
 |
Mink

Joined: 03 Nov 2007 Posts: 173
|
Posted: Mon Feb 22, 2010 1:39 am Post subject: |
|
|
| Amazing, Lemm! The extent to which you've improved modding is just astounding. I'm looking forward to writing some enemy behaviors. |
|
| Back to top |
|
 |
levellass
Joined: 11 Oct 2006 Posts: 1404 Location: Ngaruawahia New Zealand
|
Posted: Mon Feb 22, 2010 5:14 am Post subject: |
|
|
| I can do QB or a limited amount of Assembly, those are the only two languages I understand well enough. |
|
| Back to top |
|
 |
lemm
Joined: 05 Jul 2009 Posts: 419
|
Posted: Wed Feb 24, 2010 6:27 pm Post subject: |
|
|
Bamp.
Check out the new link. You can start fooling around with stuff now. Let me know if you are successful. |
|
| Back to top |
|
 |
pizza2004
Joined: 07 Jul 2009 Posts: 15
|
Posted: Mon Mar 01, 2010 12:19 am Post subject: |
|
|
| This is awesome, I'm going to look into using this in Commander Genius. How hard would it be to do this with the physics? |
|
| Back to top |
|
 |
gerstrong
Joined: 25 Jan 2009 Posts: 51
|
Posted: Sat Jul 31, 2010 4:23 pm Post subject: |
|
|
| This code seems to me quite similar in Commander Genius. Well it has to be... Interesting in fact |
|
| Back to top |
|
 |
|